Skip to content

Commit

Permalink
✨ Add Production Deployment (#20)
Browse files Browse the repository at this point in the history
  • Loading branch information
connormaglynn authored Aug 19, 2024
1 parent fd38854 commit 4f0c062
Show file tree
Hide file tree
Showing 2 changed files with 87 additions and 0 deletions.
79 changes: 79 additions & 0 deletions .github/workflows/cicd-deploy-to-prod.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
name: "♻️ Deploy to Production Namespace"

on:
workflow_dispatch:
push:
branches: [main]
env:
KUBE_CLUSTER: ${{ secrets.KUBE_CLUSTER }}
KUBE_NAMESPACE: ${{ secrets.PROD_KUBE_NAMESPACE }}
KUBE_CERT: ${{ secrets.PROD_KUBE_CERT }}
KUBE_TOKEN: ${{ secrets.PROD_KUBE_TOKEN }}

IMAGE_TAG: ${{ github.sha }}
ECR_REGISTRY: ${{ vars.PRODUCTION_ECR_REGISTRY }}
ECR_REPOSITORY: ${{ vars.PRODUCTION_ECR_REPOSITORY }}

API_KEY: ${{ secrets.PROD_API_KEY }}

POSTGRES_USER: ${{secrets.PROD_POSTGRES_USER}}
POSTGRES_PASSWORD: ${{secrets.PROD_POSTGRES_PASSWORD}}
POSTGRES_DB: ${{secrets.PROD_POSTGRES_DB}}
POSTGRES_HOST: ${{secrets.PROD_POSTGRES_HOST}}
POSTGRES_PORT: ${{secrets.PROD_POSTGRES_PORT}}

jobs:
build-push:
runs-on: ubuntu-latest
permissions:
id-token: write
contents: read
steps:
- uses: actions/checkout@v4

- uses: aws-actions/configure-aws-credentials@v4
with:
role-to-assume: ${{ secrets.PRODUCTION_ECR_ROLE_TO_ASSUME }}
aws-region: ${{ vars.PRODUCTION_ECR_REGION }}

- uses: aws-actions/amazon-ecr-login@v2
id: login-ecr
- run: |
docker build -t $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG .
docker push $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG
deploy-to-prod:
needs: build-push
runs-on: ubuntu-latest
container: alpine/k8s:1.23.17
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Authenticate to the cluster
run: |
echo "${KUBE_CERT}" > ca.crt
kubectl config set-cluster ${KUBE_CLUSTER} --certificate-authority=./ca.crt --server=https://${KUBE_CLUSTER}
kubectl config set-credentials deploy-user --token=${KUBE_TOKEN}
kubectl config set-context ${KUBE_CLUSTER} --cluster=${KUBE_CLUSTER} --user=deploy-user --namespace=${KUBE_NAMESPACE}
kubectl config get-contexts
kubectl config use-context ${KUBE_CLUSTER}
- name: Deploy helm chart to Production
run: |
helm upgrade kpi-dashboard \
helm/kpi-dashboard \
--install \
--force \
--wait \
--timeout 10m \
--namespace ${KUBE_NAMESPACE} \
--values=helm/kpi-dashboard/values-prod.yaml \
--set app.deployment.env.API_KEY=${API_KEY} \
--set app.deployment.env.POSTGRES_USER=${POSTGRES_USER} \
--set app.deployment.env.POSTGRES_PASSWORD=${POSTGRES_PASSWORD} \
--set app.deployment.env.POSTGRES_DB=${POSTGRES_DB} \
--set app.deployment.env.POSTGRES_HOST=${POSTGRES_HOST} \
--set app.deployment.env.POSTGRES_PORT=${POSTGRES_PORT} \
--set app.deployment.image.repository=${ECR_REGISTRY}/${ECR_REPOSITORY} \
--set app.deployment.image.tag=${IMAGE_TAG}
8 changes: 8 additions & 0 deletions helm/kpi-dashboard/values-prod.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
app:
ingress:
host: "kpi-dashboard.cloud-platform.service.justice.gov.uk"

deployment:
replicaCount: 1
env:
LOGGING_LEVEL: INFO

0 comments on commit 4f0c062

Please sign in to comment.