-
Notifications
You must be signed in to change notification settings - Fork 24
172 lines (146 loc) · 6.23 KB
/
deploy-to-test.yaml
File metadata and controls
172 lines (146 loc) · 6.23 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
# =============================================================================
# Deploy to Test
# =============================================================================
# Manually triggered workflow to deploy a version to test environment.
# Requires semantic version tag (v1.2.3).
# Creates Git tag and GitHub Release if this is a new version.
# =============================================================================
name: Deploy to Test
on:
workflow_dispatch:
inputs:
version:
description: 'Version tag (e.g., v1.2.3)'
required: true
type: string
permissions: write-all
env:
OPENSHIFT_NAMESPACE_TOOLS: 6cdc9e-tools
OPENSHIFT_NAMESPACE_TEST: 6cdc9e-test
IMAGE_NAME: eagle-api
APP_NAME: eagle-api
jobs:
validate:
name: Validate Version
runs-on: ubuntu-latest
outputs:
tag_exists: ${{ steps.check-tag.outputs.exists }}
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Validate version format
run: |
if [[ ! "${{ inputs.version }}" =~ ^v[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
echo "Error: Version must be in format v1.2.3"
exit 1
fi
- name: Check if tag exists
id: check-tag
run: |
if git rev-parse "${{ inputs.version }}" >/dev/null 2>&1; then
echo "exists=true" >> $GITHUB_OUTPUT
echo "Tag ${{ inputs.version }} already exists"
else
echo "exists=false" >> $GITHUB_OUTPUT
echo "Tag ${{ inputs.version }} does not exist - will create"
fi
release:
name: Create Release
needs: validate
if: needs.validate.outputs.tag_exists == 'false'
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Create Git tag
run: |
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
git tag -a "${{ inputs.version }}" -m "Release ${{ inputs.version }}"
git push origin "${{ inputs.version }}"
- name: Create GitHub Release
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
gh release create "${{ inputs.version }}" \
--title "Release ${{ inputs.version }}" \
--generate-notes
deploy:
name: Deploying ${{ inputs.version }} to Test
needs: [validate, release]
if: always() && needs.validate.result == 'success'
runs-on: ubuntu-latest
steps:
- name: Checkout repository at version tag
uses: actions/checkout@v4
with:
ref: ${{ inputs.version }}
- name: Install OpenShift CLI
uses: redhat-actions/openshift-tools-installer@v1
with:
oc: "4.14"
- name: Log into OpenShift
uses: redhat-actions/oc-login@v1
with:
openshift_server_url: ${{ secrets.OPENSHIFT_URL }}
openshift_token: ${{ secrets.OPENSHIFT_TOKEN }}
namespace: ${{ env.OPENSHIFT_NAMESPACE_TOOLS }}
- name: Check if image exists and tag if needed
run: |
if oc -n ${{ env.OPENSHIFT_NAMESPACE_TOOLS }} get imagestreamtag ${{ env.IMAGE_NAME }}:${{ inputs.version }} &>/dev/null; then
echo "Image tag ${{ inputs.version }} already exists - using existing image"
else
echo "Image tag ${{ inputs.version }} does not exist - tagging from ci-latest"
oc -n ${{ env.OPENSHIFT_NAMESPACE_TOOLS }} tag \
${{ env.IMAGE_NAME }}:ci-latest ${{ env.IMAGE_NAME }}:${{ inputs.version }}
fi
- name: Tag version as test
run: |
echo "Tagging ${{ inputs.version }} as test..."
oc -n ${{ env.OPENSHIFT_NAMESPACE_TOOLS }} tag \
${{ env.IMAGE_NAME }}:${{ inputs.version }} ${{ env.IMAGE_NAME }}:test
- name: Install Helm
run: |
curl -fsSL https://raw.githubusercontent.com/helm/helm/main/scripts/get-helm-3 | bash
helm version
- name: Migrate MongoDB from DeploymentConfig to Deployment
run: |
echo "Checking MongoDB deployment status..."
# Check if new Helm-managed MongoDB Deployment exists
if oc get deployment eagle-api-mongodb -n ${{ env.OPENSHIFT_NAMESPACE_TEST }} &>/dev/null; then
echo "✓ MongoDB Deployment already exists (Helm-managed)"
else
echo "MongoDB Deployment not found - migrating from DeploymentConfig..."
# Check if legacy DeploymentConfig exists
if oc get dc eagle-api-mongodb -n ${{ env.OPENSHIFT_NAMESPACE_TEST }} &>/dev/null; then
echo "Scaling down legacy MongoDB DeploymentConfig to 0 replicas..."
oc scale dc/eagle-api-mongodb --replicas=0 -n ${{ env.OPENSHIFT_NAMESPACE_TEST }}
echo "Waiting for MongoDB pod to terminate..."
oc wait --for=delete pod -l name=eagle-api-mongodb -n ${{ env.OPENSHIFT_NAMESPACE_TEST }} --timeout=120s || true
echo "✓ Legacy DeploymentConfig scaled down - Helm will create new Deployment"
else
echo "No legacy DeploymentConfig found - proceeding with fresh Helm install"
fi
fi
- name: Deploy with Helm
run: |
helm upgrade --install ${{ env.APP_NAME }} ./helm/${{ env.APP_NAME }} \
--namespace ${{ env.OPENSHIFT_NAMESPACE_TEST }} \
--values ./helm/${{ env.APP_NAME }}/values-test.yaml \
--set image.tag=test \
--wait --timeout=5m
- name: Verify deployment
run: |
echo "Deployment successful!"
oc get pods -n ${{ env.OPENSHIFT_NAMESPACE_TEST }} -l app.kubernetes.io/name=${{ env.APP_NAME }}
# Verify MongoDB deployment if enabled
if oc get deployment eagle-api-mongodb -n ${{ env.OPENSHIFT_NAMESPACE_TEST }} &>/dev/null; then
echo ""
echo "Verifying MongoDB deployment..."
oc rollout status deployment/eagle-api-mongodb -n ${{ env.OPENSHIFT_NAMESPACE_TEST }} --timeout=3m
echo "✓ MongoDB deployment verified"
fi