This repository has been archived by the owner on Aug 24, 2023. It is now read-only.
121 lines (102 loc) · 4.05 KB
/
release-docker.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
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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
name: CD
on:
release:
types: [published]
push:
branches: [main]
pull_request:
branches: [main]
concurrency:
group: ${{ github.workflow }}-${{ github.event_name }}-${{ github.ref }}
cancel-in-progress: true
jobs:
main:
if: github.event.pull_request.head.repo.full_name == github.repository && github.actor != 'dependabot[bot]'
name: Publish
runs-on: ubuntu-latest
environment: Release Docker
steps:
- name: Checkout
uses: actions/checkout@93ea575cb5d8a053eaa0ac8fa3b40d7e05a33cc8 # tag=v3.1.0
- name: Cache
uses: actions/cache@9b0c1fce7a93df8e3bb8926b0d6e9d89e92f20a7 # tag=v3.0.11
with:
path: |
~/.cargo/bin/
~/.cargo/registry/index/
~/.cargo/registry/cache/
~/.cargo/git/db/
target/
key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}
- name: Set up rust toolchain
uses: actions-rs/toolchain@16499b5e05bf2e26879000db0c1d13f7e13fa3af # tag=v1.0.7
with:
profile: minimal
toolchain: nightly
target: wasm32-unknown-unknown
default: true
override: true
- name: Cargo build
uses: actions-rs/cargo@844f36862e911db73fe0815f00a4a2602c279505 # tag=v1.0.3
with:
command: build
args: --release --all
- name: Save binary
run: |
mkdir -p build
cp target/release/meta-node build/
- name: Set up QEMU
uses: docker/setup-qemu-action@e81a89b1732b9c48d79cd809d8d81d79c4647a18 # tag=v2.1.0
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@8c0edbc76e98fa90f69d9a2c020dcb50019dc325 # tag=v2.2.1
- name: Login to GitHub Container Registry
uses: docker/login-action@f4ef78c080cd8ba55a85445d5b36e214a81df20a # tag=v2.1.0
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Tags
uses: actions/github-script@d556feaca394842dc55e4734bf3bb9f685482fa0 # tag=v6.3.3
id: tags
with:
script: |
const prefix = 'ghcr.io/defich/metachain'
if (context.eventName === 'release') {
const semver = context.payload?.release?.tag_name
if (semver.match(/^v[0-9]+\.[0-9]+\.[0-9]+$/) === null) {
throw new Error(`Release Violation: Provided version '${semver}' is not valid semver.`)
}
return `${prefix}:latest,${prefix}:${semver.replace('v','')}`
}
if (context.eventName === 'push' && context.ref === 'refs/heads/main') {
return `${prefix}:main,${prefix}:${context.sha}`
}
if (context.eventName === 'pull_request') {
return `${prefix}:${context.payload.number},${prefix}:${context.sha}`
}
result-encoding: string
- name: Support multi-platform
run: |
sed -i 's/FROM /FROM --platform=$BUILDPLATFORM /g' ./Dockerfile
- name: Build & Publish
uses: docker/build-push-action@c56af957549030174b10d6867f20e78cfd7debc5 # tag=v3.2.0
with:
context: .
file: ./Dockerfile
push: true
platforms: |
linux/amd64
linux/arm64
tags: ${{ steps.tags.outputs.result }}
cache-from: type=registry,ref=ghcr.io/defich/metachain:buildcache
cache-to: type=registry,ref=ghcr.io/defich/metachain:buildcache,mode=max
- name: Post Report
if: github.event_name == 'pull_request'
uses: marocchino/sticky-pull-request-comment@adca94abcaf73c10466a71cc83ae561fd66d1a56 # tag=v2.3.0
with:
header: release
message: |
Docker image for defich/metachain is ready!
Built with commit ${{ github.sha }}
- `docker pull ghcr.io/defich/metachain:${{ github.sha }}`
- `docker pull ghcr.io/defich/metachain:pr-${{ github.event.number }}`