diff --git a/Dockerfile b/Dockerfile index 7b4a825..874ca0e 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,5 +1,4 @@ -# keeping latest as we would have to individually change version if anything changes there -FROM stakater/pipeline-tools:latest +FROM stakater/pipeline-tools:v1.16.8 # Default to UTF-8 file.encoding ENV LANG C.UTF-8 @@ -16,21 +15,37 @@ RUN { \ ENV JAVA_HOME /usr/lib/jvm/java-1.8-openjdk ENV PATH $PATH:/usr/lib/jvm/java-1.8-openjdk/jre/bin:/usr/lib/jvm/java-1.8-openjdk/bin -ENV JAVA_VERSION 8u171 -ENV JAVA_ALPINE_VERSION 8.171.11-r0 +ENV JAVA_VERSION 8u191 +ENV JAVA_ALPINE_VERSION 8.191.12-r0 RUN set -x \ && apk add --no-cache \ openjdk8="$JAVA_ALPINE_VERSION" \ && [ "$JAVA_HOME" = "$(docker-java-home)" ] +# Changing user to root to install maven +USER root + # Setting Maven Version that needs to be installed ARG MAVEN_VERSION=3.5.4 -# Changing user to root to install maven -USER root +# Maven RUN curl -fsSL https://archive.apache.org/dist/maven/maven-3/$MAVEN_VERSION/binaries/apache-maven-$MAVEN_VERSION-bin.tar.gz | tar xzf - -C /usr/share \ && mv /usr/share/apache-maven-$MAVEN_VERSION /usr/share/maven \ && ln -s /usr/share/maven/bin/mvn /usr/bin/mvn +ENV MAVEN_VERSION=${MAVEN_VERSION} \ + M2_HOME=/usr/share/maven \ + maven.home=$M2_HOME \ + M2=$M2_HOME/bin \ + PATH=$M2:$PATH + +# Add jenkins user with hardcoded ID (the one that jenkins expects) +RUN addgroup -g 233 docker && \ + adduser -D -u 10000 -h /home/jenkins -G docker jenkins + +# Change to jenkins user +USER jenkins +# Define default command, can be overriden by passing an argument when running the container +CMD ["mvn","-version"] \ No newline at end of file diff --git a/Jenkinsfile b/Jenkinsfile index 42679d4..dc46239 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -2,6 +2,6 @@ @Library('github.com/stakater/fabric8-pipeline-library@master') _ pushDockerImage { - dockerRegistryURL = "docker.io" - imagePrefix = "3.5.4-jdk1.8-apline8" + dockerRepositoryURL = "docker.io" + imagePrefix = "3.5.4-jdk1.8-v1.16.8" } \ No newline at end of file diff --git a/README.md b/README.md index 50a31de..eca9fae 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,4 @@ # builder-maven A maven builder image used to build maven apps + +This image runs as user `jenkins` with id `10000`, so that it can run maven as a non-root user which can access Jenkins directories and files as well, in order to seamlessly run as a Jenkins slave. \ No newline at end of file