diff --git a/.github/workflows/container.yml b/.github/workflows/container.yml index 7d04d39..c079d80 100644 --- a/.github/workflows/container.yml +++ b/.github/workflows/container.yml @@ -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 }} \ No newline at end of file + 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 }} diff --git a/Dockerfile b/Dockerfile index 8633ff9..41b61f1 100644 --- a/Dockerfile +++ b/Dockerfile @@ -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/* @@ -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;"]