Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Trying new test workflow deployment #132

Merged
merged 29 commits into from
Mar 11, 2024
Merged
Show file tree
Hide file tree
Changes from 28 commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
bd8a25d
Trying new test workflow deployment
murdo-moj Mar 6, 2024
9c414e9
Added deploy_test to test workflow
murdo-moj Mar 6, 2024
9c9785d
Removed needs block for deploy_test
murdo-moj Mar 6, 2024
95554eb
Trying new workflow
murdo-moj Mar 7, 2024
093dd8d
Added name to deploy-test workflow
murdo-moj Mar 7, 2024
b21f79a
Add concurrency for deploy-test
murdo-moj Mar 7, 2024
30911cc
Removed quoting of variable
murdo-moj Mar 7, 2024
406700d
trying to fix the workflow
murdo-moj Mar 7, 2024
52c45b2
deleted offending variable
murdo-moj Mar 7, 2024
48adb72
testing
murdo-moj Mar 7, 2024
363bf9c
Tweaking
murdo-moj Mar 7, 2024
f3ac825
tweaking
murdo-moj Mar 7, 2024
c7c8d5d
Add deploy-test to test workflow
murdo-moj Mar 7, 2024
33fe64f
Deleted workflow
murdo-moj Mar 7, 2024
695784b
Trying to fix debug var
murdo-moj Mar 7, 2024
0e6cd50
tweaking
murdo-moj Mar 7, 2024
75ab081
Merge branch 'main' into fmd-123/gated-deployments
murdo-moj Mar 7, 2024
4c95b2f
Added environments to deploy workflow
murdo-moj Mar 7, 2024
0aaa7a6
corrected variable name
murdo-moj Mar 7, 2024
aed3a59
take debug var out of quotes
murdo-moj Mar 7, 2024
fbef9b2
Lose quotes
murdo-moj Mar 7, 2024
ef9a2d6
Removed variable quoting
murdo-moj Mar 8, 2024
efad6d9
Corrected environment specific variables in deploy
murdo-moj Mar 8, 2024
4413e21
Used environment variables instead of workflow inputs
murdo-moj Mar 8, 2024
e082235
Improve job naming on deploy
murdo-moj Mar 11, 2024
eccca8c
Revert job id
murdo-moj Mar 11, 2024
f96d45c
Split docker build and docker push into steps
murdo-moj Mar 11, 2024
660ee73
Properly capitalise job names
murdo-moj Mar 11, 2024
5e26504
Restricted test deployment on main
murdo-moj Mar 11, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
111 changes: 111 additions & 0 deletions .github/workflows/deploy-generic.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
name: Deploy

on:
workflow_call:
inputs:
env:
description: "which environment to deploy to"
required: true
type: string
ecr_repository:
description: "ecr repo to hold container image"
required: true
type: string
ecr_region:
description: "ecr region to hold container image"
required: true
type: string
secrets:
kube_namespace:
description: "the kubernetes namespace to deploy to"
required: true
kube_cert:
description: "cert used to verify identity to cluster"
required: true
kube_cluster:
description: "address of the cluster to connect to"
required: true
kube_token:
description: "used to authenticate to the cluster"
required: true
ecr_role_to_assume:
description: "role to authenticate ecr image repository push"
required: true
secret_key:
description: "secret key"
required: true
catalogue_token:
description: "token to authenticate with the catalogue"
required: true

jobs:
deploy:
name: Deploy Helm chart into Cloud Platform
environment: ${{ inputs.env }}
runs-on: ubuntu-latest
permissions:
id-token: write # This is required for requesting the JWT
contents: read # This is required for actions/checkout
steps:
- uses: actions/checkout@v4

- uses: aws-actions/configure-aws-credentials@v2
with:
role-to-assume: ${{ secrets.ECR_ROLE_TO_ASSUME }}
aws-region: ${{ inputs.ECR_REGION }}

- name: Login to ECR
id: login-to-ecr
uses: aws-actions/amazon-ecr-login@v2

- name: Build Docker image
id: build-docker-image
env:
REGISTRY: ${{ steps.login-to-ecr.outputs.registry }}
REPOSITORY: ${{ inputs.ECR_REPOSITORY }}
IMAGE_TAG: ${{ github.sha }}
run: docker build -t $REGISTRY/$REPOSITORY:$IMAGE_TAG .

- name: Push Docker image to ECR
id: push-docker-image-to-ecr
env:
REGISTRY: ${{ steps.login-to-ecr.outputs.registry }}
REPOSITORY: ${{ inputs.ECR_REPOSITORY }}
IMAGE_TAG: ${{ github.sha }}
run: docker push $REGISTRY/$REPOSITORY:$IMAGE_TAG

- name: Prepare Helm deployment
id: prepare-helm-deployment
env:
murdo-moj marked this conversation as resolved.
Show resolved Hide resolved
CATALOGUE_URL: ${{ env.CATALOGUE_URL }}
DEBUG: ${{ env.DEBUG }}
DJANGO_ALLOWED_HOSTS: ${{ env.DJANGO_ALLOWED_HOSTS }}
SECRET_KEY: ${{ secrets.SECRET_KEY }}
CATALOGUE_TOKEN: ${{ secrets.CATALOGUE_TOKEN }}
IMAGE_TAG: ${{ github.sha }}
REGISTRY: ${{ steps.login-to-ecr.outputs.registry }}
REPOSITORY: ${{ inputs.ECR_REPOSITORY }}
NAMESPACE: ${{ secrets.KUBE_NAMESPACE }}
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

- name: Configure Kubernetes cluster
id: configure-kubernetes-cluster
env:
KUBE_NAMESPACE: ${{ secrets.KUBE_NAMESPACE }}
KUBE_CLUSTER: ${{ secrets.KUBE_CLUSTER }}
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}

- name: Apply Helm deployment
id: apply-helm-deployment
env:
KUBE_NAMESPACE: ${{ secrets.KUBE_NAMESPACE }}
run: kubectl -n ${KUBE_NAMESPACE} apply -f deployments/
99 changes: 47 additions & 52 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,57 +2,52 @@ name: deploy

on:
push:
branches:
[main]
workflow_dispatch:

permissions: {}
concurrency: dev
branches: [main]

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@v4
- uses: aws-actions/configure-aws-credentials@v2
with:
role-to-assume: ${{ secrets.DEV_ECR_ROLE_TO_ASSUME }}
aws-region: ${{ vars.DEV_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.DEV_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.DEV_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 }}
test:
uses: "./.github/workflows/deploy-generic.yml"
with:
env: "test"
ecr_repository: ${{ vars.TEST_ECR_REPOSITORY }}
ecr_region: ${{ vars.TEST_ECR_REGION }}
secrets:
kube_namespace: ${{ secrets.KUBE_NAMESPACE }}
kube_cert: ${{ secrets.KUBE_CERT }}
kube_cluster: ${{ secrets.KUBE_CLUSTER }}
kube_token: ${{ secrets.KUBE_TOKEN }}
ecr_role_to_assume: ${{ secrets.TEST_ECR_ROLE_TO_ASSUME }}
secret_key: ${{ secrets.SECRET_KEY }}
catalogue_token: ${{ secrets.CATALOGUE_TOKEN }}

murdo-moj marked this conversation as resolved.
Show resolved Hide resolved
dev:
uses: "./.github/workflows/deploy-generic.yml"
needs: test
with:
env: "dev"
ecr_repository: ${{ vars.DEV_ECR_REPOSITORY }}
ecr_region: ${{ vars.DEV_ECR_REGION }}
secrets:
kube_namespace: ${{ secrets.KUBE_NAMESPACE }}
kube_cert: ${{ secrets.KUBE_CERT }}
kube_cluster: ${{ secrets.KUBE_CLUSTER }}
kube_token: ${{ secrets.KUBE_TOKEN }}
ecr_role_to_assume: ${{ secrets.DEV_ECR_ROLE_TO_ASSUME }}
secret_key: ${{ secrets.SECRET_KEY }}
catalogue_token: ${{ secrets.CATALOGUE_TOKEN }}

preprod:
uses: "./.github/workflows/deploy-generic.yml"
needs: dev
murdo-moj marked this conversation as resolved.
Show resolved Hide resolved
with:
env: "preprod"
ecr_repository: ${{ vars.PREPROD_ECR_REPOSITORY }}
ecr_region: ${{ vars.PREPROD_ECR_REGION }}
secrets:
kube_namespace: ${{ secrets.KUBE_NAMESPACE }}
kube_cert: ${{ secrets.KUBE_CERT }}
kube_cluster: ${{ secrets.KUBE_CLUSTER }}
kube_token: ${{ secrets.KUBE_TOKEN }}
ecr_role_to_assume: ${{ secrets.PREPROD_ECR_ROLE_TO_ASSUME }}
secret_key: ${{ secrets.SECRET_KEY }}
catalogue_token: ${{ secrets.CATALOGUE_TOKEN }}
19 changes: 17 additions & 2 deletions .github/workflows/test.yml
murdo-moj marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ on:
- main

jobs:
test:
unit:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
Expand Down Expand Up @@ -53,7 +53,7 @@ jobs:
if: steps.fast-tests.outcome == 'success'
murdo-moj marked this conversation as resolved.
Show resolved Hide resolved
run: poetry run pytest -m 'slow' --chromedriver-path=$(npm root -g)/chromedriver/bin/chromedriver

test_javascript:
javascript:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
Expand Down Expand Up @@ -81,3 +81,18 @@ jobs:

- name: Run javascript tests
run: npm test

deploy:
uses: "./.github/workflows/deploy-generic.yml"
with:
env: "test"
ecr_repository: ${{ vars.TEST_ECR_REPOSITORY }}
ecr_region: ${{ vars.TEST_ECR_REGION }}
secrets:
kube_namespace: ${{ secrets.KUBE_NAMESPACE }}
kube_cert: ${{ secrets.KUBE_CERT }}
kube_cluster: ${{ secrets.KUBE_CLUSTER }}
kube_token: ${{ secrets.KUBE_TOKEN }}
ecr_role_to_assume: ${{ secrets.TEST_ECR_ROLE_TO_ASSUME }}
secret_key: ${{ secrets.SECRET_KEY }}
catalogue_token: ${{ secrets.CATALOGUE_TOKEN }}
Loading