-
Notifications
You must be signed in to change notification settings - Fork 0
105 lines (104 loc) · 3.41 KB
/
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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
---
# ------------------------------------------------------------------------------
# Run workflow:
# https://github.com/DFE-Digital/early-years-foundation-recovery/actions/workflows/staging.yml
#
# Build image:
# ghcr.io/dfe-digital/early-years-foundation-recovery:rc0.0.1
#
# Deploy to:
# https://ey-recovery-staging.london.cloudapps.digital
#
name: Deploy Staging App
# on:
# workflow_dispatch:
# inputs:
# candidate:
# description: Create release candidate version ("rcx.x.x")
# type: string
# required: true
# ref:
# description: Git ref or branch to deploy
# type: string
# required: true
# default: main
# push:
# tags:
# - rc*
jobs:
deploy:
runs-on: ubuntu-latest
environment: staging
env:
WORKSPACE: staging
REGISTRY: ghcr.io/dfe-digital/early-years-foundation-recovery
steps:
-
name: Checkout Code
uses: actions/checkout@v4
with:
ref: ${{ inputs.ref || github.ref_name }}
-
name: Tag candidate
if: ${{ inputs.candidate }}
run: |
git tag --force ${{ inputs.candidate }}
git push --force origin refs/tags/${{ inputs.candidate }}
echo "HEAD=$(git rev-parse ${{ inputs.candidate }})" >> $GITHUB_ENV
-
name: Pin Terraform version
uses: hashicorp/setup-terraform@v3
with:
terraform_version: 1.1.7
-
name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
with:
version: v0.9.1
-
name: Login to Github Container Registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}
-
name: Build and push Docker image
uses: docker/build-push-action@v5
with:
target: app
context: .
push: true
build-args: |
BUILDKIT_INLINE_CACHE=1
SHA=${{ github.sha }}
cache-from: |
${{ env.REGISTRY }}:${{ github.sha }}
${{ env.REGISTRY }}:${{ inputs.ref || github.ref_name }}
tags: |
${{ env.REGISTRY }}:${{ github.sha }}
${{ env.REGISTRY }}:${{ inputs.candidate || github.ref_name }}
-
name: Deploy Release Candidate
env:
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
TF_VAR_paas_cf_user: ${{ secrets.CLOUD_FOUNDRY_USERNAME }}
TF_VAR_paas_cf_password: ${{ secrets.CLOUD_FOUNDRY_PASSWORD }}
TF_VAR_paas_app_docker_image: ${{ env.REGISTRY }}:${{ inputs.candidate || github.ref_name }}
TF_VAR_paas_app_hostname: staging
TF_VAR_paas_app_env_secrets: ${{ toJson(secrets) }}
TF_VAR_paas_app_envs: ${{ toJson(env) }}
run: |
cd terraform/app
terraform init \
-reconfigure \
-input=false \
-backend-config="bucket=${{ secrets.AWS_BUCKET }}" \
-backend-config="key=${{ env.WORKSPACE }}/terraform.tfstate"
terraform plan \
-var-file ../workspace-variables/${{ env.WORKSPACE }}.tfvars
terraform apply \
-input=false \
-auto-approve \
-var-file ../workspace-variables/${{ env.WORKSPACE }}.tfvars