-
Notifications
You must be signed in to change notification settings - Fork 2
83 lines (73 loc) · 2.45 KB
/
build-deploy.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
name: "Build and Deploy"
on:
push:
branches:
- main
env:
TF_CLOUD_ORGANIZATION: "${{secrets.ORGANIZATION_TF}}"
TF_API_TOKEN: "${{ secrets.TF_API_TOKEN }}"
AWS_ACCESS_KEY_ID: "${{ secrets.AWS_ACCESS_KEY_ID }}"
AWS_SECRET_ACCESS_KEY: "${{ secrets.AWS_SECRET_ACCESS_KEY }}"
BUILD_VERSION: "${{ github.sha }}"
TF_WORKSPACE: "PROD-zwell-calculator"
CONFIG_DIRECTORY: "./terraform/"
AWS_DEFAULT_REGION: "us-west-2"
jobs:
# builds and pushes image to ecr
terraform:
name: "Terraform Apply"
runs-on: ubuntu-latest
permissions:
contents: read
steps:
- name: Checkout
uses: actions/checkout@v3
# Gets the most current config (tf.plan) for org + workspace combo
- name: Upload Configuration
uses: hashicorp/tfc-workflows-github/actions/upload-configuration@v1.2.0
id: apply-upload
with:
workspace: ${{ env.TF_WORKSPACE }}
directory: ${{ env.CONFIG_DIRECTORY }}
# runs changes in terrafrom/ against current state to create a tf.plan
# tarraform plan
- name: Create Apply Run
uses: hashicorp/tfc-workflows-github/actions/create-run@v1.2.0
id: apply-run
with:
workspace: ${{ env.TF_WORKSPACE }}
configuration_version: ${{ steps.apply-upload.outputs.configuration_version_id }}
# uncomment to tear down infra
# is_destroy: true
# terraform apply the plan
- name: Apply
uses: hashicorp/tfc-workflows-github/actions/apply-run@v1.2.0
if: fromJSON(steps.apply-run.outputs.payload).data.attributes.actions.IsConfirmable
id: apply
with:
run: ${{ steps.apply-run.outputs.run_id }}
comment: "Apply Run from GitHub Actions CI ${{ github.sha }}"
# Once uplaoding current build and not squashing, move before tf apply
# bucket needs to be there first...
s3:
name: "Push to s3"
needs: terraform
runs-on: ubuntu-latest
permissions:
contents: read
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v4
with:
aws-region: ${{ env.AWS_DEFAULT_REGION }}
- uses: actions/setup-node@v4
with:
node-version: 20.x
- name: Build and Push assets to s3
shell: bash
run: |
npm ci
npm run build
aws s3 sync ./build/ s3://app.zwell.io/