Create docker-image.yml #13
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Docker Image CI | |
on: | |
push: | |
branches: [ "main" ] | |
pull_request: | |
branches: [ "main" ] | |
jobs: | |
build: | |
runs-on: ubuntu-latest | |
services: | |
db: | |
image: kartoza/postgis:16-3.4 | |
ports: | |
- 5432:5432 | |
options: >- | |
--health-cmd="pg_isready -h localhost -p 5432 -U postgres" | |
--health-interval=10s | |
--health-timeout=5s | |
--health-retries=5 | |
env: | |
POSTGRES_DB: minisass | |
POSTGRES_USER: docker | |
POSTGRES_PASSWORD: docker | |
steps: | |
- uses: actions/checkout@v4 | |
- name: Set up Docker Buildx | |
uses: docker/setup-buildx-action@v3 | |
- name: Copy docker-compose.override.template.yml to docker-compose.override.yml | |
run: cp docker-compose.override.template.yml docker-compose.override.yml | |
- name: Copy .example.env to .env | |
run: cp .example.env .env | |
- name: Cache Docker layers | |
uses: actions/cache@v3 | |
with: | |
path: /tmp/.buildx-cache | |
key: ${{ runner.os }}-buildx-${{ github.event.pull_request.number }} | |
restore-keys: | | |
${{ runner.os }}-buildx-${{ github.event.pull_request.number }} | |
${{ runner.os }}-buildx- | |
- name: Build Django Container with Cache | |
run: | | |
docker buildx build --cache-from=type=local,src=/tmp/.buildx-cache \ | |
--cache-to=type=local,dest=/tmp/.buildx-cache,mode=max \ | |
-t minisass/django -f deployment/docker/Dockerfile . | |
- name: Start Docker Compose services | |
run: | | |
docker compose --env-file .env -p minisass -f docker-compose.yml -f docker-compose.override.yml up -d db minio django | |
env: | |
BUILDKIT_PROGRESS: plain | |
DOCKER_BUILDKIT: 1 | |
BUILDX_CACHE_PATH: /tmp/.buildx-cache | |
# Wait for PostGIS container to be healthy before running tests | |
- name: Wait for PostGIS to be ready | |
run: | | |
export POSTGRES_USER=${POSTGRES_USER:-docker} | |
export POSTGRES_PASS=${POSTGRES_PASS:-docker} | |
docker compose --env-file .env -p minisass -f docker-compose.yml -f docker-compose.override.yml \ | |
exec db bash -c "until pg_isready -h localhost -U $POSTGRES_USER; do sleep 1; done" | |
- name: Run Django tests | |
run: | | |
docker compose --env-file .env -p minisass -f docker-compose.yml -f docker-compose.override.yml exec django \ | |
bash -c "python manage.py test" | |
- name: Stop and remove services | |
run: docker compose -p minisass -f docker-compose.yml -f docker-compose.override.yml down |