Initial project setup with docker and github ci #23
Workflow file for this run
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: 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: | |
COMPOSE_FILE: ./docker-compose.yml:./gh-docker-compose.yml | |
DOCKER_IMAGE_BACKEND: ${{ steps.prep.outputs.tagged_image }} | |
run: | | |
docker compose -f ./gh-docker-compose.yml 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 |