-
Notifications
You must be signed in to change notification settings - Fork 1
175 lines (160 loc) · 6.78 KB
/
contributor.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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
name: Generate contributor image
env:
GITHUB_OUTPUT: ""
on:
workflow_call:
inputs:
new_tools:
description: "Whether a newly generated tools image should be used for this workflow"
type: boolean
required: true
default: false
new_base:
description: "Whether a newly generated base image should be used for this workflow"
type: boolean
required: true
default: false
jobs:
psibase-contributor:
name: psibase-contributor
strategy:
matrix:
include:
- runner: ubuntu-latest
platform: "linux/amd64"
platform_short: "amd64"
- runner: arm-runner-2
platform: "linux/arm64"
platform_short: "arm64"
runs-on: ${{ matrix.runner }}
services:
registry:
image: registry:2
ports:
- 5000:5000
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
submodules: false
fetch-depth: 0
- name: Building ${{ matrix.platform_short }}
run: true
- name: Config docker buildx
if: ${{ github.event_name != 'pull_request' }}
uses: docker/setup-buildx-action@v3
- name: (PR only) - Config docker buildx host network
if: ${{ github.event_name == 'pull_request' }}
uses: docker/setup-buildx-action@v3
with:
driver-opts: network=host
- name: Login in to registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Download local base image
if: ${{ inputs.new_base && github.event_name == 'pull_request' }}
uses: actions/download-artifact@v4
with:
name: psibase-builder-ubuntu-2204-${{ matrix.platform_short }}-image
- name: Set BASE_IMAGE
id: base_img
env:
NEW_BASE: ${{ inputs.new_base }}
IS_PR: ${{ github.event_name == 'pull_request' }}
run: |
if [[ "$NEW_BASE" == "true" && "$IS_PR" == "true" ]]; then
docker load -i psibase-builder-ubuntu-2204-${{ matrix.platform_short }}-image.tar
rm psibase-builder-ubuntu-2204-${{ matrix.platform_short }}-image.tar
IMAGE=$(docker images --format "{{.Repository}}:{{.Tag}}" | head -n 1)
LOCAL_TAG=localhost:5000/local_base_image:latest
docker tag ${IMAGE} ${LOCAL_TAG}
docker push ${LOCAL_TAG}
echo "BASE_IMAGE=${LOCAL_TAG}" >> $GITHUB_OUTPUT
elif [[ "$NEW_BASE" == "true" ]]; then
echo "BASE_IMAGE=ghcr.io/gofractally/psibase-builder-ubuntu-2204:${{ github.sha }}" >> $GITHUB_OUTPUT
else
latest_tag=$(./.github/scripts/latest-tag.sh "gofractally/psibase-builder-ubuntu-2204")
echo "BASE_IMAGE=ghcr.io/gofractally/psibase-builder-ubuntu-2204:${latest_tag}" >> $GITHUB_OUTPUT
fi
- name: Download local tools image
if: ${{ inputs.new_tools && github.event_name == 'pull_request' }}
uses: actions/download-artifact@v4
with:
name: https-tool-config-${{ matrix.platform_short }}-image
- name: Set TOOL_CONFIG_IMAGE
id: tool_cfg_img
env:
NEW_TOOLS: ${{ inputs.new_tools }}
IS_PR: ${{ github.event_name == 'pull_request' }}
run: |
if [[ "$NEW_TOOLS" == "true" && "$IS_PR" == "true" ]]; then
docker load -i https-tool-config-${{ matrix.platform_short }}-image.tar
rm https-tool-config-${{ matrix.platform_short }}-image.tar
IMAGE=$(docker images --format "{{.Repository}}:{{.Tag}}" | head -n 1)
LOCAL_TAG=localhost:5000/local_tools_image:latest
docker tag ${IMAGE} ${LOCAL_TAG}
docker push ${LOCAL_TAG}
echo "TOOL_CONFIG_IMAGE=${LOCAL_TAG}" >> $GITHUB_OUTPUT
elif [[ "$NEW_TOOLS" == "true" ]]; then
echo "TOOL_CONFIG_IMAGE=ghcr.io/gofractally/https-tool-config:${{ github.sha }}" >> $GITHUB_OUTPUT
else
latest_tag=$(./.github/scripts/latest-tag.sh "gofractally/https-tool-config")
echo "TOOL_CONFIG_IMAGE=ghcr.io/gofractally/https-tool-config:${latest_tag}" >> $GITHUB_OUTPUT
fi
- name: Build & publish
if: ${{ github.event_name != 'pull_request' }}
uses: docker/build-push-action@v5
with:
context: .
push: true
file: docker/psibase-contributor.Dockerfile
build-args: |
BASE_IMAGE=${{ steps.base_img.outputs.BASE_IMAGE }}
TOOL_CONFIG_IMAGE=${{ steps.tool_cfg_img.outputs.TOOL_CONFIG_IMAGE }}
tags: "ghcr.io/${{ github.repository_owner }}/psibase-contributor:${{ github.sha }}-${{ matrix.platform_short }}"
platforms: ${{ matrix.platform }}
provenance: false
outputs: type=image
- name: (PR Only) - Build image archive
if: ${{ github.event_name == 'pull_request' }}
uses: docker/build-push-action@v5
with:
context: .
build-args: |
BASE_IMAGE=${{ steps.base_img.outputs.BASE_IMAGE }}
TOOL_CONFIG_IMAGE=${{ steps.tool_cfg_img.outputs.TOOL_CONFIG_IMAGE }}
file: docker/psibase-contributor.Dockerfile
tags: "ghcr.io/${{ github.repository_owner }}/psibase-contributor:${{ github.sha }}-${{ matrix.platform_short }}"
platforms: ${{ matrix.platform }}
outputs: type=docker,dest=psibase_contributor-${{ matrix.platform_short }}.tar
- name: (PR only) - Upload image archive as artifact
if: ${{ github.event_name == 'pull_request' }}
uses: actions/upload-artifact@v4
with:
name: psibase_contributor-${{ matrix.platform_short }}
path: psibase_contributor-${{ matrix.platform_short }}.tar
retention-days: 1
merge:
name: merge multi-platform images
if: ${{ github.event_name != 'pull_request' }}
runs-on: ubuntu-latest
needs: [psibase-contributor]
steps:
- name: Config docker buildx
uses: docker/setup-buildx-action@v3
- name: Login in to registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Create and push manifest
run: |
IMAGE="ghcr.io/${{ github.repository_owner }}/psibase-contributor:${{ github.sha }}"
docker manifest create ${IMAGE} \
--amend ${IMAGE}-arm64 \
--amend ${IMAGE}-amd64
docker manifest push ${IMAGE}