Skip to content

Commit

Permalink
Merge pull request #4 from stakater-docker/run-as-jenkins
Browse files Browse the repository at this point in the history
Run as jenkins user and update pipeline library
  • Loading branch information
hazim1093 authored Jan 14, 2019
2 parents 5c51719 + c6c7c11 commit c53947d
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 8 deletions.
27 changes: 21 additions & 6 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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"]
4 changes: 2 additions & 2 deletions Jenkinsfile
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -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.

0 comments on commit c53947d

Please sign in to comment.