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 windows container support, simplify binary generation #6

Merged
merged 24 commits into from
May 14, 2021
Merged
Show file tree
Hide file tree
Changes from 12 commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
b51b6be
Remove docker maven plugin, refactor for windows builds
car-roll Apr 29, 2021
ded8f54
add windows build scripts
car-roll Apr 29, 2021
2c75805
Create windows build scripts, refactor dockerfile
car-roll Apr 30, 2021
d26e5d7
updating permission of go.mod and go.sum files
car-roll Apr 30, 2021
7772e49
Revert "updating permission of go.mod and go.sum files"
car-roll Apr 30, 2021
bc7e7ca
set GODEBUG=modcacheunzipinplace=1 to resolve go.mod/sum access denie…
car-roll Apr 30, 2021
fa1b3dc
remove GODEBUG flag, directly add gotestsum to go.mod
car-roll Apr 30, 2021
deae006
Revert "remove GODEBUG flag, directly add gotestsum to go.mod"
car-roll Apr 30, 2021
0f1bff1
use golang 1.14.15
car-roll Apr 30, 2021
e6439cb
Remove junit reporting in windows
car-roll Apr 30, 2021
16b2a51
tweak jenkinsfile
car-roll Apr 30, 2021
d50b8ba
add dockerfile for linux
car-roll May 7, 2021
aa135b4
add dockerfile for windows, update to golang 1.16, build on apple sil…
car-roll May 8, 2021
c7fed25
no windows support for buildkit, replace with docker create script
car-roll May 8, 2021
48efa4f
refactor pom to call simplified docker binary generation scripts
car-roll May 9, 2021
f8784c1
additional cleanup
car-roll May 9, 2021
ef79fc3
switch to parent pom for libraries, fix pom profile bug
car-roll May 9, 2021
9194a82
Fix dockerfiles
car-roll May 9, 2021
e0d0556
remove godebug variable, no longer recognized in 1.16
car-roll May 9, 2021
c7651ed
add disable read-only flag for windows container
car-roll May 9, 2021
a071b0a
manually grab each dependency
car-roll May 9, 2021
e992563
document windows CI behavior
car-roll May 9, 2021
c204294
removed incorrect comment
car-roll May 9, 2021
edf248c
set BUILD_KIT flag, change from ADD to COPY
car-roll May 12, 2021
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
6 changes: 3 additions & 3 deletions Jenkinsfile
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#!/usr/bin/env groovy

/* `buildPlugin` step provided by: https://github.com/jenkins-infra/pipeline-library */
// tests skipped because no surefire reports generated on windows. However, unit tests are still being run and will fail build if failed
buildPlugin(failFast: false, skipTests: true, configurations: [
// tests skipped because no junit reports generated.
buildPlugin(failFast: false, tests: [skip: true], configurations: [
[ platform: "docker", jdk: "8", jenkins: null ],
[ platform: "windock", jdk: "8", jenkins: null ]
[ platform: "windock", jdk: "8", jenkins: null ],
])
99 changes: 10 additions & 89 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -27,18 +27,17 @@
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>plugin</artifactId>
<version>4.18</version>
<groupId>org.jenkins-ci</groupId>
<artifactId>jenkins</artifactId>
<version>1.63</version>
<relativePath />
</parent>
<groupId>io.jenkins.plugins</groupId>
<artifactId>lib-durable-task</artifactId>
<packaging>jar</packaging>
<version>${revision}${changelist}</version>
<name>Durable Task Library</name>
<description>Generates and packages the binaries used by Durable Task Plugin</description>
<url>http://maven.apache.org</url>
<url>https://github.com/jenkinsci/lib-durable-task</url>
<licenses>
<license>
<name>MIT License</name>
Expand Down Expand Up @@ -74,12 +73,12 @@

<profiles>
<profile>
<id>linux</id>
<id>bash</id>
<activation>
<activeByDefault>true</activeByDefault>
car-roll marked this conversation as resolved.
Show resolved Hide resolved
</activation>
<properties>
<docker.creation.script>generate-binaries.sh</docker.creation.script>
<binary.generation.script>docker-generate-binaries.sh</binary.generation.script>
</properties>
</profile>
<profile>
Expand All @@ -90,7 +89,7 @@
</os>
</activation>
<properties>
<docker.creation.script>generate-binaries.bat</docker.creation.script>
<binary.generation.script>docker-generate-binaries.bat</binary.generation.script>
</properties>
</profile>
</profiles>
Expand All @@ -102,11 +101,11 @@
<artifactId>exec-maven-plugin</artifactId>
<version>1.6.0</version>
<configuration>
<executable>${project.build.directory}/src/${docker.creation.script}</executable>
<workingDirectory>${project.build.directory}/src</workingDirectory>
<executable>${project.basedir}/src/${binary.generation.script}</executable>
<workingDirectory>${project.basedir}/src</workingDirectory>
<arguments>
<argument>${revision}</argument>
<argument>${project.build.directory}/src</argument>
<argument>${project.build.directory}/classes</argument>
</arguments>
</configuration>
<executions>
Expand All @@ -119,85 +118,7 @@
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<version>3.2.0</version>
<executions>
<execution>
<id>copy-source</id>
<phase>generate-sources</phase>
<goals>
<goal>copy-resources</goal>
</goals>
<configuration>
<outputDirectory>${project.build.directory}</outputDirectory>
<overwrite>true</overwrite>
<resources>
<resource>
<directory>${project.basedir}</directory>
<includes>
<include>src/**</include>
</includes>
</resource>
</resources>
</configuration>
</execution>
<execution>
<id>copy-test-results</id>
<phase>test</phase>
<goals>
<goal>copy-resources</goal>
</goals>
<configuration>
<outputDirectory>${project.build.directory}/surefire-reports/</outputDirectory>
<overwrite>true</overwrite>
<resources>
<resource>
<directory>${project.build.directory}/src/test-results</directory>
<includes>
<include>*</include>
</includes>
</resource>
</resources>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-enforcer-plugin</artifactId>
<version>3.0.0-M3</version>
<executions>
<execution>
<id>enforce-no-test-failures</id>
<phase>verify</phase>
<goals>
<goal>enforce</goal>
</goals>
<configuration>
<rules>
<requireFilesDontExist>
<files>
<file>${project.build.directory}/surefire-reports/failed</file>
</files>
</requireFilesDontExist>
</rules>
<fail>true</fail>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
<resources>
<resource>
<directory>${project.build.directory}/src/bin</directory>
<includes>
<include>durable_task_monitor_*_darwin_*</include>
<include>durable_task_monitor_*_unix_*</include>
</includes>
</resource>
</resources>
</build>

</project>
4 changes: 0 additions & 4 deletions src/Dockerfile

This file was deleted.

30 changes: 30 additions & 0 deletions src/Dockerfile.linux
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
ARG BASE_DIR=/durabletask
Copy link
Member

Choose a reason for hiding this comment

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

To get syntax coloring, suggest moving this to e.g. src/docker/linux/Dockerfile. github-linguist/linguist#4566

Copy link
Contributor Author

Choose a reason for hiding this comment

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

So I gave it a whirl and came across the issue of ADD/COPY requiring the source files to reside in the build context. Don't think this will work for this repo as I am adding the go source files into the image

Copy link
Member

Choose a reason for hiding this comment

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

Yeah, can be worked around by copying the desired Dockerfile along with other inputs into a temp directory and running docker build -t xxx target/xxx, but it is more hassle.

ARG NAME=durable_task_monitor
ARG VERSION=0.0

FROM golang:1.16.4-buster AS builder
ARG BASE_DIR
ARG NAME
ARG VERSION
ADD cmd $BASE_DIR/cmd
ADD pkg $BASE_DIR/pkg
WORKDIR $BASE_DIR/pkg/common
RUN go mod tidy
RUN go test -v
WORKDIR $BASE_DIR/cmd/bash
RUN go mod tidy
RUN go test -v
RUN CGO_ENABLED=0 GOOS=darwin GOARCH=amd64 go build -a -o ${NAME}_${VERSION}_darwin_amd_64
RUN CGO_ENABLED=0 GOOS=darwin GOARCH=arm64 go build -a -o ${NAME}_${VERSION}_darwin_arm_64
RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -a -o ${NAME}_${VERSION}_linux_64
RUN CGO_ENABLED=0 GOOS=linux GOARCH=386 go build -a -o ${NAME}_${VERSION}_linux_32
# TODO WINDOWS
# WORKDIR $BASE_DIR/cmd/windows
# RUN go mod tidy
# RUN go test -v

FROM scratch AS export-stage
ARG BASE_DIR
ARG NAME
ARG VERSION
COPY --from=builder $BASE_DIR/cmd/bash/${NAME}_${VERSION}_* /
39 changes: 39 additions & 0 deletions src/Dockerfile.windows
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
ARG BASE_DIR=/durabletask
ARG NAME=durable_task_monitor
ARG VERSION=0.0

FROM golang:1.16.4-nanoserver AS builder
ARG BASE_DIR
ARG NAME
ARG VERSION
ADD cmd $BASE_DIR/cmd
ADD pkg $BASE_DIR/pkg
WORKDIR $BASE_DIR/pkg/common
RUN go test -v
WORKDIR $BASE_DIR/cmd/bash
# go mod tidy fails in windows CI due to permissions of module cache. Each dependency needs to be fetched with -modcacherw flag
# see golang.org/issue/31481
# RUN go mod tidy
RUN go get -modcacherw jenkinsci.org/plugins/durabletask/common
RUN go get -modcacherw golang.org/x/sys
# can't test bash on windows
RUN set CGO_ENABLED=0& set GOOS=darwin& set GOARCH=amd64& go build -a -o %NAME%_%VERSION%_darwin_amd_64
RUN set CGO_ENABLED=0& set GOOS=darwin& set GOARCH=arm64& go build -a -o %NAME%_%VERSION%_darwin_arm_64
RUN set CGO_ENABLED=0& set GOOS=linux& set GOARCH=amd64& go build -a -o %NAME%_%VERSION%_linux_64
RUN set CGO_ENABLED=0& set GOOS=linux& set GOARCH=386& go build -a -o %NAME%_%VERSION%_linux_32
# TODO: WINDOWS
# WORKDIR $BASE_DIR/cmd/windows
# RUN go mod tidy
# RUN go test -v

# TODO: uncomment once docker build --output (i.e. BuildKit) is available for windows containers
# see: https://github.com/microsoft/Windows-Containers/issues/34
# FROM mcr.microsoft.com/windows/nanoserver:20H2 as export-stage
# ARG BASE_DIR
# ARG NAME
# ARG VERSION
# WORKDIR $BASE_DIR
# COPY --from=builder $BASE_DIR/cmd/bash/${NAME}_${VERSION}_darwin_amd_64 $BASE_DIR
# COPY --from=builder $BASE_DIR/cmd/bash/${NAME}_${VERSION}_darwin_arm_64 $BASE_DIR
# COPY --from=builder $BASE_DIR/cmd/bash/${NAME}_${VERSION}_linux_64 $BASE_DIR
# COPY --from=builder $BASE_DIR/cmd/bash/${NAME}_${VERSION}_linux_32 $BASE_DIR
5 changes: 2 additions & 3 deletions src/cmd/bash/go.mod
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
module jenkinsci.org/plugins/durabletask/bash

go 1.14
go 1.16

replace jenkinsci.org/plugins/durabletask/common => ../../pkg/common

require (
// pin x/sys to 1.14 by manually running: go get golang.org/x/[email protected]
golang.org/x/sys v0.0.0-20200201011859-915c9c3d4ccf
golang.org/x/sys v0.0.0-20210507161434-a76c4d0a0096
jenkinsci.org/plugins/durabletask/common v0.0.0-00010101000000-000000000000
)
4 changes: 2 additions & 2 deletions src/cmd/bash/go.sum
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
golang.org/x/sys v0.0.0-20200201011859-915c9c3d4ccf h1:+4j7oujXP478CVb/AFvHJmVX5+Pczx2NGts5yirA0oY=
golang.org/x/sys v0.0.0-20200201011859-915c9c3d4ccf/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210507161434-a76c4d0a0096 h1:5PbJGn5Sp3GEUjJ61aYbUP6RIo3Z3r2E4Tv9y2z8UHo=
golang.org/x/sys v0.0.0-20210507161434-a76c4d0a0096/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
26 changes: 26 additions & 0 deletions src/docker-generate-binaries.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
@echo off
setlocal

rem docker build --output requires BuildKit, not available for windows containers
rem see https://github.com/microsoft/Windows-Containers/issues/34
rem instead, create a temporary writeable container layer to copy out the binaries

rem maven plugin version
set VER=%1
rem output directory of binaries
set DEST=%2
set IMG_NAME=durable-task-binary-generator
set BINARY_NAME=durable_task_monitor
set OUTPUT_DIR=/durabletask/cmd/bash
mkdir "%DEST%"
docker build --build-arg VERSION=%VER% -f Dockerfile.windows -t %IMG_NAME%:%VER% .
docker create -ti --name scratch %IMG_NAME%:%VER%
docker cp scratch:%OUTPUT_DIR%/%BINARY_NAME%_%VER%_darwin_amd_64 %DEST%
docker cp scratch:%OUTPUT_DIR%/%BINARY_NAME%_%VER%_darwin_arm_64 %DEST%
docker cp scratch:%OUTPUT_DIR%/%BINARY_NAME%_%VER%_linux_64 %DEST%
docker cp scratch:%OUTPUT_DIR%/%BINARY_NAME%_%VER%_linux_32 %DEST%
docker rm -f scratch
docker rmi %IMG_NAME%:%VER%

endlocal
@echo on
7 changes: 7 additions & 0 deletions src/docker-generate-binaries.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#! /bin/sh
set -ex
# maven plugin version
VER=$1
# output directory of binaries
DEST=$2
docker build --build-arg VERSION=$VER -o $DEST -f Dockerfile.linux .
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
docker build --build-arg VERSION=$VER -o $DEST -f Dockerfile.linux .
export DOCKER_BUILDKIT=1
docker build --build-arg VERSION=$VER -o $DEST -f Dockerfile.linux .

?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ahh, was this why you were producing empty jars? Or is this a separate issue?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Set docker buildkit flag in edf248c

Copy link
Member

Choose a reason for hiding this comment

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

14 changes: 0 additions & 14 deletions src/generate-binaries.bat

This file was deleted.

10 changes: 0 additions & 10 deletions src/generate-binaries.sh

This file was deleted.

2 changes: 1 addition & 1 deletion src/pkg/common/go.mod
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module jenkinsci.org/plugins/durabletask/common

go 1.14
go 1.16
45 changes: 0 additions & 45 deletions src/test-and-compile.bat

This file was deleted.

Loading