forked from ObolNetwork/charon
-
Notifications
You must be signed in to change notification settings - Fork 0
102 lines (87 loc) · 3.76 KB
/
build-push-deploy.yml
File metadata and controls
102 lines (87 loc) · 3.76 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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
on:
push:
branches:
- main*
- electra
tags:
- 'v*'
name: Build and Publish Docker Image
jobs:
build-docker:
runs-on: charon-ci
name: Build Docker Image
steps:
- uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v6.0.1
with:
fetch-depth: 0
- name: Set up QEMU
id: qemu
uses: docker/setup-qemu-action@c7c53464625b32c7a7e944ae62b3e17d2b600130 # v3.7.0
- uses: docker/setup-buildx-action@8d2750c68a42422c14e847fe6c8ac0403b4cbd6f # v3.12.0
with:
driver-opts: "image=moby/buildkit:v0.10.5" # avoid unknown/unknown arch in ghcr
- name: Get app/version.Version from the code
if: github.ref_type == 'branch'
run: echo "APP_VERSION=$(grep 'var version' app/version/version.go | cut -d'"' -f2)" >> $GITHUB_ENV
- name: Define docker image meta data tags
id: meta
uses: docker/metadata-action@c299e40c65443455700f0fdfc63efafe5b349051 # v5.10.0
with:
images: |
obolnetwork/charon
ghcr.io/obolnetwork/charon
tags: |
# Tag "git short sha" on all git events
type=sha,prefix=
# Tag "next" on git-push-to-main-branch events
type=raw,value=next,event=branch,enable={{is_default_branch}}
# Tag "latest" on git-tag events
type=raw,value=latest,event=tag,enable=${{ startsWith(github.ref, 'refs/tags/v') }}
# Tag "electra" only when pushing to the "electra" branch
type=raw,value=electra,event=branch,enable=${{ github.ref == 'refs/heads/electra' }}
# Tag "$APP_VERSION" on git-push-to-branch events
type=raw,value=${{ env.APP_VERSION }},event=branch,enable=${{ github.ref != 'refs/heads/electra' }}
# Tag "tag ref" on git-tag events
type=ref,event=tag
- name: Login to Github container registry
uses: docker/login-action@5e57cd118135c172c3672efd75eb46360885c0ef # v3.6.0
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Login to Dockerhub container registry
uses: docker/login-action@5e57cd118135c172c3672efd75eb46360885c0ef # v3.6.0
with:
username: obolnetwork
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Maybe overwrite app/version.Version with git tag
if: github.ref_type == 'tag'
run: echo 'GO_BUILD_FLAG=-ldflags=-X github.com/obolnetwork/charon/app/version.version=${{ github.ref_name }}' >> $GITHUB_ENV
- uses: docker/build-push-action@263435318d21b8e681c14492fe198d362a7d2c83 # v6.18.0
with:
context: .
platforms: linux/amd64,linux/arm64
push: true
build-args: |
GITHUB_SHA=${{ github.sha }}
GO_BUILD_FLAG=${{ env.GO_BUILD_FLAG }}
tags: ${{ steps.meta.outputs.tags }}
- name: Set short git commit SHA
id: vars
run: |
calculatedSha=$(git rev-parse --short=7 ${{ github.sha }})
echo "::set-output name=short_sha::$calculatedSha"
- name: Trigger dev relay deploy job
uses: peter-evans/repository-dispatch@28959ce8df70de7be546dd1250a005dd32156697 # v4.0.1
with:
token: ${{ secrets.CHARON_K8S_REPO_ACCESS_TOKEN }}
repository: ObolNetwork/obol-infrastructure
event-type: relay-nonprod-deployment
client-payload: '{"relay_name": "relay-dev","relay_version": "${{ steps.vars.outputs.short_sha }}"}'
- name: Trigger charon-K8S deploy job
uses: peter-evans/repository-dispatch@28959ce8df70de7be546dd1250a005dd32156697 # v4.0.1
with:
token: ${{ secrets.CHARON_K8S_REPO_ACCESS_TOKEN }}
repository: ObolNetwork/obol-infrastructure
event-type: charon-package-published
client-payload: '{"sha": "${{ github.sha }}"}'