diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml index 69f01d09..c5a70994 100644 --- a/.github/workflows/release.yaml +++ b/.github/workflows/release.yaml @@ -5,19 +5,66 @@ on: tags: - "*" + pull_request: + types: + - synchronize + - labeled + permissions: contents: write packages: write jobs: - lint: - uses: ./.github/workflows/lint.yaml - vuln: - uses: ./.github/workflows/vuln.yaml + setup: + runs-on: ubuntu-latest + outputs: + 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 build context + id: build-context + run: | + LABELS="${{ toJson(github.event.pull_request.labels.*.name) }}" + DRY_RUN="false" + + if [[ $LABELS == *"build:dry-run"* ]]; then + DRY_RUN="true" + fi + + VERSION="${{ github.ref_name }}" + + if [[ "${{ github.event_name }}" == 'pull_request' ]]; then + PR_ID=$(echo "${{ github.ref }}" | cut -d '/' -f 3) + VERSION="dev.$PR_ID" + fi + + 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 +# vuln: +# uses: ./.github/workflows/vuln.yaml release: + if: "startsWith(github.ref, 'refs/tags/') || needs.setup.outputs.dry-run == 'true'" needs: - - lint - - vuln + - setup +# - lint +# - vuln runs-on: ubuntu-latest steps: - name: Set up Go @@ -37,19 +84,30 @@ jobs: mkdir -p $HOME/.cache/snapcraft/download mkdir -p $HOME/.cache/snapcraft/stage-packages - - name: Run GoReleaser - uses: goreleaser/goreleaser-action@v5 - with: - distribution: goreleaser - version: latest - args: release --clean - env: - 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: + - name: Prepare GoReleaser extra args + run: | + ARGS="" + if [[ "${{ needs.setup.outputs.dry-run }}" == "true" ]]; then + ARGS="$ARGS --skip=validate --skip=publish" + 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 }} + + images-linux: + if: "startsWith(github.ref, 'refs/tags/') || needs.setup.outputs.dry-run == 'true'" strategy: matrix: image: @@ -59,7 +117,54 @@ jobs: - redhat runs-on: ubuntu-latest needs: + - setup + - release + 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: + 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 + 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 + 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'" + strategy: + matrix: + image: +# - nanoserver + - windows-server + needs: + - setup - release + runs-on: windows-2019 + steps: - name: checkout uses: actions/checkout@v4 @@ -72,16 +177,28 @@ 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 + shell: powershell 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: 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 - run: VERSION=${{ github.ref_name }} make publish-ghcr-${{ matrix.image }} + env: + VERSION: ${{ needs.setup.outputs.version }} + 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 - run: VERSION=${{ github.ref_name }} make publish-dockerhub-${{ matrix.image }} + env: + VERSION: ${{ needs.setup.outputs.version }} + run: make VERSION="${{ env.VERSION }}" 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 diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 2735b5e4..c623fa14 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -34,14 +34,33 @@ 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 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 +92,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. + diff --git a/images/Makefile b/images/Makefile index d87148ac..d13153dc 100644 --- a/images/Makefile +++ b/images/Makefile @@ -81,6 +81,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..6a8e1c4a --- /dev/null +++ b/images/nanoserver.Dockerfile @@ -0,0 +1,27 @@ +# 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';"] + +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" + +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/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 new file mode 100644 index 00000000..8de9962d --- /dev/null +++ b/images/windowserver.Dockerfile @@ -0,0 +1,21 @@ +# syntax=docker/dockerfile:1 +FROM golang:1.22-windowsservercore-1809 as build + +ARG VERSION +ARG COMMIT +ARG BUILD_DATE + +ENV GOOS=windows + +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" + +FROM mcr.microsoft.com/windows/servercore:1809 as release + +WORKDIR /bin +COPY --from=build /build/dist/glide.exe /bin/ + +ENTRYPOINT ["/bin/glide.exe"]