-
Notifications
You must be signed in to change notification settings - Fork 48
143 lines (137 loc) · 4.87 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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
name: Continuous Integration and Delivery
on: [push]
env:
IMAGE: ghcr.io/$(echo $GITHUB_REPOSITORY | tr '[A-Z]' '[a-z]')/summarizer
jobs:
build:
name: Build Docker Image
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
with:
ref: main
- name: Log in to GitHub Packages
run: echo ${GITHUB_TOKEN} | docker login -u ${GITHUB_ACTOR} --password-stdin ghcr.io
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Pull images
run: |
docker pull ${{ env.IMAGE }}-builder:latest || true
docker pull ${{ env.IMAGE }}-final:latest || true
- name: Build images
run: |
docker build \
--target builder \
--cache-from ${{ env.IMAGE }}-builder:latest \
--tag ${{ env.IMAGE }}-builder:latest \
--file ./project/Dockerfile.prod \
"./project"
docker build \
--cache-from ${{ env.IMAGE }}-final:latest \
--tag ${{ env.IMAGE }}-final:latest \
--file ./project/Dockerfile.prod \
"./project"
- name: Push images
run: |
docker push ${{ env.IMAGE }}-builder:latest
docker push ${{ env.IMAGE }}-final:latest
test:
name: Test Docker Image
runs-on: ubuntu-latest
needs: build
steps:
- name: Checkout
uses: actions/checkout@v3
with:
ref: main
- name: Log in to GitHub Packages
run: echo ${GITHUB_TOKEN} | docker login -u ${GITHUB_ACTOR} --password-stdin ghcr.io
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Pull images
run: |
docker pull ${{ env.IMAGE }}-builder:latest || true
docker pull ${{ env.IMAGE }}-final:latest || true
- name: Build images
run: |
docker build \
--target builder \
--cache-from ${{ env.IMAGE }}-builder:latest \
--tag ${{ env.IMAGE }}-builder:latest \
--file ./project/Dockerfile.prod \
"./project"
docker build \
--cache-from ${{ env.IMAGE }}-final:latest \
--tag ${{ env.IMAGE }}-final:latest \
--file ./project/Dockerfile.prod \
"./project"
- name: Run container
run: |
docker run \
-d \
--name fastapi-tdd \
-e PORT=8765 \
-e ENVIRONMENT=dev \
-e DATABASE_URL=sqlite://sqlite.db \
-e DATABASE_TEST_URL=sqlite://sqlite.db \
-p 5003:8765 \
${{ env.IMAGE }}-final:latest
- name: Install requirements
run: docker exec fastapi-tdd pip install black==23.12.1 flake8==7.0.0 isort==5.13.2 pytest==7.4.4
- name: Pytest
run: docker exec fastapi-tdd python -m pytest .
- name: Flake8
run: docker exec fastapi-tdd python -m flake8 .
- name: Black
run: docker exec fastapi-tdd python -m black . --check
- name: isort
run: docker exec fastapi-tdd python -m isort . --check-only
deploy:
name: Deploy to Heroku
runs-on: ubuntu-latest
needs: [build, test]
env:
HEROKU_APP_NAME: quiet-citadel-80656
HEROKU_REGISTRY_IMAGE: registry.heroku.com/${HEROKU_APP_NAME}/summarizer
steps:
- name: Checkout
uses: actions/checkout@v3
with:
ref: main
- name: Log in to GitHub Packages
run: echo ${GITHUB_TOKEN} | docker login -u ${GITHUB_ACTOR} --password-stdin ghcr.io
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Pull images
run: |
docker pull ${{ env.IMAGE }}-builder:latest || true
docker pull ${{ env.IMAGE }}-final:latest || true
- name: Build images
run: |
docker build \
--target builder \
--cache-from ${{ env.IMAGE }}-builder:latest \
--tag ${{ env.IMAGE }}-builder:latest \
--file ./project/Dockerfile.prod \
"./project"
docker build \
--cache-from ${{ env.IMAGE }}-final:latest \
--tag ${{ env.IMAGE }}:latest \
--tag ${{ env.HEROKU_REGISTRY_IMAGE }}:latest \
--file ./project/Dockerfile.prod \
"./project"
- 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 to the registry
run: docker push ${{ env.HEROKU_REGISTRY_IMAGE }}:latest
- name: Set environment variables
run: |
echo "HEROKU_REGISTRY_IMAGE=${{ env.HEROKU_REGISTRY_IMAGE }}" >> $GITHUB_ENV
echo "HEROKU_AUTH_TOKEN=${{ secrets.HEROKU_AUTH_TOKEN }}" >> $GITHUB_ENV
- name: Release
run: |
chmod +x ./release.sh
./release.sh