-
Notifications
You must be signed in to change notification settings - Fork 5
85 lines (73 loc) · 2.52 KB
/
Copy pathdocker-image.yml
File metadata and controls
85 lines (73 loc) · 2.52 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
name: Docker CI/CD
on:
push:
branches:
- main
- dev
- staging
release:
types: [created]
env:
REGISTRY: ghcr.io
ORG: breadchaincoop
permissions:
contents: read
packages: write
jobs:
docker:
strategy:
matrix:
arch: [amd64, arm64]
target: [node, router]
runs-on: ${{ matrix.arch == 'arm64' && 'ubuntu-24.04-arm' || 'ubuntu-latest' }}
steps:
- uses: actions/checkout@v4
- uses: docker/setup-buildx-action@v3
- uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Build and push (per-arch)
uses: docker/build-push-action@v5
with:
context: .
file: examples/counter/${{ matrix.target }}/Dockerfile
platforms: linux/${{ matrix.arch }}
push: true
tags: ${{ env.REGISTRY }}/${{ env.ORG }}/commonware-restaking-${{ matrix.target }}:${{ matrix.arch }}-${{ github.sha }}
cache-from: type=gha,scope=${{ matrix.target }}-${{ matrix.arch }}
cache-to: type=gha,mode=max,scope=${{ matrix.target }}-${{ matrix.arch }}
manifest:
needs: docker
runs-on: ubuntu-latest
strategy:
matrix:
target: [node, router]
steps:
- uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Derive tags (branch/release + short sha)
id: vars
shell: bash
run: |
SHORT_SHA="$(echo "${GITHUB_SHA}" | cut -c1-7)"
CHANNEL_TAG="${GITHUB_REF_NAME}"
[[ "${GITHUB_EVENT_NAME}" != "release" && "$CHANNEL_TAG" == "main" ]] && CHANNEL_TAG="latest"
echo "short_sha=${SHORT_SHA}" >> "$GITHUB_OUTPUT"
echo "channel_tag=${CHANNEL_TAG}" >> "$GITHUB_OUTPUT"
- name: Create and push multi-arch manifest
shell: bash
run: |
NAME="${{ env.REGISTRY }}/${{ env.ORG }}/commonware-restaking-${{ matrix.target }}"
TAG_PRIMARY="${{ steps.vars.outputs.channel_tag }}"
TAG_WITH_SHA="${TAG_PRIMARY}-${{ steps.vars.outputs.short_sha }}"
echo "Creating manifest tags: ${TAG_PRIMARY} and ${TAG_WITH_SHA}"
docker buildx imagetools create \
-t "${NAME}:${TAG_PRIMARY}" \
-t "${NAME}:${TAG_WITH_SHA}" \
"${NAME}:amd64-${{ github.sha }}" \
"${NAME}:arm64-${{ github.sha }}"