Skip to content

Commit

Permalink
build and push helm charts in actions
Browse files Browse the repository at this point in the history
  • Loading branch information
maxmwang committed Nov 18, 2024
1 parent 311aa3b commit 67f384f
Show file tree
Hide file tree
Showing 4 changed files with 83 additions and 33 deletions.
56 changes: 25 additions & 31 deletions .github/workflows/cd-dev.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -30,44 +30,38 @@ jobs:
echo "sha_short=$(git rev-parse --short ${{ github.sha }})" >> $GITHUB_OUTPUT
build-push:
name: Build and Push Images
name: Build and Push Images and Charts
needs: [compute-sha]
uses: ./.github/workflows/cd.yaml
with:
tag: ${{ needs.compute-sha.outputs.sha_short }}
image_tag: ${{ needs.compute-sha.outputs.sha_short }}
chart_ver: 0.1.0-dev.${{ needs.compute-sha.outputs.sha_short }}
secrets: inherit

deploy:
name: Deploy with SSH
name: SSH and Deploy
needs: [compute-sha, build-push]
runs-on: ubuntu-latest
environment: development

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
uses: ./.github/workflows/deploy.yaml
with:
environment: development
script: |
set -e # Exit immediately if a command fails
cd ./infra
# Uninstall the old helm chart if it exists
helm uninstall bt-dev-app-${{ needs.compute-sha.outputs.sha_short }} || true
# Uninstall the old helm chart if it exists
helm uninstall bt-dev-app-${{ needs.compute-sha.outputs.sha_short }} || true
# Install new chart
helm install bt-dev-app-${{ needs.compute-sha.outputs.sha_short }} ./app --namespace=bt \
--set env=dev \
--set ttl=${{ inputs.ttl }} \
--set-string frontend.image.tag=${{ needs.compute-sha.outputs.sha_short }} \
--set-string backend.image.tag=${{ needs.compute-sha.outputs.sha_short }} \
--set host=${{ needs.compute-sha.outputs.sha_short }}.stanfurdtime.com \
--set mongoUri=mongodb://bt-dev-mongo-mongodb.bt.svc.cluster.local:27017/bt \
--set redisUri=redis://bt-dev-redis-master.bt.svc.cluster.local:6379 \
--set nodeEnv=development
# Install new chart
helm install bt-dev-app-${{ needs.compute-sha.outputs.sha_short }} ./app --namespace=bt \
--set env=dev \
--set ttl=${{ inputs.ttl }} \
--set-string frontend.image.tag=${{ needs.compute-sha.outputs.sha_short }} \
--set-string backend.image.tag=${{ needs.compute-sha.outputs.sha_short }} \
--set host=${{ needs.compute-sha.outputs.sha_short }}.dev.stanfurdtime.com \
--set mongoUri=mongodb://bt-dev-mongo-mongodb.bt.svc.cluster.local:27017/bt \
--set redisUri=redis://bt-dev-redis-master.bt.svc.cluster.local:6379 \
--set nodeEnv=development
# Check container status
kubectl rollout status --timeout=180s deployment bt-dev-app-${{ needs.compute-sha.outputs.sha_short }}-backend
kubectl rollout status --timeout=180s deployment bt-dev-app-${{ needs.compute-sha.outputs.sha_short }}-frontend
# Check container status
kubectl rollout status --timeout=180s deployment bt-dev-app-${{ needs.compute-sha.outputs.sha_short }}-backend
kubectl rollout status --timeout=180s deployment bt-dev-app-${{ needs.compute-sha.outputs.sha_short }}-frontend
31 changes: 29 additions & 2 deletions .github/workflows/cd.yaml
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
name: Deploy to Development
name: Build and Push Images and Charts

on:
workflow_call:
inputs:
tag:
image_tag:
description: "Image build tag"
required: true
type: string
chart_ver:
description: "Chart build tag"
required: true
type: string

jobs:
build-push-image:
Expand All @@ -30,3 +34,26 @@ jobs:
run: |
docker build --no-cache --platform=linux/amd64 --target ${{ matrix.image }}-prod --tag "${{ secrets.DOCKER_USERNAME }}/bt-${{ matrix.image }}:${{ inputs.tag }}" .
docker push "${{ secrets.DOCKER_USERNAME }}/bt-${{ matrix.image }}:${{ inputs.tag }}"
build-push-chart:
name: Build and Push Helm Chart
runs-on: ubuntu-latest
strategy:
matrix:
chart: [app, base, mongo, redis]

steps:
- name: Checkout Repository
uses: actions/checkout@v4

- name: Login to Docker Hub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}

- name: Build and Push Helm Chart
run: |
cd ./infra
helm package ${{ matrix.chart }} --version ${{ inputs.chart_ver }}
helm push bt-${{ matrix.chart }}-${{ inputs.chart_ver }}.tgz oci://registry-1.docker.io/${{ secrets.DOCKER_USERNAME }}
28 changes: 28 additions & 0 deletions .github/workflows/deploy.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
name: SSH and Deploy

on:
workflow_call:
inputs:
environment:
description: "Github action environment to deploy within"
required: true
type: string
script:
description: "Script to run on remote server"
required: true
type: string

jobs:
deploy:
name: SSH and Deploy
runs-on: ubuntu-latest
environment: ${{ inputs.environment }}

steps:
- name: SSH and Helm Install
uses: appleboy/[email protected]
with:
host: ${{ secrets.SSH_HOST }}
username: ${{ secrets.SSH_USERNAME }}
key: ${{ secrets.SSH_KEY }}
script: ${{ inputs.script }}
1 change: 1 addition & 0 deletions infra/base/templates/certificate.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,4 @@ spec:
dnsNames:
- stanfurdtime.com
- "*.stanfurdtime.com"
- "*.dev.stanfurdtime.com"

0 comments on commit 67f384f

Please sign in to comment.