-
Notifications
You must be signed in to change notification settings - Fork 2
164 lines (151 loc) · 5.66 KB
/
docker.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
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
name: Docker Image CI
on:
workflow_dispatch:
push:
paths-ignore:
- 'docs/**'
branches:
- '**'
tags:
- v*
env:
DOCKER_BUILDKIT: 1
concurrency:
group: ${{ github.ref }}
cancel-in-progress: true
jobs:
build:
services:
postgres:
image: kartoza/postgis:15-3.4
env:
ALLOW_IP_RANGE: "0.0.0.0/0" # we need that to allow 'api' to connect
POSTGRES_USER: docker
POSTGRES_PASS: docker
DB_NAME: gis
options: --health-cmd pg_isready --health-interval 10s --health-timeout 5s --health-retries 5
ports:
- 5432:5432
runs-on: ubuntu-latest
outputs:
image: "agencebio/cartobio-api:${{ steps.publish.outputs.tag }}"
version: ${{ steps.version.outputs.name }}
steps:
- uses: actions/checkout@v4
- uses: docker/setup-buildx-action@v3
- run: docker build -t agencebio/cartobio-api .
- name: Get services bridge network name
id: network
run: echo "SERVICES_NETWORK=$(docker network ls --filter name=github --format '{{.Name}}')" >> "${GITHUB_ENV}"
- name: Test the Docker image
run: >
docker run
-e DATABASE_URL
-e NOTIFICATIONS_AB_SSO_CLIENT_ID
-e NOTIFICATIONS_AB_SSO_CLIENT_SECRET
-e NOTIFICATIONS_AB_ENDPOINT
-e CARTOBIO_JWT_SECRET
-e GEOFOLIA_OAUTH_HOST
-e GEOFOLIA_OAUTH_TENANT
-e GEOFOLIA_OAUTH_CLIENT_ID
-e GEOFOLIA_OAUTH_CLIENT_SECRET
-e GEOFOLIA_API_HOST
-e GEOFOLIA_API_SUBSCRIPTION_KEY
-e CI
--network ${{ env.SERVICES_NETWORK }}
agencebio/cartobio-api npm test
env:
CI: true
DATABASE_URL: postgresql://docker:docker@postgres:5432/gis
NOTIFICATIONS_AB_ENDPOINT: https://preprod-notifications.agencebio.org:444
CARTOBIO_JWT_SECRET: zzzzz
GEOFOLIA_OAUTH_HOST: https://login.microsoftonline.com
GEOFOLIA_OAUTH_TENANT: "test"
GEOFOLIA_OAUTH_CLIENT_ID: "test"
GEOFOLIA_OAUTH_CLIENT_SECRET: "test"
GEOFOLIA_API_HOST: "https://test-api.azure-api.net/"
GEOFOLIA_API_SUBSCRIPTION_KEY: "test"
NOTIFICATIONS_AB_SSO_CLIENT_ID: "test"
NOTIFICATIONS_AB_SSO_CLIENT_SECRET: "test"
- name: Login to Docker Hub
run: echo "${{ secrets.DOCKER_HUB_ACCESS_TOKEN }}" | docker login -u ${{ secrets.DOCKER_HUB_USERNAME }} --password-stdin
- name: Assign Docker ref
id: publish
run: |
if [[ $GITHUB_REF == 'refs/heads/main' ]]; then
echo "tag=latest" >> $GITHUB_OUTPUT
else
echo "tag=${GITHUB_REF_NAME#v*}" >> $GITHUB_OUTPUT
fi
- name: Publish to Docker Hub
if: ${{ github.ref == 'refs/heads/main' || github.ref == 'refs/heads/test' || startsWith(github.ref, 'refs/tags/') }}
run: |
docker tag agencebio/cartobio-api agencebio/cartobio-api:${{ steps.publish.outputs.tag }}
docker push agencebio/cartobio-api:${{ steps.publish.outputs.tag }}
- name: Get package.json version
id: version
run: echo name=$(node -p "require('./package.json').version") >> $GITHUB_OUTPUT
deploy-staging:
needs: [build]
if: github.ref == 'refs/heads/main'
environment: staging
runs-on: ubuntu-latest
steps:
- uses: garygrossgarten/[email protected]
with:
host: ${{ secrets.AGENCEBIO_SSH_HOST }}
username: ${{ secrets.AGENCEBIO_SSH_USERNAME }}
privateKey: ${{ secrets.AGENCEBIO_SSH_PRIVATE_KEY }}
command: |
docker pull ${{ needs.build.outputs.image }} \
&& docker stop cartobio-api-staging \
&& docker container rm cartobio-api-staging \
&& docker run -d --restart unless-stopped \
-p 127.0.0.1:7500:8000 \
--env-file=.env.cartobio-api-staging \
--env SENTRY_RELEASE=${{ needs.build.outputs.version }}-dev-${{ github.sha }} \
--name cartobio-api-staging \
${{ needs.build.outputs.image }}
deploy-test:
needs: [build]
if: github.ref == 'refs/heads/test'
environment: test
runs-on: ubuntu-latest
steps:
- uses: garygrossgarten/[email protected]
with:
host: ${{ secrets.AGENCEBIO_SSH_HOST }}
username: ${{ secrets.AGENCEBIO_SSH_USERNAME }}
privateKey: ${{ secrets.AGENCEBIO_SSH_PRIVATE_KEY }}
command: |
docker pull ${{ needs.build.outputs.image }} \
&& docker stop cartobio-api-test \
&& docker container rm cartobio-api-test \
&& docker run -d --restart unless-stopped \
--network cartobio-test \
-p 127.0.0.1:7501:8000 \
--env-file=.env.cartobio-api-test \
--env SENTRY_RELEASE=${{ needs.build.outputs.version }}-test-${{ github.sha }} \
--name cartobio-api-test \
${{ needs.build.outputs.image }} \
&& docker network connect bridge cartobio-api-test
deploy-production:
needs: [build]
if: startsWith(github.ref, 'refs/tags/')
environment: production
runs-on: ubuntu-latest
steps:
- uses: garygrossgarten/[email protected]
with:
host: ${{ secrets.AGENCEBIO_SSH_HOST }}
username: ${{ secrets.AGENCEBIO_SSH_USERNAME }}
privateKey: ${{ secrets.AGENCEBIO_SSH_PRIVATE_KEY }}
command: |
docker pull ${{ needs.build.outputs.image }} \
&& docker stop cartobio-api-production \
&& docker container rm cartobio-api-production \
&& docker run -d --restart unless-stopped \
-p 127.0.0.1:8000:8000 \
--env-file=.env.cartobio-api-production \
--name cartobio-api-production \
${{ needs.build.outputs.image }}