-
Notifications
You must be signed in to change notification settings - Fork 19
60 lines (58 loc) · 2.51 KB
/
tag-staging.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
name: Push a tagged PR to staging env
on:
pull_request:
types: [labeled]
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
ECR_NAME: ${{ secrets.ECR_NAME }}
KUBE_CLUSTER: ${{ secrets.KUBE_CLUSTER }}
KUBE_NAMESPACE: ${{ secrets.KUBE_NAMESPACE }}
jobs:
push-to-staging:
runs-on: ubuntu-latest
permissions:
id-token: write
contents: read
pull-requests: write
if: ${{ github.event.label.name == 'staging:request' }}
steps:
- uses: actions/checkout@v4
- name: Remove active labels from other PRs
run: |
for number in $(gh pr list --label "staging:active" --json number | jq -r '.[].number'); do
gh pr edit ${number} --remove-label "staging:active"
done
- uses: aws-actions/configure-aws-credentials@v4
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 --target=staging -t $REGISTRY/$REPOSITORY:$IMAGE_TAG .
docker push $REGISTRY/$REPOSITORY:$IMAGE_TAG
cat kubernetes-deploy-staging.tpl | envsubst > kubernetes-deploy-staging.yaml
env:
REGISTRY: ${{ steps.login-ecr.outputs.registry }}
REPOSITORY: ${{ vars.ECR_REPOSITORY }}
IMAGE_TAG: ${{ github.sha }}
BRANCH: "staging"
- 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-staging.yaml
env:
KUBE_CERT: ${{ secrets.KUBE_CERT }}
KUBE_TOKEN: ${{ secrets.KUBE_TOKEN }}
KUBE_CLUSTER: ${{ secrets.KUBE_CLUSTER }}
- name: Update PR with success
run: |
echo -e "🚀 Deploying to [staging environment](https://moj-frontend-staging.apps.live.cloud-platform.service.justice.gov.uk/)\n\n**Username:** \`staging\`, **Password:** \`moj\`" > comment.txt
gh pr comment $PRNUM --body-file comment.txt
gh pr edit $PRNUM --remove-label "staging:request"
gh pr edit $PRNUM --add-label "staging:active"
env:
PRNUM: ${{ github.event.number }}