From 47881688a7111a58895047c835200827f3e37e53 Mon Sep 17 00:00:00 2001 From: Lukas Garberg Date: Thu, 13 Jun 2024 14:37:18 +0200 Subject: [PATCH 1/3] nipapd: Updated SQL makefile for CI Made some changes to the SQL Makefile to make it suitable to use for setting up PostgreSQL for testing from Docker. --- nipap/sql/Makefile | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/nipap/sql/Makefile b/nipap/sql/Makefile index 0ca1962c9..b4f537167 100644 --- a/nipap/sql/Makefile +++ b/nipap/sql/Makefile @@ -1,4 +1,4 @@ -#.PHONY: install +#.PHONY: install auth db tables clean clean-db clean-tables # vim: ts=8 : PSQL=psql @@ -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)'" From 98221acb2514e32cd8ba1437c37bda3a64cfdc81 Mon Sep 17 00:00:00 2001 From: Lukas Garberg Date: Thu, 13 Jun 2024 14:38:29 +0200 Subject: [PATCH 2/3] nipapd: Set default database name in Dockerfile Set a default database name in the Dockerfile. --- Dockerfile.nipapd | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Dockerfile.nipapd b/Dockerfile.nipapd index bec5c5593..ac3bcd8e5 100644 --- a/Dockerfile.nipapd +++ b/Dockerfile.nipapd @@ -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"] From 8c378f12377d28ac081d186c2f34d3b4e775ed72 Mon Sep 17 00:00:00 2001 From: Lukas Garberg Date: Thu, 13 Jun 2024 14:39:20 +0200 Subject: [PATCH 3/3] ci: Docker test and push Build docker images, run test suite (except for CLI tests) and push to Docker Hub if merged/pushed to master. --- .github/workflows/ci.yml | 139 ++++++++++++++++++++++++++++++++++++--- 1 file changed, 129 insertions(+), 10 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 734101c6f..0e79181b6 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -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: @@ -27,16 +29,6 @@ jobs: - name: "Check out NIPAP repository" uses: actions/checkout@v2 - - name: "Hadolint nipapd" - uses: hadolint/hadolint-action@v3.1.0 - with: - Dockerfile: Dockerfile.nipapd - - - name: "Hadolint WWW" - uses: hadolint/hadolint-action@v3.1.0 - with: - Dockerfile: Dockerfile.www - - name: "Install dependencies and prepare NIPAP" run: | # Set up NIPAP repo @@ -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/hadolint-action@v3.1.0 + with: + Dockerfile: Dockerfile.nipapd + + - name: "Hadolint WWW" + uses: hadolint/hadolint-action@v3.1.0 + 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