Repository navigation
158 lines (141 loc) · 4.7 KB
/
Copy pathsandbox-image.yml
File metadata and controls
158 lines (141 loc) · 4.7 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
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
name: Sandbox Image
on:
workflow_dispatch:
inputs:
tag:
description: Extra tag to publish alongside the package version and commit sha
default: latest
required: false
pull_request:
paths:
- Dockerfile.sandbox
- scripts/sandbox-dockerd-start.sh
- .github/workflows/sandbox-image.yml
env:
IMAGE: docker.io/cstechdev/ocm-sandbox
permissions:
contents: read
jobs:
build:
if: github.event_name == 'workflow_dispatch' || github.event.pull_request.head.repo.full_name == github.repository
strategy:
fail-fast: true
matrix:
include:
- platform: linux/amd64
runner: ubuntu-latest
- platform: linux/arm64
runner: ubuntu-24.04-arm
runs-on: ${{ matrix.runner }}
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Platform slug
id: platform
run: echo "slug=${PLATFORM//\//-}" >> "$GITHUB_OUTPUT"
env:
PLATFORM: ${{ matrix.platform }}
- name: Login to Docker Hub
if: github.event_name == 'workflow_dispatch'
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Build and verify native image
id: build
uses: docker/build-push-action@v5
with:
context: .
file: Dockerfile.sandbox
platforms: ${{ matrix.platform }}
outputs: ${{ github.event_name == 'workflow_dispatch' && format('type=image,name={0},push-by-digest=true,name-canonical=true,push=true', env.IMAGE) || 'type=cacheonly' }}
cache-from: type=gha,scope=sandbox-${{ steps.platform.outputs.slug }}
cache-to: type=gha,scope=sandbox-${{ steps.platform.outputs.slug }},mode=max
- name: Export digest
if: github.event_name == 'workflow_dispatch'
run: |
mkdir -p /tmp/digests
touch "/tmp/digests/${DIGEST#sha256:}"
env:
DIGEST: ${{ steps.build.outputs.digest }}
- name: Upload digest
if: github.event_name == 'workflow_dispatch'
uses: actions/upload-artifact@v4
with:
name: digests-${{ steps.platform.outputs.slug }}
path: /tmp/digests/*
if-no-files-found: error
retention-days: 1
merge:
if: github.event_name == 'workflow_dispatch'
needs: build
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Download digests
uses: actions/download-artifact@v4
with:
path: /tmp/digests
pattern: digests-*
merge-multiple: true
- name: Login to Docker Hub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Resolve tags
id: tags
run: |
version="$(jq -er .version package.json)"
tags="sha-${GITHUB_SHA::12} $version"
for tag in "$version" "$EXTRA_TAG"; do
if [ -n "$tag" ] && [[ ! "$tag" =~ ^[a-zA-Z0-9_][a-zA-Z0-9_.-]{0,127}$ ]]; then
printf 'Invalid image tag: %s\n' "$tag" >&2
exit 1
fi
done
if [ -n "$EXTRA_TAG" ]; then
tags="$tags $EXTRA_TAG"
fi
echo "tags=$tags" >> "$GITHUB_OUTPUT"
env:
EXTRA_TAG: ${{ inputs.tag }}
- name: Create manifest list and push
working-directory: /tmp/digests
run: |
read -ra tags <<< "$TAGS"
args=()
for tag in "${tags[@]}"; do
args+=(-t "$IMAGE:$tag")
done
digests=(*)
test "${#digests[@]}" -eq 2
for digest in "${digests[@]}"; do
[[ "$digest" =~ ^[a-f0-9]{64}$ ]]
args+=("$IMAGE@sha256:$digest")
done
docker buildx imagetools create "${args[@]}"
env:
TAGS: ${{ steps.tags.outputs.tags }}
- name: Report index digest
run: |
digest="$(docker buildx imagetools inspect "$IMAGE:sha-${GITHUB_SHA::12}" --format '{{json .Manifest.Digest}}' | tr -d '"')"
{
echo "## Sandbox image"
echo
echo "Tags: $TAGS"
echo
echo "Pin \`SANDBOX_IMAGE\` to:"
echo
echo '```'
echo "$IMAGE@$digest"
echo '```'
} >> "$GITHUB_STEP_SUMMARY"
echo "$IMAGE@$digest"
env:
TAGS: ${{ steps.tags.outputs.tags }}