Skip to content

Merge pull request #20 from ministryofjustice/environment-variables #13

Merge pull request #20 from ministryofjustice/environment-variables

Merge pull request #20 from ministryofjustice/environment-variables #13

Workflow file for this run

name: deploy
on:
push:
branches:
[main]
workflow_dispatch:
permissions: {}
concurrency: dev
jobs:
ecr:
runs-on: ubuntu-latest
environment: dev
permissions:
id-token: write # This is required for requesting the JWT
contents: read # This is required for actions/checkout
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@v2
id: login-ecr
- run: |
docker build -t $REGISTRY/$REPOSITORY:$IMAGE_TAG .
docker push $REGISTRY/$REPOSITORY:$IMAGE_TAG
env:
REGISTRY: ${{ steps.login-ecr.outputs.registry }}
REPOSITORY: ${{ vars.ECR_REPOSITORY }}
IMAGE_TAG: ${{ github.sha }}
- run: |
cat deployments/templates/deployment.yml | envsubst > deployments/deployment.yml
cat deployments/templates/ingress.yml | envsubst > deployments/ingress.yml
cat deployments/templates/service.yml | envsubst > deployments/service.yml
cat deployments/templates/secrets.yml | envsubst > deployments/secrets.yml
env:
CATALOGUE_URL: ${{ vars.CATALOGUE_URL }}
DEBUG: ${{ vars.DEBUG }}
DJANGO_ALLOWED_HOSTS: ${{ vars.DJANGO_ALLOWED_HOSTS }}
SECRET_KEY: ${{ secrets.SECRET_KEY }}
CATALOGUE_TOKEN: ${{ secrets.CATALOGUE_TOKEN }}
IMAGE_TAG: ${{ github.sha }}
REGISTRY: ${{ steps.login-ecr.outputs.registry }}
REPOSITORY: ${{ vars.ECR_REPOSITORY }}
NAMESPACE: ${{ secrets.KUBE_NAMESPACE }}
- run: |
echo "${{ secrets.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=${{ secrets.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 deployments/
env:
KUBE_NAMESPACE: ${{ secrets.KUBE_NAMESPACE }}
KUBE_CLUSTER: ${{ secrets.KUBE_CLUSTER }}