Skip to content

Commit

Permalink
fix dockerfile
Browse files Browse the repository at this point in the history
  • Loading branch information
domdinicola committed Dec 17, 2024
2 parents df0b41c + 13099ba commit 20b8ae6
Show file tree
Hide file tree
Showing 4 changed files with 71 additions and 47 deletions.
29 changes: 25 additions & 4 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -108,11 +108,32 @@ jobs:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}

- name: Unit tests
- name: Run Test suite
run: |
backend_image=${{ vars.DOCKERHUB_ORGANIZATION }}/hope-support-images:payment-gateway-${{ github.sha }}-dev docker compose \
-f ./ops/compose.ci-test.yml \
up --exit-code-from backend
mkdir output
docker run --rm \
--network host \
-e PYTHONPATH=/app/src \
-e DATABASE_URL=${DATABASE_URL} \
-e CELERY_BROKER_URL=${CELERY_BROKER_URL} \
-e CACHE_URL=${CACHE_URL} \
-v "./output/:/app/output" \
-v "./src/:/app/src" \
-v "./tests:/app/tests" \
-v "./pytest.ini:/app/pytest.ini" \
-t ${{env.IMAGE}} \
pytest tests/ --selenium -n auto -v --maxfail=5 --migrations --cov-report xml:./output/coverage.xml
- name: Upload coverage to Codecov
uses: codecov/codecov-action@v4
continue-on-error: true
with:
env_vars: OS,PYTHON
fail_ci_if_error: true
files: /app/output/coverage.xml
token: ${{ secrets.CODECOV_TOKEN }}
verbose: false
name: codecov-${{env.GITHUB_REF_NAME}}

build_and_push_prd:
needs: [build_and_push_dev]
Expand Down
8 changes: 5 additions & 3 deletions docker/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ RUN --mount=type=cache,target=/root/.uv-cache \
--python=/usr/local/bin/python \
--python-preference=system \
--frozen
RUN pip install uwsgi
RUN uv pip install . uwsgi

WORKDIR /app
COPY .. ./
Expand All @@ -69,11 +69,13 @@ ENV PATH=$PATH:/app/.venv/bin/ \
RUN pip install uv uwsgi

RUN --mount=type=cache,target=/root/.uv-cache \
--mount=type=bind,source=./src/hope_payment_gateway,target=/app/src/hope_payment_gateway \
--mount=type=bind,source=./src/hope_api_auth,target=/app/src/hope_api_auth \
uv sync --cache-dir=/root/.uv-cache \
--python=/usr/local/bin/python \
--python-preference=system \
--frozen
RUN pip install uwsgi
--frozen \
uv pip install .

COPY --chown=hpg:hpg .. ./
COPY --chown=hpg:hpg --from=builder /app /app
Expand Down
79 changes: 40 additions & 39 deletions docker/entrypoint.sh
Original file line number Diff line number Diff line change
@@ -1,44 +1,45 @@
#!/bin/bash

set -eou pipefail

production() {
uwsgi \
--http :8000 \
--master \
--module=hope_payment_gateway.config.wsgi \
--processes=2 \
--buffer-size=8192
}

if [ $# -eq 0 ]; then
production
fi
export MEDIA_ROOT="${MEDIA_ROOT:-/var/run/app/media}"
export STATIC_ROOT="${STATIC_ROOT:-/var/run/app/static}"
export UWSGI_PROCESSES="${UWSGI_PROCESSES:-"4"}"
export DJANGO_SETTINGS_MODULE="${DJANGO_SETTINGS_MODULE:-hope_payment_gateway.config.settings}"

case "$1" in
dev)
./docker/wait-for-it.sh db:5432
django-admin upgrade
django-admin runserver 0.0.0.0:8000
;;
tests)
./docker/wait-for-it.sh db:5432
pytest --create-db
;;
prd)
production
;;
celery_worker)
export C_FORCE_ROOT=1
celery -A hope_payment_gateway.celery worker -l info
;;
celery_beat)
celery -A hope_payment_gateway.celery beat -l info
;;
celery_flower)
celery flower -A hope_payment_gateway.celery --address=0.0.0.0 --broker=$CELERY_BROKER_URL
;;
*)
exec "$@"
;;
esac
run)
django-admin upgrade --with-check
set -- tini -- "$@"
MAPPING=""
if [ "${STATIC_URL}" = "/static/" ]; then
MAPPING="--static-map ${STATIC_URL}=${STATIC_ROOT}"
fi
set -- tini -- "$@"
set -- uwsgi --http :8000 \
--module hope_payment_gateway.config.wsgi \
--mimefile=/conf/mime.types \
--uid hope \
--gid unicef \
--buffer-size 8192 \
--http-buffer-size 8192 \
$MAPPING
;;
upgrade)
django-admin upgrade --with-check
;;
worker)
set -- tini -- "$@"
set -- gosu user:app celery -A hope_payment_gateway.config.celery worker -E --loglevel=ERROR --concurrency=4
;;
beat)
set -- tini -- "$@"
set -- gosu user:app celery -A hope_payment_gateway.config.celery beat --loglevel=ERROR --scheduler django_celery_beat.schedulers:DatabaseScheduler
;;
flower)
export DATABASE_URL="sqlite://:memory:"
set -- tini -- "$@"
set -- gosu user:app celery -A hope_payment_gateway.config.celery flower
;;
esac

exec "$@"
2 changes: 1 addition & 1 deletion ops/compose.ci-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ version: '3.8'
services:
backend:
image: ${backend_image}
command: tests
command: pytest tests/ -n auto -v --maxfail=5 --migrations --cov-report xml:./output/coverage.xml
environment:
- SECRET_KEY=secret-key
- DATABASE_URL=postgres://postgres:postgres@db:5432/postgres
Expand Down

0 comments on commit 20b8ae6

Please sign in to comment.