Skip to content

Commit 271626d

Browse files
fix workflow (#17)
1 parent cc62c05 commit 271626d

1 file changed

Lines changed: 133 additions & 132 deletions

File tree

Lines changed: 133 additions & 132 deletions
Original file line numberDiff line numberDiff line change
@@ -1,134 +1,135 @@
11
name: Build, publish and deploy docker
22

3-
on:
4-
push:
5-
branches: [ 'main' ]
6-
tags:
7-
- 'v*'
8-
9-
10-
env:
11-
REGISTRY: ghcr.io
12-
IMAGE_NAME: ${{ github.repository }}
13-
14-
jobs:
15-
build-and-push-image:
16-
name: Build and push
17-
runs-on: ubuntu-latest
18-
permissions:
19-
contents: read
20-
packages: write
21-
22-
steps:
23-
- name: Checkout repository
24-
uses: actions/checkout@v2
25-
26-
- name: Log in to the Container registry
27-
uses: docker/login-action@f054a8b539a109f9f41c372932f1ae047eff08c9
28-
with:
29-
registry: ${{ env.REGISTRY }}
30-
username: ${{ github.actor }}
31-
password: ${{ secrets.GITHUB_TOKEN }}
32-
33-
- name: Extract metadata (tags, labels) for Docker
34-
id: meta
35-
uses: docker/metadata-action@98669ae865ea3cffbcbaa878cf57c20bbf1c6c38
36-
with:
37-
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
38-
tags: |
39-
type=ref,event=tag,enable=${{ startsWith(github.ref, 'refs/tags/v') }}
40-
type=raw,value=latest,enable=${{ startsWith(github.ref, 'refs/tags/v') }}
41-
type=raw,value=test,enable=true
42-
43-
- name: Build and push Docker image
44-
uses: docker/build-push-action@ad44023a93711e3deb337508980b4b5e9bcdc5dc
45-
with:
46-
context: .
47-
push: true
48-
tags: ${{ steps.meta.outputs.tags }}
49-
labels: ${{ steps.meta.outputs.labels }}
50-
51-
deploy-testing:
52-
name: Deploy Testing
53-
needs: build-and-push-image
54-
runs-on: [ self-hosted, Linux ]
55-
environment:
56-
name: Testing
57-
url: https://auth.api.test.profcomff.com/
58-
env:
59-
CONTAITER_NAME: com_profcomff_api_auth_test
60-
permissions:
61-
packages: read
62-
63-
steps:
64-
- name: Pull new version
65-
run: docker pull ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:test
66-
67-
- name: Migrate DB
68-
run: |
69-
docker run \
70-
--rm \
71-
--network=web \
72-
--env DB_DSN=${{ secrets.DB_DSN }} \
73-
--name ${{ env.CONTAITER_NAME }}_migration \
74-
${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:test \
75-
alembic upgrade head
76-
77-
- name: Run new version
78-
id: run_test
79-
run: |
80-
docker stop ${{ env.CONTAITER_NAME }} || true && docker rm ${{ env.CONTAITER_NAME }} || true
81-
docker run \
82-
--detach \
83-
--restart always \
84-
--network=web \
85-
--env DB_DSN='${{ secrets.DB_DSN }}' \
86-
--env EMAIL='${{ secrets.EMAIL }}' \
87-
--env EMAIL_PASS='${{ secrets.EMAIL_PASS }}' \
88-
--env SMTP_HOST='smtp.gmail.com' \
89-
--env SMTP_PORT='587' \
90-
--name ${{ env.CONTAITER_NAME }} \
91-
${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:test
92-
93-
deploy-production:
94-
name: Deploy Production
95-
needs: build-and-push-image
96-
if: startsWith(github.ref, 'refs/tags/v')
97-
runs-on: [ self-hosted, Linux ]
98-
environment:
99-
name: Production
100-
url: https://auth.api.profcomff.com/
101-
env:
102-
CONTAITER_NAME: com_profcomff_api_auth
103-
permissions:
104-
packages: read
105-
106-
steps:
107-
- name: Pull new version
108-
run: docker pull ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:latest
109-
110-
- name: Migrate DB
111-
run: |
112-
docker run \
113-
--rm \
114-
--network=web \
115-
--env DB_DSN=${{ secrets.DB_DSN }} \
116-
--name ${{ env.CONTAITER_NAME }}_migration \
117-
${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:latest \
118-
alembic upgrade head
119-
120-
- name: Run new version
121-
id: run_test
122-
run: |
123-
docker stop ${{ env.CONTAITER_NAME }} || true && docker rm ${{ env.CONTAITER_NAME }} || true
124-
docker run \
125-
--detach \
126-
--restart always \
127-
--network=web \
128-
--env DB_DSN='${{ secrets.DB_DSN }}' \
129-
--env EMAIL='${{ secrets.EMAIL }}' \
130-
--env EMAIL_PASS='${{ secrets.EMAIL_PASS }}' \
131-
--env SMTP_HOST='smtp.gmail.com' \
132-
--env SMTP_PORT='587' \
133-
--name ${{ env.CONTAITER_NAME }} \
134-
${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:latest
3+
on:
4+
push:
5+
branches: [ 'main' ]
6+
tags:
7+
- 'v*'
8+
9+
10+
env:
11+
REGISTRY: ghcr.io
12+
IMAGE_NAME: ${{ github.repository }}
13+
14+
jobs:
15+
build-and-push-image:
16+
name: Build and push
17+
runs-on: ubuntu-latest
18+
permissions:
19+
contents: read
20+
packages: write
21+
22+
steps:
23+
- name: Checkout repository
24+
uses: actions/checkout@v2
25+
26+
- name: Log in to the Container registry
27+
uses: docker/login-action@f054a8b539a109f9f41c372932f1ae047eff08c9
28+
with:
29+
registry: ${{ env.REGISTRY }}
30+
username: ${{ github.actor }}
31+
password: ${{ secrets.GITHUB_TOKEN }}
32+
33+
- name: Extract metadata (tags, labels) for Docker
34+
id: meta
35+
uses: docker/metadata-action@98669ae865ea3cffbcbaa878cf57c20bbf1c6c38
36+
with:
37+
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
38+
tags: |
39+
type=ref,event=tag,enable=${{ startsWith(github.ref, 'refs/tags/v') }}
40+
type=raw,value=latest,enable=${{ startsWith(github.ref, 'refs/tags/v') }}
41+
type=raw,value=test,enable=true
42+
43+
- name: Build and push Docker image
44+
uses: docker/build-push-action@ad44023a93711e3deb337508980b4b5e9bcdc5dc
45+
with:
46+
context: .
47+
push: true
48+
tags: ${{ steps.meta.outputs.tags }}
49+
labels: ${{ steps.meta.outputs.labels }}
50+
51+
deploy-testing:
52+
name: Deploy Testing
53+
needs: build-and-push-image
54+
runs-on: [ self-hosted, Linux ]
55+
environment:
56+
name: Testing
57+
url: https://auth.api.test.profcomff.com/
58+
env:
59+
CONTAITER_NAME: com_profcomff_api_auth_test
60+
permissions:
61+
packages: read
62+
63+
steps:
64+
- name: Pull new version
65+
run: docker pull ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:test
66+
67+
- name: Migrate DB
68+
run: |
69+
docker run \
70+
--rm \
71+
--network=web \
72+
--env DB_DSN=${{ secrets.DB_DSN }} \
73+
--name ${{ env.CONTAITER_NAME }}_migration \
74+
${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:test \
75+
alembic upgrade head
76+
77+
- name: Run new version
78+
id: run_test
79+
run: |
80+
docker stop ${{ env.CONTAITER_NAME }} || true && docker rm ${{ env.CONTAITER_NAME }} || true
81+
docker run \
82+
--detach \
83+
--restart always \
84+
--network=web \
85+
--env DB_DSN='${{ secrets.DB_DSN }}' \
86+
--env EMAIL='${{ secrets.EMAIL }}' \
87+
--env EMAIL_PASS='${{ secrets.EMAIL_PASS }}' \
88+
--env SMTP_HOST='smtp.gmail.com' \
89+
--env SMTP_PORT='587' \
90+
--name ${{ env.CONTAITER_NAME }} \
91+
${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:test
92+
93+
deploy-production:
94+
name: Deploy Production
95+
needs: build-and-push-image
96+
if: startsWith(github.ref, 'refs/tags/v')
97+
runs-on: [ self-hosted, Linux ]
98+
environment:
99+
name: Production
100+
url: https://auth.api.profcomff.com/
101+
env:
102+
CONTAITER_NAME: com_profcomff_api_auth
103+
permissions:
104+
packages: read
105+
106+
steps:
107+
- name: Pull new version
108+
run: docker pull ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:latest
109+
110+
- name: Migrate DB
111+
run: |
112+
docker run \
113+
--rm \
114+
--network=web \
115+
--env DB_DSN=${{ secrets.DB_DSN }} \
116+
--name ${{ env.CONTAITER_NAME }}_migration \
117+
${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:latest \
118+
alembic upgrade head
119+
120+
- name: Run new version
121+
id: run_test
122+
run: |
123+
docker stop ${{ env.CONTAITER_NAME }} || true && docker rm ${{ env.CONTAITER_NAME }} || true
124+
docker run \
125+
--detach \
126+
--restart always \
127+
--network=web \
128+
--env DB_DSN='${{ secrets.DB_DSN }}' \
129+
--env EMAIL='${{ secrets.EMAIL }}' \
130+
--env EMAIL_PASS='${{ secrets.EMAIL_PASS }}' \
131+
--env ENABLED_AUTH_METHODS='${{ secrets.ENABLED_AUTH_METHODS }}' \
132+
--env SMTP_HOST='smtp.gmail.com' \
133+
--env SMTP_PORT='587' \
134+
--name ${{ env.CONTAITER_NAME }} \
135+
${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:latest

0 commit comments

Comments
 (0)