Skip to content

Extend the project description #129

Extend the project description

Extend the project description #129

Workflow file for this run

name: Continuous Integration and Delivery
on: [push]
env:
WEB_IMAGE: ghcr.io/$(echo $GITHUB_ACTOR | tr '[A-Z]' '[a-z]')/web
WORKER_IMAGE: ghcr.io/$(echo $GITHUB_ACTOR | tr '[A-Z]' '[a-z]')/worker
jobs:
test:
name: Test and check quality
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Build and run containers
run: docker-compose up -d
- name: Wait for database
run: sleep 30
- name: Apply database migrations
run: docker-compose exec -T web alembic upgrade head
- name: Check for pending database schema upgrade
run: docker-compose exec -T web alembic check
- name: Check code linting with ruff
run: docker-compose exec -T -u root web ruff check .
- name: Check code formatting with black
run: docker-compose exec -T -u root web black --check .
- name: Test code with pytest
run: docker-compose exec -T -u root web pytest -n auto .
- name: Cleanup
run: docker-compose down -v
build-and-deploy:
name: Build Docker Images and Deploy to Heroku
runs-on: ubuntu-latest
needs: [test]
strategy:
matrix:
include:
- image_name: "WEB"
docker_file: "Dockerfile.web"
image_env: "WEB_IMAGE"
registry_image_env: "HEROKU_REGISTRY_WEB_IMAGE"
- image_name: "WORKER"
docker_file: "Dockerfile.worker"
image_env: "WORKER_IMAGE"
registry_image_env: "HEROKU_REGISTRY_WORKER_IMAGE"
env:
HEROKU_APP_NAME: fastapi-tdd-docker-spyker77
HEROKU_REGISTRY_WEB_IMAGE: registry.heroku.com/${HEROKU_APP_NAME}/web
HEROKU_REGISTRY_WORKER_IMAGE: registry.heroku.com/${HEROKU_APP_NAME}/worker
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Log in to GitHub Packages
run: echo ${GITHUB_TOKEN} | docker login ghcr.io -u ${GITHUB_ACTOR} --password-stdin
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Pull images
run: |
docker pull ${{ env[matrix.image_env] }}-builder:latest || true
docker pull ${{ env[matrix.image_env] }}-final:latest || true
- name: Build images
run: |
# Build Builder Stage
docker build \
--target builder \
--cache-from ${{ env[matrix.image_env] }}-builder:latest \
--tag ${{ env[matrix.image_env] }}-builder:latest \
--file ./${{ matrix.docker_file }} \
"."
# Build Final Stage
docker build \
--cache-from ${{ env[matrix.image_env] }}-final:latest \
--tag ${{ env[matrix.image_env] }}-final:latest \
--tag ${{ env[matrix.registry_image_env] }}:latest \
--file ./${{ matrix.docker_file }} \
"."
- name: Push images to the packages
run: |
docker push ${{ env[matrix.image_env] }}-builder:latest
docker push ${{ env[matrix.image_env] }}-final:latest
# 🚨 Disable continuous delivery to Heroku 🚨
# - name: Log in to the Heroku Container Registry
# run: docker login -u _ -p ${HEROKU_AUTH_TOKEN} registry.heroku.com
# env:
# HEROKU_AUTH_TOKEN: ${{ secrets.HEROKU_AUTH_TOKEN }}
# - name: Push images to the registry
# run: docker push ${{ env[matrix.registry_image_env] }}:latest
# - name: Set environment variables
# run: |
# echo "HEROKU_REGISTRY_${{ matrix.image_name }}_IMAGE=${{ env[matrix.registry_image_env] }}" >> $GITHUB_ENV
# echo "HEROKU_AUTH_TOKEN=${{ secrets.HEROKU_AUTH_TOKEN }}" >> $GITHUB_ENV
# - name: Release
# run: |
# chmod +x ./scripts/release.sh
# ./scripts/release.sh