From e9ebf93f54f2fc55fe1bd43710cb05f7203763ff Mon Sep 17 00:00:00 2001 From: yury mid <94337419+pieceowater@users.noreply.github.com> Date: Sun, 11 Aug 2024 21:26:40 +0500 Subject: [PATCH 1/6] test docker-publish.yml --- .github/workflows/docker-publish.yml | 92 ++++++++++++++++++++++++++++ 1 file changed, 92 insertions(+) create mode 100644 .github/workflows/docker-publish.yml diff --git a/.github/workflows/docker-publish.yml b/.github/workflows/docker-publish.yml new file mode 100644 index 0000000..3b3702a --- /dev/null +++ b/.github/workflows/docker-publish.yml @@ -0,0 +1,92 @@ +name: Docker + +on: + # schedule: + # - cron: '19 5 * * *' + push: + branches: [ "main" ] + # tags: [ 'v*.*.*' ] + # pull_request: + # branches: [ "main" ] + +env: + # Use docker.io for Docker Hub if empty + REGISTRY: ghcr.io + # github.repository as / + IMAGE_NAME: ${{ github.repository }} + + +jobs: + build: + + runs-on: ubuntu-latest + permissions: + contents: read + packages: write + # This is used to complete the identity challenge + # with sigstore/fulcio when running outside of PRs. + id-token: write + + steps: + - name: Checkout repository + uses: actions/checkout@v4 + + # Install the cosign tool except on PR + # https://github.com/sigstore/cosign-installer + - name: Install cosign + if: github.event_name != 'pull_request' + uses: sigstore/cosign-installer@59acb6260d9c0ba8f4a2f9d9b48431a222b68e20 #v3.5.0 + with: + cosign-release: 'v2.2.4' + + # Set up BuildKit Docker container builder to be able to build + # multi-platform images and export cache + # https://github.com/docker/setup-buildx-action + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@f95db51fddba0c2d1ec667646a06c2ce06100226 # v3.0.0 + + # Login against a Docker registry except on PR + # https://github.com/docker/login-action + - name: Log into registry ${{ env.REGISTRY }} + if: github.event_name != 'pull_request' + uses: docker/login-action@343f7c4344506bcbf9b4de18042ae17996df046d # v3.0.0 + with: + registry: ${{ env.REGISTRY }} + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + + # Extract metadata (tags, labels) for Docker + # https://github.com/docker/metadata-action + - name: Extract Docker metadata + id: meta + uses: docker/metadata-action@96383f45573cb7f253c731d3b3ab81c87ef81934 # v5.0.0 + with: + images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} + + # Build and push Docker image with Buildx (don't push on PR) + # https://github.com/docker/build-push-action + - name: Build and push Docker image + id: build-and-push + uses: docker/build-push-action@0565240e2d4ab88bba5387d719585280857ece09 # v5.0.0 + with: + context: . + push: ${{ github.event_name != 'pull_request' }} + tags: ${{ steps.meta.outputs.tags }} + labels: ${{ steps.meta.outputs.labels }} + cache-from: type=gha + cache-to: type=gha,mode=max + + # Sign the resulting Docker image digest except on PRs. + # This will only write to the public Rekor transparency log when the Docker + # repository is public to avoid leaking data. If you would like to publish + # transparency data even for private images, pass --force to cosign below. + # https://github.com/sigstore/cosign + - name: Sign the published Docker image + if: ${{ github.event_name != 'pull_request' }} + env: + # https://docs.github.com/en/actions/security-guides/security-hardening-for-github-actions#using-an-intermediate-environment-variable + TAGS: ${{ steps.meta.outputs.tags }} + DIGEST: ${{ steps.build-and-push.outputs.digest }} + # This step uses the identity token to provision an ephemeral certificate + # against the sigstore community Fulcio instance. + run: echo "${TAGS}" | xargs -I {} cosign sign --yes {}@${DIGEST} From b4ab22b702168bf97ffbb448db13465c090c2f32 Mon Sep 17 00:00:00 2001 From: pieceowater Date: Sun, 11 Aug 2024 21:38:23 +0500 Subject: [PATCH 2/6] fix: Dockerfile --- Dockerfile | 1 - 1 file changed, 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index a1de917..236d3b3 100644 --- a/Dockerfile +++ b/Dockerfile @@ -28,7 +28,6 @@ WORKDIR /app # Copy only necessary files from the build stage COPY --from=build /app/package*.json ./ COPY --from=build /app/dist ./dist -COPY --from=build /app/schema.gql ./schema.gql # Install only production dependencies RUN apt-get update && npm install --omit=dev From e7cf6cfb57675c2879c1842188e5c81037524c79 Mon Sep 17 00:00:00 2001 From: pieceowater Date: Sun, 11 Aug 2024 21:50:12 +0500 Subject: [PATCH 3/6] test without cosign --- .github/workflows/docker-publish.yml | 38 ++++++++++++++-------------- 1 file changed, 19 insertions(+), 19 deletions(-) diff --git a/.github/workflows/docker-publish.yml b/.github/workflows/docker-publish.yml index 3b3702a..3c7f1d2 100644 --- a/.github/workflows/docker-publish.yml +++ b/.github/workflows/docker-publish.yml @@ -5,9 +5,9 @@ on: # - cron: '19 5 * * *' push: branches: [ "main" ] - # tags: [ 'v*.*.*' ] - # pull_request: - # branches: [ "main" ] + tags: [ 'v*.*.*' ] + pull_request: + branches: [ "main" ] env: # Use docker.io for Docker Hub if empty @@ -31,13 +31,13 @@ jobs: - name: Checkout repository uses: actions/checkout@v4 - # Install the cosign tool except on PR - # https://github.com/sigstore/cosign-installer - - name: Install cosign - if: github.event_name != 'pull_request' - uses: sigstore/cosign-installer@59acb6260d9c0ba8f4a2f9d9b48431a222b68e20 #v3.5.0 - with: - cosign-release: 'v2.2.4' +# # Install the cosign tool except on PR +# # https://github.com/sigstore/cosign-installer +# - name: Install cosign +# if: github.event_name != 'pull_request' +# uses: sigstore/cosign-installer@59acb6260d9c0ba8f4a2f9d9b48431a222b68e20 #v3.5.0 +# with: +# cosign-release: 'v2.2.4' # Set up BuildKit Docker container builder to be able to build # multi-platform images and export cache @@ -81,12 +81,12 @@ jobs: # repository is public to avoid leaking data. If you would like to publish # transparency data even for private images, pass --force to cosign below. # https://github.com/sigstore/cosign - - name: Sign the published Docker image - if: ${{ github.event_name != 'pull_request' }} - env: - # https://docs.github.com/en/actions/security-guides/security-hardening-for-github-actions#using-an-intermediate-environment-variable - TAGS: ${{ steps.meta.outputs.tags }} - DIGEST: ${{ steps.build-and-push.outputs.digest }} - # This step uses the identity token to provision an ephemeral certificate - # against the sigstore community Fulcio instance. - run: echo "${TAGS}" | xargs -I {} cosign sign --yes {}@${DIGEST} +# - name: Sign the published Docker image +# if: ${{ github.event_name != 'pull_request' }} +# env: +# # https://docs.github.com/en/actions/security-guides/security-hardening-for-github-actions#using-an-intermediate-environment-variable +# TAGS: ${{ steps.meta.outputs.tags }} +# DIGEST: ${{ steps.build-and-push.outputs.digest }} +# # This step uses the identity token to provision an ephemeral certificate +# # against the sigstore community Fulcio instance. +# run: echo "${TAGS}" | xargs -I {} cosign sign --yes {}@${DIGEST} From 25db16794e9cbe9de2c0cee797cb2bf164c52413 Mon Sep 17 00:00:00 2001 From: pieceowater Date: Sun, 11 Aug 2024 21:50:36 +0500 Subject: [PATCH 4/6] test without cosign --- .github/workflows/docker-publish.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/docker-publish.yml b/.github/workflows/docker-publish.yml index 3c7f1d2..55d191b 100644 --- a/.github/workflows/docker-publish.yml +++ b/.github/workflows/docker-publish.yml @@ -5,9 +5,9 @@ on: # - cron: '19 5 * * *' push: branches: [ "main" ] - tags: [ 'v*.*.*' ] - pull_request: - branches: [ "main" ] +# tags: [ 'v*.*.*' ] +# pull_request: +# branches: [ "main" ] env: # Use docker.io for Docker Hub if empty From 92903f15b9b2b790fb3695e0036a034d54b7365b Mon Sep 17 00:00:00 2001 From: pieceowater Date: Sun, 11 Aug 2024 22:01:02 +0500 Subject: [PATCH 5/6] mode build arg --- .github/workflows/docker-publish.yml | 53 ++++------------------------ 1 file changed, 7 insertions(+), 46 deletions(-) diff --git a/.github/workflows/docker-publish.yml b/.github/workflows/docker-publish.yml index 55d191b..62672c4 100644 --- a/.github/workflows/docker-publish.yml +++ b/.github/workflows/docker-publish.yml @@ -1,73 +1,47 @@ name: Docker on: - # schedule: - # - cron: '19 5 * * *' push: branches: [ "main" ] -# tags: [ 'v*.*.*' ] -# pull_request: -# branches: [ "main" ] + tags: [ 'v*.*.*' ] env: - # Use docker.io for Docker Hub if empty REGISTRY: ghcr.io - # github.repository as / IMAGE_NAME: ${{ github.repository }} jobs: build: - runs-on: ubuntu-latest permissions: contents: read packages: write - # This is used to complete the identity challenge - # with sigstore/fulcio when running outside of PRs. id-token: write steps: - name: Checkout repository uses: actions/checkout@v4 -# # Install the cosign tool except on PR -# # https://github.com/sigstore/cosign-installer -# - name: Install cosign -# if: github.event_name != 'pull_request' -# uses: sigstore/cosign-installer@59acb6260d9c0ba8f4a2f9d9b48431a222b68e20 #v3.5.0 -# with: -# cosign-release: 'v2.2.4' - - # Set up BuildKit Docker container builder to be able to build - # multi-platform images and export cache - # https://github.com/docker/setup-buildx-action - name: Set up Docker Buildx - uses: docker/setup-buildx-action@f95db51fddba0c2d1ec667646a06c2ce06100226 # v3.0.0 + uses: docker/setup-buildx-action@v3.0.0 - # Login against a Docker registry except on PR - # https://github.com/docker/login-action - name: Log into registry ${{ env.REGISTRY }} if: github.event_name != 'pull_request' - uses: docker/login-action@343f7c4344506bcbf9b4de18042ae17996df046d # v3.0.0 + uses: docker/login-action@v3.0.0 with: registry: ${{ env.REGISTRY }} username: ${{ github.actor }} password: ${{ secrets.GITHUB_TOKEN }} - # Extract metadata (tags, labels) for Docker - # https://github.com/docker/metadata-action - name: Extract Docker metadata id: meta - uses: docker/metadata-action@96383f45573cb7f253c731d3b3ab81c87ef81934 # v5.0.0 + uses: docker/metadata-action@v5.0.0 with: images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} - # Build and push Docker image with Buildx (don't push on PR) - # https://github.com/docker/build-push-action - name: Build and push Docker image id: build-and-push - uses: docker/build-push-action@0565240e2d4ab88bba5387d719585280857ece09 # v5.0.0 + uses: docker/build-push-action@v5.0.0 with: context: . push: ${{ github.event_name != 'pull_request' }} @@ -75,18 +49,5 @@ jobs: labels: ${{ steps.meta.outputs.labels }} cache-from: type=gha cache-to: type=gha,mode=max - - # Sign the resulting Docker image digest except on PRs. - # This will only write to the public Rekor transparency log when the Docker - # repository is public to avoid leaking data. If you would like to publish - # transparency data even for private images, pass --force to cosign below. - # https://github.com/sigstore/cosign -# - name: Sign the published Docker image -# if: ${{ github.event_name != 'pull_request' }} -# env: -# # https://docs.github.com/en/actions/security-guides/security-hardening-for-github-actions#using-an-intermediate-environment-variable -# TAGS: ${{ steps.meta.outputs.tags }} -# DIGEST: ${{ steps.build-and-push.outputs.digest }} -# # This step uses the identity token to provision an ephemeral certificate -# # against the sigstore community Fulcio instance. -# run: echo "${TAGS}" | xargs -I {} cosign sign --yes {}@${DIGEST} + build-args: | + BUILD_MODE=${{ github.ref_name }} \ No newline at end of file From f7c3a978323617ae5d3c260fe8d17c8f2a250c63 Mon Sep 17 00:00:00 2001 From: pieceowater Date: Sun, 11 Aug 2024 22:06:26 +0500 Subject: [PATCH 6/6] test --- .github/workflows/docker-publish.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/docker-publish.yml b/.github/workflows/docker-publish.yml index 62672c4..84dac70 100644 --- a/.github/workflows/docker-publish.yml +++ b/.github/workflows/docker-publish.yml @@ -4,6 +4,8 @@ on: push: branches: [ "main" ] tags: [ 'v*.*.*' ] + pull_request: + branches: [ "main" ] env: REGISTRY: ghcr.io