-
Notifications
You must be signed in to change notification settings - Fork 26
68 lines (58 loc) · 2.32 KB
/
build-push-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
name: Build, push, and deploy
on:
push:
branches:
- main
jobs:
build-push-deploy:
runs-on: ubuntu-latest
steps:
# We have to do this to workaround these errors:
# ERROR: failed to configure registry cache importer: invalid reference format: repository name must be lowercase
- name: Create REPO env var that contains lowercase github.repository name
run: echo "REPO=${GITHUB_REPOSITORY,,}" >>${GITHUB_ENV}
- name: Docker Metadata action
uses: docker/[email protected]
id: meta
with:
images: |
ghcr.io/${{ env.REPO }}
# Using `branch` to give a predictable name to cache from, and using
# `sha` so we always have a unique tag which will trigger
# star-server-infra terraform to run.
tags: |
type=ref,event=branch
type=sha
- name: Docker Setup Buildx
uses: docker/[email protected]
- name: Docker Login
uses: docker/[email protected]
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ github.token }}
- name: Build and push Docker images
uses: docker/[email protected]
with:
cache-from: type=registry,ref=ghcr.io/${{ env.REPO }}:${{ github.ref_name }}
cache-to: type=inline
labels: ${{ steps.meta.outputs.labels }}
push: true
tags: ${{ steps.meta.outputs.tags }}
# TODO: Currently using a personal access token to do this, which is not
# secure. Need to switch to switch to one of these maybe?
#
# * https://github.com/marketplace/actions/workflow-dispatch
# * https://github.com/marketplace/actions/trigger-workflow-and-wait
- name: Checkout
uses: actions/[email protected]
with:
repository: 'Equal-Vote/star-server-infra'
token: ${{ secrets.GH_PAT }}
- name: Update star-server-infra repo variables.tf with new container tag
run: |
sed -i "s#\"ghcr.io/${{ env.REPO }}:.*#\"ghcr.io/${{ env.REPO }}:sha-${GITHUB_SHA::7}\"#" variables.tf
git config user.name github-actions
git config user.email [email protected]
git commit -am "Automatically updating star-server image."
git push