Merge pull request #215 from ministryofjustice/sprint-26 #95
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: Continuous Deployment | |
# For a description of how this works, see this Cloud Platform User Guide page: | |
# https://user-guide.cloud-platform.service.justice.gov.uk/documentation/deploying-an-app/github-actions-continuous-deployment.html | |
on: | |
workflow_dispatch: | |
push: | |
branches: | |
- "main" | |
env: | |
KUBE_NAMESPACE: ${{ secrets.KUBE_NAMESPACE }} # used in kubernetes-deploy.yaml too | |
jobs: | |
main: | |
runs-on: ubuntu-latest | |
permissions: | |
id-token: write | |
contents: read | |
steps: | |
- uses: actions/checkout@v3 | |
- uses: aws-actions/configure-aws-credentials@v2 | |
with: | |
role-to-assume: ${{ secrets.ECR_ROLE_TO_ASSUME }} | |
aws-region: ${{ vars.ECR_REGION }} | |
- uses: aws-actions/amazon-ecr-login@v1 | |
id: login-ecr | |
- run: | | |
docker build -t $REGISTRY/$REPOSITORY:$IMAGE_TAG . | |
docker push $REGISTRY/$REPOSITORY:$IMAGE_TAG | |
cat kubernetes-deploy-${{ github.ref_name }}.tpl | envsubst > kubernetes-deploy.yaml | |
env: | |
REGISTRY: ${{ steps.login-ecr.outputs.registry }} | |
REPOSITORY: ${{ vars.ECR_REPOSITORY }} | |
IMAGE_TAG: ${{ github.sha }} | |
BRANCH: ${{ github.ref_name }} | |
- 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 use-context ${KUBE_CLUSTER} | |
kubectl -n ${KUBE_NAMESPACE} apply -f kubernetes-deploy.yaml | |
env: | |
KUBE_CERT: ${{ secrets.KUBE_CERT }} | |
KUBE_TOKEN: ${{ secrets.KUBE_TOKEN }} | |
KUBE_CLUSTER: ${{ secrets.KUBE_CLUSTER }} |