Skip to content

Commit a402df9

Browse files
committed
Add CD configuration
1 parent d6f4e51 commit a402df9

File tree

4 files changed

+194
-0
lines changed

4 files changed

+194
-0
lines changed

.github/workflows/deploy.yml

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
name: Production Deploy
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
- master
8+
9+
jobs:
10+
build_image:
11+
runs-on: ubuntu-latest
12+
permissions:
13+
contents: read
14+
packages: write
15+
attestations: write
16+
id-token: write
17+
18+
steps:
19+
- name: Checkout code
20+
uses: actions/checkout@v2
21+
22+
- name: Set up Python
23+
uses: actions/setup-python@v2
24+
with:
25+
python-version: '3.x'
26+
27+
- name: Install docker-stack
28+
run: pip install --upgrade docker-stack
29+
30+
- name: Log in to the Container registry
31+
uses: docker/login-action@v3
32+
with:
33+
registry: ghcr.io
34+
username: ${{ github.actor }}
35+
password: ${{ secrets.GITHUB_TOKEN }}
36+
37+
- name: Build and push Docker images
38+
## build step can use any of the yaml file it doesn't matter
39+
run: docker-stack build --push docker-compose-mainnet.yml
40+
working-directory: deploy
41+
env:
42+
IMAGE_TAG: ${{ github.sha }}
43+
44+
deploy_services:
45+
name: Production Deploy [${{ matrix.network }}]
46+
needs: build_image
47+
strategy:
48+
matrix:
49+
network:
50+
- preview
51+
- preprod
52+
- mainnet
53+
max-parallel: 1
54+
runs-on: builder
55+
steps:
56+
- name: Checkout code
57+
uses: actions/checkout@v2
58+
59+
- name: Set up Python
60+
uses: actions/setup-python@v2
61+
with:
62+
python-version: '3.x'
63+
64+
- name: Install docker-stack
65+
run: pip install --upgrade docker-stack
66+
67+
68+
- name: Deploy stack
69+
run: docker-stack deploy --with-registry-auth dbsync-api docker-compose-${{ matrix.network}}.yml
70+
working-directory: deploy
71+
env:
72+
NETWORK_NAME: ${{ matrix.network }}
73+
COMMIT_SHA: ${{ github.sha }}
74+
IMAGE_TAG: ${{ github.sha }}
75+
DOCKER_HOST: 172.31.0.5:2376
76+
DATABASE_PASSWORD: ${{ secrets.DATABASE_PASSWORD }}
77+
DATABASE_HOST: ${{ vars.DATABASE_HOST }}
78+
ELASTIC_APM_API_KEY: ${{ secrets.ELASTIC_APM_API_KEY }}
79+
ELASTIC_APM_SERVER_URL: ${{ vars.ELASTIC_APM_SERVER_URL }}

deploy/docker-compose-mainnet.yml

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
services:
2+
${NETWORK_NAME}:
3+
image: ghcr.io/cardanoapi/dbsync-api:${IMAGE_TAG}
4+
build:
5+
context: ..
6+
dockerfile: Dockerfile
7+
environment:
8+
- DATABASE_URL=postgres://postgres:${DATABASE_PASSWORD}@${DATABASE_HOST}:5432/dbsync_${NETWORK_NAME}?connection_limit=100
9+
- CORS_ENABLE=true
10+
- PORT=8080
11+
- VIRTUAL_HOST=https://${NETWORK_NAME}.${BASE_HOSTNAME}
12+
- VIRTUAL_HOST=https://${BASE_HOSTNAME}
13+
- ELASTIC_APM_API_KEY=$ELASTIC_APM_API_KEY
14+
- ELASTIC_APM_SERVER_URL=${ELASTIC_APM_SERVER_URL}
15+
- ELASTIC_APM_ENVIRONMENT=${NETWORK_NAME}
16+
networks:
17+
frontend-internal:
18+
dbsync:
19+
default:
20+
aliases:
21+
- dbsync-api-${NETWORK_NAME}
22+
- ${NETWORK_NAME}-dbsync
23+
- dbsync-${NETWORK_NAME}
24+
deploy:
25+
restart_policy:
26+
delay: 10s
27+
28+
placement:
29+
constraints:
30+
- node.labels.dbsync1==true
31+
networks:
32+
frontend-internal:
33+
external: true
34+
default:
35+
name: dbsync-api
36+
attachable: true
37+
dbsync:
38+
external: true
39+

deploy/docker-compose-preprod.yml

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
services:
2+
${NETWORK_NAME}:
3+
image: ghcr.io/cardanoapi/dbsync-api:${IMAGE_TAG}
4+
build:
5+
context: ..
6+
dockerfile: Dockerfile
7+
environment:
8+
- DATABASE_URL=postgres://postgres:${DATABASE_PASSWORD}@${DATABASE_HOST}:5432/dbsync_${NETWORK_NAME}?connection_limit=100
9+
- CORS_ENABLE=true
10+
- PORT=8080
11+
- VIRTUAL_HOST=https://${NETWORK_NAME}.${BASE_HOSTNAME}
12+
- ELASTIC_APM_API_KEY=$ELASTIC_APM_API_KEY
13+
- ELASTIC_APM_SERVER_URL=${ELASTIC_APM_SERVER_URL}
14+
- ELASTIC_APM_ENVIRONMENT=${NETWORK_NAME}
15+
networks:
16+
frontend-internal:
17+
dbsync:
18+
default:
19+
aliases:
20+
- dbsync-api-${NETWORK_NAME}
21+
- ${NETWORK_NAME}-dbsync
22+
- dbsync-${NETWORK_NAME}
23+
deploy:
24+
restart_policy:
25+
delay: 10s
26+
27+
placement:
28+
constraints:
29+
- node.labels.dbsync1==true
30+
networks:
31+
frontend-internal:
32+
external: true
33+
default:
34+
name: dbsync-api
35+
attachable: true
36+
dbsync:
37+
external: true
38+

deploy/docker-compose-preview.yml

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
services:
2+
${NETWORK_NAME}:
3+
image: ghcr.io/cardanoapi/dbsync-api:${IMAGE_TAG}
4+
build:
5+
context: ..
6+
dockerfile: Dockerfile
7+
environment:
8+
- DATABASE_URL=postgres://postgres:${DATABASE_PASSWORD}@${DATABASE_HOST}:5432/dbsync_${NETWORK_NAME}?connection_limit=100
9+
- CORS_ENABLE=true
10+
- PORT=8080
11+
- VIRTUAL_HOST=https://${NETWORK_NAME}.${BASE_HOSTNAME}
12+
- ELASTIC_APM_API_KEY=$ELASTIC_APM_API_KEY
13+
- ELASTIC_APM_SERVER_URL=${ELASTIC_APM_SERVER_URL}
14+
- ELASTIC_APM_ENVIRONMENT=${NETWORK_NAME}
15+
networks:
16+
frontend-internal:
17+
dbsync:
18+
default:
19+
aliases:
20+
- dbsync-api-${NETWORK_NAME}
21+
- ${NETWORK_NAME}-dbsync
22+
- dbsync-${NETWORK_NAME}
23+
deploy:
24+
restart_policy:
25+
delay: 10s
26+
27+
placement:
28+
constraints:
29+
- node.labels.dbsync1==true
30+
networks:
31+
frontend-internal:
32+
external: true
33+
default:
34+
name: dbsync-api
35+
attachable: true
36+
dbsync:
37+
external: true
38+

0 commit comments

Comments
 (0)