Skip to content

Commit

Permalink
Rewrite workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
xepozz committed Sep 1, 2024
1 parent 8d4e275 commit 3a41120
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 59 deletions.
96 changes: 39 additions & 57 deletions .github/workflows/container.yml
Original file line number Diff line number Diff line change
Expand Up @@ -57,87 +57,69 @@ on:
# ${{ env.REGISTRY_IMAGE }}:latest, ${{ env.REGISTRY_IMAGE }}:${{ steps.previoustag.outputs.tag }}

jobs:
build:
build-node:
runs-on: ubuntu-latest
strategy:
fail-fast: true
matrix:
platform:
- linux/amd64
- linux/arm64
steps:
- name: Prepare
run: |
platform=${{ matrix.platform }}
echo "PLATFORM_PAIR=${platform//\//-}" >> $GITHUB_ENV
- name: Docker meta
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ env.REGISTRY_IMAGE }}

- name: Set up QEMU
uses: docker/setup-qemu-action@v3
- name: Log in to registry
run: echo "${{ secrets.GITHUB_TOKEN }}" | docker login ghcr.io -u ${{ github.actor }} --password-stdin

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

- name: Log in to registry
run: echo "${{ secrets.GITHUB_TOKEN }}" | docker login ghcr.io -u ${{ github.actor }} --password-stdin

- name: Build and push by digest
id: build
uses: docker/build-push-action@v6
with:
platforms: ${{ matrix.platform }}
context: .
load: true
target: builder
file: ./Dockerfile
cache-from: type=gha
cache-to: type=gha,mode=max
build-args: VITE_BUILD_ID="Github Actions"
platforms: linux/amd64
labels: ${{ steps.meta.outputs.labels }}
outputs: type=image,name=${{ env.REGISTRY_IMAGE }},push-by-digest=true,name-canonical=true,push=true
outputs: type=docker,dest=/tmp/docker-builder.tar

- name: Export digest
run: |
mkdir -p /tmp/digests
digest="${{ steps.build.outputs.digest }}"
touch "/tmp/digests/${digest#sha256:}"
- name: Upload digest
- name: Share builder image
uses: actions/upload-artifact@v4
with:
name: digests-${{ env.PLATFORM_PAIR }}
path: /tmp/digests/*
name: docker-builder
path: /tmp/docker-builder.tar
if-no-files-found: error
retention-days: 1

merge:
build:
runs-on: ubuntu-latest
needs:
- build
needs: [build-node]
steps:
- name: Download digests
- name: Log in to registry
run: echo "${{ secrets.GITHUB_TOKEN }}" | docker login ghcr.io -u ${{ github.actor }} --password-stdin

- name: Download builder image
uses: actions/download-artifact@v4
with:
path: /tmp/digests
pattern: digests-*
path: /tmp/docker-builder
merge-multiple: true

- name: Load image
run: |
docker load --input /tmp/docker-builder.tar
docker image ls -a
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3

- name: Docker meta
id: meta
uses: docker/metadata-action@v5
- name: Build and push
id: docker_build
uses: docker/build-push-action@v6
with:
images: ${{ env.REGISTRY_IMAGE }}

- name: Log in to registry
run: echo "${{ secrets.GITHUB_TOKEN }}" | docker login ghcr.io -u ${{ github.actor }} --password-stdin

- name: Create manifest list and push
working-directory: /tmp/digests
run: |
docker buildx imagetools create $(jq -cr '.tags | map("-t " + .) | join(" ")' <<< "$DOCKER_METADATA_OUTPUT_JSON") \
$(printf '${{ env.REGISTRY_IMAGE }}@sha256:%s ' *)
- name: Inspect image
run: |
docker buildx imagetools inspect ${{ env.REGISTRY_IMAGE }}:${{ steps.meta.outputs.version }}
push: true
context: .
target: target
file: ./Dockerfile
cache-from: type=gha
cache-to: type=gha,mode=max
platforms: linux/amd64,linux/arm64
tags:
${{ env.REGISTRY_IMAGE }}:latest, ${{ env.REGISTRY_IMAGE }}:${{ steps.previoustag.outputs.tag }}
4 changes: 2 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM node:21.7-alpine AS build
FROM node:21.7-alpine AS builder

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

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

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

0 comments on commit 3a41120

Please sign in to comment.