Skip to content

Commit

Permalink
Merge pull request #1389 from garberg/docker_tests
Browse files Browse the repository at this point in the history
Docker tests and push
  • Loading branch information
garberg authored Jun 14, 2024
2 parents a36eeef + 8c378f1 commit bd3d9b6
Show file tree
Hide file tree
Showing 3 changed files with 135 additions and 16 deletions.
139 changes: 129 additions & 10 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ on:
env:
ACTIONS_RUNNER_DEBUG: true
ACTIONS_STEP_DEBUG: true
NIPAPD_IMAGE: nipap/nipapd
WWW_IMAGE: nipap/nipap-www

jobs:
test:
Expand All @@ -27,16 +29,6 @@ jobs:
- name: "Check out NIPAP repository"
uses: actions/checkout@v2

- name: "Hadolint nipapd"
uses: hadolint/[email protected]
with:
Dockerfile: Dockerfile.nipapd

- name: "Hadolint WWW"
uses: hadolint/[email protected]
with:
Dockerfile: Dockerfile.www

- name: "Install dependencies and prepare NIPAP"
run: |
# Set up NIPAP repo
Expand Down Expand Up @@ -175,3 +167,130 @@ jobs:
sudo cat /var/log/syslog || true
sudo cat /var/log/postgresql/postgresql-*-main.log || true
sudo cat /tmp/nipap.log || true
docker:
name: docker
runs-on: ubuntu-22.04
steps:

- name: "Set up QEMU"
uses: docker/setup-qemu-action@v3

- name: "Set up Docker Buildx"
uses: docker/setup-buildx-action@v3

- name: "Check out NIPAP repository"
uses: actions/checkout@v2

- name: "Hadolint nipapd"
uses: hadolint/[email protected]
with:
Dockerfile: Dockerfile.nipapd

- name: "Hadolint WWW"
uses: hadolint/[email protected]
with:
Dockerfile: Dockerfile.www

- name: "nipapd metadata"
id: nipapd_meta
uses: docker/metadata-action@v5
with:
images: ${{ env.NIPAPD_IMAGE }}
tags: |
type=sha,prefix=
- name: "Build nipapd Docker image"
uses: docker/build-push-action@v5
with:
context: .
file: ./Dockerfile.nipapd
load: true
tags: |
${{ env.NIPAPD_IMAGE }}:ci
${{ steps.nipapd_meta.outputs.tags }}
push: false

- name: "www metadata"
id: www_meta
uses: docker/metadata-action@v5
with:
images: ${{ env.WWW_IMAGE }}
tags: |
type=sha,prefix=
- name: "Build www Docker image"
uses: docker/build-push-action@v5
with:
context: .
file: ./Dockerfile.www
load: true
tags: |
${{ env.WWW_IMAGE }}:ci
${{ steps.www_meta.outputs.tags }}
push: false

- name: "Setup Docker test"
run: |
# Install dependencies
sudo apt install -y \
libldap-dev \
libsasl2-dev \
python3-wheel \
python3-nose \
python3-requests \
postgresql-14-ip4r
sudo -H pip3 install -r nipap/requirements.txt # needed to run test suite
# Set up PostgreSQL
sudo service postgresql start
pg_isready
sudo su -c "cd nipap/sql; PGPASSWORD=papin make install" postgres
# Start nipapd container
docker run --rm --network=host -d --name=nipapd_ci -e DB_HOST=127.0.0.1 -e DB_USERNAME=nipap -e DB_PASSWORD=papin ${{ env.NIPAPD_IMAGE }}:ci
sleep 10
docker logs nipapd_ci
# Set up for test
sudo mkdir -p /etc/nipap
sudo docker cp nipapd_ci:/etc/nipap/nipap.conf /etc/nipap/
sudo docker cp nipapd_ci:/etc/nipap/local_auth.db /etc/nipap/
docker exec -t nipapd_ci nipap-passwd add -u unittest -p gottatest -n unittest
docker exec -t nipapd_ci nipap-passwd add -u readonly -p gottatest --readonly -n "Read-only user for running unit tests"
- name: "Run docker tests"
run: |
# Run tests
nosetests3 tests/test_xmlrpc.py
nosetests3 tests/nipaptest.py
nosetests3 tests/test_nipap_ro.py
nosetests3 tests/test_rest.py
- name: "Login to Docker Hub"
if: ${{ github.ref_name == 'master' }}
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}

- name: "Build and push nipapd Docker image"
if: ${{ github.ref_name == 'master' }}
uses: docker/build-push-action@v5
with:
context: .
file: ./Dockerfile.nipapd
load: true
tags: ${{ steps.nipapd_meta.outputs.tags }}
push: true

- name: "Build and push www Docker image"
if: ${{ github.ref_name == 'master' }}
uses: docker/build-push-action@v5
with:
context: .
file: ./Dockerfile.www
load: true
tags: ${{ steps.www_meta.outputs.tags }}
push: true
2 changes: 1 addition & 1 deletion Dockerfile.nipapd
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,6 @@ RUN pip3 --no-input install --no-cache-dir envtpl==0.7.2 \
&& python3 setup.py install

EXPOSE 1337
ENV LISTEN_ADDRESS=0.0.0.0 LISTEN_PORT=1337 SYSLOG=false DB_PORT=5432 DB_SSLMODE=disable
ENV LISTEN_ADDRESS=0.0.0.0 LISTEN_PORT=1337 SYSLOG=false DB_PORT=5432 DB_SSLMODE=disable DB_NAME=nipap

ENTRYPOINT ["/nipap/entrypoint.sh"]
10 changes: 5 additions & 5 deletions nipap/sql/Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#.PHONY: install
#.PHONY: install auth db tables clean clean-db clean-tables
# vim: ts=8 :

PSQL=psql
Expand Down Expand Up @@ -30,23 +30,23 @@ endif
all:
@echo "Please run \"make install\" as postgres user."


db:
auth:
createuser -S -D -R $(DB_USER)
createdb -O $(DB_USER) $(DB_NAME)
-psql -q -c "ALTER USER $(DB_USER) ENCRYPTED PASSWORD '$(DB_PASS)'"

db:
-psql -d $(DB_NAME) -c "CREATE EXTENSION ip4r;"
-psql -d $(DB_NAME) -c "CREATE EXTENSION hstore;"
-psql -d $(DB_NAME) -c "CREATE EXTENSION citext;"


tables:
PGPASSWORD=$(DB_PASS) cat ip_net.plsql | sed -e 's/%s/$(DB_NAME)/' | psql -q -h localhost -U $(DB_USER) -d $(DB_NAME)
PGPASSWORD=$(DB_PASS) psql -q -h localhost -U $(DB_USER) -d $(DB_NAME) < functions.plsql
PGPASSWORD=$(DB_PASS) psql -q -h localhost -U $(DB_USER) -d $(DB_NAME) < triggers.plsql


install: db tables
install: auth db tables
@echo "##"
ifdef PG_PASS_RAND
@echo "## A random password was generated '$(DB_PASS)'"
Expand Down

0 comments on commit bd3d9b6

Please sign in to comment.