-
Notifications
You must be signed in to change notification settings - Fork 1
104 lines (99 loc) · 3.4 KB
/
build.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
name: build
on:
push:
branches:
- main
jobs:
build:
name: Build
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Setup Go
uses: actions/setup-go@v2
with:
go-version: '^1.16.0'
- name: Build App
run: cd go && CGO_ENABLED=0 go build -o demoapp main.go && cd ..
- name: Upload demoapp binary
uses: actions/upload-artifact@v2
with:
name: demoapp
path: go/demoapp
image:
name: Image
runs-on: ubuntu-latest
needs: build
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Download demoapp binary
uses: actions/download-artifact@v2
with:
name: demoapp
- name: Setup Packer
uses: hashicorp-contrib/setup-packer@v1
- name: Init Packer Plugins
run: packer init packer/app.pkr.hcl
- name: Install Manual Packer Plugins
run: |
curl -L -o packer-provisioner-goss.tgz https://github.com/YaleUniversity/packer-provisioner-goss/releases/download/v3.0.3/packer-provisioner-goss-v3.0.3-linux-amd64.tar.gz
tar zxf packer-provisioner-goss.tgz
mv packer-provisioner-goss $HOME/.packer.d/plugins/
sleep 30
- name: Validate Template
run: packer validate -syntax-only packer/app.pkr.hcl
- name: Build Image
run: packer build packer/app.pkr.hcl
env:
UPCLOUD_API_PASSWORD: ${{ secrets.UPCLOUD_API_PASSWORD }}
UPCLOUD_API_USER: github
terraform:
name: Apply Terraform
runs-on: ubuntu-latest
needs: image
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Setup Terraform
uses: hashicorp/setup-terraform@v1
with:
cli_config_credentials_token: ${{ secrets.TF_API_TOKEN }}
- name: Get Upctl CLI
run: |
curl -L -o upcloud_cli.tar.gz https://github.com/UpCloudLtd/upcloud-cli/releases/download/v1.0.0/upcloud-cli_1.0.0_linux_x86_64.tar.gz
tar zxf upcloud_cli.tar.gz
chmod +x upctl
./upctl -h
- name: Get Latest Image
run: |
set -o pipefail
cd terraform
echo "template_id = \"$(../upctl storage list --template -o json | jq '[.[] | select(.title | startswith("oc-uc-app-"))] | sort_by(.title) | reverse[0] | .uuid' -r)\"" > terraform.auto.tfvars
env:
UPCLOUD_PASSWORD: ${{ secrets.UPCLOUD_API_PASSWORD }}
UPCLOUD_USERNAME: github
- name: Terraform Init
run: cd terraform && terraform init
- name: Terraform Plan
run: cd terraform && terraform plan
- name: Terraform Apply
run: cd terraform && terraform apply -auto-approve
image_tidy:
name: Tidy Old Images
runs-on: ubuntu-latest
needs: terraform
steps:
- name: Get Upctl CLI
run: |
curl -L -o upcloud_cli.tar.gz https://github.com/UpCloudLtd/upcloud-cli/releases/download/v1.0.0/upcloud-cli_1.0.0_linux_x86_64.tar.gz
tar zxf upcloud_cli.tar.gz
chmod +x upctl
./upctl -h
- name: Delete all but the last 5 images
run: |
./upctl storage list --template -o json | jq '.[] | .title' -r | sort | head -n -5 | xargs -I{} ./upctl storage delete {}
env:
UPCLOUD_PASSWORD: ${{ secrets.UPCLOUD_API_PASSWORD }}
UPCLOUD_USERNAME: github