diff --git a/.github/workflows/reusable-test.yml b/.github/workflows/reusable-test.yml index 27d5301ce7..8ecc633d01 100644 --- a/.github/workflows/reusable-test.yml +++ b/.github/workflows/reusable-test.yml @@ -38,7 +38,7 @@ jobs: *.cache-to=type=local,dest=/tmp/.buildx-cache-new files: docker-compose.yaml,docker-compose.local.yaml env: - DOCKER_BUILD_NO_SUMMARY: true + DOCKER_BUILD_SUMMARY: false - name: Start services run: | @@ -57,6 +57,10 @@ jobs: - name: Validate integrity of fixtures run: make load-dummy-data + - name: Dump db + if: ${{ inputs.event_name == 'push' || github.event_name == 'push' }} + run: make dump-db + - name: Run tests run: make test-coverage @@ -76,3 +80,13 @@ jobs: with: path: /tmp/.buildx-cache key: ${{ runner.os }}-buildx-${{ hashFiles('Pipfile.lock', 'docker/dev.Dockerfile') }} + + - name: Upload db artifact + if: ${{ inputs.event_name == 'push' || github.event_name == 'push' }} + uses: actions/upload-artifact@v4 + with: + name: care-db-dump + path: care_db.dump + retention-days: 30 + compression-level: 0 # file is already compressed + overwrite: true # keep only the last artifact diff --git a/.gitignore b/.gitignore index 162fc2bcba..84a84d610f 100644 --- a/.gitignore +++ b/.gitignore @@ -354,3 +354,5 @@ secrets.sh *.rdb jwks.b64.txt + +care_db.dump diff --git a/Makefile b/Makefile index aa4ff85e2a..12d25fc83b 100644 --- a/Makefile +++ b/Makefile @@ -1,4 +1,4 @@ -.PHONY: build, re-build, up, down, list, logs, test, makemigrations, reset_db +.PHONY: logs DOCKER_VERSION := $(shell docker --version 2>/dev/null) @@ -19,6 +19,9 @@ re-build: build: docker compose -f docker-compose.yaml -f $(docker_config_file) build +pull: + docker compose -f docker-compose.yaml -f $(docker_config_file) pull + up: docker compose -f docker-compose.yaml -f $(docker_config_file) up -d --wait @@ -40,6 +43,9 @@ checkmigration: makemigrations: docker compose exec backend bash -c "python manage.py makemigrations" +migrate: + docker compose exec backend bash -c "python manage.py migrate" + test: docker compose exec backend bash -c "python manage.py test --keepdb --parallel --shuffle" @@ -48,9 +54,16 @@ test-coverage: docker compose exec backend bash -c "coverage combine || true; coverage xml" docker compose cp backend:/app/coverage.xml coverage.xml -reset_db: +dump-db: + docker compose exec db sh -c "pg_dump -U postgres -Fc care > /tmp/care_db.dump" + docker compose cp db:/tmp/care_db.dump care_db.dump + +load-db: + docker compose cp care_db.dump db:/tmp/care_db.dump + docker compose exec db sh -c "pg_restore -U postgres --clean --if-exists -d care /tmp/care_db.dump" + +reset-db: docker compose exec backend bash -c "python manage.py reset_db --noinput" - docker compose exec backend bash -c "python manage.py migrate" ruff-all: ruff check .