Deploy to Production #8
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Deploy to Production | |
concurrency: prod | |
on: | |
workflow_dispatch: | |
jobs: | |
branch-check: | |
name: Environment Check | |
runs-on: ubuntu-latest | |
environment: production | |
steps: | |
- name: Pass | |
run: echo "Passed check" | |
build-push: | |
name: Build and Push Images | |
needs: [branch-check] | |
uses: ./.github/workflows/cd.yaml | |
with: | |
tag: prod | |
secrets: inherit | |
deploy: | |
name: Deploy with SSH | |
needs: [build-push] | |
runs-on: ubuntu-latest | |
steps: | |
- name: SSH and Helm Install | |
uses: appleboy/[email protected] | |
with: | |
host: ${{ secrets.SSH_HOST }} | |
username: root | |
key: ${{ secrets.SSH_KEY }} | |
script: | | |
set -e # Exit immediately if a command fails | |
cd ./infra | |
# Check if the Helm release exists | |
if helm status bt-prod-app ; then | |
# Restart deployments if the Helm release exists | |
kubectl rollout restart deployment bt-prod-app-backend | |
kubectl rollout restart deployment bt-prod-app-frontend | |
else | |
# Install the Helm release if it doesn't exist | |
helm install bt-prod-app ./app --namespace=bt \ | |
--set host=stanfurdtime.com | |
fi | |
# Check container status | |
kubectl rollout status --timeout=180s deployment bt-prod-app-backend | |
kubectl rollout status --timeout=180s deployment bt-prod-app-frontend |