-
Notifications
You must be signed in to change notification settings - Fork 45
70 lines (59 loc) · 2.37 KB
/
build_and_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
name: Build and Deploy
on:
push:
tags: ["v[0-9].[0-9]+.[0-9]+"]
branches:
- "development"
- "staging"
- "main"
env:
HCP_CLIENT_ID: ${{ secrets.HCP_CLIENT_ID }}
HCP_CLIENT_SECRET: ${{ secrets.HCP_CLIENT_SECRET }}
HCP_PROJECT_ID: ${{ secrets.HCP_PROJECT_ID }}
HCP_ORGANIZATION_ID: ${{ secrets.HCP_ORGANIZATION_ID }}
HCP_BUCKET_NAME: "learn-packer-github-actions"
jobs:
build-artifact:
name: Build
runs-on: ubuntu-latest
outputs:
version_fingerprint: ${{ steps.hcp.outputs.version_fingerprint }}
steps:
- name: Setup Packer
uses: hashicorp/setup-packer@main
id: setup
- name: Checkout Repository
uses: actions/checkout@3df4ab11eba7bda6032a0b82a6bb43b11571feac # v4.0.0
- name: Configure AWS Credentials
uses: aws-actions/configure-aws-credentials@8c3f20df09ac63af7b3ae3d7c91f105f857d8497 # v4.0.0
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
aws-region: us-west-1
- name: Packer Init
run: packer init .
- name: Packer Build - Branches
if: startsWith(github.ref, 'refs/heads/')
run: packer build .
- name: Packer Build - Tags
if: startsWith(github.ref, 'refs/tags/v')
run: HCP_PACKER_BUILD_FINGERPRINT=$(date +'%m%d%YT%H%M%S') packer build .
- name: Get HCP Packer version fingerprint from Packer Manifest
id: hcp
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")
version_fingerprint=$(echo "$build" | jq -r '.custom_data.version_fingerprint')
echo "::set-output name=version_fingerprint::$version_fingerprint"
update-hcp-packer-channel:
name: Update HCP Packer channel
needs: ["build-artifact"]
runs-on: ubuntu-latest
steps:
- name: Checkout Repository
uses: actions/checkout@3df4ab11eba7bda6032a0b82a6bb43b11571feac # v4.0.0
- name: Create and set channel
working-directory: .github/scripts
run: |
channel_name=$( echo ${{github.ref_name}} | sed 's/\./-/g')
./create_channel_version.sh $HCP_BUCKET_NAME $channel_name "${{ needs.build-artifact.outputs.version_fingerprint }}"