-
Notifications
You must be signed in to change notification settings - Fork 0
165 lines (147 loc) · 5.81 KB
/
build_ghcr.yaml
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
name: Build Container Images
on:
workflow_dispatch:
push:
paths:
- "**/Dockerfile"
schedule:
- cron: '0 0 */2 * *'
# Avoids Github UI bugs https://github.com/orgs/community/discussions/45969
env:
BUILDX_NO_DEFAULT_ATTESTATIONS: 1
jobs:
ghcrbuild:
strategy:
fail-fast: false
matrix:
type: [builder, user]
ubuntu: [focal, jammy]
platform: [linux/amd64]
name: Build container images for GHCR
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Extract metadata for container image
id: meta
uses: docker/metadata-action@v4
with:
images: ghcr.io/${{ github.repository }}-${{ matrix.type }}
tags: |
type=raw,value=${{ matrix.ubuntu }}
- name: Extract container name without tag
id: vars
run: |
echo container=$(echo '${{ steps.meta.outputs.tags }}' | awk -F':' '{print $1}') >> $GITHUB_OUTPUT
- name: Set up QEMU
uses: docker/setup-qemu-action@v2
with:
platforms: arm64
if: contains(steps.versions.outputs.platform, 'arm64')
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
with:
platforms: ${{matrix.platform}}
- name: Login to GHCR
uses: docker/login-action@v2
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Build and push container image to ghcr
id: build
uses: docker/build-push-action@v4
with:
build-args: |
UBUNTU_TAG=${{matrix.ubuntu}}
file: ${{ matrix.type }}.Dockerfile
labels: ${{ steps.meta.outputs.labels }}
outputs: type=image,name=${{ steps.vars.outputs.container }},push-by-digest=true,name-canonical=true,push=true
platforms: ${{matrix.platform}}
provenance: false
- name: Prepare Dockerfile to extract R version with emulator
run: |
mkdir -p ${{matrix.ubuntu}}-${{matrix.platform}}
cat << "EOF" > ${{matrix.ubuntu}}-${{matrix.platform}}-r.Dockerfile
FROM ${{ steps.vars.outputs.container }}@${{ steps.build.outputs.digest }} as extract
RUN mkdir /r2utmp && R --version > /r2utmp/rver && cat /etc/os-release > /r2utmp/os-release
FROM scratch as export
COPY --from=extract /r2utmp/* /
EOF
- name: Build and push container image to ghcr
uses: docker/build-push-action@v4
with:
file: ${{matrix.ubuntu}}-${{matrix.platform}}-r.Dockerfile
context: .
push: false
load: false
provenance: false
outputs: type=tar,dest=${{matrix.ubuntu}}-${{matrix.platform}}/r.tar
tags: ${{ steps.meta.outputs.tags }}-r
platforms: ${{ matrix.platform }}
- name: Extract rversion
id: versions
run: |
cd ${{matrix.ubuntu}}-${{matrix.platform}}
tar -xvf r.tar
echo rver=$(cat rver | awk 'NR==1{print $3}') >> $GITHUB_OUTPUT
echo osver=$(awk -F= '/VERSION_ID/ {gsub("\"", "", $2); print $2}' os-release) >> $GITHUB_OUTPUT
- name: Export digest by ubuntu and r versions
run: |
digest="${{ steps.build.outputs.digest }}"
mkdir -p /tmp/digests/${{matrix.type}}/${{matrix.ubuntu}}
touch "/tmp/digests/${{matrix.type}}/${{matrix.ubuntu}}/${digest#sha256:}"
mkdir -p /tmp/digests/${{matrix.type}}/${{matrix.ubuntu}}-r-${{steps.versions.outputs.rver}}
touch "/tmp/digests/${{matrix.type}}/${{matrix.ubuntu}}-r-${{steps.versions.outputs.rver}}/${digest#sha256:}"
mkdir -p /tmp/digests/${{matrix.type}}/${{steps.versions.outputs.osver}}
touch "/tmp/digests/${{matrix.type}}/${{steps.versions.outputs.osver}}/${digest#sha256:}"
mkdir -p /tmp/digests/${{matrix.type}}/${{steps.versions.outputs.osver}}-r-${{steps.versions.outputs.rver}}
touch "/tmp/digests/${{matrix.type}}/${{steps.versions.outputs.osver}}-r-${{steps.versions.outputs.rver}}/${digest#sha256:}"
- name: Upload digests
uses: actions/upload-artifact@v3
with:
name: r2udigests-${{ github.run_id }}
path: /tmp/digests/**
if-no-files-found: error
retention-days: 1
merge:
runs-on: ubuntu-latest
needs:
- ghcrbuild
if: always()
strategy:
fail-fast: false
matrix:
ubuntu: [focal, jammy]
type: [builder, user]
steps:
- name: Download digests
uses: actions/download-artifact@v3
with:
name: r2udigests-${{ github.run_id }}
path: /tmp/digests
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
with:
platforms: ${{matrix.platform}}
- name: Login to GHCR
uses: docker/login-action@v2
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Extract metadata for container image
id: meta
uses: docker/metadata-action@v4
with:
images: ghcr.io/${{ github.repository }}-${{ matrix.type }}
tags: |
type=raw,value=${{ matrix.ubuntu }}
- name: Extract container name without tag
id: vars
run: |
echo container=$(echo '${{ steps.meta.outputs.tags }}' | awk -F':' '{print $1}') >> $GITHUB_OUTPUT
- name: Create manifest list and push
run: |
cd /tmp/digests/${{matrix.type}}
ls --hide=digestdirs > digestdirs
cat digestdirs | xargs -i bash -c 'docker buildx imagetools create -t ${{steps.vars.outputs.container}}:{} $(for f in {}/*; do basename "$f"; done | xargs printf "${{steps.vars.outputs.container}}@sha256:%s ")'