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

Commit

Permalink
👷 Get tests up and running with docker
Browse files Browse the repository at this point in the history
  • Loading branch information
stevenbal committed Jul 29, 2024
1 parent ade7a4b commit 2aa7601
Show file tree
Hide file tree
Showing 2 changed files with 130 additions and 28 deletions.
136 changes: 108 additions & 28 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,58 +10,138 @@ on:
pull_request:
workflow_dispatch:

env:
IMAGE_NAME: openformulieren/open-forms-ext-stuf-zds-payments

jobs:
tests:
name: Run the Django test suite
runs-on: ubuntu-latest
strategy:
matrix:
python: ['3.10', '3.11', '3.12']
django: ['4.2']

name: Run the test suite (Python ${{ matrix.python }}, Django ${{ matrix.django }})
env:
PIP_CONSTRAINT: pip-constraints.txt
services:
postgres:
image: postgres:14
env:
POSTGRES_HOST_AUTH_METHOD: trust
ports:
- 5432:5432
# Needed because the postgres container does not provide a healthcheck
options:
--health-cmd pg_isready --health-interval 10s --health-timeout 5s --health-retries 5
--name postgres
redis:
image: redis:6
ports:
- 6379:6379

steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
- name: Checkout Open Forms
uses: actions/checkout@v3
with:
repository: open-formulieren/open-forms
path: open-forms

- name: Checkout StUF-ZDS payments extension
uses: actions/checkout@v3
with:
path: extension

- name: Set up backend environment
uses: maykinmedia/[email protected]
with:
python-version: ${{ matrix.python }}
apt-packages: 'libxml2-dev libxmlsec1-dev libxmlsec1-openssl gettext postgresql-client gdal-bin'
python-version: '3.10'
optimize-postgres: 'yes'
pg-service: 'postgres'
setup-node: 'yes'
nvmrc-custom-dir: 'open-forms'
npm-ci-flags: '--legacy-peer-deps'
working-directory: ${{ github.workspace }}/open-forms

- name: Install dependencies
run: pip install tox tox-gh-actions
- name: Make symlink in OF to the extension
run: |
ln -s ${{ github.workspace }}/extension/stuf_zds_payments ${{ github.workspace }}/open-forms/src
- name: Run tests
run: tox
run: |
export OPEN_FORMS_EXTENSIONS=stuf_zds_payments
python src/manage.py compilemessages
coverage run --source=stuf_zds_payments src/manage.py test stuf_zds_payments
coverage combine
coverage xml -o coverage-extension.xml
env:
PYTHON_VERSION: ${{ matrix.python }}
DJANGO: ${{ matrix.django }}
DJANGO_SETTINGS_MODULE: openforms.conf.ci
SECRET_KEY: dummy
DB_USER: postgres
DB_PASSWORD: ''
working-directory: ${{ github.workspace }}/open-forms

- name: Publish coverage report
uses: codecov/codecov-action@v4
uses: codecov/[email protected]
with:
root_dir: ${{ github.workspace }}/extension
working-directory: ${{ github.workspace }}/open-forms
files: ./coverage-extension.xml

docker_build:
name: Build Docker image
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3

- name: Set tag
id: vars
run: |
# Strip git ref prefix from version
VERSION=$(echo "${{ github.ref }}" | sed -e 's,.*/\(.*\),\1,')
# Strip "v" prefix from tag name (if present at all)
[[ "${{ github.ref }}" == "refs/tags/"* ]] && VERSION=$(echo $VERSION | sed -e 's/^v//')
# Use Docker `latest` tag convention
[ "$VERSION" == "main" ] && VERSION=latest
# PRs result in version 'merge' -> transform that into 'latest'
[ "$VERSION" == "merge" ] && VERSION=latest
echo ::set-output name=tag::${VERSION}
- name: Build the Docker image
run: |
docker build . \
--tag $IMAGE_NAME:$RELEASE_VERSION
env:
RELEASE_VERSION: ${{ steps.vars.outputs.tag }}

- run: docker image save -o image.tar $IMAGE_NAME:${{ steps.vars.outputs.tag }}
- name: Store image artifact
uses: actions/upload-artifact@v3
with:
token: ${{ secrets.CODECOV_TOKEN }}
name: docker-image
path: image.tar
retention-days: 1

publish:
name: Publish package to PyPI
runs-on: ubuntu-latest
needs: tests
environment: release
permissions:
id-token: write
needs:
- tests
- docker_build

if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags')

steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
- uses: actions/checkout@v3
- uses: actions/setup-python@v4
with:
python-version: '3.10'

- name: Build sdist and wheel
run: |
pip install build --upgrade
python -m build
pip install pip setuptools wheel --upgrade
python setup.py sdist bdist_wheel
- name: Publish a Python distribution to PyPI
uses: pypa/gh-action-pypi-publish@release/v1

with:
user: __token__
password: ${{ secrets.PYPI_TOKEN }}
22 changes: 22 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Stage 1 - Build stuf_zds_payments environment
FROM python:3.12-slim-bullseye AS stuf-zds-payments-build

WORKDIR /app

RUN pip install pip -U
COPY . /app
RUN pip install .


# Stage 2 - Build the production image with the stuf_zds_payments
FROM openformulieren/open-forms:latest AS production-build

WORKDIR /app

# Copy the dependencies of the stuf_zds_payments
COPY --from=stuf-zds-payments-build /usr/local/lib/python3.12 /usr/local/lib/python3.12

# Add stuf_zds_payments code to the image
COPY --chown=maykin:root ./stuf_zds_payments /app/src/stuf_zds_payments

USER maykin

0 comments on commit 2aa7601

Please sign in to comment.