Skip to content

👷 #91: Build Windows images #181

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 36 commits into
base: develop
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
7af7d7c
#91: Build windows images
roma-glushko Mar 17, 2024
b71eb8f
Merge branch 'develop' into 91-build-win-images
roma-glushko Apr 28, 2024
aad8eb6
#91: Fixed the version package import path
roma-glushko Apr 28, 2024
a0d41d9
#91: Added CI steps to build win images
roma-glushko Apr 28, 2024
b19a9a7
#91: Introduced some functionality to build images without pushing them
roma-glushko Apr 28, 2024
1e30ade
#91: Changed a way to set dryrun mode for goreleaser
roma-glushko Apr 28, 2024
7f5cc6c
#91: trigger the release pipeline on PRs as well
roma-glushko Apr 28, 2024
489aa68
#91: added sync trigger
roma-glushko Apr 28, 2024
efd79bc
#91: made sure conditions are achievable
roma-glushko Apr 28, 2024
88ec6fb
#91: Remove the debug step and documented the label in the contrib guide
roma-glushko Apr 28, 2024
f3da97d
#91 skipping the prebuild validation in the dry-run mode
roma-glushko Apr 28, 2024
da4a458
#91: Introduced the setup state to define dry run mode. Skipping gore…
roma-glushko Apr 28, 2024
2e8859d
#91: Disabling initial linting to speed up testing
roma-glushko Apr 28, 2024
750e1c9
#91: removed deprecated usage of output setting
roma-glushko Apr 28, 2024
ededd53
#91: removed deprecated args
roma-glushko Apr 28, 2024
dac37fc
#91: Moved all build info to be computed on the setup step & fixed th…
roma-glushko Apr 28, 2024
8e0af10
#91: Escaped strings
roma-glushko Apr 28, 2024
380821f
#91: moved values of build vars to a sep bash vars
roma-glushko Apr 28, 2024
c325db9
#91: fixed version resolution
roma-glushko Apr 28, 2024
f21e07b
#91 add dependencies on the setup step
roma-glushko Apr 28, 2024
5333dfe
#91: Made sure make is installed on win machines
roma-glushko Apr 28, 2024
8cc664f
#91 added debug command
roma-glushko Apr 28, 2024
90768e4
#91: debug
roma-glushko Apr 28, 2024
34d9197
#91: debug
roma-glushko Apr 28, 2024
7b8f849
#91: trying to build the image from pwsh
roma-glushko Apr 28, 2024
8ebb4db
#91 trying to use powershell
roma-glushko Apr 28, 2024
084cde4
#91: disabling the nanoserver image building for now
roma-glushko Apr 28, 2024
ffa11fd
#91: Trying to pass build args as env vars
roma-glushko Apr 28, 2024
3c05ba4
#91: Change positions of -o flag
roma-glushko Apr 28, 2024
810490c
#91: removed -w arg
roma-glushko Apr 28, 2024
a5f7522
#91: Quote all -X args
roma-glushko Apr 28, 2024
518f204
#91 quoting -X values in a diff way
roma-glushko Apr 28, 2024
36d30c1
#91 getting back to the prev way of setting goos
roma-glushko Apr 28, 2024
ee5526f
#91: Build win binary in linux image
roma-glushko Apr 28, 2024
e344f1a
#91: using another way to pass flags value
roma-glushko Apr 28, 2024
467e1fd
Merge branch 'develop' into 91-build-win-images
roma-glushko Apr 29, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
163 changes: 140 additions & 23 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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:
Expand All @@ -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
Expand All @@ -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 }}
2 changes: 1 addition & 1 deletion .goreleaser.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ builds:
goarch: arm

changelog:
skip: true
disable: true

archives:
- id: glide
Expand Down
24 changes: 22 additions & 2 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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.


34 changes: 34 additions & 0 deletions images/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
27 changes: 27 additions & 0 deletions images/nanoserver.Dockerfile
Original file line number Diff line number Diff line change
@@ -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"]
2 changes: 1 addition & 1 deletion images/redhat.Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion images/ubuntu.Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
21 changes: 21 additions & 0 deletions images/windowserver.Dockerfile
Original file line number Diff line number Diff line change
@@ -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"]
Loading