Skip to content

Commit a632377

Browse files
committed
add a new prod workflow
1 parent 61b8967 commit a632377

1 file changed

Lines changed: 116 additions & 0 deletions

File tree

.github/workflows/prod.yml

Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
name: Production Deployment
2+
3+
on:
4+
push:
5+
branches:
6+
- ch-update-deployment
7+
release:
8+
types:
9+
- released
10+
- prereleased
11+
12+
jobs:
13+
build_and_deploy_production:
14+
outputs:
15+
image: ${{ steps.export.outputs.image }}
16+
tag: ${{ steps.export.outputs.tag }}
17+
release_version: ${{ steps.version.outputs.version }}
18+
19+
runs-on: ubuntu-latest
20+
env:
21+
image: cranecloud/documentation
22+
namespace: cranecloud-prod
23+
24+
steps:
25+
- name: Checkout code
26+
uses: actions/checkout@v4
27+
28+
- name: Get version
29+
id: version
30+
run: |
31+
if [[ $GITHUB_EVENT_NAME == "release" ]]; then
32+
echo "version=${GITHUB_REF#refs/tags/}" >> $GITHUB_OUTPUT
33+
else
34+
echo "version=dev-$(date +'%Y%m%d')-$(git rev-parse --short HEAD)" >> $GITHUB_OUTPUT
35+
fi
36+
37+
- name: Install (Buildx)
38+
uses: docker/setup-buildx-action@v3
39+
40+
- name: Login to Docker Hub
41+
uses: docker/login-action@v2
42+
with:
43+
username: ${{ secrets.DOCKERHUB_USERNAME }}
44+
password: ${{ secrets.DOCKERHUB_TOKEN }}
45+
46+
- name: Login (GCP)
47+
uses: google-github-actions/auth@v2
48+
with:
49+
credentials_json: ${{ secrets.CREDENTIALS_JSON }}
50+
51+
- name: Install (Gcloud)
52+
uses: google-github-actions/setup-gcloud@v2
53+
with:
54+
project_id: crane-cloud-274413
55+
install_components: "gke-gcloud-auth-plugin"
56+
57+
- name: Get Kubernetes credentials
58+
run: |
59+
gcloud container clusters get-credentials staging-cluster --zone us-central1-a
60+
61+
- id: meta
62+
name: Tag
63+
uses: docker/metadata-action@v3
64+
with:
65+
flavor: |
66+
latest=auto
67+
prefix=
68+
images: ${{ env.image }}
69+
tags: |
70+
type=ref,event=branch
71+
type=ref,event=pr
72+
type=sha
73+
type=semver,pattern={{version}}
74+
type=semver,pattern={{major}}.{{minor}}
75+
type=semver,pattern={{major}}
76+
77+
- name: Build
78+
uses: docker/build-push-action@v5
79+
with:
80+
cache-from: type=gha
81+
cache-to: type=gha,mode=max
82+
context: .
83+
file: Dockerfile
84+
labels: ${{ steps.meta.outputs.labels }}
85+
push: true
86+
tags: ${{ steps.meta.outputs.tags }}
87+
88+
- id: export
89+
name: Export
90+
uses: actions/github-script@v7
91+
with:
92+
script: |
93+
const metadata = JSON.parse(`${{ steps.meta.outputs.json }}`)
94+
const fullUrl = metadata.tags.find((t) => t.includes(':sha-'))
95+
if (fullUrl == null) {
96+
core.error('Unable to find sha tag of image')
97+
} else {
98+
const tag = fullUrl.split(':')[1]
99+
core.setOutput('image', fullUrl)
100+
core.setOutput('tag', tag)
101+
}
102+
103+
- name: Update deployment image
104+
run: |
105+
kubectl set image deployment/cranecloud-docs cranecloud-docs=${{ env.image }}:${{ steps.export.outputs.tag }} -n $namespace
106+
107+
- name: Verify deployment
108+
run: |
109+
echo "Waiting for deployment to roll out..."
110+
kubectl rollout status deployment/cranecloud-docs -n $namespace --timeout=300s
111+
112+
echo "Verifying deployment health..."
113+
kubectl get pods -n $namespace -l app=cranecloud-docs -o wide
114+
115+
env:
116+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

0 commit comments

Comments
 (0)