Skip to content

Commit

Permalink
Adds workflow to test build docker image (#461)
Browse files Browse the repository at this point in the history
* Adds workflow to test build docker image

* fix checkmigrations command

* Adds missing `dev-packes` category in pipenv sync for local docker
  • Loading branch information
rithviknishad authored Feb 6, 2024
1 parent c2308a1 commit d12d877
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 1 deletion.
46 changes: 46 additions & 0 deletions .github/workflows/test-base.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
name: Test

on:
workflow_call:

jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

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

- name: Cache Docker layers
uses: actions/cache@v3
with:
path: /tmp/.buildx-cache
key: ${{ runner.os }}-buildx-${{ hashFiles('Pipfile.lock', 'compose/local/django/Dockerfile') }}
restore-keys: |
${{ runner.os }}-buildx-
- name: Bake docker images
uses: docker/bake-action@v4
with:
load: true
set: |
*.cache-from=type=local,src=/tmp/.buildx-cache
*.cache-to=type=local,dest=/tmp/.buildx-cache-new
files: docker-compose.local.yaml

- name: Start services
run: docker compose -f docker-compose.local.yaml up -d --wait --no-build

- name: Check migrations
run: make checkmigration

# - name: Run tests
# run: make test-coverage

# - name: Upload coverage report
# uses: codecov/codecov-action@v3

- name: Move cache
run: |
rm -rf /tmp/.buildx-cache
mv /tmp/.buildx-cache-new /tmp/.buildx-cache
12 changes: 12 additions & 0 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
name: Test PR

on:
pull_request:

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

jobs:
test:
uses: ./.github/workflows/test-base.yaml
3 changes: 3 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ logs:

makemigrations: up
docker exec django bash -c "python manage.py makemigrations"

checkmigration:
docker compose -f $(docker_config_file) exec django bash -c "python manage.py makemigrations --check --dry-run"

test: up
docker exec django bash -c "python manage.py test --keepdb --parallel=$(nproc)"
Expand Down
2 changes: 1 addition & 1 deletion compose/local/django/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ RUN pip install pipenv

# Requirements are installed here to ensure they will be cached.
COPY Pipfile Pipfile.lock ./
RUN pipenv sync --system --categories "packages"
RUN pipenv sync --system --categories "packages dev-packages"

# Python 'run' stage
FROM python as python-run-stage
Expand Down

0 comments on commit d12d877

Please sign in to comment.