-
Notifications
You must be signed in to change notification settings - Fork 0
114 lines (109 loc) · 3.43 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
name: Build and Test
on:
push:
branches:
- main
env:
IMAGE: ghcr.io/$(echo $GITHUB_REPOSITORY | tr '[A-Z]' '[a-z]')/jokesapi
jobs:
build:
name: Build Docker Image
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2.4.0
with:
ref: main
- name: Login to Github Packages
run: echo ${CR_PAT} | docker login ghcr.io -u ${GITHUB_ACTOR} --password-stdin
env:
CR_PAT: ${{ secrets.CR_PAT }}
- name: Pull Image
run: |
docker pull ${{ env.IMAGE }}:latest || true
- name: Build image
run: |
docker build \
--cache-from ${{ env.IMAGE }}:latest \
--tag ${{ env.IMAGE }}:latest \
--file ./project/Dockerfile.prod \
"./project"
- name: Push Image
run: |
docker push ghcr.io/dannduati/jokes_api/jokesapi:latest
test:
name: Test Docker Image
runs-on: ubuntu-latest
needs: build
steps:
- name: Checkout
uses: actions/checkout@v2.4.0
with:
ref: main
- name: Login to Github Packages
run: echo ${CR_PAT} | docker login ghcr.io -u ${GITHUB_ACTOR} --password-stdin
env:
CR_PAT: ${{ secrets.CR_PAT }}
- name: Pull image
run: |
docker pull ghcr.io/dannduati/jokes_api/jokesapi:latest || true
- name: Build image
run: |
docker build \
--cache-from ${{ env.IMAGE }}:latest \
--tag ${{ env.IMAGE }}:latest \
--file ./project/Dockerfile.prod \
"./project"
- name: Run Container
run: |
docker run \
-d \
--name fastapi-tdd \
-e PORT=8675 \
-e ENVIRONMENT=dev \
-e DATABASE_URL=sqlite://sqlite.db \
-e DATABASE_TEST_URL=sqlite://sqlite.db \
-p 5003:8765 \
${{ env.IMAGE }}:latest
- name: Pytest
run: docker exec fastapi-tdd python -m pytest .
deploy:
name: Deploy to Heroku
runs-on: ubuntu-latest
needs: [build, test]
env:
HEROKU_APP_NAME: gentle-dusk-50795
HEROKU_REGISTRY_IMAGE: registry.heroku.com/${HEROKU_APP_NAME}/web
steps:
- name: Checkout
uses: actions/checkout@v2.4.0
with:
ref: main
- name: Login to Github Packages
run: echo ${CR_PAT} | docker login ghcr.io -u ${GITHUB_ACTOR} --password-stdin
env:
CR_PAT: ${{ secrets.CR_PAT }}
- name: Pull image
run: |
docker pull ${{ env.IMAGE }}:latest || true
- name: Build image
run: |
docker build \
--cache-from ${{ env.IMAGE }}:latest \
--tag ${{ env.HEROKU_REGISTRY_IMAGE }}:latest \
--file ./project/Dockerfile.prod \
"./project"
- name: Log in to Heroku Container Registry
run: docker login -u _ -p ${HEROKU_AUTH_TOKEN} registry.heroku.com
env:
HEROKU_AUTH_TOKEN: ${{ secrets.HEROKU_AUTH_TOKEN }}
- name: Push image to heroku registry
run: docker push ${{ env.HEROKU_REGISTRY_IMAGE }}
- 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