From 7af7d7ce6668ababa5afbad192bf96c5a508172a Mon Sep 17 00:00:00 2001 From: Roman Glushko Date: Sun, 17 Mar 2024 21:51:00 +0200 Subject: [PATCH 01/34] #91: Build windows images --- images/Makefile | 34 ++++++++++++++++++++++++++++++++++ images/nanoserver.Dockerfile | 23 +++++++++++++++++++++++ images/windowserver.Dockerfile | 23 +++++++++++++++++++++++ 3 files changed, 80 insertions(+) create mode 100644 images/nanoserver.Dockerfile create mode 100644 images/windowserver.Dockerfile diff --git a/images/Makefile b/images/Makefile index 145f8b59..efa9aa58 100644 --- a/images/Makefile +++ b/images/Makefile @@ -82,6 +82,40 @@ redhat: ## Make an Red Hat-based image --label=org.opencontainers.image.licenses=$(LICENSE) \ --label=org.opencontainers.image.description=$(DESCRIPTION) +nanoserver: ## Make an Windows NanoServer-based image + @echo "🛠️ Build a Windows nanoserver image ($(VERSION)).." + @echo "- Commit: $(COMMIT)" + @echo "- Build Date: $(BUILD_DATE)" + @docker build .. -t $(REPOSITORY):$(VERSION)-nanoserver -f nanoserver.Dockerfile \ + --build-arg VERSION="$(VERSION)" \ + --build-arg COMMIT="$(COMMIT)" \ + --build-arg BUILD_DATE="$(BUILD_DATE)" \ + --label=org.opencontainers.image.vendor=$(VENDOR) \ + --label=org.opencontainers.image.title=$(PROJECT) \ + --label=org.opencontainers.image.revision="$(COMMIT)" \ + --label=org.opencontainers.image.version="$(VERSION)" \ + --label=org.opencontainers.image.created="$(BUILD_DATE)" \ + --label=org.opencontainers.image.source=$(SOURCE) \ + --label=org.opencontainers.image.licenses=$(LICENSE) \ + --label=org.opencontainers.image.description=$(DESCRIPTION) + +windows-server: ## Make an Windows Server-based image + @echo "🛠️ Build a Windows Server image ($(VERSION)).." + @echo "- Commit: $(COMMIT)" + @echo "- Build Date: $(BUILD_DATE)" + @docker build .. -t $(REPOSITORY):$(VERSION)-nanoserver -f windowserver.Dockerfile \ + --build-arg VERSION="$(VERSION)" \ + --build-arg COMMIT="$(COMMIT)" \ + --build-arg BUILD_DATE="$(BUILD_DATE)" \ + --label=org.opencontainers.image.vendor=$(VENDOR) \ + --label=org.opencontainers.image.title=$(PROJECT) \ + --label=org.opencontainers.image.revision="$(COMMIT)" \ + --label=org.opencontainers.image.version="$(VERSION)" \ + --label=org.opencontainers.image.created="$(BUILD_DATE)" \ + --label=org.opencontainers.image.source=$(SOURCE) \ + --label=org.opencontainers.image.licenses=$(LICENSE) \ + --label=org.opencontainers.image.description=$(DESCRIPTION) + all: alpine ubuntu distroless redhat publish-ghcr-%: ## Push images to Github Registry diff --git a/images/nanoserver.Dockerfile b/images/nanoserver.Dockerfile new file mode 100644 index 00000000..baf3c48b --- /dev/null +++ b/images/nanoserver.Dockerfile @@ -0,0 +1,23 @@ +# syntax=docker/dockerfile:1 +FROM golang:1.22-nanoserver-1809 as build + +ARG VERSION +ARG COMMIT +ARG BUILD_DATE + +ENV GOOS=windows + +WORKDIR /build + +SHELL ["powershell", "-Command", "$ErrorActionPreference = 'Stop'; $ProgressPreference = 'SilentlyContinue';"] + +COPY . /build/ +RUN go mod download +RUN go build -ldflags "-s -w -X glide/pkg.version=$VERSION -X glide/pkg.commitSha=$COMMIT -X glide/pkg.buildDate=$BUILD_DATE" -o /build/dist/glide.exe + +FROM mcr.microsoft.com/windows/nanoserver:1809 as release + +WORKDIR /bin +COPY --from=build /build/dist/glide.exe /bin/ + +ENTRYPOINT ["/bin/glide.exe"] diff --git a/images/windowserver.Dockerfile b/images/windowserver.Dockerfile new file mode 100644 index 00000000..c922f69f --- /dev/null +++ b/images/windowserver.Dockerfile @@ -0,0 +1,23 @@ +# syntax=docker/dockerfile:1 +FROM golang:1.22-windowsservercore-1809 as build + +ARG VERSION +ARG COMMIT +ARG BUILD_DATE + +ENV GOOS=windows + +WORKDIR /build + +SHELL ["powershell", "-Command", "$ErrorActionPreference = 'Stop'; $ProgressPreference = 'SilentlyContinue';"] + +COPY . /build/ +RUN go mod download +RUN go build -ldflags "-s -w -X glide/pkg.version=$VERSION -X glide/pkg.commitSha=$COMMIT -X glide/pkg.buildDate=$BUILD_DATE" -o /build/dist/glide.exe + +FROM mcr.microsoft.com/windows/servercore:1809 as release + +WORKDIR /bin +COPY --from=build /build/dist/glide.exe /bin/ + +ENTRYPOINT ["/bin/glide.exe"] From aad8eb6bf47d3bea2d1c4e878a6606e83d3a5217 Mon Sep 17 00:00:00 2001 From: Roman Glushko Date: Sun, 28 Apr 2024 12:10:49 +0300 Subject: [PATCH 02/34] #91: Fixed the version package import path --- images/nanoserver.Dockerfile | 2 +- images/redhat.Dockerfile | 2 +- images/ubuntu.Dockerfile | 2 +- images/windowserver.Dockerfile | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/images/nanoserver.Dockerfile b/images/nanoserver.Dockerfile index baf3c48b..fb60a318 100644 --- a/images/nanoserver.Dockerfile +++ b/images/nanoserver.Dockerfile @@ -13,7 +13,7 @@ SHELL ["powershell", "-Command", "$ErrorActionPreference = 'Stop'; $ProgressPref COPY . /build/ RUN go mod download -RUN go build -ldflags "-s -w -X glide/pkg.version=$VERSION -X glide/pkg.commitSha=$COMMIT -X glide/pkg.buildDate=$BUILD_DATE" -o /build/dist/glide.exe +RUN go build -ldflags "-s -w -X glide/pkg/version.Version=$VERSION -X glide/pkg.commitSha=$COMMIT -X glide/pkg.buildDate=$BUILD_DATE" -o /build/dist/glide.exe FROM mcr.microsoft.com/windows/nanoserver:1809 as release diff --git a/images/redhat.Dockerfile b/images/redhat.Dockerfile index aacdc0aa..ca486057 100644 --- a/images/redhat.Dockerfile +++ b/images/redhat.Dockerfile @@ -11,7 +11,7 @@ WORKDIR /build COPY . /build/ RUN go mod download -RUN go build -ldflags "-s -w -X glide/pkg/version.version=$VERSION -X glide/pkg/version.commitSha=$COMMIT -X glide/pkg/version.buildDate=$BUILD_DATE" -o /build/dist/glide +RUN go build -ldflags "-s -w -X glide/pkg/version.Version=$VERSION -X glide/pkg/version.commitSha=$COMMIT -X glide/pkg/version.buildDate=$BUILD_DATE" -o /build/dist/glide FROM redhat/ubi8-micro:8.9 as release diff --git a/images/ubuntu.Dockerfile b/images/ubuntu.Dockerfile index 78c8e024..a5bc0be6 100644 --- a/images/ubuntu.Dockerfile +++ b/images/ubuntu.Dockerfile @@ -11,7 +11,7 @@ WORKDIR /build COPY . /build/ RUN go mod download -RUN go build -ldflags "-s -w -X glide/pkg/version.version=$VERSION -X glide/pkg/version.commitSha=$COMMIT -X glide/pkg/version.buildDate=$BUILD_DATE" -o /build/dist/glide +RUN go build -ldflags "-s -w -X glide/pkg/version.Version=$VERSION -X glide/pkg/version.commitSha=$COMMIT -X glide/pkg/version.buildDate=$BUILD_DATE" -o /build/dist/glide FROM ubuntu:22.04 as release diff --git a/images/windowserver.Dockerfile b/images/windowserver.Dockerfile index c922f69f..0f5886f6 100644 --- a/images/windowserver.Dockerfile +++ b/images/windowserver.Dockerfile @@ -13,7 +13,7 @@ SHELL ["powershell", "-Command", "$ErrorActionPreference = 'Stop'; $ProgressPref COPY . /build/ RUN go mod download -RUN go build -ldflags "-s -w -X glide/pkg.version=$VERSION -X glide/pkg.commitSha=$COMMIT -X glide/pkg.buildDate=$BUILD_DATE" -o /build/dist/glide.exe +RUN go build -ldflags "-s -w -X glide/pkg/version.version=$VERSION -X glide/pkg.commitSha=$COMMIT -X glide/pkg.buildDate=$BUILD_DATE" -o /build/dist/glide.exe FROM mcr.microsoft.com/windows/servercore:1809 as release From a0d41d9c2e731cb88edc4525f74f37fd0c143944 Mon Sep 17 00:00:00 2001 From: Roman Glushko Date: Sun, 28 Apr 2024 12:46:08 +0300 Subject: [PATCH 03/34] #91: Added CI steps to build win images --- .github/workflows/release.yaml | 32 +++++++++++++++++++++++++++++++- images/nanoserver.Dockerfile | 2 +- images/windowserver.Dockerfile | 2 +- 3 files changed, 33 insertions(+), 3 deletions(-) diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml index 69f01d09..0eba0307 100644 --- a/.github/workflows/release.yaml +++ b/.github/workflows/release.yaml @@ -49,7 +49,8 @@ jobs: DISCORD_WEBHOOK_ID: ${{ secrets.DISCORD_WEBHOOK_ID }} DISCORD_WEBHOOK_TOKEN: ${{ secrets.DISCORD_WEBHOOK_TOKEN }} BREW_TAP_PRIVATE_KEY: ${{ secrets.BREW_TAP_PRIVATE_KEY }} - images: + + images-linux: strategy: matrix: image: @@ -85,3 +86,32 @@ jobs: - name: publish ${{ matrix.image }} image to DockerHub working-directory: ./images run: VERSION=${{ github.ref_name }} make publish-dockerhub-${{ matrix.image }} + + images-win: + strategy: + matrix: + image: + - nanoserver + - windows-server + needs: + - release + + runs-on: windows-2019 + + steps: + - name: checkout + uses: actions/checkout@v4 + with: + fetch-depth: 0 + + - name: login into Github Container Registry + run: echo "${{ secrets.GITHUB_TOKEN }}" | docker login ghcr.io -u $ --password-stdin + + - name: login into Docker + run: echo "${{ secrets.DOCKER_HUB_TOKEN }}" | docker login -u einstack --password-stdin + + - name: build ${{ matrix.image }} image + working-directory: ./images + env: + BUILD_TIME: ${{needs.build_time.outputs.BUILD_TIME}} + run: VERSION=${{ github.ref_name }} COMMIT=$(git rev-parse --short "$GITHUB_SHA") make ${{ matrix.image }} diff --git a/images/nanoserver.Dockerfile b/images/nanoserver.Dockerfile index fb60a318..3f0605bc 100644 --- a/images/nanoserver.Dockerfile +++ b/images/nanoserver.Dockerfile @@ -13,7 +13,7 @@ SHELL ["powershell", "-Command", "$ErrorActionPreference = 'Stop'; $ProgressPref COPY . /build/ RUN go mod download -RUN go build -ldflags "-s -w -X glide/pkg/version.Version=$VERSION -X glide/pkg.commitSha=$COMMIT -X glide/pkg.buildDate=$BUILD_DATE" -o /build/dist/glide.exe +RUN go build -ldflags "-s -w -X glide/pkg/version.Version=$VERSION -X glide/pkg/version.commitSha=$COMMIT -X glide/pkg/version.buildDate=$BUILD_DATE" -o /build/dist/glide.exe FROM mcr.microsoft.com/windows/nanoserver:1809 as release diff --git a/images/windowserver.Dockerfile b/images/windowserver.Dockerfile index 0f5886f6..86005897 100644 --- a/images/windowserver.Dockerfile +++ b/images/windowserver.Dockerfile @@ -13,7 +13,7 @@ SHELL ["powershell", "-Command", "$ErrorActionPreference = 'Stop'; $ProgressPref COPY . /build/ RUN go mod download -RUN go build -ldflags "-s -w -X glide/pkg/version.version=$VERSION -X glide/pkg.commitSha=$COMMIT -X glide/pkg.buildDate=$BUILD_DATE" -o /build/dist/glide.exe +RUN go build -ldflags "-s -w -X glide/pkg/version.version=$VERSION -X glide/pkg/version.commitSha=$COMMIT -X glide/pkg/version.buildDate=$BUILD_DATE" -o /build/dist/glide.exe FROM mcr.microsoft.com/windows/servercore:1809 as release From b19a9a788cba636073d9aa1852f40261de344e4c Mon Sep 17 00:00:00 2001 From: Roman Glushko Date: Sun, 28 Apr 2024 13:02:29 +0300 Subject: [PATCH 04/34] #91: Introduced some functionality to build images without pushing them --- .github/workflows/release.yaml | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml index 0eba0307..c8327a71 100644 --- a/.github/workflows/release.yaml +++ b/.github/workflows/release.yaml @@ -44,6 +44,7 @@ jobs: version: latest args: release --clean env: + GORELEASER_DRY_RUN: ${{ contains(github.event.pull_request.labels.*.name, 'build:dry-run') && 'true' || 'false' }} GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} SNAPCRAFT_STORE_CREDENTIALS: ${{ secrets.SNAP_TOKEN }} DISCORD_WEBHOOK_ID: ${{ secrets.DISCORD_WEBHOOK_ID }} @@ -80,10 +81,12 @@ jobs: run: VERSION=${{ github.ref_name }} COMMIT=$(git rev-parse --short "$GITHUB_SHA") make ${{ matrix.image }} - name: publish ${{ matrix.image }} image to Github Container Registry + if: "!contains(github.event.pull_request.labels.*.name, 'build:dry-run')" working-directory: ./images run: VERSION=${{ github.ref_name }} make publish-ghcr-${{ matrix.image }} - name: publish ${{ matrix.image }} image to DockerHub + if: "!contains(github.event.pull_request.labels.*.name, 'build:dry-run')" working-directory: ./images run: VERSION=${{ github.ref_name }} make publish-dockerhub-${{ matrix.image }} @@ -93,6 +96,7 @@ jobs: image: - nanoserver - windows-server + needs: - release @@ -115,3 +119,13 @@ jobs: env: BUILD_TIME: ${{needs.build_time.outputs.BUILD_TIME}} run: VERSION=${{ github.ref_name }} COMMIT=$(git rev-parse --short "$GITHUB_SHA") make ${{ matrix.image }} + + - name: publish ${{ matrix.image }} image to Github Container Registry + if: "!contains(github.event.pull_request.labels.*.name, 'build:dry-run')" + working-directory: ./images + run: VERSION=${{ github.ref_name }} make publish-ghcr-${{ matrix.image }} + + - name: publish ${{ matrix.image }} image to DockerHub + if: "!contains(github.event.pull_request.labels.*.name, 'build:dry-run')" + working-directory: ./images + run: VERSION=${{ github.ref_name }} make publish-dockerhub-${{ matrix.image }} From 1e30adeec1660908eff9abc5a4bca9f888585499 Mon Sep 17 00:00:00 2001 From: Roman Glushko Date: Sun, 28 Apr 2024 13:14:24 +0300 Subject: [PATCH 05/34] #91: Changed a way to set dryrun mode for goreleaser --- .github/workflows/release.yaml | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml index c8327a71..70a25aba 100644 --- a/.github/workflows/release.yaml +++ b/.github/workflows/release.yaml @@ -37,6 +37,17 @@ jobs: mkdir -p $HOME/.cache/snapcraft/download mkdir -p $HOME/.cache/snapcraft/stage-packages + - name: List PR Labels + run: | + echo "Pull Request Labels: ${{ toJson(github.event.pull_request.labels) }}" + + - name: Should publish bins? + run: | + echo "DRY_RUN=false" >> $GITHUB_ENV + if [[ "${{ github.event.pull_request.labels.*.name }}" == *"build:dry-run"* ]]; then + echo "DRY_RUN=true" >> $GITHUB_ENV + fi + - name: Run GoReleaser uses: goreleaser/goreleaser-action@v5 with: @@ -44,7 +55,7 @@ jobs: version: latest args: release --clean env: - GORELEASER_DRY_RUN: ${{ contains(github.event.pull_request.labels.*.name, 'build:dry-run') && 'true' || 'false' }} + GORELEASER_DRY_RUN: ${{ env.DRY_RUN }} GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} SNAPCRAFT_STORE_CREDENTIALS: ${{ secrets.SNAP_TOKEN }} DISCORD_WEBHOOK_ID: ${{ secrets.DISCORD_WEBHOOK_ID }} From 7f5cc6c07cd7349011dd250e295855d09999bfc9 Mon Sep 17 00:00:00 2001 From: Roman Glushko Date: Sun, 28 Apr 2024 13:28:51 +0300 Subject: [PATCH 06/34] #91: trigger the release pipeline on PRs as well --- .github/workflows/release.yaml | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml index 70a25aba..5e98f4bd 100644 --- a/.github/workflows/release.yaml +++ b/.github/workflows/release.yaml @@ -5,16 +5,23 @@ on: tags: - "*" + pull_request: + types: + - labeled + permissions: contents: write packages: write jobs: lint: + if: "startsWith(github.ref, 'refs/tags/')" uses: ./.github/workflows/lint.yaml vuln: + if: "startsWith(github.ref, 'refs/tags/')" uses: ./.github/workflows/vuln.yaml release: + if: "startsWith(github.ref, 'refs/tags/') || contains(github.event.pull_request.labels.*.name, 'build:dry-run')" needs: - lint - vuln @@ -63,6 +70,7 @@ jobs: BREW_TAP_PRIVATE_KEY: ${{ secrets.BREW_TAP_PRIVATE_KEY }} images-linux: + if: "startsWith(github.ref, 'refs/tags/') || contains(github.event.pull_request.labels.*.name, 'build:dry-run')" strategy: matrix: image: @@ -102,6 +110,7 @@ jobs: run: VERSION=${{ github.ref_name }} make publish-dockerhub-${{ matrix.image }} images-win: + if: "startsWith(github.ref, 'refs/tags/') || contains(github.event.pull_request.labels.*.name, 'build:dry-run')" strategy: matrix: image: From 489aa6820e7f9b2826d618f3e33babf26c04d330 Mon Sep 17 00:00:00 2001 From: Roman Glushko Date: Sun, 28 Apr 2024 13:30:40 +0300 Subject: [PATCH 07/34] #91: added sync trigger --- .github/workflows/release.yaml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml index 5e98f4bd..30dc0a78 100644 --- a/.github/workflows/release.yaml +++ b/.github/workflows/release.yaml @@ -7,6 +7,7 @@ on: pull_request: types: + - synchronize - labeled permissions: From efd79bce5eaf629fca170a415fb43480d6854737 Mon Sep 17 00:00:00 2001 From: Roman Glushko Date: Sun, 28 Apr 2024 13:32:05 +0300 Subject: [PATCH 08/34] #91: made sure conditions are achievable --- .github/workflows/release.yaml | 2 -- 1 file changed, 2 deletions(-) diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml index 30dc0a78..5e17e739 100644 --- a/.github/workflows/release.yaml +++ b/.github/workflows/release.yaml @@ -16,10 +16,8 @@ permissions: jobs: lint: - if: "startsWith(github.ref, 'refs/tags/')" uses: ./.github/workflows/lint.yaml vuln: - if: "startsWith(github.ref, 'refs/tags/')" uses: ./.github/workflows/vuln.yaml release: if: "startsWith(github.ref, 'refs/tags/') || contains(github.event.pull_request.labels.*.name, 'build:dry-run')" From 88ec6fb9583f03b724e8a0269ef263dc1888da54 Mon Sep 17 00:00:00 2001 From: Roman Glushko Date: Sun, 28 Apr 2024 13:37:58 +0300 Subject: [PATCH 09/34] #91: Remove the debug step and documented the label in the contrib guide --- .github/workflows/release.yaml | 13 +------------ CONTRIBUTING.md | 8 ++++++++ 2 files changed, 9 insertions(+), 12 deletions(-) diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml index 5e17e739..74476e69 100644 --- a/.github/workflows/release.yaml +++ b/.github/workflows/release.yaml @@ -43,17 +43,6 @@ jobs: mkdir -p $HOME/.cache/snapcraft/download mkdir -p $HOME/.cache/snapcraft/stage-packages - - name: List PR Labels - run: | - echo "Pull Request Labels: ${{ toJson(github.event.pull_request.labels) }}" - - - name: Should publish bins? - run: | - echo "DRY_RUN=false" >> $GITHUB_ENV - if [[ "${{ github.event.pull_request.labels.*.name }}" == *"build:dry-run"* ]]; then - echo "DRY_RUN=true" >> $GITHUB_ENV - fi - - name: Run GoReleaser uses: goreleaser/goreleaser-action@v5 with: @@ -61,7 +50,7 @@ jobs: version: latest args: release --clean env: - GORELEASER_DRY_RUN: ${{ env.DRY_RUN }} + GORELEASER_DRY_RUN: ${{ contains(github.event.pull_request.labels.*.name, 'build:dry-run') && 'true' || 'false' }} GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} SNAPCRAFT_STORE_CREDENTIALS: ${{ secrets.SNAP_TOKEN }} DISCORD_WEBHOOK_ID: ${{ secrets.DISCORD_WEBHOOK_ID }} diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 2735b5e4..7a60bb7c 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -42,6 +42,13 @@ Be sure to take a look at all available commands. All important checks are automated on the level of pull request checks. Be sure to keep your PRs green, before moving the PR to the review stage. +#### build:dry-run + +The Glide repository has a special `build:dry-run` label that allows to run the release workflow without actually publishing Glide artefacts. +This is helpful for: +- testing image building +- making sure any changes to the release workflow works fine + ## Improve Our Documentation ### Typos & Uncovered Functionality @@ -73,3 +80,4 @@ That's perfectly fine! Feel free to connect with us in [Discord](https://discord.gg/rsBzprY7uT) and ask any question you have. Remember, there are no dumb questions, but there can be missing opportunities to make your life easier if you don't speak up about things you struggle with. + From f3da97d95847de92db36b4047a8a61faca3c9f47 Mon Sep 17 00:00:00 2001 From: Roman Glushko Date: Sun, 28 Apr 2024 13:49:14 +0300 Subject: [PATCH 10/34] #91 skipping the prebuild validation in the dry-run mode --- .github/workflows/release.yaml | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml index 74476e69..4054bfef 100644 --- a/.github/workflows/release.yaml +++ b/.github/workflows/release.yaml @@ -43,14 +43,28 @@ jobs: mkdir -p $HOME/.cache/snapcraft/download mkdir -p $HOME/.cache/snapcraft/stage-packages + - name: Determine GoReleaser Mode + run: | + echo "GORELEASER_DRY_RUN=$GORELEASER_DRY_RUN" >> $GITHUB_ENV + env: + GORELEASER_DRY_RUN: ${{ contains(github.event.pull_request.labels.*.name, 'build:dry-run') && 'true' || 'false' }} + + - name: Prepare GoReleaser extra args + run: | + ARGS="--rm-dist" + if [[ "${{ env.GORELEASER_DRY_RUN }}" == "true" ]]; then + ARGS="$ARGS --skip-validate" + fi + echo "GORELEASER_EXTRA_ARGS=$ARGS" >> $GITHUB_ENV + - name: Run GoReleaser uses: goreleaser/goreleaser-action@v5 with: distribution: goreleaser version: latest - args: release --clean + args: release --clean ${{ env.GORELEASER_EXTRA_ARGS }} env: - GORELEASER_DRY_RUN: ${{ contains(github.event.pull_request.labels.*.name, 'build:dry-run') && 'true' || 'false' }} + GORELEASER_DRY_RUN: ${{ env.GORELEASER_DRY_RUN }} GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} SNAPCRAFT_STORE_CREDENTIALS: ${{ secrets.SNAP_TOKEN }} DISCORD_WEBHOOK_ID: ${{ secrets.DISCORD_WEBHOOK_ID }} From da4a4583f69199ae999e4a07062c4f202addf08b Mon Sep 17 00:00:00 2001 From: Roman Glushko Date: Sun, 28 Apr 2024 14:06:09 +0300 Subject: [PATCH 11/34] #91: Introduced the setup state to define dry run mode. Skipping goreleaser publishing in other way --- .github/workflows/release.yaml | 47 ++++++++++++++++++++++------------ 1 file changed, 31 insertions(+), 16 deletions(-) diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml index 4054bfef..785c6289 100644 --- a/.github/workflows/release.yaml +++ b/.github/workflows/release.yaml @@ -15,13 +15,34 @@ permissions: packages: write jobs: + setup: + runs-on: ubuntu-latest + outputs: + dry-run: ${{ steps.set-flags.outputs.dry-run }} + steps: + - name: Checkout code + uses: actions/checkout@v2 + - name: Set flag based on PR label + id: set-flags + run: | + LABELS="${{ toJson(github.event.pull_request.labels.*.name) }}" + DRY_RUN="false" + + if [[ $LABELS == *"build:dry-run"* ]]; then + DRY_RUN="true" + fi + + echo "dry-run=$DRY_RUN" >> $GITHUB_ENV + echo "::set-output name=dry-run::$DRY_RUN" + lint: uses: ./.github/workflows/lint.yaml vuln: uses: ./.github/workflows/vuln.yaml release: - if: "startsWith(github.ref, 'refs/tags/') || contains(github.event.pull_request.labels.*.name, 'build:dry-run')" + if: "startsWith(github.ref, 'refs/tags/') || needs.setup.outputs.dry-run == 'true'" needs: + - setup - lint - vuln runs-on: ubuntu-latest @@ -43,17 +64,11 @@ jobs: mkdir -p $HOME/.cache/snapcraft/download mkdir -p $HOME/.cache/snapcraft/stage-packages - - name: Determine GoReleaser Mode - run: | - echo "GORELEASER_DRY_RUN=$GORELEASER_DRY_RUN" >> $GITHUB_ENV - env: - GORELEASER_DRY_RUN: ${{ contains(github.event.pull_request.labels.*.name, 'build:dry-run') && 'true' || 'false' }} - - name: Prepare GoReleaser extra args run: | - ARGS="--rm-dist" - if [[ "${{ env.GORELEASER_DRY_RUN }}" == "true" ]]; then - ARGS="$ARGS --skip-validate" + ARGS="" + if [[ "${{ needs.setup.outputs.dry-run }}" == "true" ]]; then + ARGS="$ARGS --skip=validate --skip-publish" fi echo "GORELEASER_EXTRA_ARGS=$ARGS" >> $GITHUB_ENV @@ -72,7 +87,7 @@ jobs: BREW_TAP_PRIVATE_KEY: ${{ secrets.BREW_TAP_PRIVATE_KEY }} images-linux: - if: "startsWith(github.ref, 'refs/tags/') || contains(github.event.pull_request.labels.*.name, 'build:dry-run')" + if: "startsWith(github.ref, 'refs/tags/') || needs.setup.outputs.dry-run == 'true'" strategy: matrix: image: @@ -102,17 +117,17 @@ jobs: run: VERSION=${{ github.ref_name }} COMMIT=$(git rev-parse --short "$GITHUB_SHA") make ${{ matrix.image }} - name: publish ${{ matrix.image }} image to Github Container Registry - if: "!contains(github.event.pull_request.labels.*.name, 'build:dry-run')" + if: "needs.setup.outputs.dry-run != 'true'" working-directory: ./images run: VERSION=${{ github.ref_name }} make publish-ghcr-${{ matrix.image }} - name: publish ${{ matrix.image }} image to DockerHub - if: "!contains(github.event.pull_request.labels.*.name, 'build:dry-run')" + if: "needs.setup.outputs.dry-run != 'true'" working-directory: ./images run: VERSION=${{ github.ref_name }} make publish-dockerhub-${{ matrix.image }} images-win: - if: "startsWith(github.ref, 'refs/tags/') || contains(github.event.pull_request.labels.*.name, 'build:dry-run')" + if: "startsWith(github.ref, 'refs/tags/') || needs.setup.outputs.dry-run == 'true'" strategy: matrix: image: @@ -143,11 +158,11 @@ jobs: run: VERSION=${{ github.ref_name }} COMMIT=$(git rev-parse --short "$GITHUB_SHA") make ${{ matrix.image }} - name: publish ${{ matrix.image }} image to Github Container Registry - if: "!contains(github.event.pull_request.labels.*.name, 'build:dry-run')" + if: "needs.setup.outputs.dry-run != 'true'" working-directory: ./images run: VERSION=${{ github.ref_name }} make publish-ghcr-${{ matrix.image }} - name: publish ${{ matrix.image }} image to DockerHub - if: "!contains(github.event.pull_request.labels.*.name, 'build:dry-run')" + if: "needs.setup.outputs.dry-run != 'true'" working-directory: ./images run: VERSION=${{ github.ref_name }} make publish-dockerhub-${{ matrix.image }} From 2e8859d887b5029f3c1cf787beec8001ae35b4ba Mon Sep 17 00:00:00 2001 From: Roman Glushko Date: Sun, 28 Apr 2024 14:07:04 +0300 Subject: [PATCH 12/34] #91: Disabling initial linting to speed up testing --- .github/workflows/release.yaml | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml index 785c6289..b0f2eae1 100644 --- a/.github/workflows/release.yaml +++ b/.github/workflows/release.yaml @@ -35,16 +35,16 @@ jobs: echo "dry-run=$DRY_RUN" >> $GITHUB_ENV echo "::set-output name=dry-run::$DRY_RUN" - lint: - uses: ./.github/workflows/lint.yaml - vuln: - uses: ./.github/workflows/vuln.yaml +# lint: +# uses: ./.github/workflows/lint.yaml +# vuln: +# uses: ./.github/workflows/vuln.yaml release: if: "startsWith(github.ref, 'refs/tags/') || needs.setup.outputs.dry-run == 'true'" needs: - setup - - lint - - vuln +# - lint +# - vuln runs-on: ubuntu-latest steps: - name: Set up Go From 750e1c90f3c86c415823275b44d52efacc9b426a Mon Sep 17 00:00:00 2001 From: Roman Glushko Date: Sun, 28 Apr 2024 14:08:51 +0300 Subject: [PATCH 13/34] #91: removed deprecated usage of output setting --- .github/workflows/release.yaml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml index b0f2eae1..4d9dd67d 100644 --- a/.github/workflows/release.yaml +++ b/.github/workflows/release.yaml @@ -32,8 +32,7 @@ jobs: DRY_RUN="true" fi - echo "dry-run=$DRY_RUN" >> $GITHUB_ENV - echo "::set-output name=dry-run::$DRY_RUN" + echo "dry-run=$DRY_RUN" >> $GITHUB_OUTPUT # lint: # uses: ./.github/workflows/lint.yaml From ededd53c271cc9ec560ee5187d91dcf0cd57da74 Mon Sep 17 00:00:00 2001 From: Roman Glushko Date: Sun, 28 Apr 2024 14:11:05 +0300 Subject: [PATCH 14/34] #91: removed deprecated args --- .github/workflows/release.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml index 4d9dd67d..0c011174 100644 --- a/.github/workflows/release.yaml +++ b/.github/workflows/release.yaml @@ -67,7 +67,7 @@ jobs: run: | ARGS="" if [[ "${{ needs.setup.outputs.dry-run }}" == "true" ]]; then - ARGS="$ARGS --skip=validate --skip-publish" + ARGS="$ARGS --skip=validate --skip=publish" fi echo "GORELEASER_EXTRA_ARGS=$ARGS" >> $GITHUB_ENV From dac37fc27a48aa523832702d463ee6067d69cc89 Mon Sep 17 00:00:00 2001 From: Roman Glushko Date: Sun, 28 Apr 2024 14:34:58 +0300 Subject: [PATCH 15/34] #91: Moved all build info to be computed on the setup step & fixed the version value on PR builds --- .github/workflows/release.yaml | 73 +++++++++++++++++++++++----------- .goreleaser.yml | 2 +- 2 files changed, 50 insertions(+), 25 deletions(-) diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml index 0c011174..0041a279 100644 --- a/.github/workflows/release.yaml +++ b/.github/workflows/release.yaml @@ -18,12 +18,15 @@ jobs: setup: runs-on: ubuntu-latest outputs: - dry-run: ${{ steps.set-flags.outputs.dry-run }} + dry-run: ${{ steps.build-context.outputs.dry-run }} + version: ${{ steps.build-context.outputs.version }} + commit: ${{ steps.build-context.outputs.commit }} + build_date: ${{ steps.build-context.outputs.build_date }} steps: - name: Checkout code uses: actions/checkout@v2 - - name: Set flag based on PR label - id: set-flags + - name: Set build context + id: build-context run: | LABELS="${{ toJson(github.event.pull_request.labels.*.name) }}" DRY_RUN="false" @@ -33,6 +36,16 @@ jobs: fi echo "dry-run=$DRY_RUN" >> $GITHUB_OUTPUT + + if [[ ${{ github.event_name }} == 'pull_request' ]]; then + PR_ID=$(echo ${{ github.ref }} | cut -d '/' -f 3) + echo "version=dev.$PR_ID" >> $GITHUB_OUTPUT + else + echo "version=${{ github.ref_name }}" >> $GITHUB_OUTPUT + fi + + echo "commit=$(git rev-parse --short '$GITHUB_SHA')" >> $GITHUB_OUTPUT + echo "build_date=$(date -u +'%Y-%m-%dT%H:%M:%SZ')" >> $GITHUB_OUTPUT # lint: # uses: ./.github/workflows/lint.yaml @@ -71,19 +84,19 @@ jobs: fi echo "GORELEASER_EXTRA_ARGS=$ARGS" >> $GITHUB_ENV - - name: Run GoReleaser - uses: goreleaser/goreleaser-action@v5 - with: - distribution: goreleaser - version: latest - args: release --clean ${{ env.GORELEASER_EXTRA_ARGS }} - env: - GORELEASER_DRY_RUN: ${{ env.GORELEASER_DRY_RUN }} - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - SNAPCRAFT_STORE_CREDENTIALS: ${{ secrets.SNAP_TOKEN }} - DISCORD_WEBHOOK_ID: ${{ secrets.DISCORD_WEBHOOK_ID }} - DISCORD_WEBHOOK_TOKEN: ${{ secrets.DISCORD_WEBHOOK_TOKEN }} - BREW_TAP_PRIVATE_KEY: ${{ secrets.BREW_TAP_PRIVATE_KEY }} +# - name: Run GoReleaser +# uses: goreleaser/goreleaser-action@v5 +# with: +# distribution: goreleaser +# version: latest +# args: release --clean ${{ env.GORELEASER_EXTRA_ARGS }} +# env: +# GORELEASER_DRY_RUN: ${{ env.GORELEASER_DRY_RUN }} +# GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} +# SNAPCRAFT_STORE_CREDENTIALS: ${{ secrets.SNAP_TOKEN }} +# DISCORD_WEBHOOK_ID: ${{ secrets.DISCORD_WEBHOOK_ID }} +# DISCORD_WEBHOOK_TOKEN: ${{ secrets.DISCORD_WEBHOOK_TOKEN }} +# BREW_TAP_PRIVATE_KEY: ${{ secrets.BREW_TAP_PRIVATE_KEY }} images-linux: if: "startsWith(github.ref, 'refs/tags/') || needs.setup.outputs.dry-run == 'true'" @@ -112,18 +125,24 @@ jobs: - name: build ${{ matrix.image }} image working-directory: ./images env: - BUILD_TIME: ${{needs.build_time.outputs.BUILD_TIME}} - run: VERSION=${{ github.ref_name }} COMMIT=$(git rev-parse --short "$GITHUB_SHA") make ${{ matrix.image }} + VERSION: ${{ needs.setup.outputs.version }} + COMMIT: ${{ needs.setup.outputs.commit }} + BUILD_DATE: ${{ needs.setup.outputs.build_date }} + run: VERSION="${{ env.VERSION }}" COMMIT="${{ env.COMMIT }}" BUILD_DATE="${{ env.BUILD_DATE }}" make ${{ matrix.image }} - name: publish ${{ matrix.image }} image to Github Container Registry if: "needs.setup.outputs.dry-run != 'true'" working-directory: ./images - run: VERSION=${{ github.ref_name }} make publish-ghcr-${{ matrix.image }} + env: + VERSION: ${{ needs.setup.outputs.version }} + run: VERSION="${{ env.VERSION }}" make publish-ghcr-${{ matrix.image }} - name: publish ${{ matrix.image }} image to DockerHub if: "needs.setup.outputs.dry-run != 'true'" working-directory: ./images - run: VERSION=${{ github.ref_name }} make publish-dockerhub-${{ matrix.image }} + env: + VERSION: ${{ needs.setup.outputs.version }} + run: VERSION="${{ env.VERSION }}" make publish-dockerhub-${{ matrix.image }} images-win: if: "startsWith(github.ref, 'refs/tags/') || needs.setup.outputs.dry-run == 'true'" @@ -153,15 +172,21 @@ jobs: - name: build ${{ matrix.image }} image working-directory: ./images env: - BUILD_TIME: ${{needs.build_time.outputs.BUILD_TIME}} - run: VERSION=${{ github.ref_name }} COMMIT=$(git rev-parse --short "$GITHUB_SHA") make ${{ matrix.image }} + VERSION: ${{ needs.setup.outputs.version }} + COMMIT: ${{ needs.setup.outputs.commit }} + BUILD_DATE: ${{ needs.setup.outputs.build_date }} + run: VERSION="${{ env.VERSION }}" COMMIT="${{ needs.setup.outputs.commit }}" BUILD_DATE="${{ needs.setup.outputs.build_date }}" make ${{ matrix.image }} - name: publish ${{ matrix.image }} image to Github Container Registry if: "needs.setup.outputs.dry-run != 'true'" working-directory: ./images - run: VERSION=${{ github.ref_name }} make publish-ghcr-${{ matrix.image }} + env: + VERSION: ${{ needs.setup.outputs.version }} + run: VERSION="${{ env.VERSION }}" make publish-ghcr-${{ matrix.image }} - name: publish ${{ matrix.image }} image to DockerHub if: "needs.setup.outputs.dry-run != 'true'" working-directory: ./images - run: VERSION=${{ github.ref_name }} make publish-dockerhub-${{ matrix.image }} + env: + VERSION: ${{ needs.setup.outputs.version }} + run: VERSION="${{ env.VERSION }}" make publish-dockerhub-${{ matrix.image }} diff --git a/.goreleaser.yml b/.goreleaser.yml index 653e3a27..028c9ffc 100644 --- a/.goreleaser.yml +++ b/.goreleaser.yml @@ -41,7 +41,7 @@ builds: goarch: arm changelog: - skip: true + disable: true archives: - id: glide From 8e0af10dc4617e5680b9934fb267c96505cfc193 Mon Sep 17 00:00:00 2001 From: Roman Glushko Date: Sun, 28 Apr 2024 14:40:30 +0300 Subject: [PATCH 16/34] #91: Escaped strings --- .github/workflows/release.yaml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml index 0041a279..9db34df7 100644 --- a/.github/workflows/release.yaml +++ b/.github/workflows/release.yaml @@ -37,8 +37,8 @@ jobs: echo "dry-run=$DRY_RUN" >> $GITHUB_OUTPUT - if [[ ${{ github.event_name }} == 'pull_request' ]]; then - PR_ID=$(echo ${{ github.ref }} | cut -d '/' -f 3) + if [[ "${{ github.event_name }}" == 'pull_request' ]]; then + PR_ID=$(echo "${{ github.ref }}" | cut -d '/' -f 3) echo "version=dev.$PR_ID" >> $GITHUB_OUTPUT else echo "version=${{ github.ref_name }}" >> $GITHUB_OUTPUT From 380821fba67471311c6411fac077a19609d92841 Mon Sep 17 00:00:00 2001 From: Roman Glushko Date: Sun, 28 Apr 2024 14:47:42 +0300 Subject: [PATCH 17/34] #91: moved values of build vars to a sep bash vars --- .github/workflows/release.yaml | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml index 9db34df7..4bc40b6e 100644 --- a/.github/workflows/release.yaml +++ b/.github/workflows/release.yaml @@ -34,18 +34,26 @@ jobs: if [[ $LABELS == *"build:dry-run"* ]]; then DRY_RUN="true" fi - - echo "dry-run=$DRY_RUN" >> $GITHUB_OUTPUT + + VERSION="${{ github.ref_name }}" if [[ "${{ github.event_name }}" == 'pull_request' ]]; then PR_ID=$(echo "${{ github.ref }}" | cut -d '/' -f 3) - echo "version=dev.$PR_ID" >> $GITHUB_OUTPUT - else - echo "version=${{ github.ref_name }}" >> $GITHUB_OUTPUT + VERSION='dev.$PR_ID' fi - echo "commit=$(git rev-parse --short '$GITHUB_SHA')" >> $GITHUB_OUTPUT - echo "build_date=$(date -u +'%Y-%m-%dT%H:%M:%SZ')" >> $GITHUB_OUTPUT + COMMIT=$(git rev-parse --short "$GITHUB_SHA") + BUILD_DATE=$(date -u +"%Y-%m-%dT%H:%M:%SZ") + + echo "Dry Run: $DRY_RUN" + echo "Version: $VERSION" + echo "Commit: $COMMIT" + echo "Build Date: $BUILD_DATE" + + echo "dry-run=$DRY_RUN" >> $GITHUB_OUTPUT + echo "version=$VERSION" >> $GITHUB_OUTPUT + echo "commit=$COMMIT" >> $GITHUB_OUTPUT + echo "build_date=$BUILD_DATE" >> $GITHUB_OUTPUT # lint: # uses: ./.github/workflows/lint.yaml From c325db968321f0164e871a974b917712c44adf0f Mon Sep 17 00:00:00 2001 From: Roman Glushko Date: Sun, 28 Apr 2024 14:48:48 +0300 Subject: [PATCH 18/34] #91: fixed version resolution --- .github/workflows/release.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml index 4bc40b6e..4e91cb15 100644 --- a/.github/workflows/release.yaml +++ b/.github/workflows/release.yaml @@ -39,7 +39,7 @@ jobs: if [[ "${{ github.event_name }}" == 'pull_request' ]]; then PR_ID=$(echo "${{ github.ref }}" | cut -d '/' -f 3) - VERSION='dev.$PR_ID' + VERSION="dev.$PR_ID" fi COMMIT=$(git rev-parse --short "$GITHUB_SHA") From f21e07bdd01a62c4887a0e042d35a8ec8b7b91ed Mon Sep 17 00:00:00 2001 From: Roman Glushko Date: Sun, 28 Apr 2024 14:52:33 +0300 Subject: [PATCH 19/34] #91 add dependencies on the setup step --- .github/workflows/release.yaml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml index 4e91cb15..57622145 100644 --- a/.github/workflows/release.yaml +++ b/.github/workflows/release.yaml @@ -117,6 +117,7 @@ jobs: - redhat runs-on: ubuntu-latest needs: + - setup - release steps: - name: checkout @@ -159,10 +160,9 @@ jobs: image: - nanoserver - windows-server - needs: + - setup - release - runs-on: windows-2019 steps: From 5333dfe6465adbe755908bd99bddf097282470d0 Mon Sep 17 00:00:00 2001 From: Roman Glushko Date: Sun, 28 Apr 2024 15:07:34 +0300 Subject: [PATCH 20/34] #91: Made sure make is installed on win machines --- .github/workflows/release.yaml | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml index 57622145..8effcb93 100644 --- a/.github/workflows/release.yaml +++ b/.github/workflows/release.yaml @@ -177,24 +177,27 @@ jobs: - name: login into Docker run: echo "${{ secrets.DOCKER_HUB_TOKEN }}" | docker login -u einstack --password-stdin + - name: Set up Make + run: choco install make + - name: build ${{ matrix.image }} image working-directory: ./images env: VERSION: ${{ needs.setup.outputs.version }} COMMIT: ${{ needs.setup.outputs.commit }} BUILD_DATE: ${{ needs.setup.outputs.build_date }} - run: VERSION="${{ env.VERSION }}" COMMIT="${{ needs.setup.outputs.commit }}" BUILD_DATE="${{ needs.setup.outputs.build_date }}" make ${{ matrix.image }} + run: make VERSION="${{ env.VERSION }}" COMMIT="${{ needs.setup.outputs.commit }}" BUILD_DATE="${{ needs.setup.outputs.build_date }}" ${{ matrix.image }} - name: publish ${{ matrix.image }} image to Github Container Registry if: "needs.setup.outputs.dry-run != 'true'" working-directory: ./images env: VERSION: ${{ needs.setup.outputs.version }} - run: VERSION="${{ env.VERSION }}" make publish-ghcr-${{ matrix.image }} + run: make VERSION="${{ env.VERSION }}" publish-ghcr-${{ matrix.image }} - name: publish ${{ matrix.image }} image to DockerHub if: "needs.setup.outputs.dry-run != 'true'" working-directory: ./images env: VERSION: ${{ needs.setup.outputs.version }} - run: VERSION="${{ env.VERSION }}" make publish-dockerhub-${{ matrix.image }} + run: make VERSION="${{ env.VERSION }}" publish-dockerhub-${{ matrix.image }} From 8cc664fbd1bc6b651a5fffcbcba78fb74a4bc5c3 Mon Sep 17 00:00:00 2001 From: Roman Glushko Date: Sun, 28 Apr 2024 15:21:21 +0300 Subject: [PATCH 21/34] #91 added debug command --- images/nanoserver.Dockerfile | 1 + 1 file changed, 1 insertion(+) diff --git a/images/nanoserver.Dockerfile b/images/nanoserver.Dockerfile index 3f0605bc..a9966a36 100644 --- a/images/nanoserver.Dockerfile +++ b/images/nanoserver.Dockerfile @@ -12,6 +12,7 @@ WORKDIR /build SHELL ["powershell", "-Command", "$ErrorActionPreference = 'Stop'; $ProgressPreference = 'SilentlyContinue';"] COPY . /build/ +RUN pwd; Get-ChildItem RUN go mod download RUN go build -ldflags "-s -w -X glide/pkg/version.Version=$VERSION -X glide/pkg/version.commitSha=$COMMIT -X glide/pkg/version.buildDate=$BUILD_DATE" -o /build/dist/glide.exe From 90768e45a2c7ef5c0faed5d033e026118cdea0ee Mon Sep 17 00:00:00 2001 From: Roman Glushko Date: Sun, 28 Apr 2024 16:04:27 +0300 Subject: [PATCH 22/34] #91: debug --- images/nanoserver.Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/images/nanoserver.Dockerfile b/images/nanoserver.Dockerfile index a9966a36..67a2a167 100644 --- a/images/nanoserver.Dockerfile +++ b/images/nanoserver.Dockerfile @@ -12,7 +12,7 @@ WORKDIR /build SHELL ["powershell", "-Command", "$ErrorActionPreference = 'Stop'; $ProgressPreference = 'SilentlyContinue';"] COPY . /build/ -RUN pwd; Get-ChildItem +RUN dir RUN go mod download RUN go build -ldflags "-s -w -X glide/pkg/version.Version=$VERSION -X glide/pkg/version.commitSha=$COMMIT -X glide/pkg/version.buildDate=$BUILD_DATE" -o /build/dist/glide.exe From 34d919796c7a9870b8b9c33d7808471866bba14c Mon Sep 17 00:00:00 2001 From: Roman Glushko Date: Sun, 28 Apr 2024 16:10:16 +0300 Subject: [PATCH 23/34] #91: debug --- images/nanoserver.Dockerfile | 2 ++ 1 file changed, 2 insertions(+) diff --git a/images/nanoserver.Dockerfile b/images/nanoserver.Dockerfile index 67a2a167..05db1ba7 100644 --- a/images/nanoserver.Dockerfile +++ b/images/nanoserver.Dockerfile @@ -11,6 +11,8 @@ WORKDIR /build SHELL ["powershell", "-Command", "$ErrorActionPreference = 'Stop'; $ProgressPreference = 'SilentlyContinue';"] +RUN dir + COPY . /build/ RUN dir RUN go mod download From 7b8f849107dcd0501284bd05448b4b4013458c30 Mon Sep 17 00:00:00 2001 From: Roman Glushko Date: Sun, 28 Apr 2024 16:19:00 +0300 Subject: [PATCH 24/34] #91: trying to build the image from pwsh --- .github/workflows/release.yaml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml index 8effcb93..29f31c14 100644 --- a/.github/workflows/release.yaml +++ b/.github/workflows/release.yaml @@ -182,6 +182,7 @@ jobs: - name: build ${{ matrix.image }} image working-directory: ./images + shell: pwsh env: VERSION: ${{ needs.setup.outputs.version }} COMMIT: ${{ needs.setup.outputs.commit }} From 8ebb4db4f5de8bf37235480bc6767b837a7af40e Mon Sep 17 00:00:00 2001 From: Roman Glushko Date: Sun, 28 Apr 2024 16:24:21 +0300 Subject: [PATCH 25/34] #91 trying to use powershell --- .github/workflows/release.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml index 29f31c14..030cff35 100644 --- a/.github/workflows/release.yaml +++ b/.github/workflows/release.yaml @@ -182,7 +182,7 @@ jobs: - name: build ${{ matrix.image }} image working-directory: ./images - shell: pwsh + shell: powershell env: VERSION: ${{ needs.setup.outputs.version }} COMMIT: ${{ needs.setup.outputs.commit }} From 084cde43bf7aa2c0e738f2cc443b050df93f9013 Mon Sep 17 00:00:00 2001 From: Roman Glushko Date: Sun, 28 Apr 2024 16:35:59 +0300 Subject: [PATCH 26/34] #91: disabling the nanoserver image building for now --- .github/workflows/release.yaml | 2 +- images/nanoserver.Dockerfile | 6 ++++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml index 030cff35..c5a70994 100644 --- a/.github/workflows/release.yaml +++ b/.github/workflows/release.yaml @@ -158,7 +158,7 @@ jobs: strategy: matrix: image: - - nanoserver +# - nanoserver - windows-server needs: - setup diff --git a/images/nanoserver.Dockerfile b/images/nanoserver.Dockerfile index 05db1ba7..4a55add7 100644 --- a/images/nanoserver.Dockerfile +++ b/images/nanoserver.Dockerfile @@ -11,10 +11,12 @@ WORKDIR /build SHELL ["powershell", "-Command", "$ErrorActionPreference = 'Stop'; $ProgressPreference = 'SilentlyContinue';"] -RUN dir +RUN powershell -Command "Get-ChildItem"; COPY . /build/ -RUN dir + +RUN powershell -Command "Get-ChildItem"; + RUN go mod download RUN go build -ldflags "-s -w -X glide/pkg/version.Version=$VERSION -X glide/pkg/version.commitSha=$COMMIT -X glide/pkg/version.buildDate=$BUILD_DATE" -o /build/dist/glide.exe From ffa11fd030cb523386516c38e924378fa4ce97cc Mon Sep 17 00:00:00 2001 From: Roman Glushko Date: Sun, 28 Apr 2024 17:00:19 +0300 Subject: [PATCH 27/34] #91: Trying to pass build args as env vars --- images/nanoserver.Dockerfile | 11 +++++------ images/windowserver.Dockerfile | 6 +++++- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/images/nanoserver.Dockerfile b/images/nanoserver.Dockerfile index 4a55add7..cf535efe 100644 --- a/images/nanoserver.Dockerfile +++ b/images/nanoserver.Dockerfile @@ -1,5 +1,5 @@ # syntax=docker/dockerfile:1 -FROM golang:1.22-nanoserver-1809 as build +FROM golang:1.22-windowsservercore-1809 as build ARG VERSION ARG COMMIT @@ -11,14 +11,13 @@ WORKDIR /build SHELL ["powershell", "-Command", "$ErrorActionPreference = 'Stop'; $ProgressPreference = 'SilentlyContinue';"] -RUN powershell -Command "Get-ChildItem"; +RUN $env:VERSION = '$VERSION'; \ + $env:COMMIT = '$COMMIT'; \ + $env:BUILD_DATE = '$BUILD_DATE'; COPY . /build/ - -RUN powershell -Command "Get-ChildItem"; - RUN go mod download -RUN go build -ldflags "-s -w -X glide/pkg/version.Version=$VERSION -X glide/pkg/version.commitSha=$COMMIT -X glide/pkg/version.buildDate=$BUILD_DATE" -o /build/dist/glide.exe +RUN go build -ldflags "-s -w -X glide/pkg/version.Version=$env:VERSION -X glide/pkg/version.commitSha=$env:COMMIT -X glide/pkg/version.buildDate=$env:BUILD_DATE" -o /build/dist/glide.exe FROM mcr.microsoft.com/windows/nanoserver:1809 as release diff --git a/images/windowserver.Dockerfile b/images/windowserver.Dockerfile index 86005897..3e5a5c66 100644 --- a/images/windowserver.Dockerfile +++ b/images/windowserver.Dockerfile @@ -11,9 +11,13 @@ WORKDIR /build SHELL ["powershell", "-Command", "$ErrorActionPreference = 'Stop'; $ProgressPreference = 'SilentlyContinue';"] +RUN $env:VERSION = '$VERSION'; \ + $env:COMMIT = '$COMMIT'; \ + $env:BUILD_DATE = '$BUILD_DATE'; + COPY . /build/ RUN go mod download -RUN go build -ldflags "-s -w -X glide/pkg/version.version=$VERSION -X glide/pkg/version.commitSha=$COMMIT -X glide/pkg/version.buildDate=$BUILD_DATE" -o /build/dist/glide.exe +RUN go build -ldflags "-s -w -X glide/pkg/version.Version=$env:VERSION -X glide/pkg/version.commitSha=$env:COMMIT -X glide/pkg/version.buildDate=$env:BUILD_DATE" -o /build/dist/glide.exe FROM mcr.microsoft.com/windows/servercore:1809 as release From 3c05ba47b850fcecdc859b304dd439d494ceafd7 Mon Sep 17 00:00:00 2001 From: Roman Glushko Date: Sun, 28 Apr 2024 17:10:03 +0300 Subject: [PATCH 28/34] #91: Change positions of -o flag --- images/nanoserver.Dockerfile | 2 +- images/windowserver.Dockerfile | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/images/nanoserver.Dockerfile b/images/nanoserver.Dockerfile index cf535efe..6a8e1c4a 100644 --- a/images/nanoserver.Dockerfile +++ b/images/nanoserver.Dockerfile @@ -17,7 +17,7 @@ RUN $env:VERSION = '$VERSION'; \ COPY . /build/ RUN go mod download -RUN go build -ldflags "-s -w -X glide/pkg/version.Version=$env:VERSION -X glide/pkg/version.commitSha=$env:COMMIT -X glide/pkg/version.buildDate=$env:BUILD_DATE" -o /build/dist/glide.exe +RUN go build -o /build/dist/glide.exe -ldflags "-s -w -X glide/pkg/version.Version=$env:VERSION -X glide/pkg/version.commitSha=$env:COMMIT -X glide/pkg/version.buildDate=$env:BUILD_DATE" FROM mcr.microsoft.com/windows/nanoserver:1809 as release diff --git a/images/windowserver.Dockerfile b/images/windowserver.Dockerfile index 3e5a5c66..7142aef1 100644 --- a/images/windowserver.Dockerfile +++ b/images/windowserver.Dockerfile @@ -17,7 +17,7 @@ RUN $env:VERSION = '$VERSION'; \ COPY . /build/ RUN go mod download -RUN go build -ldflags "-s -w -X glide/pkg/version.Version=$env:VERSION -X glide/pkg/version.commitSha=$env:COMMIT -X glide/pkg/version.buildDate=$env:BUILD_DATE" -o /build/dist/glide.exe +RUN go build -o /build/dist/glide.exe -ldflags "-s -w -X glide/pkg/version.Version=$env:VERSION -X glide/pkg/version.commitSha=$env:COMMIT -X glide/pkg/version.buildDate=$env:BUILD_DATE" FROM mcr.microsoft.com/windows/servercore:1809 as release From 810490c5d655a23af3f0136d5b29a71bd145dea7 Mon Sep 17 00:00:00 2001 From: Roman Glushko Date: Sun, 28 Apr 2024 17:16:15 +0300 Subject: [PATCH 29/34] #91: removed -w arg --- images/windowserver.Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/images/windowserver.Dockerfile b/images/windowserver.Dockerfile index 7142aef1..94c02b03 100644 --- a/images/windowserver.Dockerfile +++ b/images/windowserver.Dockerfile @@ -17,7 +17,7 @@ RUN $env:VERSION = '$VERSION'; \ COPY . /build/ RUN go mod download -RUN go build -o /build/dist/glide.exe -ldflags "-s -w -X glide/pkg/version.Version=$env:VERSION -X glide/pkg/version.commitSha=$env:COMMIT -X glide/pkg/version.buildDate=$env:BUILD_DATE" +RUN go build -o /build/dist/glide.exe -ldflags "-s -X glide/pkg/version.Version=$env:VERSION -X glide/pkg/version.commitSha=$env:COMMIT -X glide/pkg/version.buildDate=$env:BUILD_DATE" FROM mcr.microsoft.com/windows/servercore:1809 as release From a5f7522a4c4e6c0a42fa1f13879cc7a9f6918b84 Mon Sep 17 00:00:00 2001 From: Roman Glushko Date: Sun, 28 Apr 2024 17:25:58 +0300 Subject: [PATCH 30/34] #91: Quote all -X args --- images/windowserver.Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/images/windowserver.Dockerfile b/images/windowserver.Dockerfile index 94c02b03..890a8501 100644 --- a/images/windowserver.Dockerfile +++ b/images/windowserver.Dockerfile @@ -17,7 +17,7 @@ RUN $env:VERSION = '$VERSION'; \ COPY . /build/ RUN go mod download -RUN go build -o /build/dist/glide.exe -ldflags "-s -X glide/pkg/version.Version=$env:VERSION -X glide/pkg/version.commitSha=$env:COMMIT -X glide/pkg/version.buildDate=$env:BUILD_DATE" +RUN go build -o /build/dist/glide.exe -ldflags "-s -w -X `glide/pkg/version.Version=$env:VERSION` -X `glide/pkg/version.commitSha=$env:COMMIT` -X `glide/pkg/version.buildDate=$env:BUILD_DATE`" FROM mcr.microsoft.com/windows/servercore:1809 as release From 518f204846285399a0c7afb86105d65766fd31fc Mon Sep 17 00:00:00 2001 From: Roman Glushko Date: Sun, 28 Apr 2024 17:51:47 +0300 Subject: [PATCH 31/34] #91 quoting -X values in a diff way --- images/windowserver.Dockerfile | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/images/windowserver.Dockerfile b/images/windowserver.Dockerfile index 890a8501..328c3353 100644 --- a/images/windowserver.Dockerfile +++ b/images/windowserver.Dockerfile @@ -5,19 +5,13 @@ ARG VERSION ARG COMMIT ARG BUILD_DATE -ENV GOOS=windows - WORKDIR /build SHELL ["powershell", "-Command", "$ErrorActionPreference = 'Stop'; $ProgressPreference = 'SilentlyContinue';"] -RUN $env:VERSION = '$VERSION'; \ - $env:COMMIT = '$COMMIT'; \ - $env:BUILD_DATE = '$BUILD_DATE'; - COPY . /build/ RUN go mod download -RUN go build -o /build/dist/glide.exe -ldflags "-s -w -X `glide/pkg/version.Version=$env:VERSION` -X `glide/pkg/version.commitSha=$env:COMMIT` -X `glide/pkg/version.buildDate=$env:BUILD_DATE`" +RUN GOOS=windows go build -v -o /build/dist/glide.exe -ldflags "-s -w -X glide/pkg/version.Version="$VERSION" -X glide/pkg/version.commitSha="$COMMIT" -X glide/pkg/version.buildDate="$BUILD_DATE"" FROM mcr.microsoft.com/windows/servercore:1809 as release From 36d30c12dda8c741cad6870f5b3b70ce63dd0864 Mon Sep 17 00:00:00 2001 From: Roman Glushko Date: Sun, 28 Apr 2024 18:01:31 +0300 Subject: [PATCH 32/34] #91 getting back to the prev way of setting goos --- images/windowserver.Dockerfile | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/images/windowserver.Dockerfile b/images/windowserver.Dockerfile index 328c3353..fb1e0933 100644 --- a/images/windowserver.Dockerfile +++ b/images/windowserver.Dockerfile @@ -5,13 +5,15 @@ ARG VERSION ARG COMMIT ARG BUILD_DATE +ENV GOOS=windows + WORKDIR /build SHELL ["powershell", "-Command", "$ErrorActionPreference = 'Stop'; $ProgressPreference = 'SilentlyContinue';"] COPY . /build/ RUN go mod download -RUN GOOS=windows go build -v -o /build/dist/glide.exe -ldflags "-s -w -X glide/pkg/version.Version="$VERSION" -X glide/pkg/version.commitSha="$COMMIT" -X glide/pkg/version.buildDate="$BUILD_DATE"" +RUN go build -v -o /build/dist/glide.exe -ldflags "-s -w -X glide/pkg/version.Version="$VERSION" -X glide/pkg/version.commitSha="$COMMIT" -X glide/pkg/version.buildDate="$BUILD_DATE"" FROM mcr.microsoft.com/windows/servercore:1809 as release From ee5526f928239c8b0400664a28db1e11d4ccf5c2 Mon Sep 17 00:00:00 2001 From: Roman Glushko Date: Sun, 28 Apr 2024 18:13:58 +0300 Subject: [PATCH 33/34] #91: Build win binary in linux image --- CONTRIBUTING.md | 16 ++++++++++++++-- images/windowserver.Dockerfile | 7 ++++--- 2 files changed, 18 insertions(+), 5 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 7a60bb7c..c623fa14 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -34,8 +34,20 @@ You can outline gaps and let other people contribute their ideas on possible sol ### Dev Commands Many useful commands are in [the root makefile](Makefile). -We use make as a convenient interface to automate a bunch of commands like codebase linting, running tests, running dev binary, etc. -Be sure to take a look at all available commands. + +> [!Warning] +> Windows doesn't come with `make` installed. You need to install it via [Chocolatey](https://chocolatey.org/), for example: +> ```powershell +> choco install make +> ``` + +We use make as a convenient interface to automate a bunch of commands like: +- codebase linting via `make lint` +- running tests via `make test` +- running dev binary `make run` +- etc. + +Be sure to take a look at all available commands via running `make` (from the project root directory). ### CI Checks diff --git a/images/windowserver.Dockerfile b/images/windowserver.Dockerfile index fb1e0933..f8f05370 100644 --- a/images/windowserver.Dockerfile +++ b/images/windowserver.Dockerfile @@ -1,5 +1,5 @@ # syntax=docker/dockerfile:1 -FROM golang:1.22-windowsservercore-1809 as build +FROM golang:1.22-alpine as build ARG VERSION ARG COMMIT @@ -9,8 +9,6 @@ ENV GOOS=windows WORKDIR /build -SHELL ["powershell", "-Command", "$ErrorActionPreference = 'Stop'; $ProgressPreference = 'SilentlyContinue';"] - COPY . /build/ RUN go mod download RUN go build -v -o /build/dist/glide.exe -ldflags "-s -w -X glide/pkg/version.Version="$VERSION" -X glide/pkg/version.commitSha="$COMMIT" -X glide/pkg/version.buildDate="$BUILD_DATE"" @@ -18,6 +16,9 @@ RUN go build -v -o /build/dist/glide.exe -ldflags "-s -w -X glide/pkg/version.Ve FROM mcr.microsoft.com/windows/servercore:1809 as release WORKDIR /bin + +SHELL ["powershell", "-Command", "$ErrorActionPreference = 'Stop'; $ProgressPreference = 'SilentlyContinue';"] + COPY --from=build /build/dist/glide.exe /bin/ ENTRYPOINT ["/bin/glide.exe"] From e344f1a061df081fc2dfc370554b17de87a5b577 Mon Sep 17 00:00:00 2001 From: Roman Glushko Date: Sun, 28 Apr 2024 18:27:24 +0300 Subject: [PATCH 34/34] #91: using another way to pass flags value --- images/windowserver.Dockerfile | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/images/windowserver.Dockerfile b/images/windowserver.Dockerfile index f8f05370..8de9962d 100644 --- a/images/windowserver.Dockerfile +++ b/images/windowserver.Dockerfile @@ -1,5 +1,5 @@ # syntax=docker/dockerfile:1 -FROM golang:1.22-alpine as build +FROM golang:1.22-windowsservercore-1809 as build ARG VERSION ARG COMMIT @@ -11,14 +11,11 @@ WORKDIR /build COPY . /build/ RUN go mod download -RUN go build -v -o /build/dist/glide.exe -ldflags "-s -w -X glide/pkg/version.Version="$VERSION" -X glide/pkg/version.commitSha="$COMMIT" -X glide/pkg/version.buildDate="$BUILD_DATE"" +RUN go build -v -o /build/dist/glide.exe -ldflags="-s -w -X glide/pkg/version.Version=$VERSION -X glide/pkg/version.commitSha=$COMMIT -X glide/pkg/version.buildDate=$BUILD_DATE" FROM mcr.microsoft.com/windows/servercore:1809 as release WORKDIR /bin - -SHELL ["powershell", "-Command", "$ErrorActionPreference = 'Stop'; $ProgressPreference = 'SilentlyContinue';"] - COPY --from=build /build/dist/glide.exe /bin/ ENTRYPOINT ["/bin/glide.exe"]