-
Notifications
You must be signed in to change notification settings - Fork 265
130 lines (130 loc) · 4.57 KB
/
docker-build.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
name: Docker Build
on:
release:
types: [created]
jobs:
setup:
if: contains('["libsgh"]', github.actor)
name: build setup
runs-on: ubuntu-latest
outputs:
branch: ${{ steps.setup.outputs.branch }}
target: ${{ steps.setup.outputs.target }}
image_name: ${{ steps.setup.outputs.image_name }}
version: ${{ steps.setup.outputs.version }}
image_base: ${{ steps.setup.outputs.image_base }}
steps:
- name: setup
id: setup
run: |
target='["linux/amd64", "linux/arm64", "linux/ppc64le", "linux/s390x", "linux/386", "linux/arm/v7", "linux/arm/v6"]'
branch='["main"]'
image_base='iicm/pan-index'
ref=${{ github.ref }}
version=$(basename ${ref})
image_name='["'${image_base}':'${version}'", "'${image_base}':latest"]'
list=$(echo ${target} | jq -c)
echo "target=${list}" >> $GITHUB_OUTPUT
b=$(echo ${branch} | jq -c)
echo "branch=${b}" >> $GITHUB_OUTPUT
images=$(echo ${image_name} | jq -c)
echo "image_name=${images}" >> $GITHUB_OUTPUT
echo "version=${version}" >> $GITHUB_OUTPUT
echo "image_base=${image_base}" >> $GITHUB_OUTPUT
build:
if: contains('["libsgh"]', github.actor)
needs: setup
strategy:
matrix:
target: ${{ fromJson(needs.setup.outputs.target) }}
branch: ${{ fromJson(needs.setup.outputs.branch) }}
go-version: [1.20.1]
name: build
runs-on: ubuntu-latest
outputs:
artifact_name: ${{ steps.artifact.outputs.name }}
steps:
- name: Setup Artifact Name
id: artifact
run: |
tar=${{ matrix.target }}
a=${tar//'/'/'-'}
echo "name=${a}" >> $GITHUB_OUTPUT
- name: Setup Go
uses: actions/setup-go@v3
with:
go-version: ${{ matrix.go-version }}
- name: Checkout
uses: actions/checkout@v3
with:
persist-credentials: false
ref: ${{ matrix.branch }}
fetch-depth: 0
- name: Set up QEMU
uses: docker/setup-qemu-action@v2
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
- name: Cache Docker layers
uses: actions/cache@v3
with:
path: /tmp/.buildx-cache
key: ${{ runner.os }}-buildx-${{ steps.artifact.outputs.name }}-${{ github.sha }}
restore-keys: |
${{ runner.os }}-buildx-${{ steps.artifact.outputs.name }}
- name: Login to DockerHub
uses: docker/login-action@v2
with:
username: iicm
password: ${{ secrets.DOCKERHUB_PASSWORD }}
- name: Build and push
id: docker_build
uses: docker/build-push-action@v4
with:
context: .
push: true
provenance: false
sbom: false
build-args: |
GO_VERSION=${{ matrix.go-version }}
VERSION=${{ github.ref }}
TYPE=nightly_build_docker
APP_NAME=PanIndex
tags: ${{ needs.setup.outputs.image_base }}:latest-${{ steps.artifact.outputs.name }},${{ needs.setup.outputs.image_base }}:${{ needs.setup.outputs.version }}-${{ steps.artifact.outputs.name }}
labels: ${{ steps.meta.outputs.labels }}
platforms: ${{ matrix.target }}
cache-from: type=local,src=/tmp/.buildx-cache
cache-to: type=local,dest=/tmp/.buildx-cache-new,mode=max
- name: Move cache
run: |
rm -rf /tmp/.buildx-cache
mv /tmp/.buildx-cache-new /tmp/.buildx-cache
combine:
if: contains('["libsgh"]', github.actor)
runs-on: ubuntu-latest
needs:
- setup
- build
steps:
- name: Login to Docker Hub
uses: docker/login-action@v2
with:
username: iicm
password: ${{ secrets.DOCKERHUB_PASSWORD }}
- name: Combine images
run: |
for image_name in ${{ join(fromJson(needs.setup.outputs.image_name), ' ') }}
do
args=""
remove_tags=""
for target in ${{ join(fromJson(needs.setup.outputs.target), ' ') }}
do
name=${target//'/'/'-'}
remove_tags="$remove_tags ${image_name}-$name"
args="$args --amend ${image_name}-$name"
done
docker manifest create ${image_name} ${args}
docker manifest push --purge ${image_name}
docker run --rm lumir/remove-dockerhub-tag --user iicm \
--password ${{ secrets.DOCKERHUB_PASSWORD }} ${remove_tags}
done
shell: bash