Repository navigation
142 lines (125 loc) · 4.65 KB
/
Copy pathdocker.yml
File metadata and controls
142 lines (125 loc) · 4.65 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
name: Docker image
# Builds the image from docker/Dockerfile and publishes it as
# ghcr.io/henmedia/layerling with the release's version and "latest". When the
# repository has the secrets DOCKERHUB_USERNAME and DOCKERHUB_TOKEN, the same
# multi-arch image is copied to Docker Hub as well (docker.io/<user>/layerling),
# where a NAS finds it in its registry search; without them that step is skipped.
# It starts by itself when a GitHub release is published and runs in the
# background - nothing in the release waits for it. amd64 and arm64 are built
# side by side on native runners (no emulation), then joined into one tag.
# "Run workflow" builds it again for an existing release tag.
on:
release:
types: [published]
workflow_dispatch:
inputs:
tag:
description: "Release tag to build, for example v1.34.0"
required: true
permissions:
contents: read
packages: write
concurrency:
group: docker-${{ github.event.release.tag_name || inputs.tag }}
cancel-in-progress: false
env:
IMAGE: ghcr.io/${{ github.repository }}
TAG: ${{ github.event.release.tag_name || inputs.tag }}
jobs:
build:
name: Build ${{ matrix.platform }}
strategy:
fail-fast: false
matrix:
include:
- platform: linux/amd64
runner: ubuntu-24.04
- platform: linux/arm64
runner: ubuntu-24.04-arm
runs-on: ${{ matrix.runner }}
steps:
- name: Checkout the release
uses: actions/checkout@v7
with:
ref: ${{ env.TAG }}
- name: Set up Buildx
uses: docker/setup-buildx-action@v4
- name: Log in to GitHub Container Registry
uses: docker/login-action@v4
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Build and push by digest
id: build
uses: docker/build-push-action@v7
with:
context: .
file: docker/Dockerfile
platforms: ${{ matrix.platform }}
labels: |
org.opencontainers.image.source=https://github.com/${{ github.repository }}
org.opencontainers.image.title=layerling
org.opencontainers.image.description=Easy 3D CAD for 3D printing, in your browser
org.opencontainers.image.licenses=AGPL-3.0-only
org.opencontainers.image.version=${{ env.TAG }}
outputs: type=image,name=${{ env.IMAGE }},push-by-digest=true,name-canonical=true,push=true
cache-from: type=gha,scope=${{ matrix.platform }}
cache-to: type=gha,scope=${{ matrix.platform }},mode=max
- name: Keep the digest
run: |
mkdir -p "$RUNNER_TEMP/digests"
digest="${{ steps.build.outputs.digest }}"
touch "$RUNNER_TEMP/digests/${digest#sha256:}"
- name: Upload the digest
uses: actions/upload-artifact@v7
with:
name: digest-${{ strategy.job-index }}
path: ${{ runner.temp }}/digests/*
retention-days: 1
publish:
name: Publish ${{ github.event.release.tag_name || inputs.tag }}
needs: build
runs-on: ubuntu-24.04
env:
DOCKERHUB_USERNAME: ${{ secrets.DOCKERHUB_USERNAME }}
steps:
- name: Collect the digests
uses: actions/download-artifact@v8
with:
path: ${{ runner.temp }}/digests
pattern: digest-*
merge-multiple: true
- name: Set up Buildx
uses: docker/setup-buildx-action@v4
- name: Log in to GitHub Container Registry
uses: docker/login-action@v4
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Tag both architectures as the version and latest
working-directory: ${{ runner.temp }}/digests
run: |
version="${TAG#v}"
docker buildx imagetools create \
-t "$IMAGE:$version" \
-t "$IMAGE:latest" \
$(printf "$IMAGE@sha256:%s " *)
docker buildx imagetools inspect "$IMAGE:$version"
- name: Log in to Docker Hub
if: ${{ env.DOCKERHUB_USERNAME != '' }}
uses: docker/login-action@v4
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Copy the image to Docker Hub
if: ${{ env.DOCKERHUB_USERNAME != '' }}
run: |
version="${TAG#v}"
hub="docker.io/${DOCKERHUB_USERNAME}/layerling"
docker buildx imagetools create \
-t "$hub:$version" \
-t "$hub:latest" \
"$IMAGE:$version"
docker buildx imagetools inspect "$hub:$version"