-
Notifications
You must be signed in to change notification settings - Fork 24
101 lines (86 loc) · 3.18 KB
/
deploy-to-prod.yaml
File metadata and controls
101 lines (86 loc) · 3.18 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
name: Deploy to Prod
on:
workflow_dispatch:
inputs:
version:
description: 'Version tag to promote (e.g., v1.2.3)'
required: true
type: string
permissions: write-all
env:
OPENSHIFT_NAMESPACE_TOOLS: 6cdc9e-tools
OPENSHIFT_NAMESPACE_PROD: 6cdc9e-prod
IMAGE_NAME: eagle-admin
APP_NAME: eagle-admin
jobs:
validate:
name: Validate Version
runs-on: ubuntu-latest
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: Verify Git tag exists
run: |
if ! git rev-parse "${{ inputs.version }}" >/dev/null 2>&1; then
echo "Error: Git tag ${{ inputs.version }} does not exist"
echo "Please deploy to test first to create the version"
exit 1
fi
echo "Git tag ${{ inputs.version }} verified"
deploy:
name: Deploying ${{ inputs.version }} to Prod
needs: validate
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: Verify image tag exists
run: |
echo "Verifying image tag ${{ inputs.version }} exists..."
if ! oc -n ${{ env.OPENSHIFT_NAMESPACE_TOOLS }} get imagestreamtag ${{ env.IMAGE_NAME }}:${{ inputs.version }} &>/dev/null; then
echo "Error: Image tag ${{ inputs.version }} does not exist"
exit 1
fi
echo "Image tag verified"
- name: Tag version as prod
run: |
echo "Tagging ${{ inputs.version }} as prod..."
oc -n ${{ env.OPENSHIFT_NAMESPACE_TOOLS }} tag \
${{ env.IMAGE_NAME }}:${{ inputs.version }} ${{ env.IMAGE_NAME }}:prod
- name: Install Helm
run: |
curl -fsSL https://raw.githubusercontent.com/helm/helm/main/scripts/get-helm-3 | bash
helm version
- name: Deploy with Helm
run: |
helm upgrade --install ${{ env.APP_NAME }} ./helm/${{ env.APP_NAME }} \
--namespace ${{ env.OPENSHIFT_NAMESPACE_PROD }} \
--values ./helm/${{ env.APP_NAME }}/values-prod.yaml \
--set image.tag=prod \
--wait --timeout=5m
- name: Verify deployment
run: |
echo "Deployment successful!"
oc get pods -n ${{ env.OPENSHIFT_NAMESPACE_PROD }} -l app.kubernetes.io/name=${{ env.APP_NAME }}
echo "Deployment successful!"
oc get pods -n ${{ env.OPENSHIFT_NAMESPACE_PROD }} -l app.kubernetes.io/name=${{ env.APP_NAME }}