Skip to content

Instantly share code, notes, and snippets.

@orpiske
Created Dec 10, 2020
Embed
What would you like to do?
Camel Apache CI simulated environment
###
# How to build the container:
#
# To create a container that uses OpenJDK:
# docker build --build-arg CI_USER=$(whoami) --target ci-openjdk --tag ci-openjdk .
#
# To create a container that uses Oracle JDK (as in CI):
# 1. First download the Oracle JDK from the Oracle web site (ie.: jdk-11.0.9_linux-x64_bin.tar.gz)
#
# 2. Then build the container with:
# docker build --build-arg CI_USER=$(whoami) --target ci-oracle-jdk --tag ci-oracle-jdk .
#
# Note: there are other parameters that can be configured, like JDK version, but they are untested.
###
# How to run the container:
#
# You have to mount the local source code dir on the container and also mount the maven
# repository and settings. To do so, run:
#
# docker run -it -v $HOME/code/java/camel:/home/$(whoami)/code -v $HOME/.m2/repository:/home/$(whoami)/.m2/repository -v $HOME/.m2/settings.xml:/home/$(whoami)/.m2/settings.xml:ro -u $(whoami):$(whoami) --privileged ci-openjdk:latest
#
###
FROM ubuntu:latest as ci-base
ARG MAVEN_MIRROR
ENV MAVEN_MIRROR ${MAVEN_MIRROR:-https://mirror.dkm.cz}
ARG MAVEN_VERSION
ENV MAVEN_VERSION ${MAVEN_VERSION:-3.6.3}
ARG CI_USER
ENV CI_USER ${CI_USER:-opiske}
ARG CI_USER_ID
ENV CI_USER_ID ${CI_USER_ID:-1001}
RUN apt-get update && \
apt-get install -y wget git && \
mkdir -p /opt/java && \
cd /opt/java && \
wget ${MAVEN_MIRROR}/apache/maven/maven-3/${MAVEN_VERSION}/binaries/apache-maven-${MAVEN_VERSION}-bin.tar.gz && \
tar -xvf apache-maven-${MAVEN_VERSION}-bin.tar.gz && \
ln -s apache-maven-${MAVEN_VERSION} maven && \
rm apache-maven-${MAVEN_VERSION}-bin.tar.gz && \
groupadd -g ${CI_USER_ID} ${CI_USER} && \
useradd -m -u ${CI_USER_ID} -g ${CI_USER_ID} ${CI_USER} && \
apt-get clean
ENV M2_HOME /opt/java/maven
FROM ci-base as ci-openjdk
RUN apt-get update && \
apt-get install -y openjdk-11-jdk-headless && \
apt-get clean
ARG CI_USER
ENV CI_USER ${CI_USER:-opiske}
USER ${CI_USER}
VOLUME /home/${CI_USER}/code/
WORKDIR /home/${CI_USER}/code/
ENV PATH /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:${M2_HOME}/bin
FROM ci-base as ci-oracle-jdk
ARG CI_USER
ENV CI_USER ${CI_USER:-opiske}
ARG JDK_VERSION
ENV JDK_VERSION ${JDK_VERSION:-11.0.9}
ARG JDK_ARCH
ENV JDK_ARCH ${JDK_ARCH:-x64}
COPY jdk-${JDK_VERSION}_linux-${JDK_ARCH}_bin.tar.gz /opt/java/jdk-${JDK_VERSION}_linux-${JDK_ARCH}_bin.tar.gz
RUN tar -xvf /opt/java/jdk-${JDK_VERSION}_linux-${JDK_ARCH}_bin.tar.gz -C /opt/java
ENV JAVA_HOME /opt/java/jdk-${JDK_VERSION}
ENV PATH /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:${JAVA_HOME}/bin:${M2_HOME}/bin
USER ${CI_USER}
VOLUME /home/${CI_USER}/code/
WORKDIR /home/${CI_USER}/code/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment