-
Notifications
You must be signed in to change notification settings - Fork 0
82 lines (71 loc) · 3.22 KB
/
Copy pathrelease-action.yml
File metadata and controls
82 lines (71 loc) · 3.22 KB
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
name: Release New Version
on:
push:
branches: main
tags:
- v*
# Manual trigger, so a feature branch can be built without merging to main first. GitHub only
# offers this for workflows present on the DEFAULT branch, so the button appears once this file
# reaches main; after that it can target any branch. Images are tagged by commit SHA either way,
# so a branch build cannot be mistaken for a main one.
workflow_dispatch:
inputs:
deploy:
description: 'Also run the Nomad job after building (leave off to build only)'
type: boolean
default: false
env:
IMAGE_NAME: operator-checks
jobs:
push:
runs-on: ubuntu-latest
# runs-on: self-hosted
# runs-on: anyone-arc-runner-set
permissions:
packages: write
contents: read
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Build image
run: docker build . --file Dockerfile --tag $IMAGE_NAME --label "runnumber=${GITHUB_RUN_ID}"
- name: Log in to registry
run: echo "${{ secrets.GITHUB_TOKEN }}" | docker login ghcr.io -u $ --password-stdin
- name: Push image
run: |
IMAGE_ID=ghcr.io/${{ github.repository_owner }}/$IMAGE_NAME
# Change all uppercase to lowercase
IMAGE_ID=$(echo $IMAGE_ID | tr '[A-Z]' '[a-z]')
# Strip git ref prefix from version
VERSION=$(echo "${{ github.ref }}" | sed -e 's,.*/\(.*\),\1,')
# Strip "v" prefix from tag name
[[ "${{ github.ref }}" == "refs/tags/"* ]] && VERSION=$(echo $VERSION | sed -e 's/^v//')
# Use Docker `latest` tag convention
[ "$VERSION" == "main" ] && VERSION=stage
echo IMAGE_ID=$IMAGE_ID
echo VERSION=$VERSION
echo -e "{\"deploy\":\"$VERSION\",\"commit_sha\":\"${GITHUB_SHA}\"}" > deploy-vars.json
docker tag $IMAGE_NAME $IMAGE_ID:$GITHUB_SHA
docker push $IMAGE_ID:$GITHUB_SHA
# Deploying is MANUAL for now. A push to main used to build and immediately
# `nomad job run` operator-checks-stage (VERSION=stage when the ref is main), and a v* tag
# did the same for live, so merging deployed without anyone choosing to. This step now runs
# only when a workflow_dispatch explicitly ticks `deploy`; a push builds and pushes the
# image and stops there, and the jobspec is run by hand against the SHA-tagged image.
- name: Deploy new version
if: ${{ github.event_name == 'workflow_dispatch' && inputs.deploy }}
env:
NOMAD_CACERT: operations/admin-ui-ca.crt
NOMAD_TOKEN: ${{ secrets.NOMAD_TOKEN_OPERATOR_CHECKS_DEPLOY }}
NOMAD_ADDR: ${{ secrets.NOMAD_ADDR }}
run: |
curl -L https://releases.hashicorp.com/nomad/1.10.2/nomad_1.10.2_linux_amd64.zip -o nomad.zip
unzip nomad.zip
if grep -q "stage" deploy-vars.json; then
sed -i "s/\[\[ .commit_sha \]\]/${GITHUB_SHA}/g" operations/operator-checks-stage.hcl
./nomad job run operations/operator-checks-stage.hcl
else
sed -i "s/\[\[ .commit_sha \]\]/${GITHUB_SHA}/g" operations/operator-checks-live.hcl
./nomad job run operations/operator-checks-live.hcl
fi