-
Notifications
You must be signed in to change notification settings - Fork 0
119 lines (102 loc) · 3.73 KB
/
room-api.yaml
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
name: room-api-cicd
on:
push:
paths:
- room-api/**
- .github/workflows/room-api.yaml
- scripts/az-bootstrap-containerapp.bash
workflow_dispatch:
permissions:
# required for federated credentials to access azure
id-token: write
# required for federated credentials to access azure
contents: read
# required to push to ghcr
packages: write
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Login to ghcr
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Build
run: |
tags="-t ghcr.io/christianfosli/stellerom/room-api:${{ github.sha }}"
if [[ "${{ github.ref }}" == "refs/heads/main" ]]; then
printf 'Banch is main! Tagging with latest\n'
tags="$tags -t ghcr.io/christianfosli/stellerom/room-api:latest"
fi
cd room-api
docker buildx build \
--cache-from "type=gha,scope=room-api" \
--cache-to "type=gha,mode=max,scope=room-api" \
$tags \
.
env:
DOCKER_BUILDKIT: "1"
- name: Push
run: |
docker push --all-tags ghcr.io/christianfosli/stellerom/room-api
deploy_dev:
needs: build
runs-on: ubuntu-latest
environment: Development
steps:
- uses: actions/checkout@v4
- name: Azure login
uses: azure/login@v2
with:
client-id: ${{ secrets.AZ_CLIENT_ID }}
tenant-id: ${{ secrets.AZ_TENANT_ID }}
subscription-id: ${{ secrets.AZ_SUBS_ID }}
- name: Infra
run: ./scripts/az-bootstrap-containerapp.bash
env:
ENVIRONMENT: dev
SERVICE_NAME: room-api
TARGET_PORT: 3000
- name: Deploy
run: |
set -eo pipefail
az containerapp secret set -n capp-stellerom-room-api-dev -g rg-stellerom-dev \
--secrets "db-connstr=$DB_CONNSTR"
az containerapp update -n capp-stellerom-room-api-dev -g rg-stellerom-dev \
--image ghcr.io/christianfosli/stellerom/room-api:${{ github.sha }} \
--min-replicas 0 --max-replicas 2 \
--set-env-vars "ROOM_API_DB_CONNSTR=secretref:db-connstr" "ROOM_API_DB_NAME=room-api-dev"
env:
DB_CONNSTR: "mongodb+srv://${{ secrets.ROOM_API_DB_USERNAME }}:${{ secrets.ROOM_API_DB_PASSWORD}}@azure-stellerom.au87e49.mongodb.net"
deploy_prod:
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
needs: deploy_dev
runs-on: ubuntu-latest
environment: Production
steps:
- uses: actions/checkout@v4
- name: Azure login
uses: azure/login@v2
with:
client-id: ${{ secrets.AZ_CLIENT_ID }}
tenant-id: ${{ secrets.AZ_TENANT_ID }}
subscription-id: ${{ secrets.AZ_SUBS_ID }}
- name: Infra
run: ./scripts/az-bootstrap-containerapp.bash
env:
ENVIRONMENT: prod
SERVICE_NAME: room-api
TARGET_PORT: 3000
- name: Deploy
run: |
az containerapp secret set -n capp-stellerom-room-api-prod -g rg-stellerom-prod \
--secrets "db-connstr=$DB_CONNSTR"
az containerapp update -n capp-stellerom-room-api-prod -g rg-stellerom-prod \
--image ghcr.io/christianfosli/stellerom/room-api:${{ github.sha }} \
--min-replicas 1 --max-replicas 5 \
--set-env-vars "ROOM_API_DB_CONNSTR=secretref:db-connstr" "ROOM_API_DB_NAME=room-api-prod"
env:
DB_CONNSTR: "mongodb+srv://${{ secrets.ROOM_API_DB_USERNAME }}:${{ secrets.ROOM_API_DB_PASSWORD}}@azure-stellerom.au87e49.mongodb.net"