Skip to content

Commit 1c46bc9

Browse files
authored
Merge pull request #18 from SetoKaiba/docker_fix
docker fix
2 parents bef6cbf + 214936f commit 1c46bc9

File tree

1 file changed

+78
-133
lines changed

1 file changed

+78
-133
lines changed

.github/workflows/docker.yml

+78-133
Original file line numberDiff line numberDiff line change
@@ -1,69 +1,54 @@
11
name: Publish Docker Image
2-
on:
2+
on:
33
push:
4-
branches: [master]
4+
branches: [ master ]
5+
tags:
6+
- '**'
57

6-
concurrency:
8+
concurrency:
79
group: ${{ github.ref }}-${{ github.workflow }}
810
cancel-in-progress: true
911

12+
env:
13+
REGISTRY_IMAGE: ghcr.io/metacubex/subconverter
14+
1015
jobs:
11-
amd64_build:
12-
name: Build AMD64 Image
13-
runs-on: ubuntu-latest
16+
build:
17+
strategy:
18+
matrix:
19+
include:
20+
- platform: linux/amd64
21+
os: ubuntu-latest
22+
- platform: linux/386
23+
os: ubuntu-latest
24+
- platform: linux/arm/v7
25+
os: ubuntu-latest
26+
- platform: linux/arm64
27+
os: ubuntu-latest
28+
runs-on: ${{ matrix.os }}
29+
name: Build ${{ matrix.platform }} Image
1430
steps:
31+
- name: Prepare
32+
run: |
33+
platform=${{ matrix.platform }}
34+
echo "PLATFORM_PAIR=${platform//\//-}" >> $GITHUB_ENV
35+
1536
- name: Checkout base
16-
uses: actions/checkout@v3
37+
uses: actions/checkout@v4
1738
with:
1839
fetch-depth: 0
1940

2041
- name: Set up Docker Buildx
21-
uses: docker/setup-buildx-action@v2
22-
23-
- name: login to ghcr.io
24-
uses: docker/login-action@v3
25-
with:
26-
registry: ghcr.io
27-
username: ${{ github.actor }}
28-
password: ${{ secrets.GITHUB_TOKEN }}
29-
30-
- name: Get commit SHA
31-
id: vars
32-
run: echo "::set-output name=sha_short::$(git rev-parse --short HEAD)"
33-
34-
- name: Build and export
35-
id: build
36-
if: github.ref == 'refs/heads/master'
37-
uses: docker/build-push-action@v3
38-
with:
39-
platforms: linux/amd64
40-
context: scripts/
41-
tags: ghcr.io/metacubex/subconverter:latest
42-
build-args: |
43-
SHA=${{ steps.vars.outputs.sha_short }}
44-
outputs: type=image,push=true
45-
46-
- name: Save digest
47-
if: github.ref == 'refs/heads/master'
48-
run: echo ${{ steps.build.outputs.digest }} > /tmp/digest.txt
42+
uses: docker/setup-buildx-action@v3
4943

50-
- name: Upload artifact
51-
uses: actions/upload-artifact@v3
52-
with:
53-
name: digest_amd64
54-
path: /tmp/digest.txt
55-
56-
x86_build:
57-
name: Build x86 Image
58-
runs-on: ubuntu-latest
59-
steps:
60-
- name: Checkout base
61-
uses: actions/checkout@v3
44+
- name: Docker meta
45+
id: meta
46+
uses: docker/metadata-action@v5
6247
with:
63-
fetch-depth: 0
64-
65-
- name: Set up Docker Buildx
66-
uses: docker/setup-buildx-action@v2
48+
images: ${{ env.REGISTRY_IMAGE }}
49+
tags: |
50+
type=semver,pattern={{version}}
51+
type=raw,value=latest,enable={{is_default_branch}}
6752
6853
- name: login to ghcr.io
6954
uses: docker/login-action@v3
@@ -73,105 +58,59 @@ jobs:
7358
password: ${{ secrets.GITHUB_TOKEN }}
7459

7560
- name: Get commit SHA
76-
id: vars
77-
run: echo "::set-output name=sha_short::$(git rev-parse --short HEAD)"
78-
79-
- name: Build and export
80-
id: build
8161
if: github.ref == 'refs/heads/master'
82-
uses: docker/build-push-action@v3
83-
with:
84-
platforms: linux/386
85-
context: scripts/
86-
tags: ghcr.io/metacubex/subconverter:latest
87-
build-args: |
88-
SHA=${{ steps.vars.outputs.sha_short }}
89-
outputs: type=image,push=true
90-
91-
- name: Save digest
92-
if: github.ref == 'refs/heads/master'
93-
run: echo ${{ steps.build.outputs.digest }} > /tmp/digest.txt
94-
95-
- name: Upload artifact
96-
uses: actions/upload-artifact@v3
97-
with:
98-
name: digest_386
99-
path: /tmp/digest.txt
100-
101-
arm64_build:
102-
name: Build ARM64 Image
103-
runs-on: ubuntu-latest
104-
steps:
105-
- name: Checkout base
106-
uses: actions/checkout@v3
107-
with:
108-
fetch-depth: 0
109-
110-
- name: Set up QEMU
111-
uses: docker/setup-qemu-action@v2
112-
113-
- name: Set up Docker Buildx
114-
uses: docker/setup-buildx-action@v2
115-
116-
- name: login to ghcr.io
117-
uses: docker/login-action@v3
118-
with:
119-
registry: ghcr.io
120-
username: ${{ github.actor }}
121-
password: ${{ secrets.GITHUB_TOKEN }}
122-
123-
- name: Get commit SHA
12462
id: vars
125-
run: echo "::set-output name=sha_short::$(git rev-parse --short HEAD)"
63+
run: echo "sha_short=$(git rev-parse --short HEAD)" >> $GITHUB_OUTPUT
12664

12765
- name: Build and export
12866
id: build
129-
if: github.ref == 'refs/heads/master'
130-
uses: docker/build-push-action@v3
67+
uses: docker/build-push-action@v5
13168
with:
132-
platforms: linux/arm64
69+
platforms: ${{ matrix.platform }}
13370
context: scripts/
134-
tags: ghcr.io/metacubex/subconverter:latest
71+
labels: ${{ steps.meta.outputs.labels }}
13572
build-args: |
13673
SHA=${{ steps.vars.outputs.sha_short }}
137-
THREADS=2
138-
outputs: type=image,push=true
74+
outputs: type=image,name=${{ env.REGISTRY_IMAGE }},push-by-digest=true,name-canonical=true,push=true
13975

140-
- name: Save digest
141-
if: github.ref == 'refs/heads/master'
142-
run: echo ${{ steps.build.outputs.digest }} > /tmp/digest.txt
76+
- name: Export digest
77+
run: |
78+
rm -rf /tmp/digests
79+
mkdir -p /tmp/digests
80+
digest="${{ steps.build.outputs.digest }}"
81+
touch "/tmp/digests/${digest#sha256:}"
14382
14483
- name: Upload artifact
145-
uses: actions/upload-artifact@v3
84+
uses: actions/upload-artifact@v4
14685
with:
147-
name: digest_arm64
148-
path: /tmp/digest.txt
149-
build:
150-
name: Build
151-
needs: [amd64_build, x86_build, arm64_build]
86+
name: digest-${{ env.PLATFORM_PAIR }}
87+
path: /tmp/digests/*
88+
if-no-files-found: error
89+
retention-days: 1
90+
91+
merge:
92+
name: Merge
93+
needs: build
15294
runs-on: ubuntu-latest
15395
steps:
154-
- name: Checkout base
155-
uses: actions/checkout@v3
96+
- name: Download digests
97+
uses: actions/download-artifact@v4
15698
with:
157-
fetch-depth: 0
158-
159-
# https://github.com/docker/setup-qemu-action
160-
- name: Set up QEMU
161-
uses: docker/setup-qemu-action@v2
99+
path: /tmp/digests
100+
pattern: digest-*
101+
merge-multiple: true
162102

163-
# https://github.com/docker/setup-buildx-action
164103
- name: Set up Docker Buildx
165-
uses: docker/setup-buildx-action@v2
166-
with:
167-
config-inline: |
168-
[worker.oci]
169-
max-parallelism = 1
104+
uses: docker/setup-buildx-action@v3
170105

171-
- name: Download artifact
172-
uses: actions/download-artifact@v3
106+
- name: Docker meta
107+
id: meta
108+
uses: docker/metadata-action@v5
173109
with:
174-
path: /tmp/images/
110+
images: ${{ env.REGISTRY_IMAGE }}
111+
tags: |
112+
type=semver,pattern={{version}}
113+
type=raw,value=latest,enable={{is_default_branch}}
175114
176115
- name: login to ghcr.io
177116
uses: docker/login-action@v3
@@ -180,6 +119,12 @@ jobs:
180119
username: ${{ github.actor }}
181120
password: ${{ secrets.GITHUB_TOKEN }}
182121

183-
- name: Merge and push manifest on master branch
184-
if: github.ref == 'refs/heads/master'
185-
run: python scripts/merge_manifest.py
122+
- name: Create manifest list and push
123+
working-directory: /tmp/digests
124+
run: |
125+
docker buildx imagetools create $(jq -cr '.tags | map("-t " + .) | join(" ")' <<< "$DOCKER_METADATA_OUTPUT_JSON") \
126+
$(printf '${{ env.REGISTRY_IMAGE }}@sha256:%s ' *)
127+
128+
- name: Inspect image
129+
run: |
130+
docker buildx imagetools inspect ${{ env.REGISTRY_IMAGE }}:${{ steps.meta.outputs.version }}

0 commit comments

Comments
 (0)