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

Create folder hierarchy #105

Merged
merged 15 commits into from
Apr 9, 2020
File renamed without changes.
2 changes: 1 addition & 1 deletion Dockerfile-jdk11 → 11/stretch/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.

FROM openjdk:11-jdk
FROM openjdk:11-jdk-stretch
MAINTAINER Oleg Nenashev <o.v.nenashev@gmail.com>

ARG VERSION=4.3
Expand Down
2 changes: 1 addition & 1 deletion Dockerfile-alpine → 8/alpine/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.

FROM openjdk:8-jdk-alpine
FROM openjdk:8-jdk-alpine3.9
MAINTAINER Oleg Nenashev <o.v.nenashev@gmail.com>

ARG VERSION=4.3
Expand Down
2 changes: 1 addition & 1 deletion Dockerfile → 8/stretch/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.

FROM openjdk:8-jdk
FROM openjdk:8-jdk-stretch
MAINTAINER Oleg Nenashev <o.v.nenashev@gmail.com>

ARG VERSION=4.3
Expand Down
File renamed without changes.
File renamed without changes.
42 changes: 26 additions & 16 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,44 +1,54 @@
ROOT:=$(shell dirname $(realpath $(lastword $(MAKEFILE_LIST))))

IMAGE_NAME:=jenkins4eval/slave
IMAGE_NAME_AGENT:=jenkins4eval/agent
IMAGE_NAME:=jenkins4eval/agent
IMAGE_NAME_AGENT:=jenkins4eval/slave

.PHONY: build
.PHONY: test test-alpine test-debian test-jdk11 test-jdk11-buster

build: build-alpine build-debian build-jdk11 build-jdk11-buster

build-alpine:
docker build -t ${IMAGE_NAME}:alpine -t ${IMAGE_NAME_AGENT}:alpine --file Dockerfile-alpine .
docker build -t ${IMAGE_NAME}:alpine \
-t ${IMAGE_NAME}:jdk8-alpine \
-t ${IMAGE_NAME}:jdk8-alpine3.9 \
-t ${IMAGE_NAME_AGENT}:alpine \
8/alpine/

build-debian:
docker build -t ${IMAGE_NAME}:test -t ${IMAGE_NAME_AGENT}:test --file Dockerfile .
docker build -t ${IMAGE_NAME}:latest \
-t ${IMAGE_NAME}:jdk8 \
-t ${IMAGE_NAME}:stretch \
-t ${IMAGE_NAME}:jdk8-stretch \
-t ${IMAGE_NAME_AGENT}:latest \
8/stretch/

build-jdk11:
docker build -t ${IMAGE_NAME}:jdk11 -t ${IMAGE_NAME_AGENT}:jdk11 --file Dockerfile-jdk11 .
docker build -t ${IMAGE_NAME}:jdk11 \
-t ${IMAGE_NAME}:jdk11-stretch \
-t ${IMAGE_NAME_AGENT}:jdk11 \
11/stretch/

build-jdk11-buster:
docker build -t ${IMAGE_NAME}:jdk11-buster -t ${IMAGE_NAME_AGENT}:jdk11-buster --file Dockerfile-jdk11-buster .

docker build -t ${IMAGE_NAME}:jdk11-buster \
-t ${IMAGE_NAME_AGENT}:jdk11-buster \
11/buster/

bats:
# The lastest version is v1.1.0
@if [ ! -d bats-core ]; then git clone https://github.com/bats-core/bats-core.git; fi
@git -C bats-core reset --hard c706d1470dd1376687776bbe985ac22d09780327

.PHONY: test
test: test-alpine test-debian test-jdk11 test-jdk11-buster

.PHONY: test-alpine
test-alpine: bats
@FLAVOR=alpine bats-core/bin/bats tests/tests.bats
@FOLDER="8/alpine" bats-core/bin/bats tests/tests.bats

.PHONY: test-debian
test-debian: bats
@bats-core/bin/bats tests/tests.bats
@FOLDER="8/stretch" bats-core/bin/bats tests/tests.bats

.PHONY: test-jdk11
test-jdk11: bats
@FLAVOR=jdk11 bats-core/bin/bats tests/tests.bats
@FOLDER="11/stretch" bats-core/bin/bats tests/tests.bats

.PHONY: test-jdk11-buster
test-jdk11-buster: bats
@FLAVOR=jdk11-buster bats-core/bin/bats tests/tests.bats
@FOLDER="11/buster" bats-core/bin/bats tests/tests.bats
29 changes: 20 additions & 9 deletions make.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -21,39 +21,51 @@ if(![String]::IsNullOrWhiteSpace($env:DOCKERHUB_ORGANISATION)) {
}

$builds = @{
'jdk8' = @{'Dockerfile' = 'Dockerfile-windows' ; 'Tags' = @( "latest", "windowsservercore-$WindowsTag", "jdk8", "windowsservercore-$WindowsTag-jdk8" ) };
'jdk11' = @{'DockerFile' = 'Dockerfile-windows-jdk11'; 'Tags' = @( "windowsservercore-$WindowsTag-jdk11", "jdk11" ) };
'nanoserver' = @{'DockerFile' = 'Dockerfile-windows-nanoserver'; 'Tags' = @( "nanoserver-$WindowsTag", "nanoserver-$WindowsTag-jdk8" ) };
'nanoserver-jdk11' = @{'DockerFile' = 'Dockerfile-windows-nanoserver-jdk11'; 'Tags' = @( "nanoserver-$WindowsTag-jdk11" ) };
'jdk8' = @{
'Folder' = '8\windows\windowsservercore-1809';
krufab marked this conversation as resolved.
Show resolved Hide resolved
'Tags' = @( "latest", "windowsservercore-$WindowsTag", "jdk8", "windowsservercore-$WindowsTag-jdk8" )
};
'jdk11' = @{
'Folder' = '11\windows\windowsservercore-1809';
'Tags' = @( "windowsservercore-$WindowsTag-jdk11", "jdk11" )
};
'nanoserver' = @{
'Folder' = '8\windows\nanoserver-1809';
'Tags' = @( "nanoserver-$WindowsTag", "nanoserver-$WindowsTag-jdk8" )
};
'nanoserver-jdk11' = @{
'Folder' = '11\windows\nanoserver-1809';
'Tags' = @( "nanoserver-$WindowsTag-jdk11" )
};
}

if(![System.String]::IsNullOrWhiteSpace($Build) -and $builds.ContainsKey($Build)) {
foreach($tag in $builds[$Build]['Tags']) {
Write-Host "Building $Build => tag=$tag"
$cmd = "docker build -f {0} --build-arg WINDOWS_DOCKER_TAG=$WindowsTag --build-arg VERSION='$RemotingVersion' -t {1}/{2}:{3} {4} ." -f $builds[$Build]['Dockerfile'], $Organization, $Repository, $tag, $AdditionalArgs
$cmd = "docker build --build-arg WINDOWS_DOCKER_TAG=$WindowsTag --build-arg VERSION='$RemotingVersion' -t {0}/{1}:{2} {3} {4}" -f $Organization, $Repository, $tag, $AdditionalArgs, $builds[$Build]['Folder']
Invoke-Expression $cmd

$buildTag = "$RemotingVersion-$BuildNumber-$tag"
if($tag -eq 'latest') {
$buildTag = "$RemotingVersion-$BuildNumber"
}
Write-Host "Building $Build => tag=$buildTag"
$cmd = "docker build -f {0} --build-arg WINDOWS_DOCKER_TAG=$WindowsTag --build-arg VERSION='$RemotingVersion' -t {1}/{2}:{3} {4} ." -f $builds[$Build]['Dockerfile'], $Organization, $Repository, $buildTag, $AdditionalArgs
$cmd = "docker build --build-arg WINDOWS_DOCKER_TAG=$WindowsTag --build-arg VERSION='$RemotingVersion' -t {0}/{1}:{2} {3} {4}" -f $Organization, $Repository, $buildTag, $AdditionalArgs, $builds[$Build]['Folder']
Invoke-Expression $cmd
}
} else {
foreach($b in $builds.Keys) {
foreach($tag in $builds[$b]['Tags']) {
Write-Host "Building $b => tag=$tag"
$cmd = "docker build -f {0} --build-arg WINDOWS_DOCKER_TAG=$WindowsTag --build-arg VERSION='$RemotingVersion' -t {1}/{2}:{3} {4} ." -f $builds[$b]['Dockerfile'], $Organization, $Repository, $tag, $AdditionalArgs
$cmd = "docker build --build-arg WINDOWS_DOCKER_TAG=$WindowsTag --build-arg VERSION='$RemotingVersion' -t {0}/{1}:{2} {3} {4}" -f $Organization, $Repository, $tag, $AdditionalArgs, $builds[$b]['Folder']
Invoke-Expression $cmd

$buildTag = "$RemotingVersion-$BuildNumber-$tag"
if($tag -eq 'latest') {
$buildTag = "$RemotingVersion-$BuildNumber"
}
Write-Host "Building $Build => tag=$buildTag"
$cmd = "docker build -f {0} --build-arg WINDOWS_DOCKER_TAG=$WindowsTag --build-arg VERSION='$RemotingVersion' -t {1}/{2}:{3} {4} ." -f $builds[$b]['Dockerfile'], $Organization, $Repository, $buildTag, $AdditionalArgs
$cmd = "docker build --build-arg WINDOWS_DOCKER_TAG=$WindowsTag --build-arg VERSION='$RemotingVersion' -t {0}/{1}:{2} {3} {4}" -f $Organization, $Repository, $buildTag, $AdditionalArgs, $builds[$b]['Folder']
Invoke-Expression $cmd
}
}
Expand Down Expand Up @@ -121,7 +133,6 @@ if($target -eq "publish") {
}
}


if($lastExitCode -ne 0) {
Write-Error "Build failed!"
} else {
Expand Down
46 changes: 17 additions & 29 deletions tests/agent.Tests.ps1
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Import-Module -DisableNameChecking -Force $PSScriptRoot/test_helpers.psm1

$DOCKERFILE='Dockerfile-windows'
$FOLDER='8\windows\servercore-1809'
$JDK=8
$AGENT_IMAGE='jenkins-agent'
$AGENT_CONTAINER='pester-jenkins-agent'
Expand All @@ -10,18 +10,18 @@ $FLAVOR = Get-EnvOrDefault 'FLAVOR' ''

if([System.String]::IsNullOrWhiteSpace($FLAVOR)) {
$FLAVOR = 'jdk8'
} elseif($flavor -eq "jdk11") {
$DOCKERFILE += "-jdk11"
} elseif($FLAVOR -eq "jdk11") {
$FOLDER = '11\windows\servercore-1809'
$JDK=11
$AGENT_IMAGE += ":jdk11"
$AGENT_CONTAINER += "-jdk11"
} elseif($flavor -eq "nanoserver") {
$DOCKERFILE += "-nanoserver"
} elseif($FLAVOR -eq "nanoserver") {
$FOLDER = '8\windows\nanoserver-1809'
$AGENT_IMAGE += ":nanoserver-1809"
$AGENT_CONTAINER += "-nanoserver"
$SHELL="pwsh.exe"
} elseif($flavor -eq "nanoserver-jdk11") {
$DOCKERFILE += "-nanoserver-jdk11"
} elseif($FLAVOR -eq "nanoserver-jdk11") {
$FOLDER = '11\windows\nanoserver-1809'
$JDK=11
$AGENT_IMAGE += ":nanoserver-1809-jdk11"
$AGENT_CONTAINER += "-nanoserver-jdk11"
Expand All @@ -30,13 +30,13 @@ if([System.String]::IsNullOrWhiteSpace($FLAVOR)) {

Cleanup($AGENT_CONTAINER)

Describe "[$FLAVOR] build image" {
Describe "[$JDK $FLAVOR] build image" {
BeforeEach {
Push-Location -StackName 'agent' -Path "$PSScriptRoot/.."
}

It 'builds image' {
$exitCode, $stdout, $stderr = Run-Program 'docker.exe' "build -t $AGENT_IMAGE -f ./$DOCKERFILE ."
$exitCode, $stdout, $stderr = Run-Program 'docker.exe' "build -t $AGENT_IMAGE $FOLDER"
$exitCode | Should -Be 0
}

Expand All @@ -45,21 +45,17 @@ Describe "[$FLAVOR] build image" {
}
}

Describe "[$FLAVOR] correct image metadata" {
Describe "[$JDK $FLAVOR] correct image metadata" {
It 'has correct volumes' {
$exitCode, $stdout, $stderr = Run-Program 'docker.exe' "inspect -f '{{.Config.Volumes}}' $AGENT_IMAGE"
$stdout | Should -Match 'C:/Users/jenkins/.jenkins'
$stdout | Should -Match 'C:/Users/jenkins/Work'
}
}

Describe "[$FLAVOR] image has correct applications in the PATH" {
Describe "[$JDK $FLAVOR] image has correct applications in the PATH" {
BeforeAll {
if($DOCKERFILE.Contains('nanoserver')) {
docker run -d -it --name "$AGENT_CONTAINER" -P "$AGENT_IMAGE" pwsh
} else {
docker run -d -it --name "$AGENT_CONTAINER" -P "$AGENT_IMAGE" powershell
}
docker run -d -it --name "$AGENT_CONTAINER" -P "$AGENT_IMAGE" "$SHELL"
Is-AgentContainerRunning $AGENT_CONTAINER
}

Expand Down Expand Up @@ -92,13 +88,9 @@ Describe "[$FLAVOR] image has correct applications in the PATH" {
}
}

Describe "[$FLAVOR] check user access to directories" {
Describe "[$JDK $FLAVOR] check user access to directories" {
BeforeAll {
if($DOCKERFILE.Contains('nanoserver')) {
docker run -d -it --name "$AGENT_CONTAINER" -P "$AGENT_IMAGE" pwsh
} else {
docker run -d -it --name "$AGENT_CONTAINER" -P "$AGENT_IMAGE" powershell
}
docker run -d -it --name "$AGENT_CONTAINER" -P "$AGENT_IMAGE" "$SHELL"
Is-AgentContainerRunning $AGENT_CONTAINER
}

Expand Down Expand Up @@ -126,18 +118,14 @@ $TEST_VERSION="3.36"
$TEST_USER="test-user"
$TEST_AGENT_WORKDIR="C:/test-user/something"

Describe "[$FLAVOR] use build args correctly" {
Describe "[$JDK $FLAVOR] use build args correctly" {
BeforeAll {
Push-Location -StackName 'agent' -Path "$PSScriptRoot/.."

$exitCode, $stdout, $stderr = Run-Program 'docker.exe' "build --build-arg `"VERSION=${TEST_VERSION}`" --build-arg `"user=${TEST_USER}`" --build-arg `"AGENT_WORKDIR=${TEST_AGENT_WORKDIR}`" -t ${AGENT_IMAGE} -f ./${DOCKERFILE} ."
$exitCode, $stdout, $stderr = Run-Program 'docker.exe' "build --build-arg `"VERSION=${TEST_VERSION}`" --build-arg `"user=${TEST_USER}`" --build-arg `"AGENT_WORKDIR=${TEST_AGENT_WORKDIR}`" -t ${AGENT_IMAGE} ${FOLDER}"
$exitCode | Should -Be 0

if($DOCKERFILE.Contains('nanoserver')) {
krufab marked this conversation as resolved.
Show resolved Hide resolved
docker run -d -it --name "$AGENT_CONTAINER" -P "$AGENT_IMAGE" pwsh
} else {
docker run -d -it --name "$AGENT_CONTAINER" -P "$AGENT_IMAGE" powershell
}
docker run -d -it --name "$AGENT_CONTAINER" -P "$AGENT_IMAGE" "$SHELL"
Is-AgentContainerRunning $AGENT_CONTAINER
}

Expand Down
38 changes: 23 additions & 15 deletions tests/tests.bats
Original file line number Diff line number Diff line change
@@ -1,17 +1,21 @@
#!/usr/bin/env bats

DOCKERFILE=Dockerfile
JDK=8
AGENT_IMAGE=jenkins-agent
AGENT_CONTAINER=bats-jenkins-agent

if [[ -z "${FLAVOR}" ]]
REGEX='^([0-9]+)/(.+)$'

if [[ ${FOLDER} =~ ${REGEX} ]] && [[ -d "${FOLDER}" ]]
then
FLAVOR="debian"
elif [[ "${FLAVOR}" = "jdk11" ]]
JDK="${BASH_REMATCH[1]}"
FLAVOR="${BASH_REMATCH[2]}"
else
echo "Wrong folder format or folder does not exist: ${FOLDER}"
exit 1
fi

if [[ "${JDK}" = "11" ]]
then
DOCKERFILE+="-jdk11"
JDK=11
AGENT_IMAGE+=":jdk11"
AGENT_CONTAINER+="-jdk11"
elif [[ "${FLAVOR}" = "jdk11-buster" ]]
Expand All @@ -21,9 +25,13 @@ then
AGENT_IMAGE+=":jdk11-buster"
AGENT_CONTAINER+="-jdk11-buster"
else
DOCKERFILE+="-alpine"
AGENT_IMAGE+=":alpine"
AGENT_CONTAINER+="-alpine"
if [[ "${FLAVOR}" = "alpine*" ]]
then
AGENT_IMAGE+=":alpine"
AGENT_CONTAINER+="-alpine"
else
AGENT_IMAGE+=":latest"
fi
fi

load test_helpers
Expand All @@ -34,20 +42,20 @@ function teardown () {
clean_test_container
}

@test "[${FLAVOR}] build image" {
@test "[${JDK} ${FLAVOR}] build image" {
cd "${BATS_TEST_DIRNAME}"/.. || false
docker build -t "${AGENT_IMAGE}" -f "${DOCKERFILE}" .
docker build -t "${AGENT_IMAGE}" "${FOLDER}"
}

@test "[${FLAVOR}] checking image metadata" {
@test "[${JDK} ${FLAVOR}] checking image metadata" {
local VOLUMES_MAP
VOLUMES_MAP="$(docker inspect -f '{{.Config.Volumes}}' ${AGENT_IMAGE})"

echo "${VOLUMES_MAP}" | grep '/home/jenkins/.jenkins'
echo "${VOLUMES_MAP}" | grep '/home/jenkins/agent'
}

@test "[${FLAVOR}] image has bash and java installed and in the PATH" {
@test "[${JDK} ${FLAVOR}] image has bash and java installed and in the PATH" {
docker run -d -it --name "${AGENT_CONTAINER}" -P "${AGENT_IMAGE}" /bin/sh

is_agent_container_running
Expand Down Expand Up @@ -114,7 +122,7 @@ function teardown () {
--build-arg "gid=${TEST_GID}" \
--build-arg "AGENT_WORKDIR=${TEST_AGENT_WORKDIR}" \
-t "${AGENT_IMAGE}" \
-f "${DOCKERFILE}" .
"${FOLDER}"

docker run -d -it --name "${AGENT_CONTAINER}" -P "${AGENT_IMAGE}" /bin/sh

Expand Down