-
Notifications
You must be signed in to change notification settings - Fork 0
214 lines (182 loc) · 7.22 KB
/
Copy pathdeploy-dev.yml
File metadata and controls
214 lines (182 loc) · 7.22 KB
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
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
name: 🚀 Deploy to Development
on:
push:
branches: [ development ]
workflow_dispatch: # Manual trigger
inputs:
tag:
description: 'Image tag (optional)'
required: false
default: 'latest'
jobs:
build:
runs-on: ubuntu-latest
outputs:
artifact_name: ${{ steps.repo_name.outputs.artifact_name }}
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Set Repository Name
id: repo_name
run: |
# For Docker image
echo "name=$(echo ${{ github.repository }} | tr '[:upper:]' '[:lower:]')" >> $GITHUB_OUTPUT
# For artifact name
echo "artifact_name=$(echo ${{ github.repository }} | tr '[:upper:]' '[:lower:]' | tr '/' '-')" >> $GITHUB_OUTPUT
- name: Set up JDK
uses: actions/setup-java@v3
with:
java-version: '17'
distribution: 'temurin'
cache: 'maven'
- name: Cache Maven packages
uses: actions/cache@v3
with:
path: ~/.m2
key: ${{ runner.os }}-m2-${{ hashFiles('**/pom.xml') }}
restore-keys: ${{ runner.os }}-m2
- name: Grant execute permission for mvnw
run: chmod +x mvnw
- name: Build
run: |
chmod +x mvnw
./mvnw clean package -DskipTests
# Copy to the correct location for Docker
mkdir -p build/quarkus-app/
cp -r target/quarkus-app/* build/quarkus-app/
- name: Upload Build Artifact
uses: actions/upload-artifact@v4
with:
name: ${{ steps.repo_name.outputs.artifact_name }}
path: build/quarkus-app/
package:
needs: build
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
outputs:
image_tag: ${{ steps.generate_tag.outputs.version }}
repo_name: ${{ steps.repo_name.outputs.name }}
steps:
- uses: actions/checkout@v3
- name: Set Repository Name
id: repo_name
run: |
echo "name=$(echo ${{ github.repository }} | tr '[:upper:]' '[:lower:]')" >> $GITHUB_OUTPUT
- name: Download Build Artifact
uses: actions/download-artifact@v4
with:
name: ${{ needs.build.outputs.artifact_name }}
path: build/quarkus-app/
- name: Generate Version Tag
id: generate_tag
run: |
if [ "${{ github.event_name }}" = "workflow_dispatch" ] && [ "${{ github.event.inputs.tag }}" != "latest" ]; then
echo "version=${{ github.event.inputs.tag }}" >> $GITHUB_OUTPUT
else
echo "version=$(date +'%Y%m%d')-${GITHUB_SHA::7}" >> $GITHUB_OUTPUT
fi
- name: Login to GitHub Container Registry
uses: docker/login-action@v2
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.PACKAGE_PAT }}
- name: Build and Push Docker Image
run: |
docker build -t ghcr.io/${{ steps.repo_name.outputs.name }}:${{ steps.generate_tag.outputs.version }} .
docker push ghcr.io/${{ steps.repo_name.outputs.name }}:${{ steps.generate_tag.outputs.version }}
deploy:
needs: package
runs-on: ubuntu-latest
environment: development
outputs:
route_host: ${{ steps.route_host.outputs.name }}
steps:
- uses: actions/checkout@v3
- name: Set App Name
id: app_name
run: |
echo "name=$(echo ${{ github.event.repository.name }} | tr '[:upper:]' '[:lower:]' | tr '_' '-')" >> $GITHUB_OUTPUT
- name: Install OpenShift CLI
run: |
curl -LO https://mirror.openshift.com/pub/openshift-v4/clients/ocp/latest/openshift-client-linux.tar.gz
tar -xvf openshift-client-linux.tar.gz -C /usr/local/bin
chmod +x /usr/local/bin/oc
- name: Install Helm
uses: azure/setup-helm@v3
with:
version: v3.12.0
- name: Login to OpenShift
run: |
oc login --token=${{ secrets.OSC_DEV_TOKEN }} --server=${{ secrets.OSC_SERVER }}
- name: Clone Platform Config
uses: actions/checkout@v3
with:
repository: PTSS-Support/platform-config
path: platform-config
token: ${{ secrets.PLATFORM_CONFIG_PAT }}
- name: Apply Platform Configs
run: |
NAMESPACE=${{ vars.OSC_DEV_PROJECT }}
# Apply common configs
for config_type in configmaps secrets; do
for path in \
"platform-config/common/${config_type}" \
"platform-config/apps/${{ steps.app_name.outputs.name }}/${config_type}" \
"platform-config/environments/dev/common/${config_type}" \
"platform-config/environments/dev/apps/${{ steps.app_name.outputs.name }}/${config_type}"; do
if [ -d "${path}" ] && [ "$(ls -A ${path})" ]; then
oc apply -f "${path}" -n ${NAMESPACE}
fi
done
done
- name: Set Route Host
id: route_host
run: |
ROUTE_HOST="${{ steps.app_name.outputs.name }}-dev.${{ vars.APPS_DOMAIN }}"
echo "name=${ROUTE_HOST}" >> $GITHUB_OUTPUT
- name: Deploy to OpenShift Dev
run: |
helm upgrade --install ${{ steps.app_name.outputs.name }} ./helm \
--namespace ${{ vars.OSC_DEV_PROJECT }} \
--values ./helm/values-dev.yaml \
--set image.registry=ghcr.io \
--set image.repository=${{ needs.package.outputs.repo_name }} \
--set image.tag=${{ needs.package.outputs.image_tag }} \
--set route.host=${{ steps.route_host.outputs.name }}
- name: Wait for Deployment
run: |
oc rollout status deployment/${{ steps.app_name.outputs.name }} -n ${{ vars.OSC_DEV_PROJECT }} --timeout=150s
- name: Verify Deployment
run: |
# Check if all pods are ready
READY_PODS=$(oc get deployment ${{ steps.app_name.outputs.name }} -n ${{ vars.OSC_DEV_PROJECT }} -o jsonpath='{.status.readyReplicas}')
DESIRED_PODS=$(oc get deployment ${{ steps.app_name.outputs.name }} -n ${{ vars.OSC_DEV_PROJECT }} -o jsonpath='{.spec.replicas}')
if [ "$READY_PODS" != "$DESIRED_PODS" ]; then
echo "❌ Deployment verification failed: $READY_PODS/$DESIRED_PODS pods ready"
exit 1
fi
echo "✅ Deployment verification successful: $READY_PODS/$DESIRED_PODS pods ready"
test:
needs: deploy
runs-on: ubuntu-latest
environment: development
steps:
- name: Checkout Repository
uses: actions/checkout@v3
- name: Install k6
run: |
wget https://github.com/grafana/k6/releases/download/v0.46.0/k6-v0.46.0-linux-amd64.tar.gz
tar -xzf k6-v0.46.0-linux-amd64.tar.gz
sudo cp k6-v0.46.0-linux-amd64/k6 /usr/local/bin/
k6 version
- name: Run k6 Performance Tests
run: |
ROUTE_HOST=${{ needs.deploy.outputs.route_host }} k6 run src/test/kotlin/org/ptss/support/k6/scenarios/main.js
- name: Run E2E Tests
run: |
echo "TODO: Add E2E tests using your preferred testing framework"
echo "These tests should run against the newly deployed dev environment"