-
Notifications
You must be signed in to change notification settings - Fork 1
178 lines (150 loc) · 5.41 KB
/
ingest-push.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
165
166
167
168
169
170
171
172
173
174
175
176
177
178
name: ingest push
on:
push:
branches:
- feature/*
- dev/*
pull_request:
types: [closed]
env:
NODE_VERSION: 22.8
IMAGE_NAME: ard-eventhub-europe-west3/ingest
REGISTRY_DOMAIN: europe-west3-docker.pkg.dev
jobs:
security:
name: Check permissions for action runs
runs-on: ubuntu-latest
if: github.event.pull_request.merged == true || github.event_name == 'push'
steps:
- run: |
echo "Security checks passed!"
test:
needs: security
runs-on: ubuntu-latest
steps:
- name: 👀 Checkout Code
uses: actions/checkout@v4
- name: 🏗 Install Node.js
uses: actions/setup-node@v4
with:
node-version: ${{ env.NODE_VERSION }}
- name: 🛠 Setup Bun
uses: oven-sh/setup-bun@v2
with:
bun-version: latest
- name: 📦 Install Dependencies
run: bun install
- name: 🔑 Setup Google Cloud Auth
uses: google-github-actions/auth@v2
with:
credentials_json: ${{ secrets.GCP_GITHUB_SERVICE_ACCOUNT_KEY }}
create_credentials_file: true
- name: 📚 Lint Code
run: bun lint
- name: 🧪 Run Ingest Tests
env:
DD_TRACE_ENABLED: false
DTS_KEYS: ${{ secrets.TEST_DTS_KEYS }}
FIREBASE_API_KEY: ${{ secrets.TEST_FIREBASE_API_KEY }}
GCP_PROJECT_ID: ${{ secrets.GCP_PROJECT_ID }}
PUBSUB_SERVICE_ACCOUNT_EMAIL_INTERNAL: ${{ secrets.PUBSUB_SERVICE_ACCOUNT_EMAIL }}
SERVICE_NAME: ard-eventhub-ingest
STAGE: dev
TEST_USER: ${{ secrets.TEST_USER }}
TEST_USER_PW: ${{ secrets.TEST_USER_PW }}
run: npm run ingest:test
docker:
runs-on: ubuntu-latest
needs: test
outputs:
VERSION: ${{ steps.push.outputs.VERSION }}
steps:
- name: 👀 Checkout Code
uses: actions/checkout@v4
- name: 🔑 Setup Google Cloud Auth
uses: google-github-actions/auth@v2
with:
credentials_json: ${{ secrets.GCP_GITHUB_SERVICE_ACCOUNT_KEY }}
- name: 🔑 Login to Registry
run: 'gcloud auth configure-docker $REGISTRY_DOMAIN'
- name: 🚧 Building docker image
run: 'docker build ./ --file ./Dockerfile -t image'
- name: 🔖 Get Package Version
id: package-version
uses: martinbeentjes/npm-get-version-action@main
- name: 🏷 Tagging & Pushing docker
id: push
run: |
# Strip git ref prefix from version
BRANCH=$(echo "${{ github.ref }}" | sed -e 's,.*/\(.*\),\1,')
# Strip "v" prefix from tag name
[[ "${{ github.ref }}" == "refs/tags/"* ]] && BRANCH=$(echo $BRANCH | sed -e 's/^v//')
# Add custom wrapper syntax
VERSION=${{ steps.package-version.outputs.current-version }}-g${{ github.run_number }}
# Set registry
IMAGE_URI=$REGISTRY_DOMAIN/${{ secrets.GCP_PROJECT_ID }}/$IMAGE_NAME:$VERSION
# Push image to registry
docker tag image $IMAGE_URI
docker push $IMAGE_URI
# Update vars
echo "VERSION=$VERSION" >> $GITHUB_OUTPUT
# Print vars
echo "## Docker Version Tag" >> $GITHUB_STEP_SUMMARY
echo "\`\`\`" >> $GITHUB_STEP_SUMMARY
echo "$VERSION" >> $GITHUB_STEP_SUMMARY
echo "\`\`\`" >> $GITHUB_STEP_SUMMARY
- name: 💬 Comment Version
uses: peter-evans/create-or-update-comment@v4
if: github.event.pull_request.merged == true
with:
issue-number: ${{ github.event.pull_request.number }}
body: |
Docker container is ready!
VERSION:
```
${{ steps.push.outputs.VERSION }}
```
- name: 👋 Logout
run: 'docker logout'
deploy-A-dev-kubernetes:
if: github.event.pull_request.merged == true
environment: dev
needs: docker
runs-on: ubuntu-latest
steps:
- name: 🚀 Trigger deployment to dev
run: |
curl --location --request POST '${{ secrets.ARD_DEPLOYMENT_HOST }}' \
-s -w "%{http_code}\n" \
--header 'Authorization: Basic ${{ secrets.ARD_DEPLOYMENT_TOKEN }}' \
--form 'UMGEBUNG="dev"' \
--form 'COMPONENT="eventhub-ingest"' \
--form 'VERSION="${{ needs.docker.outputs.VERSION }}"'
deploy-B-test-kubernetes:
if: github.event.pull_request.merged == true
environment: test
needs: docker
runs-on: ubuntu-latest
steps:
- name: 🚀 Trigger deployment to test
run: |
curl --location --request POST '${{ secrets.ARD_DEPLOYMENT_HOST }}' \
-s -w "%{http_code}\n" \
--header 'Authorization: Basic ${{ secrets.ARD_DEPLOYMENT_TOKEN }}' \
--form 'UMGEBUNG="test"' \
--form 'COMPONENT="eventhub-ingest"' \
--form 'VERSION="${{ needs.docker.outputs.VERSION }}"'
deploy-C-beta-kubernetes:
if: github.event.pull_request.merged == true
environment: beta
needs: docker
runs-on: ubuntu-latest
steps:
- name: 🚀 Trigger deployment to beta
run: |
curl --location --request POST '${{ secrets.ARD_DEPLOYMENT_HOST }}' \
-s -w "%{http_code}\n" \
--header 'Authorization: Basic ${{ secrets.ARD_DEPLOYMENT_TOKEN }}' \
--form 'UMGEBUNG="beta"' \
--form 'COMPONENT="eventhub-ingest"' \
--form 'VERSION="${{ needs.docker.outputs.VERSION }}"'