Skip to content

add a new prod workflow #1

add a new prod workflow

add a new prod workflow #1

Workflow file for this run

name: Production Deployment
on:
push:
branches:
- ch-update-deployment
release:
types:
- released
- prereleased
jobs:
build_and_deploy_production:
outputs:
image: ${{ steps.export.outputs.image }}
tag: ${{ steps.export.outputs.tag }}
release_version: ${{ steps.version.outputs.version }}
runs-on: ubuntu-latest
env:
image: cranecloud/documentation
namespace: cranecloud-prod
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Get version
id: version
run: |
if [[ $GITHUB_EVENT_NAME == "release" ]]; then
echo "version=${GITHUB_REF#refs/tags/}" >> $GITHUB_OUTPUT
else
echo "version=dev-$(date +'%Y%m%d')-$(git rev-parse --short HEAD)" >> $GITHUB_OUTPUT
fi
- name: Install (Buildx)
uses: docker/setup-buildx-action@v3
- name: Login to Docker Hub
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Login (GCP)
uses: google-github-actions/auth@v2
with:
credentials_json: ${{ secrets.CREDENTIALS_JSON }}
- name: Install (Gcloud)
uses: google-github-actions/setup-gcloud@v2
with:
project_id: crane-cloud-274413
install_components: "gke-gcloud-auth-plugin"
- name: Get Kubernetes credentials
run: |
gcloud container clusters get-credentials staging-cluster --zone us-central1-a
- id: meta
name: Tag
uses: docker/metadata-action@v3
with:
flavor: |
latest=auto
prefix=
images: ${{ env.image }}
tags: |
type=ref,event=branch
type=ref,event=pr
type=sha
type=semver,pattern={{version}}
type=semver,pattern={{major}}.{{minor}}
type=semver,pattern={{major}}
- name: Build
uses: docker/build-push-action@v5
with:
cache-from: type=gha
cache-to: type=gha,mode=max
context: .
file: Dockerfile
labels: ${{ steps.meta.outputs.labels }}
push: true
tags: ${{ steps.meta.outputs.tags }}
- id: export
name: Export
uses: actions/github-script@v7
with:
script: |
const metadata = JSON.parse(`${{ steps.meta.outputs.json }}`)
const fullUrl = metadata.tags.find((t) => t.includes(':sha-'))
if (fullUrl == null) {
core.error('Unable to find sha tag of image')
} else {
const tag = fullUrl.split(':')[1]
core.setOutput('image', fullUrl)
core.setOutput('tag', tag)
}
- name: Update deployment image
run: |
kubectl set image deployment/cranecloud-docs cranecloud-docs=${{ env.image }}:${{ steps.export.outputs.tag }} -n $namespace
- name: Verify deployment
run: |
echo "Waiting for deployment to roll out..."
kubectl rollout status deployment/cranecloud-docs -n $namespace --timeout=300s
echo "Verifying deployment health..."
kubectl get pods -n $namespace -l app=cranecloud-docs -o wide
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}