Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Docker tests and push #1389

Merged
merged 3 commits into from
Jun 14, 2024
Merged
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
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 @@ -33,12 +33,12 @@
#

FROM ubuntu:jammy
MAINTAINER Kristian Larsson <[email protected]>

Check failure on line 36 in Dockerfile.nipapd

View workflow job for this annotation

GitHub Actions / docker

DL4000 info: MAINTAINER is deprecated

ENV DEBIAN_FRONTEND=noninteractive

# apt update, upgrade & install packages
RUN apt-get update -qy && apt-get upgrade -qy \

Check failure on line 41 in Dockerfile.nipapd

View workflow job for this annotation

GitHub Actions / docker

DL3008 info: Pin versions in apt get install. Instead of `apt-get install <package>` use `apt-get install <package>=<version>`

Check failure on line 41 in Dockerfile.nipapd

View workflow job for this annotation

GitHub Actions / docker

DL3009 info: Delete the apt-get lists after installing something
&& apt-get install --no-install-recommends -qy build-essential \
libpq-dev \
libldap-dev \
Expand Down Expand Up @@ -69,6 +69,6 @@
&& 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
Loading