-
Notifications
You must be signed in to change notification settings - Fork 2
107 lines (94 loc) · 3.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
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:
runs-on: ubuntu-latest
outputs:
image: "agencebio/cartobio-api:${{ steps.publish.outputs.tag }}"
version: ${{ steps.version.outputs.name }}
steps:
- uses: actions/checkout@v3
- uses: docker/setup-buildx-action@v2
- run: docker build -t agencebio/cartobio-api .
- name: Test the Docker image
run: docker run -e NOTIFICATIONS_AB_CARTOBIO_USER -e NOTIFICATIONS_AB_CARTOBIO_PASSWORD -e NOTIFICATIONS_AB_SSO_CLIENT_ID -e NOTIFICATIONS_AB_SSO_CLIENT_SECRET -e NOTIFICATIONS_AB_ENDPOINT -e CARTOBIO_JWT_SECRET -e CI agencebio/cartobio-api npm test
env:
CI: true
NOTIFICATIONS_AB_ENDPOINT: https://preprod-notifications.agencebio.org:444
CARTOBIO_JWT_SECRET: "${{ secrets.CARTOBIO_JWT_SECRET }}"
NOTIFICATIONS_AB_SSO_CLIENT_ID: "test"
NOTIFICATIONS_AB_SSO_CLIENT_SECRET: "test"
NOTIFICATIONS_AB_CARTOBIO_USER: "test"
NOTIFICATIONS_AB_CARTOBIO_PASSWORD: "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' || 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-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 }}