Skip to content
This repository has been archived by the owner on May 13, 2024. It is now read-only.

ci(travis): Add Travis-CI config #46

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions .env
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# PowerDNS configuration

PDNS_DB_NAME=pdns
PDNS_DB_USER=pdns
PDNS_DB_PASSWORD=changeme

PDNS_PROTO=http
PDNS_HOST=pdns-server
PDNS_PORT=8081
PDNS_API_KEY=changeme
PDNS_WEBSERVER_ALLOW_FROM=0.0.0.0
8 changes: 8 additions & 0 deletions .test/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
FROM alpine:3.9

COPY docker_test.sh /docker_test.sh

RUN set -ex; \
chmod 755 /docker_test.sh;

CMD ["/docker_test.sh"]
27 changes: 27 additions & 0 deletions .test/docker_test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#!/usr/bin/sh

set -e

################################################################################
# Testing docker containers

echo "Waiting to ensure everything is fully ready for the tests..."
sleep 60

echo "Checking main containers are reachable..."
if ! ping -c 10 -q "${PING_CONTAINER}" ; then
echo 'Main container is not responding!'
exit 1
fi


################################################################################
# Testing PowerDNS

# TODO Check PowerDNS is up from this container, maybe using its Web API

################################################################################
# Success
echo 'Docker tests successful'
echo 'Check the CI reports and logs for details.'
exit 0
72 changes: 72 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
os: linux
dist: bionic

services: docker

language: shell

branches:
only:
- master
- develop

before_install:
- env | sort
- export VCS_REF=`git rev-parse --short HEAD`
- export BUILD_DATE=`date -u +"%Y-%m-%dT%H:%M:%SZ"`
- export CONTAINER_NAME="pdns-server-${AUTOCONF}"
- export TAG=travis
- export IMAGE_NAME="psitrax/powerdns:${TAG}"
- export home=$(pwd)
- export travis_dir="${home}/"

install:
- cd "$travis_dir"
# Test container build
- travis_retry docker build -t "${IMAGE_NAME}" "$travis_dir"

before_script:
- docker images

script:
- cd "$travis_dir"
# Test docker run
- docker run --rm --name "cmd_help" -e AUTOCONF=$AUTOCONF "${IMAGE_NAME}" --help
#- docker run --rm --name "cmd_version" -e AUTOCONF=$AUTOCONF "${IMAGE_NAME}" --version
- docker run --name "${CONTAINER_NAME}" -e AUTOCONF=$AUTOCONF -d "${IMAGE_NAME}"
- docker ps | grep "${CONTAINER_NAME}"
- docker logs "${CONTAINER_NAME}"
- docker stop "${CONTAINER_NAME}" && docker rm -f "${CONTAINER_NAME}"
# Test docker-compose run
- mv docker-compose.$AUTOCONF.test.yml docker-compose.yml
- rm -f docker-compose_*.yml
- travis_retry travis_wait 60 docker-compose build
- docker images
- travis_retry docker-compose up -d && sleep 30
- docker-compose ps
- docker-compose logs
- docker-compose ps "${CONTAINER_NAME}" | grep "Up"
- echo 'Wait until everything ready (1-2 minutes)' && sleep 120
- docker-compose ps
- docker-compose logs
- docker-compose ps "${CONTAINER_NAME}" | grep "Up"
- docker-compose logs "sut"
- docker-compose ps "sut" | grep "Exit 0"
# Test docker-compose restart
- docker-compose down
- travis_retry docker-compose up -d && sleep 30
- echo 'Wait until everything ready (1-2 minutes)' && sleep 120
- docker-compose ps
- docker-compose logs
- docker-compose ps "${CONTAINER_NAME}" | grep "Up"
- docker-compose logs "sut"
- docker-compose ps "sut" | grep "Exit 0"

notifications:
email: false

env: # Environments
#- AUTOCONF=false
#- AUTOCONF=sqlite
#- AUTOCONF=postgres
- AUTOCONF=mysql
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# PowerDNS Docker Container

[![Build Status](https://travis-ci.org/psi-4ward/docker-powerdns.svg)](https://travis-ci.org/psi-4ward/docker-powerdns)
[![Image Size](https://images.microbadger.com/badges/image/psitrax/powerdns.svg)](https://microbadger.com/images/psitrax/powerdns)
[![Docker Stars](https://img.shields.io/docker/stars/psitrax/powerdns.svg)](https://hub.docker.com/r/psitrax/powerdns/)
[![Docker Pulls](https://img.shields.io/docker/pulls/psitrax/powerdns.svg)](https://hub.docker.com/r/psitrax/powerdns/)
Expand Down
92 changes: 92 additions & 0 deletions docker-compose.mysql.test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
version: "2.1"

services:
# https://docs.docker.com/docker-hub/builds/automated-testing/
sut:
build:
context: ./.test
dockerfile: Dockerfile
command: sh /docker_test.sh
depends_on:
- pdns-server-mysql
- pdns-mysql
environment:
# Tests setup
- PING_CONTAINER=pdns-server-mysql
volumes_from:
- pdns-server-mysql
networks:
- pdns-compose-mysql
volumes:
- /etc/localtime:/etc/localtime:ro
- /etc/timezone:/etc/timezone:ro

pdns-server-mysql:
build: .
image: ${IMAGE_NAME}
hostname: ${PDNS_HOST}
container_name: pdns-server-mysql
# If ports need to be redirected or exposed to host
#ports:
# - "5053:53"
# - "5053:53/udp"
networks:
- pdns-compose-mysql
volumes:
- /etc/localtime:/etc/localtime:ro
- /etc/timezone:/etc/timezone:ro
environment:
- MYSQL_AUTOCONF=true
#- AUTOCONF=mysql
# MySQL / MariaDB
- MYSQL_HOST=pdns-mysql
- MYSQL_PORT=3306
- MYSQL_DB=${PDNS_DB_NAME}
- MYSQL_USER=${PDNS_DB_USER}
- MYSQL_PASS=${PDNS_DB_PASSWORD}
- MYSQL_DNSSEC=no
# PDNS Config
- PDNS_LOG_DNS_QUERIES=yes
- PDNS_API=yes
- PDNS_API_KEY=${PDNS_API_KEY}
- PDNS_WEBSERVER=no
- PDNS_WEBSERVER_ADDRESS=0.0.0.0
- PDNS_WEBSERVER_PORT=8081
- PDNS_WEBSERVER_ALLOW_FROM=${PDNS_WEBSERVER_ALLOW_FROM}/0
- PDNS_SOA_REFRESH_DEFAULT=14400
depends_on:
pdns-mysql:
condition: service_healthy

pdns-mysql:
image: mariadb:10.3
hostname: pdns-mysql
container_name: pdns-mysql
mem_limit: 256M
memswap_limit: 256M
expose:
- 3306
networks:
- pdns-compose-mysql
volumes:
- powerdns-mysql-data:/var/lib/mysql
- /etc/localtime:/etc/localtime:ro
- /etc/timezone:/etc/timezone:ro
networks:
- pdns-compose-mysql
command: --character_set_client=utf8 --character-set-server=utf8mb4 --collation-server=utf8mb4_unicode_ci --character-set-client-handshake=FALSE
environment:
- MYSQL_DATABASE=${PDNS_DB_NAME}
- MYSQL_USER=${PDNS_DB_USER}
- MYSQL_PASSWORD=${PDNS_DB_PASSWORD}
- MYSQL_RANDOM_ROOT_PASSWORD=1
healthcheck:
test: ["CMD", "mysqladmin" ,"ping", "-h", "localhost"]
timeout: 10s
retries: 5

networks:
pdns-compose-mysql:

volumes:
powerdns-mysql-data:
83 changes: 83 additions & 0 deletions docker-compose.postgres.test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
version: "2.1"

services:
# https://docs.docker.com/docker-hub/builds/automated-testing/
sut:
build:
context: ./.test
dockerfile: Dockerfile
command: sh /docker_test.sh
depends_on:
- pdns-server-postgres
- pdns-postgresql
environment:
# Tests setup
- PING_CONTAINER=pdns-server-postgres
volumes_from:
- pdns-server-postgres
networks:
- pdns-compose-pgsql
volumes:
- /etc/localtime:/etc/localtime:ro
- /etc/timezone:/etc/timezone:ro

pdns-server-postgres:
build: .
image: ${IMAGE_NAME}
hostname: ${PDNS_HOST}
container_name: pdns-server-postgres
# If ports need to be redirected or exposed to host
#ports:
# - "5053:53"
# - "5053:53/udp"
networks:
- pdns-compose-pgsql
volumes:
- /etc/localtime:/etc/localtime:ro
- /etc/timezone:/etc/timezone:ro
environment:
- AUTOCONF=postgres
# PostgreSQL
- PGSQL_HOST=pdns-postgresql
- PGSQL_PORT=5432
- PGSQL_DB=${PDNS_DB_NAME}
- PGSQL_USER=${PDNS_DB_USER}
- PGSQL_PASS=${PDNS_DB_PASSWORD}
- PGSQL_DNSSEC=no
# PDNS Config
- PDNS_LOG_DNS_QUERIES=yes
- PDNS_API=yes
- PDNS_API_KEY=${PDNS_API_KEY}
- PDNS_WEBSERVER=no
- PDNS_WEBSERVER_ADDRESS=0.0.0.0
- PDNS_WEBSERVER_PORT=8081
- PDNS_WEBSERVER_ALLOW_FROM=${PDNS_WEBSERVER_ALLOW_FROM}/0
- PDNS_SOA_REFRESH_DEFAULT=14400
depends_on:
- pdns-postgresql

pdns-postgresql:
image: postgres:10-alpine
hostname: pdns-postgresql
container_name: pdns-postgresql
restart: always
expose:
- 5432
networks:
- pdns-compose-pgsql
environment:
- POSTGRES_DB=${PDNS_DB_NAME}
- POSTGRES_USER=${PDNS_DB_USER}
- POSTGRES_PASSWORD=${PDNS_DB_PASSWORD}
healthcheck:
test: ["CMD", "pg_isready", "-U", "${PDNS_DB_USER}"]
volumes:
- powerdns-postgresql-data:/var/lib/postgresql/data
- /etc/localtime:/etc/localtime:ro
- /etc/timezone:/etc/timezone:ro

networks:
pdns-compose-pgsql:

volumes:
powerdns-postgresql-data:
57 changes: 57 additions & 0 deletions docker-compose.sqlite.test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
version: "2.1"

services:
# https://docs.docker.com/docker-hub/builds/automated-testing/
sut:
build:
context: ./.test
dockerfile: Dockerfile
command: sh /docker_test.sh
depends_on:
- pdns-server-sqlite
environment:
# Tests setup
- PING_CONTAINER=pdns-server-sqlite
volumes_from:
- pdns-server-sqlite
networks:
- pdns-compose-sqlite
volumes:
- /etc/localtime:/etc/localtime:ro
- /etc/timezone:/etc/timezone:ro

pdns-server-sqlite:
build: .
image: ${IMAGE_NAME}
hostname: ${PDNS_HOST}
container_name: pdns-server-sqlite
# If ports need to be redirected or exposed to host
#ports:
# - "5053:53"
# - "5053:53/udp"
networks:
- pdns-compose-sqlite
volumes:
- powerdns-sqlite-data:/srv/pdns/db
- /etc/localtime:/etc/localtime:ro
- /etc/timezone:/etc/timezone:ro
environment:
- AUTOCONF=sqlite
# SQLite
- SQLITE_DB=/srv/pdns/db/${PDNS_DB_NAME}
- SQLITE_DNSSEC=no
# PDNS Config
- PDNS_LOG_DNS_QUERIES=yes
- PDNS_API=yes
- PDNS_API_KEY=${PDNS_API_KEY}
- PDNS_WEBSERVER=no
- PDNS_WEBSERVER_ADDRESS=0.0.0.0
- PDNS_WEBSERVER_PORT=8081
- PDNS_WEBSERVER_ALLOW_FROM=${PDNS_WEBSERVER_ALLOW_FROM}/0
- PDNS_SOA_REFRESH_DEFAULT=14400

networks:
pdns-compose-sqlite:

volumes:
powerdns-sqlite-data: