-
Notifications
You must be signed in to change notification settings - Fork 0
108 lines (104 loc) · 4.28 KB
/
main.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
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: Delete the tools folder to free up space for CUDA
run: rm -rf /opt/hostedtoolcache
- 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] }}-cuda-devel: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 CUDA-Devel Stage
docker build \
--target cuda_devel \
--cache-from ${{ env[matrix.image_env] }}-cuda-devel:latest \
--tag ${{ env[matrix.image_env] }}-cuda-devel: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] }}-cuda-devel: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