Skip to content

Commit 3a41120

Browse files
committed
Rewrite workflow
1 parent 8d4e275 commit 3a41120

File tree

2 files changed

+41
-59
lines changed

2 files changed

+41
-59
lines changed

.github/workflows/container.yml

+39-57
Original file line numberDiff line numberDiff line change
@@ -57,87 +57,69 @@ on:
5757
# ${{ env.REGISTRY_IMAGE }}:latest, ${{ env.REGISTRY_IMAGE }}:${{ steps.previoustag.outputs.tag }}
5858

5959
jobs:
60-
build:
60+
build-node:
6161
runs-on: ubuntu-latest
62-
strategy:
63-
fail-fast: true
64-
matrix:
65-
platform:
66-
- linux/amd64
67-
- linux/arm64
6862
steps:
69-
- name: Prepare
70-
run: |
71-
platform=${{ matrix.platform }}
72-
echo "PLATFORM_PAIR=${platform//\//-}" >> $GITHUB_ENV
73-
74-
- name: Docker meta
75-
id: meta
76-
uses: docker/metadata-action@v5
77-
with:
78-
images: ${{ env.REGISTRY_IMAGE }}
79-
80-
- name: Set up QEMU
81-
uses: docker/setup-qemu-action@v3
63+
- name: Log in to registry
64+
run: echo "${{ secrets.GITHUB_TOKEN }}" | docker login ghcr.io -u ${{ github.actor }} --password-stdin
8265

8366
- name: Set up Docker Buildx
8467
uses: docker/setup-buildx-action@v3
8568

86-
- name: Log in to registry
87-
run: echo "${{ secrets.GITHUB_TOKEN }}" | docker login ghcr.io -u ${{ github.actor }} --password-stdin
88-
8969
- name: Build and push by digest
9070
id: build
9171
uses: docker/build-push-action@v6
9272
with:
93-
platforms: ${{ matrix.platform }}
73+
context: .
74+
load: true
75+
target: builder
76+
file: ./Dockerfile
77+
cache-from: type=gha
78+
cache-to: type=gha,mode=max
79+
build-args: VITE_BUILD_ID="Github Actions"
80+
platforms: linux/amd64
9481
labels: ${{ steps.meta.outputs.labels }}
95-
outputs: type=image,name=${{ env.REGISTRY_IMAGE }},push-by-digest=true,name-canonical=true,push=true
82+
outputs: type=docker,dest=/tmp/docker-builder.tar
9683

97-
- name: Export digest
98-
run: |
99-
mkdir -p /tmp/digests
100-
digest="${{ steps.build.outputs.digest }}"
101-
touch "/tmp/digests/${digest#sha256:}"
102-
103-
- name: Upload digest
84+
- name: Share builder image
10485
uses: actions/upload-artifact@v4
10586
with:
106-
name: digests-${{ env.PLATFORM_PAIR }}
107-
path: /tmp/digests/*
87+
name: docker-builder
88+
path: /tmp/docker-builder.tar
10889
if-no-files-found: error
10990
retention-days: 1
11091

111-
merge:
92+
build:
11293
runs-on: ubuntu-latest
113-
needs:
114-
- build
94+
needs: [build-node]
11595
steps:
116-
- name: Download digests
96+
- name: Log in to registry
97+
run: echo "${{ secrets.GITHUB_TOKEN }}" | docker login ghcr.io -u ${{ github.actor }} --password-stdin
98+
99+
- name: Download builder image
117100
uses: actions/download-artifact@v4
118101
with:
119-
path: /tmp/digests
120-
pattern: digests-*
102+
path: /tmp/docker-builder
121103
merge-multiple: true
122104

105+
- name: Load image
106+
run: |
107+
docker load --input /tmp/docker-builder.tar
108+
docker image ls -a
109+
123110
- name: Set up Docker Buildx
124111
uses: docker/setup-buildx-action@v3
125112

126-
- name: Docker meta
127-
id: meta
128-
uses: docker/metadata-action@v5
113+
- name: Build and push
114+
id: docker_build
115+
uses: docker/build-push-action@v6
129116
with:
130-
images: ${{ env.REGISTRY_IMAGE }}
131-
132-
- name: Log in to registry
133-
run: echo "${{ secrets.GITHUB_TOKEN }}" | docker login ghcr.io -u ${{ github.actor }} --password-stdin
134-
135-
- name: Create manifest list and push
136-
working-directory: /tmp/digests
137-
run: |
138-
docker buildx imagetools create $(jq -cr '.tags | map("-t " + .) | join(" ")' <<< "$DOCKER_METADATA_OUTPUT_JSON") \
139-
$(printf '${{ env.REGISTRY_IMAGE }}@sha256:%s ' *)
140-
141-
- name: Inspect image
142-
run: |
143-
docker buildx imagetools inspect ${{ env.REGISTRY_IMAGE }}:${{ steps.meta.outputs.version }}
117+
push: true
118+
context: .
119+
target: target
120+
file: ./Dockerfile
121+
cache-from: type=gha
122+
cache-to: type=gha,mode=max
123+
platforms: linux/amd64,linux/arm64
124+
tags:
125+
${{ env.REGISTRY_IMAGE }}:latest, ${{ env.REGISTRY_IMAGE }}:${{ steps.previoustag.outputs.tag }}

Dockerfile

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
FROM node:21.7-alpine AS build
1+
FROM node:21.7-alpine AS builder
22

33
RUN apk add --update --no-cache git nano curl python3 py3-setuptools make g++\
44
&& rm -rf /var/cache/apk/*
@@ -33,6 +33,6 @@ LABEL org.opencontainers.image.description="Yii Dev Panel"
3333
LABEL org.opencontainers.image.licenses=BSD-3-Clause
3434

3535
RUN rm -rf /usr/share/nginx/html/*
36-
COPY --from=build /app/packages/yii-dev-panel/dist /usr/share/nginx/html
36+
COPY --from=builder /app/packages/yii-dev-panel/dist /usr/share/nginx/html
3737

3838
ENTRYPOINT ["nginx", "-g", "daemon off;"]

0 commit comments

Comments
 (0)