Skip to content

Initial project setup with docker and github ci #32

Initial project setup with docker and github ci

Initial project setup with docker and github ci #32

Workflow file for this run

name: Run test
on:
push:
branches:
- develop
pull_request:
env:
COMPOSE_FILE: docker-compose.yml:gh-docker-compose.yml
jobs:
test:
name: 🚴 Test 🚴
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@main
- name: 🐳 Prepare Docker
id: prep
run: |
TAG=$(echo $GITHUB_SHA | head -c7)
IMAGE="backend"
echo "tagged_image=${IMAGE}:${TAG}" >> $GITHUB_OUTPUT
echo "tag=${TAG}" >> $GITHUB_OUTPUT
- name: 🐳 Set up Docker Buildx
id: buildx
uses: docker/setup-buildx-action@v2
- name: 🐳 Cache Docker layers
uses: actions/cache@v3
with:
path: /tmp/.buildx-cache
key: ${{ runner.os }}-buildx-${{ github.ref }}
restore-keys: |
${{ runner.os }}-buildx-refs/develop
${{ runner.os }}-buildx-
- name: 🐳 Build image
uses: docker/build-push-action@v4
with:
context: .
builder: ${{ steps.buildx.outputs.name }}
file: Dockerfile
push: false
load: true
tags: ${{ steps.prep.outputs.tagged_image }}
cache-from: type=local,src=/tmp/.buildx-cache
cache-to: type=local,dest=/tmp/.buildx-cache-new
- name: 🕮 Validate if there are no pending django migrations.
env:
DOCKER_IMAGE_BACKEND: ${{ steps.prep.outputs.tagged_image }}
run: |
docker compose run --rm web bash -c 'wait-for-it db:5432 && ./manage.py makemigrations --check --dry-run' || {
echo 'There are some changes to be reflected in the migration. Make sure to run makemigrations';
exit 1;
}
- name: 🐳 Move docker cache (🧙 Hack fix)
run: |
rm -rf /tmp/.buildx-cache
mv /tmp/.buildx-cache-new /tmp/.buildx-cache