-
Notifications
You must be signed in to change notification settings - Fork 6
120 lines (100 loc) · 3.99 KB
/
build_and_deploy.yaml
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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
name: Build and Deploy
on:
workflow_dispatch:
env:
HCP_ORGANIZATION_ID: ${{ secrets.HCP_ORGANIZATION_ID }}
HCP_PROJECT_ID: ${{ secrets.HCP_PROJECT_ID }}
HCP_CLIENT_ID: ${{ secrets.HCP_CLIENT_ID }}
HCP_CLIENT_SECRET: ${{ secrets.HCP_CLIENT_SECRET }}
jobs:
build:
name: Build
runs-on: ubuntu-latest
outputs:
iteration_id: ${{ steps.hcp.outputs.iteration_id }}
steps:
- name: Checkout Repository
uses: actions/checkout@v2
- name: Configure AWS Credentials
uses: aws-actions/configure-aws-credentials@v1
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
aws-region: us-west-2
- name: Compile Application
env:
GOOS: linux
GOARCH: arm64 # target architecture is ubuntu on arm64 instances
run: go build -o bin/server app/main.go
- name: Packer Init
working-directory: ./packer
run: packer init .
- name: Packer Build
working-directory: ./packer
run: packer build .
- name: Get HCP Packer Iteration ID from Packer Manifest
id: hcp
working-directory: ./packer
run: |
last_run_uuid=$(jq -r '.last_run_uuid' "./packer_manifest.json")
build=$(jq -r '.builds[] | select(.packer_run_uuid == "'"$last_run_uuid"'")' "./packer_manifest.json")
iteration_id=$(echo "$build" | jq -r '.custom_data.iteration_id')
echo "::set-output name=iteration_id::$iteration_id"
test:
name: E2E Testing
needs: build
runs-on: ubuntu-latest
steps:
- name: Checkout Repository
uses: actions/checkout@v2
- name: Configure AWS Credentials
uses: aws-actions/configure-aws-credentials@v1
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
aws-region: us-west-2
- name: Setup Terraform
uses: hashicorp/setup-terraform@v1
with:
terraform_wrapper: false
- name: Terraform Init
working-directory: ./terraform
run: terraform init
- name: Create Ephemeral Infrastructure
id: tf_apply
working-directory: ./terraform
run: |
terraform apply -auto-approve -var="iteration_id=${{ needs.build.outputs.iteration_id }}"
health_endpoint="$(terraform output -raw health_endpoint)"
echo "::set-output name=health_endpoint::${health_endpoint}"
- name: Invoke E2E Test
working-directory: ./.github/scripts
run: ./e2e_test.sh "${{ steps.tf_apply.outputs.health_endpoint }}"
- name: Clean Up Testing Infrastructure
if: always() # always run cleanup steps, regardless of E2E test outcomes
working-directory: ./terraform
run: terraform destroy -auto-approve -var="iteration_id=${{ needs.build.outputs.iteration_id }}"
promote-dev-staging:
name: Promote to Dev and Staging Channels
needs: ['build', 'test'] # this will automatically be skipped if the test job fails
runs-on: ubuntu-latest
steps:
- name: Checkout Repository
uses: actions/checkout@v2
- name: Promote Iteration to Dev
working-directory: .github/scripts
run: ./set_iteration.sh "hcp-packer-demo" "dev" "${{ needs.build.outputs.iteration_id }}"
- name: Promote Iteration to Staging
working-directory: .github/scripts
run: ./set_iteration.sh "hcp-packer-demo" "staging" "${{ needs.build.outputs.iteration_id }}"
promote-prod:
name: Promote to Production
needs: ['build', 'test', 'promote-dev-staging']
environment: production # requires approval
runs-on: ubuntu-latest
steps:
- name: Checkout Repository
uses: actions/checkout@v2
- name: Promote Iteration to Prod
working-directory: .github/scripts
run: ./set_iteration.sh "hcp-packer-demo" "prod" "${{ needs.build.outputs.iteration_id }}"