diff --git a/.github/docker/compose.ci.yml b/.github/docker/compose.ci.yml new file mode 100644 index 0000000..f0dcaad --- /dev/null +++ b/.github/docker/compose.ci.yml @@ -0,0 +1,61 @@ +services: + tests: + image: ${image} + environment: + - DEBUG=False + - ADMIN_EMAIL=adm@hcw.org + - ADMIN_PASSWORD=123 + - CACHE_URL=redis://redis:6379/1 + - CELERY_BROKER_URL=redis://redis:6379/9 + - CELERY_TASK_ALWAYS_EAGER=False + - DATABASE_URL=postgres://hcw:password@db:5432/hope_country_workspace + - DJANGO_SETTINGS_MODULE=hope_country_workspace.config.settings + - MEDIA_ROOT=/var/hope_country_workspace/media + - PYTHONPATH=/code/src/:/code/__pypackages__/3.12/lib/ + - SECRET_KEY=sensitive-secret-key + - STATIC_ROOT=/var/hope_country_workspace/static + restart: no + depends_on: + db: + condition: service_healthy + redis: + condition: service_healthy + command: > + bash -c " + pytest -vvv --cov=src ./tests + " + volumes: + - ../../tests:/code/tests + healthcheck: + test: ["CMD", "curl", "-f", "http://localhost:8000/healthcheck"] + interval: 10s + timeout: 5s + retries: 5 + + db: + image: postgres:16 + environment: + - POSTGRES_USER=hcw + - POSTGRES_PASSWORD=password + - POSTGRES_DB=hope_country_workspace + restart: always + healthcheck: + test: ["CMD", "pg_isready", "-U", "hcw", "-d", "hope_country_workspace"] + start_period: 5s + start_interval: 1s + interval: 5s + timeout: 4s + retries: 5 + + redis: + image: redis:7.2 + ports: + - 6379:6379 + restart: always + healthcheck: + test: ["CMD", "redis-cli", "ping"] + start_period: 5s + start_interval: 1s + interval: 5s + timeout: 4s + retries: 5 diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..2ad3a1c --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,38 @@ +name: CI +on: + pull_request: + branches: [develop] # If more branches are needed, add them here. + types: [synchronize, opened, reopened, ready_for_review] + push: + branches: [develop] # If more branches are needed, add them here. +concurrency: + group: "${{ github.workflow }}-${{ github.ref }}" + cancel-in-progress: true +jobs: + test: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - name: Ensure cache directory exists + run: mkdir -p /tmp/.buildx-cache + - name: Cache Docker layers + uses: actions/cache@v3 + with: + path: /tmp/.buildx-cache + key: ${{ runner.os }}-buildx-${{ github.sha }} + restore-keys: | + ${{ runner.os }}-buildx- + - name: Build the Docker image + run: | + docker buildx create --use + docker buildx build \ + --tag unicef/hope_country_workspace:${{ github.sha }} \ + --load \ + --target python_dev_deps \ + --cache-from=type=local,src=/tmp/.buildx-cache \ + --cache-to=type=local,dest=/tmp/.buildx-cache \ + -f ./docker/Dockerfile \ + ./ + - name: Run the tests + run: |- + image=unicef/hope_country_workspace:${{ github.sha }} docker compose -f ./.github/docker/compose.ci.yml up --exit-code-from tests