From ca3f6db41dd4192ff3c918e367ac27c58472e105 Mon Sep 17 00:00:00 2001 From: Enrico Stemmer Date: Wed, 20 Nov 2024 23:47:06 +0000 Subject: [PATCH] fix: fixed dockerfile --- .github/workflows/release.yml | 41 +++++++++++++++++++++++++++-------- Dockerfile | 11 ++++++---- 2 files changed, 39 insertions(+), 13 deletions(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 911dbde..aa7e775 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -5,6 +5,9 @@ on: tags: - v* +env: + REGISTRY_IMAGE: h3rmt/filesharing + jobs: build: runs-on: ubuntu-latest @@ -18,8 +21,14 @@ jobs: contents: read packages: write steps: + - name: Prepare + run: | + platform=${{ matrix.platform }} + echo "PLATFORM_PAIR=${platform//\//-}" >> $GITHUB_ENV + - name: Checkout uses: actions/checkout@v4 + - name: Docker meta id: meta uses: docker/metadata-action@v5 @@ -27,41 +36,48 @@ jobs: images: | ${{ vars.REGISTRY_IMAGE }} ghcr.io/${{ vars.REGISTRY_IMAGE }} + - name: Set up QEMU uses: docker/setup-qemu-action@v3 + - name: Set up Docker Buildx uses: docker/setup-buildx-action@v3 + - name: Login to Docker Hub uses: docker/login-action@v3 with: username: ${{ vars.DOCKERHUB_USERNAME }} password: ${{ secrets.DOCKERHUB_TOKEN }} + - name: Login to GitHub Container Registry uses: docker/login-action@v3 with: registry: ghcr.io username: ${{ github.repository_owner }} password: ${{ secrets.GITHUB_TOKEN }} + - name: Populate info.json run: | jq -n --arg version "${{ github.ref_name }}" --arg commit "${{ github.sha }}" --arg date "$(date -u +%F)" '{ version: $version, commit: $commit, date: $date }' > info.json - name: Build and push by digest id: build - uses: docker/build-push-action@v5 + uses: docker/build-push-action@v6 with: context: . platforms: ${{ matrix.platform }} labels: ${{ steps.meta.outputs.labels }} - outputs: type=image,name-canonical=true,push=true,push-by-digest=true,name=${{ vars.REGISTRY_IMAGE }} + outputs: type=image,name=${{ env.REGISTRY_IMAGE }},push-by-digest=true,name-canonical=true,push=true + - name: Export digest run: | mkdir -p /tmp/digests digest="${{ steps.build.outputs.digest }}" touch "/tmp/digests/${digest#sha256:}" + - name: Upload digest - uses: actions/upload-artifact@v3 + uses: actions/upload-artifact@v4 with: - name: digests + name: digests-${{ env.PLATFORM_PAIR }} path: /tmp/digests/* if-no-files-found: error retention-days: 1 @@ -75,12 +91,15 @@ jobs: packages: write steps: - name: Download digests - uses: actions/download-artifact@v4.1.7 + uses: actions/download-artifact@v4 with: - name: digests path: /tmp/digests + pattern: digests-* + merge-multiple: true + - name: Set up Docker Buildx uses: docker/setup-buildx-action@v3 + - name: Docker meta id: meta uses: docker/metadata-action@v5 @@ -88,22 +107,26 @@ jobs: images: | ${{ vars.REGISTRY_IMAGE }} ghcr.io/${{ vars.REGISTRY_IMAGE }} + - name: Login to Docker Hub uses: docker/login-action@v3 with: username: ${{ vars.DOCKERHUB_USERNAME }} password: ${{ secrets.DOCKERHUB_TOKEN }} - - name: Login to GitHub Container Registry` + + - name: Login to GitHub Container Registry uses: docker/login-action@v3 with: registry: ghcr.io username: ${{ github.repository_owner }} password: ${{ secrets.GITHUB_TOKEN }} + - 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 '${{ vars.REGISTRY_IMAGE }}@sha256:%s ' *) + $(printf '${{ env.REGISTRY_IMAGE }}@sha256:%s ' *) + - name: Inspect image run: | - docker buildx imagetools inspect ${{ vars.REGISTRY_IMAGE }}:${{ steps.meta.outputs.version }} + docker buildx imagetools inspect ${{ env.REGISTRY_IMAGE }}:${{ steps.meta.outputs.version }} \ No newline at end of file diff --git a/Dockerfile b/Dockerfile index f520f42..f9b230b 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,12 +1,15 @@ -FROM golang:1.21.5 AS build-stage +FROM --platform=$BUILDPLATFORM golang:alpine AS build +ARG TARGETOS +ARG TARGETARCH + WORKDIR /app COPY go.mod go.sum ./ RUN go mod download COPY main.go ./ COPY migrations/ ./migrations -RUN CGO_ENABLED=0 GOOS=linux go build -ldflags="-s -w" -o ./FileSharing +RUN CGO_ENABLED=0 GOOS=${TARGETOS} GOARCH=${TARGETARCH} go build -ldflags="-s -w" -o ./FileSharing -FROM node:alpine AS js-base +FROM --platform=$BUILDPLATFORM node:alpine AS js-base ENV PNPM_HOME="/pnpm" ENV PATH="$PNPM_HOME:$PATH" RUN corepack enable @@ -25,5 +28,5 @@ RUN pnpm install --prod FROM node:alpine AS run COPY --from=js-base /app/dist /dist COPY --from=js-base /app/node_modules /node_modules -COPY --from=build-stage /app/FileSharing /FileSharing +COPY --from=build /app/FileSharing /FileSharing ENTRYPOINT ["/FileSharing", "serve"] \ No newline at end of file