From 32b69412335451aa46f6eac43993f3d680146fa7 Mon Sep 17 00:00:00 2001 From: Tobias Gesellchen Date: Fri, 23 Feb 2024 07:51:12 +0100 Subject: [PATCH 1/8] Add Windows and more Linux platforms to the multi-arch image --- .dockerignore | 1 + .github/dependabot.yml | 12 ++ .github/workflows/build-docker-image.yml | 68 +++++--- .github/workflows/publish-docker-image.yml | 187 +++++++++++++++------ Dockerfile => linux/Dockerfile | 0 testresources/Dockerfile | 2 +- windows/Dockerfile | 29 ++++ 7 files changed, 224 insertions(+), 75 deletions(-) rename Dockerfile => linux/Dockerfile (100%) create mode 100644 windows/Dockerfile diff --git a/.dockerignore b/.dockerignore index a563517..937e8f2 100644 --- a/.dockerignore +++ b/.dockerignore @@ -5,5 +5,6 @@ testresources/ .gitignore .golangci.yml Dockerfile +**/Dockerfile main_test.go README.md diff --git a/.github/dependabot.yml b/.github/dependabot.yml index 643e20b..a971d91 100644 --- a/.github/dependabot.yml +++ b/.github/dependabot.yml @@ -14,3 +14,15 @@ updates: day: sunday open-pull-requests-limit: 3 rebase-strategy: disabled + - package-ecosystem: docker + directory: /linux + schedule: + interval: monthly + - package-ecosystem: docker + directory: /testresources + schedule: + interval: monthly + - package-ecosystem: docker + directory: /windows + schedule: + interval: monthly diff --git a/.github/workflows/build-docker-image.yml b/.github/workflows/build-docker-image.yml index 0dc5e8d..c899b8e 100644 --- a/.github/workflows/build-docker-image.yml +++ b/.github/workflows/build-docker-image.yml @@ -2,7 +2,7 @@ name: Test & Build multi-arch Docker Image on: push: - branches: [main] + branches: [ main ] pull_request: jobs: @@ -32,33 +32,51 @@ jobs: - name: go-test run: go test -v ./... - build: + build-image-for-linux: runs-on: ubuntu-latest needs: test steps: - - uses: actions/checkout@v3 - - uses: actions/setup-go@v5 - with: - go-version: '1.21' - - run: go version + - uses: actions/checkout@v3 + - uses: actions/setup-go@v5 + with: + go-version: '1.21' + - run: go version + + - name: Set up QEMU + uses: docker/setup-qemu-action@v3 + - name: Set up Docker Buildx + id: buildx + uses: docker/setup-buildx-action@v2 + + - name: Docker info + run: docker info + - name: Buildx inspect + run: docker buildx inspect + + - name: Build image + uses: docker/build-push-action@v3 + with: + context: . + file: linux/Dockerfile + platforms: linux/amd64,linux/arm/v7,linux/arm64,linux/ppc64le,linux/s390x,linux/386,linux/arm/v6 + push: false + # Use a 'temp' tag, that won't be pushed for non-release builds + tags: testcontainers/ryuk:${{ github.event.release.tag_name || 'temp' }}-linux - - name: Set up QEMU - uses: docker/setup-qemu-action@v3 - - name: Set up Docker Buildx - id: buildx - uses: docker/setup-buildx-action@v2 + build-image-for-windows-2022: + runs-on: windows-2022 + needs: test + steps: + - uses: actions/checkout@v3 + - uses: actions/setup-go@v3 + with: + go-version: '1.21' + - run: go version - - name: Docker info - run: docker info - - name: Buildx inspect - run: docker buildx inspect + - name: Docker info + run: docker info - - name: Build image - uses: docker/build-push-action@v3 - with: - context: . - file: ./Dockerfile - platforms: linux/amd64,linux/arm/v7,linux/arm64,linux/ppc64le,linux/s390x - push: false - # Use a 'temp' tag, that won't be pushed, for non-release builds - tags: testcontainers/ryuk:${{ github.event.release.tag_name || 'temp' }} + - name: Build image + # Use a 'temp' tag, that won't be pushed for non-release builds + run: | + docker build -f windows/Dockerfile --build-arg BASE_IMAGE=mcr.microsoft.com/windows/nanoserver:ltsc2019 -t testcontainers/ryuk:${{ github.event.release.tag_name || 'temp' }}-windows.amd64 . diff --git a/.github/workflows/publish-docker-image.yml b/.github/workflows/publish-docker-image.yml index 393828a..32ae3a4 100644 --- a/.github/workflows/publish-docker-image.yml +++ b/.github/workflows/publish-docker-image.yml @@ -2,57 +2,146 @@ name: Release multi-arch Docker Image on: release: - types: [published] + types: [ published ] jobs: - release: + release-linux: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v3 - - - uses: actions/setup-go@v5 - with: - go-version: '1.21' - - run: go version - - - name: Login to Docker Hub - uses: docker/login-action@v1 - with: - username: ${{ secrets.DOCKERHUB_USERNAME }} - password: ${{ secrets.DOCKERHUB_TOKEN }} - - - name: go-mod verify - run: go mod verify - - - name: go-mod tidy - run: go mod tidy - - - name: go-build - env: - GOOS: linux - run: go build - - - name: go-test - run: go test -v ./... - - - name: Set up QEMU - uses: docker/setup-qemu-action@v3 - - - name: Set up Docker Buildx - id: buildx - uses: docker/setup-buildx-action@v2 - - - name: Docker info - run: docker info - - name: Buildx inspect - run: docker buildx inspect - - - name: Build and push image - uses: docker/build-push-action@v3 - with: - context: . - file: ./Dockerfile - platforms: linux/amd64,linux/arm/v7,linux/arm64,linux/ppc64le,linux/s390x + - name: Set up Go + uses: actions/setup-go@v5 + with: + go-version: '1.21' + - run: go version + + - name: Check out code into the Go module directory + uses: actions/checkout@v3 + + - name: Login to Docker Hub + uses: docker/login-action@v2 + with: + username: ${{ secrets.DOCKERHUB_USERNAME }} + password: ${{ secrets.DOCKERHUB_TOKEN }} + + - name: go-mod verify + run: go mod verify + + - name: go-mod tidy + run: go mod tidy + + - name: go-build + env: + GOOS: linux + run: go build + + - name: go-test + run: go test -v ./... + + - name: Set up QEMU + uses: docker/setup-qemu-action@v3 + + - name: Set up Docker Buildx + id: buildx + uses: docker/setup-buildx-action@v2 + + - name: Docker info + run: docker info + - name: Buildx inspect + run: docker buildx inspect + + - name: Build and push image + uses: docker/build-push-action@v3 + with: + context: . + file: linux/Dockerfile + platforms: linux/amd64,linux/arm/v7,linux/arm64,linux/ppc64le,linux/s390x,linux/386,linux/arm/v6 + # Only push if we are publishing a release + push: true + tags: testcontainers/ryuk:${{ github.event.release.tag_name }}-linux + + release-windows-2022: + runs-on: windows-2022 + steps: + - name: Set up Go + uses: actions/setup-go@v3 + with: + go-version: '1.21' + - run: go version + + - name: Check out code into the Go module directory + uses: actions/checkout@v3 + + - name: Login to Docker Hub + uses: docker/login-action@v2 + with: + username: ${{ secrets.DOCKERHUB_USERNAME }} + password: ${{ secrets.DOCKERHUB_TOKEN }} + + - name: go-mod verify + run: go mod verify + + - name: go-mod tidy + run: go mod tidy + + - name: go-build + env: + GOOS: windows + run: go build + + #- name: go-test + # run: go test -v ./... + + - name: Docker info + run: docker info + + - name: Build image + run: | + docker build -f windows/Dockerfile --build-arg BASE_IMAGE=mcr.microsoft.com/windows/nanoserver:ltsc2019 -t testcontainers/ryuk:${{ github.event.release.tag_name }}-windows.amd64 . + + - name: Push image # Only push if we are publishing a release - push: true - tags: testcontainers/ryuk:${{ github.event.release.tag_name }} + run: | + docker push testcontainers/ryuk:${{ github.event.release.tag_name }}-windows.amd64 . + + release: + needs: + - release-linux + - release-windows-2022 + runs-on: ubuntu-latest + steps: + - name: Login to Docker Hub + uses: docker/login-action@v2 + with: + username: ${{ secrets.DOCKERHUB_USERNAME }} + password: ${{ secrets.DOCKERHUB_TOKEN }} + + - name: Set up QEMU + uses: docker/setup-qemu-action@v2 + - name: Set up Docker Buildx + id: buildx + uses: docker/setup-buildx-action@v2 + + - name: Docker info + run: docker info + - name: Buildx inspect + run: docker buildx inspect + + - name: Get os version for nanoserver:ltsc2019 + run: >- + full_version=$(docker manifest inspect mcr.microsoft.com/windows/nanoserver:ltsc2019 | jq -r '.manifests[]|.platform|."os.version"'| sed 's@.*:@@') || true; + echo "OS_VERSION_ltsc2019=${full_version}" >> $GITHUB_ENV; + + - name: Docker Manifest + run: >- + target_image=testcontainers/ryuk:${{ github.event.release.tag_name }}; + linux_manifest=$(docker manifest inspect ${target_image}-linux); + linux_digests=$(docker manifest inspect ${target_image}-linux | jq -r '.manifests[].digest'); + manifest_list=${linux_digests//sha256:/${target_image%%:*}@sha256:}; + manifest_list+=" ${target_image}-windows.amd64"; + docker manifest create ${target_image} ${manifest_list}; + docker manifest annotate \ + --os-version ${OS_VERSION_ltsc2019} \ + --os windows \ + --arch amd64 \ + ${target_image} "${target_image}-windows.amd64"; + docker manifest push ${target_image}; diff --git a/Dockerfile b/linux/Dockerfile similarity index 100% rename from Dockerfile rename to linux/Dockerfile diff --git a/testresources/Dockerfile b/testresources/Dockerfile index 52d831a..e175a44 100644 --- a/testresources/Dockerfile +++ b/testresources/Dockerfile @@ -1 +1 @@ -FROM nginx:alpine \ No newline at end of file +FROM nginx:alpine diff --git a/windows/Dockerfile b/windows/Dockerfile new file mode 100644 index 0000000..e18a150 --- /dev/null +++ b/windows/Dockerfile @@ -0,0 +1,29 @@ +ARG BASE_IMAGE +# ----------- +# Build Image +# ----------- +FROM golang:1.21-nanoserver as build + +# Go build env +ENV CGO_ENABLED=0 + +WORKDIR /app + +# Install source deps +COPY go.mod go.sum ./ +RUN go mod download + +# Copy source & build +COPY . . +RUN go build -v -ldflags "-s" -o /bin/ryuk + +# ----------------- +# Distributed Image +# ----------------- +FROM ${BASE_IMAGE} +#FROM mcr.microsoft.com/windows/nanoserver:ltsc2019 +#FROM mcr.microsoft.com/windows/nanoserver:ltsc2022 + +COPY --from=build /bin/ryuk /bin/ryuk +CMD ["/bin/ryuk"] +LABEL org.testcontainers.ryuk=true From 79106b17817d89ea0be0295d4c5d129781c3751a Mon Sep 17 00:00:00 2001 From: Tobias Gesellchen Date: Fri, 23 Feb 2024 12:07:11 +0100 Subject: [PATCH 2/8] Bump actions/checkout to v4 and use go-version from go.mod --- .github/workflows/build-docker-image.yml | 12 ++++++------ .github/workflows/golangci-lint.yml | 4 ++-- .github/workflows/publish-docker-image.yml | 8 ++++---- 3 files changed, 12 insertions(+), 12 deletions(-) diff --git a/.github/workflows/build-docker-image.yml b/.github/workflows/build-docker-image.yml index c899b8e..49329dc 100644 --- a/.github/workflows/build-docker-image.yml +++ b/.github/workflows/build-docker-image.yml @@ -12,11 +12,11 @@ jobs: - name: Set up Go uses: actions/setup-go@v5 with: - go-version: '1.21' + go-version-file: 'go.mod' - run: go version - name: Check out code into the Go module directory - uses: actions/checkout@v3 + uses: actions/checkout@v4 - name: go-mod verify run: go mod verify @@ -36,10 +36,10 @@ jobs: runs-on: ubuntu-latest needs: test steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - uses: actions/setup-go@v5 with: - go-version: '1.21' + go-version-file: 'go.mod' - run: go version - name: Set up QEMU @@ -67,10 +67,10 @@ jobs: runs-on: windows-2022 needs: test steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - uses: actions/setup-go@v3 with: - go-version: '1.21' + go-version-file: 'go.mod' - run: go version - name: Docker info diff --git a/.github/workflows/golangci-lint.yml b/.github/workflows/golangci-lint.yml index 4e1adf3..7d0d1a5 100644 --- a/.github/workflows/golangci-lint.yml +++ b/.github/workflows/golangci-lint.yml @@ -17,8 +17,8 @@ jobs: steps: - uses: actions/setup-go@v5 with: - go-version: 1.21 - - uses: actions/checkout@v3 + go-version-file: 'go.mod' + - uses: actions/checkout@v4 - name: golangci-lint uses: golangci/golangci-lint-action@3a919529898de77ec3da873e3063ca4b10e7f5cc # v3 with: diff --git a/.github/workflows/publish-docker-image.yml b/.github/workflows/publish-docker-image.yml index 32ae3a4..7f207ba 100644 --- a/.github/workflows/publish-docker-image.yml +++ b/.github/workflows/publish-docker-image.yml @@ -11,11 +11,11 @@ jobs: - name: Set up Go uses: actions/setup-go@v5 with: - go-version: '1.21' + go-version-file: 'go.mod' - run: go version - name: Check out code into the Go module directory - uses: actions/checkout@v3 + uses: actions/checkout@v4 - name: Login to Docker Hub uses: docker/login-action@v2 @@ -65,11 +65,11 @@ jobs: - name: Set up Go uses: actions/setup-go@v3 with: - go-version: '1.21' + go-version-file: 'go.mod' - run: go version - name: Check out code into the Go module directory - uses: actions/checkout@v3 + uses: actions/checkout@v4 - name: Login to Docker Hub uses: docker/login-action@v2 From 8cf6368a9a9e4949e8e6f88e9c55200e6b49ad61 Mon Sep 17 00:00:00 2001 From: Tobias Gesellchen Date: Fri, 23 Feb 2024 12:16:13 +0100 Subject: [PATCH 3/8] Add ltsc2022 to the mix --- .github/workflows/build-docker-image.yml | 24 +++++++- .github/workflows/publish-docker-image.yml | 64 ++++++++++++++++++++-- 2 files changed, 81 insertions(+), 7 deletions(-) diff --git a/.github/workflows/build-docker-image.yml b/.github/workflows/build-docker-image.yml index 49329dc..fd447a1 100644 --- a/.github/workflows/build-docker-image.yml +++ b/.github/workflows/build-docker-image.yml @@ -32,7 +32,7 @@ jobs: - name: go-test run: go test -v ./... - build-image-for-linux: + build-image-linux: runs-on: ubuntu-latest needs: test steps: @@ -63,7 +63,7 @@ jobs: # Use a 'temp' tag, that won't be pushed for non-release builds tags: testcontainers/ryuk:${{ github.event.release.tag_name || 'temp' }}-linux - build-image-for-windows-2022: + build-image-windows-2019: runs-on: windows-2022 needs: test steps: @@ -79,4 +79,22 @@ jobs: - name: Build image # Use a 'temp' tag, that won't be pushed for non-release builds run: | - docker build -f windows/Dockerfile --build-arg BASE_IMAGE=mcr.microsoft.com/windows/nanoserver:ltsc2019 -t testcontainers/ryuk:${{ github.event.release.tag_name || 'temp' }}-windows.amd64 . + docker build -f windows/Dockerfile --build-arg BASE_IMAGE=mcr.microsoft.com/windows/nanoserver:ltsc2019 -t testcontainers/ryuk:${{ github.event.release.tag_name || 'temp' }}-windows.amd64.ltsc2019 . + + build-image-windows-2022: + runs-on: windows-2022 + needs: test + steps: + - uses: actions/checkout@v4 + - uses: actions/setup-go@v3 + with: + go-version-file: 'go.mod' + - run: go version + + - name: Docker info + run: docker info + + - name: Build image + # Use a 'temp' tag, that won't be pushed for non-release builds + run: | + docker build -f windows/Dockerfile --build-arg BASE_IMAGE=mcr.microsoft.com/windows/nanoserver:ltsc2022 -t testcontainers/ryuk:${{ github.event.release.tag_name || 'temp' }}-windows.amd64.ltsc2022 . diff --git a/.github/workflows/publish-docker-image.yml b/.github/workflows/publish-docker-image.yml index 7f207ba..c44cbd3 100644 --- a/.github/workflows/publish-docker-image.yml +++ b/.github/workflows/publish-docker-image.yml @@ -59,6 +59,50 @@ jobs: push: true tags: testcontainers/ryuk:${{ github.event.release.tag_name }}-linux + release-windows-2019: + runs-on: windows-2022 + steps: + - name: Set up Go + uses: actions/setup-go@v3 + with: + go-version-file: 'go.mod' + - run: go version + + - name: Check out code into the Go module directory + uses: actions/checkout@v4 + + - name: Login to Docker Hub + uses: docker/login-action@v2 + with: + username: ${{ secrets.DOCKERHUB_USERNAME }} + password: ${{ secrets.DOCKERHUB_TOKEN }} + + - name: go-mod verify + run: go mod verify + + - name: go-mod tidy + run: go mod tidy + + - name: go-build + env: + GOOS: windows + run: go build + + #- name: go-test + # run: go test -v ./... + + - name: Docker info + run: docker info + + - name: Build image + run: | + docker build -f windows/Dockerfile --build-arg BASE_IMAGE=mcr.microsoft.com/windows/nanoserver:ltsc2019 -t testcontainers/ryuk:${{ github.event.release.tag_name }}-windows.amd64.ltsc2019 . + + - name: Push image + # Only push if we are publishing a release + run: | + docker push testcontainers/ryuk:${{ github.event.release.tag_name }}-windows.amd64.ltsc2019 . + release-windows-2022: runs-on: windows-2022 steps: @@ -96,16 +140,17 @@ jobs: - name: Build image run: | - docker build -f windows/Dockerfile --build-arg BASE_IMAGE=mcr.microsoft.com/windows/nanoserver:ltsc2019 -t testcontainers/ryuk:${{ github.event.release.tag_name }}-windows.amd64 . + docker build -f windows/Dockerfile --build-arg BASE_IMAGE=mcr.microsoft.com/windows/nanoserver:ltsc2022 -t testcontainers/ryuk:${{ github.event.release.tag_name }}-windows.amd64.ltsc2022 . - name: Push image # Only push if we are publishing a release run: | - docker push testcontainers/ryuk:${{ github.event.release.tag_name }}-windows.amd64 . + docker push testcontainers/ryuk:${{ github.event.release.tag_name }}-windows.amd64.ltsc2022 . release: needs: - release-linux + - release-windows-2019 - release-windows-2022 runs-on: ubuntu-latest steps: @@ -131,17 +176,28 @@ jobs: full_version=$(docker manifest inspect mcr.microsoft.com/windows/nanoserver:ltsc2019 | jq -r '.manifests[]|.platform|."os.version"'| sed 's@.*:@@') || true; echo "OS_VERSION_ltsc2019=${full_version}" >> $GITHUB_ENV; + - name: Get os version for nanoserver:ltsc2022 + run: >- + full_version=$(docker manifest inspect mcr.microsoft.com/windows/nanoserver:ltsc2022 | jq -r '.manifests[]|.platform|."os.version"'| sed 's@.*:@@') || true; + echo "OS_VERSION_ltsc2022=${full_version}" >> $GITHUB_ENV; + - name: Docker Manifest run: >- target_image=testcontainers/ryuk:${{ github.event.release.tag_name }}; linux_manifest=$(docker manifest inspect ${target_image}-linux); linux_digests=$(docker manifest inspect ${target_image}-linux | jq -r '.manifests[].digest'); manifest_list=${linux_digests//sha256:/${target_image%%:*}@sha256:}; - manifest_list+=" ${target_image}-windows.amd64"; + manifest_list+=" ${target_image}-windows.amd64.ltsc2019"; + manifest_list+=" ${target_image}-windows.amd64.ltsc2022"; docker manifest create ${target_image} ${manifest_list}; docker manifest annotate \ --os-version ${OS_VERSION_ltsc2019} \ --os windows \ --arch amd64 \ - ${target_image} "${target_image}-windows.amd64"; + ${target_image} "${target_image}-windows.amd64.ltsc2019"; + docker manifest annotate \ + --os-version ${OS_VERSION_ltsc2022} \ + --os windows \ + --arch amd64 \ + ${target_image} "${target_image}-windows.amd64.ltsc2022"; docker manifest push ${target_image}; From d0bd74a1b13c115115f2eefe783cfbe0e40962d6 Mon Sep 17 00:00:00 2001 From: Tobias Gesellchen Date: Fri, 23 Feb 2024 17:03:55 +0100 Subject: [PATCH 4/8] Fix go.mod based workflow setup --- .github/workflows/build-docker-image.yml | 6 +++--- .github/workflows/golangci-lint.yml | 2 +- .github/workflows/publish-docker-image.yml | 18 +++++++++--------- 3 files changed, 13 insertions(+), 13 deletions(-) diff --git a/.github/workflows/build-docker-image.yml b/.github/workflows/build-docker-image.yml index fd447a1..50cd157 100644 --- a/.github/workflows/build-docker-image.yml +++ b/.github/workflows/build-docker-image.yml @@ -9,15 +9,15 @@ jobs: test: runs-on: ubuntu-latest steps: + - name: Check out code into the Go module directory + uses: actions/checkout@v4 + - name: Set up Go uses: actions/setup-go@v5 with: go-version-file: 'go.mod' - run: go version - - name: Check out code into the Go module directory - uses: actions/checkout@v4 - - name: go-mod verify run: go mod verify diff --git a/.github/workflows/golangci-lint.yml b/.github/workflows/golangci-lint.yml index 7d0d1a5..aca6888 100644 --- a/.github/workflows/golangci-lint.yml +++ b/.github/workflows/golangci-lint.yml @@ -15,10 +15,10 @@ jobs: name: lint runs-on: ubuntu-latest steps: + - uses: actions/checkout@v4 - uses: actions/setup-go@v5 with: go-version-file: 'go.mod' - - uses: actions/checkout@v4 - name: golangci-lint uses: golangci/golangci-lint-action@3a919529898de77ec3da873e3063ca4b10e7f5cc # v3 with: diff --git a/.github/workflows/publish-docker-image.yml b/.github/workflows/publish-docker-image.yml index c44cbd3..96d45fe 100644 --- a/.github/workflows/publish-docker-image.yml +++ b/.github/workflows/publish-docker-image.yml @@ -8,15 +8,15 @@ jobs: release-linux: runs-on: ubuntu-latest steps: + - name: Check out code into the Go module directory + uses: actions/checkout@v4 + - name: Set up Go uses: actions/setup-go@v5 with: go-version-file: 'go.mod' - run: go version - - name: Check out code into the Go module directory - uses: actions/checkout@v4 - - name: Login to Docker Hub uses: docker/login-action@v2 with: @@ -62,15 +62,15 @@ jobs: release-windows-2019: runs-on: windows-2022 steps: + - name: Check out code into the Go module directory + uses: actions/checkout@v4 + - name: Set up Go uses: actions/setup-go@v3 with: go-version-file: 'go.mod' - run: go version - - name: Check out code into the Go module directory - uses: actions/checkout@v4 - - name: Login to Docker Hub uses: docker/login-action@v2 with: @@ -106,15 +106,15 @@ jobs: release-windows-2022: runs-on: windows-2022 steps: + - name: Check out code into the Go module directory + uses: actions/checkout@v4 + - name: Set up Go uses: actions/setup-go@v3 with: go-version-file: 'go.mod' - run: go version - - name: Check out code into the Go module directory - uses: actions/checkout@v4 - - name: Login to Docker Hub uses: docker/login-action@v2 with: From 5a73dedffb36e09dc4b65d57fc0e06c9daf8dfa3 Mon Sep 17 00:00:00 2001 From: Tobias Gesellchen Date: Fri, 23 Feb 2024 18:45:54 +0100 Subject: [PATCH 5/8] Use matrix builds for the Windows os-versions --- .github/workflows/build-docker-image.yml | 34 ++++------- .github/workflows/publish-docker-image.yml | 67 +++++----------------- 2 files changed, 27 insertions(+), 74 deletions(-) diff --git a/.github/workflows/build-docker-image.yml b/.github/workflows/build-docker-image.yml index 50cd157..4f89932 100644 --- a/.github/workflows/build-docker-image.yml +++ b/.github/workflows/build-docker-image.yml @@ -5,6 +5,9 @@ on: branches: [ main ] pull_request: +env: + IMAGE_REPOSITORY: testcontainers/ryuk + jobs: test: runs-on: ubuntu-latest @@ -61,27 +64,14 @@ jobs: platforms: linux/amd64,linux/arm/v7,linux/arm64,linux/ppc64le,linux/s390x,linux/386,linux/arm/v6 push: false # Use a 'temp' tag, that won't be pushed for non-release builds - tags: testcontainers/ryuk:${{ github.event.release.tag_name || 'temp' }}-linux - - build-image-windows-2019: - runs-on: windows-2022 - needs: test - steps: - - uses: actions/checkout@v4 - - uses: actions/setup-go@v3 - with: - go-version-file: 'go.mod' - - run: go version - - - name: Docker info - run: docker info - - - name: Build image - # Use a 'temp' tag, that won't be pushed for non-release builds - run: | - docker build -f windows/Dockerfile --build-arg BASE_IMAGE=mcr.microsoft.com/windows/nanoserver:ltsc2019 -t testcontainers/ryuk:${{ github.event.release.tag_name || 'temp' }}-windows.amd64.ltsc2019 . - - build-image-windows-2022: + tags: ${{ env.IMAGE_REPOSITORY }}:${{ github.event.release.tag_name || 'temp' }}-linux + + build-image-windows: + strategy: + matrix: + os-version: + - ltsc2019 + - ltsc2022 runs-on: windows-2022 needs: test steps: @@ -97,4 +87,4 @@ jobs: - name: Build image # Use a 'temp' tag, that won't be pushed for non-release builds run: | - docker build -f windows/Dockerfile --build-arg BASE_IMAGE=mcr.microsoft.com/windows/nanoserver:ltsc2022 -t testcontainers/ryuk:${{ github.event.release.tag_name || 'temp' }}-windows.amd64.ltsc2022 . + docker build -f windows/Dockerfile --build-arg BASE_IMAGE=mcr.microsoft.com/windows/nanoserver:${{ matrix.os-version }} -t ${{ env.IMAGE_REPOSITORY }}:${{ github.event.release.tag_name || 'temp' }}-windows.amd64.${{ matrix.os-version }} . diff --git a/.github/workflows/publish-docker-image.yml b/.github/workflows/publish-docker-image.yml index 96d45fe..48ad80d 100644 --- a/.github/workflows/publish-docker-image.yml +++ b/.github/workflows/publish-docker-image.yml @@ -4,6 +4,9 @@ on: release: types: [ published ] +env: + IMAGE_REPOSITORY: testcontainers/ryuk + jobs: release-linux: runs-on: ubuntu-latest @@ -57,53 +60,14 @@ jobs: platforms: linux/amd64,linux/arm/v7,linux/arm64,linux/ppc64le,linux/s390x,linux/386,linux/arm/v6 # Only push if we are publishing a release push: true - tags: testcontainers/ryuk:${{ github.event.release.tag_name }}-linux - - release-windows-2019: - runs-on: windows-2022 - steps: - - name: Check out code into the Go module directory - uses: actions/checkout@v4 - - - name: Set up Go - uses: actions/setup-go@v3 - with: - go-version-file: 'go.mod' - - run: go version - - - name: Login to Docker Hub - uses: docker/login-action@v2 - with: - username: ${{ secrets.DOCKERHUB_USERNAME }} - password: ${{ secrets.DOCKERHUB_TOKEN }} - - - name: go-mod verify - run: go mod verify - - - name: go-mod tidy - run: go mod tidy - - - name: go-build - env: - GOOS: windows - run: go build - - #- name: go-test - # run: go test -v ./... - - - name: Docker info - run: docker info - - - name: Build image - run: | - docker build -f windows/Dockerfile --build-arg BASE_IMAGE=mcr.microsoft.com/windows/nanoserver:ltsc2019 -t testcontainers/ryuk:${{ github.event.release.tag_name }}-windows.amd64.ltsc2019 . - - - name: Push image - # Only push if we are publishing a release - run: | - docker push testcontainers/ryuk:${{ github.event.release.tag_name }}-windows.amd64.ltsc2019 . - - release-windows-2022: + tags: ${{ env.IMAGE_REPOSITORY }}:${{ github.event.release.tag_name }}-linux + + release-windows: + strategy: + matrix: + os-version: + - ltsc2019 + - ltsc2022 runs-on: windows-2022 steps: - name: Check out code into the Go module directory @@ -140,18 +104,17 @@ jobs: - name: Build image run: | - docker build -f windows/Dockerfile --build-arg BASE_IMAGE=mcr.microsoft.com/windows/nanoserver:ltsc2022 -t testcontainers/ryuk:${{ github.event.release.tag_name }}-windows.amd64.ltsc2022 . + docker build -f windows/Dockerfile --build-arg BASE_IMAGE=mcr.microsoft.com/windows/nanoserver:${{ matrix.os-version }} -t ${{ env.IMAGE_REPOSITORY }}:${{ inputs.tag_name }}-windows.amd64.${{ matrix.os-version }} . - name: Push image # Only push if we are publishing a release run: | - docker push testcontainers/ryuk:${{ github.event.release.tag_name }}-windows.amd64.ltsc2022 . + docker push ${{ env.IMAGE_REPOSITORY }}:${{ github.event.release.tag_name }}-windows.amd64.${{ matrix.os-version }} release: needs: - release-linux - - release-windows-2019 - - release-windows-2022 + - release-windows runs-on: ubuntu-latest steps: - name: Login to Docker Hub @@ -183,7 +146,7 @@ jobs: - name: Docker Manifest run: >- - target_image=testcontainers/ryuk:${{ github.event.release.tag_name }}; + target_image=${{ env.IMAGE_REPOSITORY }}:${{ github.event.release.tag_name }}; linux_manifest=$(docker manifest inspect ${target_image}-linux); linux_digests=$(docker manifest inspect ${target_image}-linux | jq -r '.manifests[].digest'); manifest_list=${linux_digests//sha256:/${target_image%%:*}@sha256:}; From 62dc8928a17f57e935e09ed87986f54681c77ecb Mon Sep 17 00:00:00 2001 From: Tobias Gesellchen Date: Sat, 24 Feb 2024 12:48:44 +0100 Subject: [PATCH 6/8] Add a build task to ensure test and build jobs to succeed --- .github/workflows/build-docker-image.yml | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/.github/workflows/build-docker-image.yml b/.github/workflows/build-docker-image.yml index 4f89932..a2a7f49 100644 --- a/.github/workflows/build-docker-image.yml +++ b/.github/workflows/build-docker-image.yml @@ -37,7 +37,6 @@ jobs: build-image-linux: runs-on: ubuntu-latest - needs: test steps: - uses: actions/checkout@v4 - uses: actions/setup-go@v5 @@ -73,7 +72,6 @@ jobs: - ltsc2019 - ltsc2022 runs-on: windows-2022 - needs: test steps: - uses: actions/checkout@v4 - uses: actions/setup-go@v3 @@ -88,3 +86,14 @@ jobs: # Use a 'temp' tag, that won't be pushed for non-release builds run: | docker build -f windows/Dockerfile --build-arg BASE_IMAGE=mcr.microsoft.com/windows/nanoserver:${{ matrix.os-version }} -t ${{ env.IMAGE_REPOSITORY }}:${{ github.event.release.tag_name || 'temp' }}-windows.amd64.${{ matrix.os-version }} . + + build: + runs-on: ubuntu-latest + needs: + - test + - build-image-linux + - build-image-windows + steps: + - name: join point for test, linux build, and windows build + run: | + echo "done" From 05f287bd172dd307e32f79482bf22e2c68a5c57b Mon Sep 17 00:00:00 2001 From: Tobias Gesellchen Date: Mon, 26 Feb 2024 22:04:50 +0100 Subject: [PATCH 7/8] chore --- windows/Dockerfile | 2 -- 1 file changed, 2 deletions(-) diff --git a/windows/Dockerfile b/windows/Dockerfile index e18a150..c77c7de 100644 --- a/windows/Dockerfile +++ b/windows/Dockerfile @@ -21,8 +21,6 @@ RUN go build -v -ldflags "-s" -o /bin/ryuk # Distributed Image # ----------------- FROM ${BASE_IMAGE} -#FROM mcr.microsoft.com/windows/nanoserver:ltsc2019 -#FROM mcr.microsoft.com/windows/nanoserver:ltsc2022 COPY --from=build /bin/ryuk /bin/ryuk CMD ["/bin/ryuk"] From 6c6b2af434a2e02f6cd1edf1beff879f807b7c7c Mon Sep 17 00:00:00 2001 From: Tobias Gesellchen Date: Wed, 28 Feb 2024 18:39:31 +0100 Subject: [PATCH 8/8] Fix the tag_name (use github.event.release.tag_name) --- .github/workflows/publish-docker-image.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/publish-docker-image.yml b/.github/workflows/publish-docker-image.yml index 48ad80d..5668f0c 100644 --- a/.github/workflows/publish-docker-image.yml +++ b/.github/workflows/publish-docker-image.yml @@ -104,7 +104,7 @@ jobs: - name: Build image run: | - docker build -f windows/Dockerfile --build-arg BASE_IMAGE=mcr.microsoft.com/windows/nanoserver:${{ matrix.os-version }} -t ${{ env.IMAGE_REPOSITORY }}:${{ inputs.tag_name }}-windows.amd64.${{ matrix.os-version }} . + docker build -f windows/Dockerfile --build-arg BASE_IMAGE=mcr.microsoft.com/windows/nanoserver:${{ matrix.os-version }} -t ${{ env.IMAGE_REPOSITORY }}:${{ github.event.release.tag_name }}-windows.amd64.${{ matrix.os-version }} . - name: Push image # Only push if we are publishing a release