Skip to content
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

Add a Windows platform native image (WCOW) #40

Closed
wants to merge 35 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
55c6dcd
Add a Windows platform native image (WCOW)
gesellix Jul 30, 2022
86b1cc1
Revert to an older docker module
gesellix Jul 31, 2022
14b5825
Publish multi-arch images including Windows
gesellix Jul 31, 2022
13ce990
Bump Golang to 1.19
gesellix Aug 7, 2022
54947b0
Fix Windows platform build
gesellix Aug 8, 2022
fa2f720
add workflow_dispatch trigger to ease debugging
gesellix Aug 8, 2022
b11ece3
linux/s390x builds currently fail with tls issues
gesellix Aug 8, 2022
1ee680f
try to fix linux/s390x
gesellix Aug 8, 2022
20825a4
add a hint about potential tls issues for linux/s390x build
gesellix Aug 8, 2022
8667d98
chore
gesellix Aug 9, 2022
cc4ce01
Try to create images based on :ltsc2019 instead of :ltsc2022
gesellix Aug 17, 2022
9d8ad21
wip
gesellix Aug 18, 2022
a13904e
wip
gesellix Aug 18, 2022
13bf159
chore
gesellix Aug 18, 2022
68a489a
BASE -> WINBASE
gesellix Aug 19, 2022
77a526b
chore: simplify
mdelapenya Dec 1, 2022
5f86485
Merge branch 'main' into wcow
mdelapenya Dec 1, 2022
01e5548
chore: bring back go commands into the GH action
mdelapenya Dec 1, 2022
3938fff
chore: add logs to each section of the script
mdelapenya Dec 1, 2022
4b6ff3b
chore: standardize shell variables
mdelapenya Dec 1, 2022
5c3ef56
chore: reduce windows OSs
mdelapenya Dec 2, 2022
057d0b2
chore: add a label with the base image name
mdelapenya Dec 2, 2022
d59c833
chore: separate Windows container Dockerfile
mdelapenya Dec 2, 2022
422bef6
chore: do not run tests while packaging
mdelapenya Dec 2, 2022
08458a2
chore: simplify logic extracting vars to env vars
mdelapenya Dec 2, 2022
95dfe01
chore: remove publish workflow, as it's already managed by the build one
mdelapenya Dec 2, 2022
3e70928
fic: keep GH check for the build
mdelapenya Dec 2, 2022
cf94a38
chore: update windows example
mdelapenya Dec 2, 2022
4e9cfaa
chore: remove useless comments
mdelapenya Dec 2, 2022
0ec7863
chore: remove default value for scratch
mdelapenya Dec 2, 2022
8e7e12f
chore: remove comment
mdelapenya Dec 2, 2022
c42df84
chore: add a job that actually runs the created images
mdelapenya Dec 9, 2022
ef0c628
chore: always push the docker images, as we want to test snapshots
mdelapenya Dec 9, 2022
b1b4dfe
fix: always login to Docker Hub
mdelapenya Dec 9, 2022
d154bfc
chore: do not access Docker Hub on PRs
mdelapenya Dec 9, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
13 changes: 11 additions & 2 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,11 @@
/bin/
/vendor/
.DS_Store
.idea/
.vscode/

vendor/
bin/

moby-ryuk
moby-ryuk.exe

Dockerfile
107 changes: 77 additions & 30 deletions .github/workflows/build-docker-image.yml
Original file line number Diff line number Diff line change
@@ -1,40 +1,87 @@
name: Build multi-arch Docker Image

on:
release:
types: [ published ]
push:
branches: [main]
branches: [ main ]
pull_request:

env:
RYUK_VERSION: ${{ github.event.release.tag_name || github.sha }}
IS_RELEASE: ${{ (github.event_name == 'release' && github.event.action == 'published' && 'yes') || 'no' }}

jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-go@v3
with:
go-version: '1.18'
- run: go version

- name: Verify project
run: make verify

- 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: 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' }}
- uses: actions/checkout@v3

- uses: actions/setup-go@v3
with:
go-version: '1.18'
mdelapenya marked this conversation as resolved.
Show resolved Hide resolved
- run: go version

- name: modVerify
run: go mod verify

- name: modTidy
run: go mod tidy

- name: ensure compilation
env:
GOOS: linux
run: go build

- name: Test
run: go test -v ./...

- name: Login to Docker Hub
if: ${{ github.event_name == 'release' && github.event.action == 'published' }}
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}

# Setup for buildx
- 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

# In case linux/s390x fails with tls issues:
# see https://github.com/testcontainers/moby-ryuk/pull/26
# and https://github.com/testcontainers/moby-ryuk/pull/40
- name: Cross Build for Linux and Windows
run: |
./build-multiarch.sh testcontainers/ryuk:${RYUK_VERSION} ${IS_RELEASE}

run-images:
if: ${{ github.event_name == 'release' && github.event.action == 'published' }}
needs: build
strategy:
fail-fast: false
matrix:
os: [ubuntu-22.04, windows-2022]

runs-on: ${{ matrix.os }}

steps:
- name: Pull Ryuk
run: docker pull testcontainers/ryuk:${RYUK_VERSION}

- name: Run Ryuk on Linux
if: ${{ matrix.os == 'ubuntu-22.04' }}
run: docker run -v /var/run/docker.sock:/var/run/docker.sock testcontainers/ryuk:${RYUK_VERSION}

- name: Run Ryuk on Windows
if: ${{ matrix.os == 'windows-2022' }}
run: docker run -v //./pipe/docker_engine://./pipe/docker_engine testcontainers/ryuk:${RYUK_VERSION}
continue-on-error: true
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this line still required?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably we need to change it slightly, but we would like to keep something like this to test the built image. Due to the complexity and amount of combinations an error sneaked in. The linux/amd64 and windows/amd64 contained the ARM binary.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I also think that the checks are required and make sense. I only asked for the "continue on error" line, which is at the very end of the workflow and doesn't have any effect (?).

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, you are right. continue-on-error is not necessary. We will adjust it with the update that fixes the binaries. Unfortunately, for Windows more changes are necessary due to: actions/runner-images#6688.

47 changes: 0 additions & 47 deletions .github/workflows/publish-docker-image.yml

This file was deleted.

3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,6 @@

vendor/
bin/

moby-ryuk
moby-ryuk.exe
23 changes: 18 additions & 5 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,11 +1,24 @@
FROM golang:1.18 as workspace
ARG BASE_IMAGE

FROM --platform=${BUILDPLATFORM} golang:1.18 AS workspace
mdelapenya marked this conversation as resolved.
Show resolved Hide resolved
LABEL builder=true

ENV CGO_ENABLED=0
ENV GOOS=${TARGETOS}
ENV GOARCH=${TARGETARCH}

WORKDIR /go/src/github.com/testcontainers/moby-ryuk
COPY go.mod go.sum ./
RUN go mod download
COPY . ./
RUN make build
RUN cd /go/src/github.com/testcontainers/moby-ryuk && go get -d \
&& if [ "$TARGETARCH" = "arm" ]; then export GOARM="${TARGETVARIANT//v}"; fi; \
go build -v -a \
-ldflags "-s -w -extldflags \"-static\"" \
-o /bin/moby-ryuk main.go; \
chmod +x /bin/moby-ryuk

FROM alpine:3.13.6
FROM ${BASE_IMAGE}
RUN apk --no-cache add ca-certificates
COPY --from=workspace /go/src/github.com/testcontainers/moby-ryuk/bin/moby-ryuk /app
CMD ["/app"]
CMD ["/moby-ryuk"]
COPY --from=workspace /bin/moby-ryuk /moby-ryuk
kiview marked this conversation as resolved.
Show resolved Hide resolved
24 changes: 24 additions & 0 deletions Dockerfile.windows
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
ARG BASE_IMAGE

FROM --platform=${BUILDPLATFORM} golang:1.18 AS workspace
mdelapenya marked this conversation as resolved.
Show resolved Hide resolved
LABEL builder=true

ENV CGO_ENABLED=0
ENV GOOS=windows
ENV GOARCH=amd64

WORKDIR /go/src/github.com/testcontainers/moby-ryuk
COPY go.mod go.sum ./
RUN go mod download
COPY . ./
RUN echo $GOOS
RUN echo $GOARCH

RUN go build -v -a \
-ldflags "-s -w -extldflags \"-static\"" \
-o /bin/moby-ryuk main.go; \
chmod +x /bin/moby-ryuk

FROM ${BASE_IMAGE}
CMD ["/moby-ryuk.exe"]
COPY --from=workspace /bin/moby-ryuk /moby-ryuk.exe
40 changes: 0 additions & 40 deletions Makefile

This file was deleted.

4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ This project helps you to remove containers/networks/volumes/images by given fil

$ ./bin/moby-ryuk -p 8080
$ # You can also run it with Docker
$ docker run -v /var/run/docker.sock:/var/run/docker.sock -p 8080:8080 quay.io/testcontainers/ryuk
$ docker run --rm -v /var/run/docker.sock:/var/run/docker.sock -p 8080:8080 testcontainers/ryuk
$ # Example for Windows
$ docker run --rm -v //./pipe/docker_engine://./pipe/docker_engine -p 8080:8080 testcontainers/ryuk

1. Connect via TCP:

Expand Down
67 changes: 67 additions & 0 deletions build-multiarch.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
TARGETIMAGE=${1:-target/image:ci}
IS_RELEASE=${2:-no}
LINUXBASE="alpine:3.16.1"
WINBASE="mcr.microsoft.com/windows/nanoserver"
OSVERSIONS=("ltsc2019" "ltsc2022")
MANIFESTLIST=""
BUILDX_PUSH=""

if [ "${IS_RELEASE}" = "yes" ]; then
export BUILDX_PUSH="--push";
fi;

echo "Building for Linux"
docker buildx build \
--platform linux/amd64,linux/arm64,linux/ppc64le,linux/s390x,linux/386,linux/arm/v7,linux/arm/v6 \
${BUILDX_PUSH} \
--pull \
--build-arg BASE_IMAGE=${LINUXBASE} \
--label "org.opencontainers.image.base.name=${LINUXBASE}" \
-t ${TARGETIMAGE} \
-f Dockerfile \
.

for VERSION in ${OSVERSIONS[*]}
do
echo "Building Windows ${VERSION}"
docker buildx build \
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One thing that I noticed in my local workspace is that I needed to create a builder for windows/amd64, with

docker buildx create --platform windows/amd64 --name windows-builder --use

Otherwise, the windows platform was not available in my build context.

Do you know if the Docker installed in the ubuntu-latest comes with that support?

We could print docker buildx ls to verify it

--platform windows/amd64 \
${BUILDX_PUSH} \
--pull \
--build-arg BASE_IMAGE=${WINBASE}:${VERSION} \
--label "org.opencontainers.image.base.name=${WINBASE}:${VERSION}" \
-t "${TARGETIMAGE}-${VERSION}" \
-f Dockerfile.windows \
.
MANIFESTLIST+="${TARGETIMAGE}-${VERSION} "
done

# Get images from Linux manifest list, append and annotate Windows images and overwrite in registry
# Not sure the remove of the manifest is needed
docker manifest rm ${TARGETIMAGE} > /dev/null 2>&1
# if you push the Docker images the manifest is not locally
docker pull ${TARGETIMAGE}
lin_images=$(docker manifest inspect ${TARGETIMAGE} | jq -r '.manifests[].digest')

echo "Creating Linux manifest: ${lin_images}"
docker manifest create ${TARGETIMAGE} ${MANIFESTLIST} ${lin_images//sha256:/${TARGETIMAGE%%:*}@sha256:}

for VERSION in ${OSVERSIONS[*]}
do
# Not sure the remove of the manifest is needed
echo "Annotating Windows platforms to the manifest: ${WINBASE}:${VERSION}"
docker manifest rm ${WINBASE}:${VERSION} > /dev/null 2>&1
mdelapenya marked this conversation as resolved.
Show resolved Hide resolved
# if you push the Docker images the manifest is not locally
docker pull ${WINBASE}:${VERSION}
full_version=$(docker manifest inspect ${WINBASE}:${VERSION} |jq -r '.manifests[]|.platform|."os.version"'| sed 's@.*:@@') || true;
docker manifest annotate \
--os-version ${full_version} \
--os windows \
--arch amd64 \
${TARGETIMAGE} "${TARGETIMAGE}-${VERSION}"
done

if [ "${IS_RELEASE}" = "yes" ]; then
echo "Pushing manifest to ${TARGETIMAGE}"
docker manifest push ${TARGETIMAGE}
fi