Skip to content

CDPT-1017 Create an image for use on Cloud Platform (#1) #1

CDPT-1017 Create an image for use on Cloud Platform (#1)

CDPT-1017 Create an image for use on Cloud Platform (#1) #1

Workflow file for this run

name: Deploy to MoJ Cloud Platform
on:
workflow_dispatch:
push:
branches:
- 'main'
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
jobs:
build_ecr:
runs-on: ubuntu-latest
permissions:
id-token: write
contents: read
steps:
- name: "Checkout"
uses: actions/checkout@v4
- name: "Configuring AWS credentials"
uses: aws-actions/configure-aws-credentials@v4
with:
role-to-assume: ${{ secrets.ECR_ROLE_TO_ASSUME }}
aws-region: ${{ vars.ECR_REGION }}
- name: "Logging into ECR"
uses: aws-actions/amazon-ecr-login@v2
id: ecr-login
- name: "Build & Push to ECR"
run: |
docker image build -t $REGISTRY/$REPOSITORY:nginx-$IMAGE_TAG --target nginx .
docker image build -t $REGISTRY/$REPOSITORY:fpm-$IMAGE_TAG --target build-fpm .
docker push $REGISTRY/$REPOSITORY:nginx-$IMAGE_TAG
docker push $REGISTRY/$REPOSITORY:fpm-$IMAGE_TAG
env:
REGISTRY: ${{ steps.ecr-login.outputs.registry }}
REPOSITORY: ${{ vars.ECR_REPOSITORY }}
IMAGE_TAG: ${{ github.sha }}
deploy-dev:
runs-on: ubuntu-latest
needs: build_ecr
env:
KUBE_NAMESPACE: ${{ secrets.KUBE_NAMESPACE }}
steps:
- name: "Checkout"
uses: actions/checkout@v4
##########################################
#### Generate hashes ####
##########################################
- name: "Auth key"
uses: licenseware/generate-password-and-hash@v1
id: auth-key-hash
with:
length: 32
- name: "Auth salt"
uses: licenseware/generate-password-and-hash@v1
id: auth-salt-hash
with:
length: 32
- name: "Logged in key"
uses: licenseware/generate-password-and-hash@v1
id: logged-in-key-hash
with:
length: 32
- name: "Logged in salt"
uses: licenseware/generate-password-and-hash@v1
id: logged-in-salt-hash
with:
length: 32
- name: "Nonce key"
uses: licenseware/generate-password-and-hash@v1
id: nonce-key-hash
with:
length: 32
- name: "Nonce salt"
uses: licenseware/generate-password-and-hash@v1
id: nonce-salt-hash
with:
length: 32
- name: "Secure key"
uses: licenseware/generate-password-and-hash@v1
id: secure-key-hash
with:
length: 32
- name: "Secure salt"
uses: licenseware/generate-password-and-hash@v1
id: secure-salt-hash
with:
length: 32
##########################################
#### =============== ####
##########################################
- name: "Inject environment variables"
env:
ECR_URL: ${{ vars.ECR_URL }}/${{ vars.ECR_REPOSITORY }}
IMAGE_TAG_NGINX: "nginx-${{ github.sha }}"
IMAGE_TAG_FPM: "fpm-${{ github.sha }}"
AUTH_KEY: ${{ steps.auth-key-hash.outputs.password-hash }}
AUTH_SALT: ${{ steps.auth-salt-hash.outputs.password-hash }}
LOGGED_IN_KEY: ${{ steps.logged-in-key-hash.outputs.password-hash }}
LOGGED_IN_SALT: ${{ steps.logged-in-salt-hash.outputs.password-hash }}
NONCE_KEY: ${{ steps.nonce-key-hash.outputs.password-hash }}
NONCE_SALT: ${{ steps.nonce-salt-hash.outputs.password-hash }}
SECURE_AUTH_KEY: ${{ steps.secure-key-hash.outputs.password-hash }}
SECURE_AUTH_SALT: ${{ steps.secure-salt-hash.outputs.password-hash }}
BASIC_AUTH: ${{ secrets.BASIC_AUTH }}
run: |
cat deploy/development/secret.tpl | envsubst > deploy/development/secret.yaml
cat deploy/development/deployment.tpl | envsubst > deploy/development/deployment.yaml
- name: "Authenticate to the cluster"
env:
KUBE_CERT: ${{ secrets.KUBE_CERT }}
KUBE_TOKEN: ${{ secrets.KUBE_TOKEN }}
KUBE_CLUSTER: ${{ secrets.KUBE_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 use-context ${KUBE_CLUSTER}
- name: "Apply manifest files"
run: |
kubectl -n ${KUBE_NAMESPACE} apply -f deploy/development