From 94fc7d715486705aaeeee2701b99e494f45a1710 Mon Sep 17 00:00:00 2001 From: "mathieu.grzybek" Date: Wed, 18 Sep 2019 14:49:26 +0200 Subject: [PATCH 01/10] [Templating] Use Makefile to manage the stack --- Makefile | 79 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 79 insertions(+) create mode 100644 Makefile diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..3ebdd6e --- /dev/null +++ b/Makefile @@ -0,0 +1,79 @@ +############################################################################## +# Environment variables +# Set locales +# +CITY=$(shell timedatectl | awk '/Time zone/ {print $$3}' | awk -F/ '{print $$2}') +COUNTRY=$(shell echo $$LANG | awk -F. '{print $$1}' | awk -F_ '{print $$2}') +LANGUAGE=$(shell echo $$LANG | awk -F. '{print $$1}' | awk -F_ '{print $$2}') +TIMEZONE=$(shell timedatectl | awk '/Time zone/ {print $$3}') + +############################################################################## +.PHONY: help # This help message +help: + @grep '^.PHONY: .* #' Makefile \ + | sed 's/\.PHONY: \(.*\) # \(.*\)/\1\t\2/' \ + | expand -t20 \ + | sort + +############################################################################## + +.PHONY: prepare # Generate Dockerfiles from templates +prepare: + # Sonar: Set locales and proxy + @sed "s!%%COUNTRY%%!${COUNTRY}! ; \ + s!%%LANGUAGE%%!${LANGUAGE}! ; \ + s!%%TIMEZONE%%!${TIMEZONE}! ; \ + s!%%HTTP_PROXY%%!${HTTP_PROXY}!" \ + sonar/Dockerfile.tmpl > sonar/Dockerfile + + # Jenkins: Set locales and proxy + @sed "s!%%HTTP_PROXY%%!${HTTP_PROXY}!" \ + jenkins/Dockerfile.tmpl > jenkins/Dockerfile + + @test -z ${HTTP_PROXY} \ + && sed '/HTTP_PROXY/d' \ + jenkins/Dockerfile.tmpl > jenkins/Dockerfile \ + || true + + # Nexus: Set proxy + @sed "s!%%HTTP_PROXY%%!${HTTP_PROXY}!" \ + nexus/Dockerfile.tmpl > nexus/Dockerfile + + @test -z ${HTTP_PROXY} \ + && sed '/^HTTP_OPTIONS/d' \ + nexus/Dockerfile.tmpl > nexus/Dockerfile \ + || true + +.PHONY: clean # Stop and remove temporary files +clean: down + @rm -f \ + jenkins/Dockerfile \ + nexus/Dockerfile \ + sonar/Dockerfile + + @docker-compose rm + +############################################################################## + +.PHONY: up # Start "docker-compose up" +up: prepare + @docker-compose up + +.PHONY: daemon # Start "docker-compose up -d" +daemon: prepare + @docker-compose up -d + +.PHONY: down # Stop the stack "docker-compose down" +down: + @docker-compose down + +.PHONY: rebuild # Rebuild the containers and run +rebuild: prepare + @docker-compose down --rmi all + @docker-compose up --build + +.PHONY: daemon-rebuild # Rebuild the containers and run +daemon-rebuild: prepare + @docker-compose down --rmi all + @docker-compose up --build -d + From eafcdcaba435dd3c236a73ab75d7a349da4d3777 Mon Sep 17 00:00:00 2001 From: "mathieu.grzybek" Date: Wed, 18 Sep 2019 14:51:06 +0200 Subject: [PATCH 02/10] [jenkins] Use proxy-aware Alpine --- jenkins/Dockerfile.tmpl | 51 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 jenkins/Dockerfile.tmpl diff --git a/jenkins/Dockerfile.tmpl b/jenkins/Dockerfile.tmpl new file mode 100644 index 0000000..00a479b --- /dev/null +++ b/jenkins/Dockerfile.tmpl @@ -0,0 +1,51 @@ +FROM jenkins/jenkins:lts-alpine + +# Authors +LABEL maintainer="Marcel Birkner " +LABEL maintainer="Mathieu Grzybek + +USER root + +ENV HTTP_PROXY="%%HTTP_PROXY%%" +ENV HTTP_OPTIONS="-x ${HTTP_PROXY}" +ENV CURL_OPTIONS="${HTTP_OPTIONS} -sSL" + +RUN apk add --no-cache sudo curl +RUN echo "jenkins ALL=NOPASSWD: ALL" >> /etc/sudoers + +# getting the docker-cli +# --- Attention: docker.sock needs to be mounted as volume in docker-compose.yml +# see: https://issues.jenkins-ci.org/browse/JENKINS-35025 +# see: https://get.docker.com/builds/ +# see: https://wiki.jenkins-ci.org/display/JENKINS/CloudBees+Docker+Custom+Build+Environment+Plugin#CloudBeesDockerCustomBuildEnvironmentPlugin-DockerinDocker +RUN curl $CURL_OPTIONS -o /bin/docker https://get.docker.io/builds/Linux/x86_64/docker-latest +RUN chmod +x /bin/docker + +USER jenkins + +# installing specific list of plugins. see: https://github.com/jenkinsci/docker#preinstalling-plugins +COPY plugins.txt /usr/share/jenkins/plugins.txt +RUN /usr/local/bin/install-plugins.sh < /usr/share/jenkins/plugins.txt + +# Adding default Jenkins Seed Job +COPY jobs/job-dsl-seed-job.xml /usr/share/jenkins/ref/jobs/job-dsl-seed-job/config.xml + +############################################ +# Configure Jenkins +############################################ +# Jenkins settings +COPY config/config.xml /usr/share/jenkins/ref/config.xml + +# Jenkins Settings, i.e. Maven, Groovy, ... +COPY config/hudson.tasks.Maven.xml /usr/share/jenkins/ref/hudson.tasks.Maven.xml +COPY config/hudson.plugins.groovy.Groovy.xml /usr/share/jenkins/ref/hudson.plugins.groovy.Groovy.xml +COPY config/maven-global-settings-files.xml /usr/share/jenkins/ref/org.jenkinsci.plugins.configfiles.GlobalConfigFiles.xml + +# SSH Keys & Credentials +COPY config/credentials.xml /usr/share/jenkins/ref/credentials.xml +COPY config/ssh-keys/cd-demo /usr/share/jenkins/ref/.ssh/id_rsa +COPY config/ssh-keys/cd-demo.pub /usr/share/jenkins/ref/.ssh/id_rsa.pub + +# tell Jenkins that no banner prompt for pipeline plugins is needed +# see: https://github.com/jenkinsci/docker#preinstalling-plugins +RUN echo 2.0 > /usr/share/jenkins/ref/jenkins.install.UpgradeWizard.state From ca2ee402dee7a33e52e5bfcdbba0379f134d9cce Mon Sep 17 00:00:00 2001 From: "mathieu.grzybek" Date: Wed, 18 Sep 2019 14:52:45 +0200 Subject: [PATCH 03/10] [nexus] Use proxy-aware Alpine --- nexus/Dockerfile.tmpl | 57 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100644 nexus/Dockerfile.tmpl diff --git a/nexus/Dockerfile.tmpl b/nexus/Dockerfile.tmpl new file mode 100644 index 0000000..4a0f1c4 --- /dev/null +++ b/nexus/Dockerfile.tmpl @@ -0,0 +1,57 @@ +# +# Creates a docker container with Nexus Artifact Repository +# + +FROM openjdk:8-alpine + +LABEL maintainer="Marcel Birkner " +LABEL maintainer="Mathieu Grzybek + +ENV SONATYPE_WORK /sonatype-work +ENV NEXUS_VERSION 2.14.1-01 +ENV NEXUS_HOME /opt/sonatype/nexus/ +ENV HTTP_PROXY=%%HTTP_PROXY%% + +# Install packages necessary +RUN apk add --no-cache unzip shadow + +ADD https://download.sonatype.com/nexus/oss/nexus-${NEXUS_VERSION}-bundle.zip nexus-${NEXUS_VERSION}-bundle.zip + +# Extract Nexus +RUN set -x \ + && unzip nexus-${NEXUS_VERSION}-bundle.zip \ + && mkdir -p ${NEXUS_HOME} \ + && cp -r nexus-${NEXUS_VERSION}/* ${NEXUS_HOME} \ + && rm -rf nexus-${NEXUS_VERSION}-bundle.tar.gz \ + && rm -rf nexus-${NEXUS_VERSION} + + +RUN groupadd -r nexus -g 3001 \ + && useradd \ + -u 3001 \ + -g nexus \ + -d ${SONATYPE_WORK} \ + -s /bin/bash \ + -c "Nexus Run User" \ + -r \ + -m \ + nexus + +VOLUME ${SONATYPE_WORK} + +EXPOSE 8081 + +WORKDIR /opt/sonatype/nexus + +ENV CONTEXT_PATH / +ENV MAX_HEAP 768m +ENV MIN_HEAP 256m +ENV JAVA_OPTS -server -XX:MaxPermSize=192m -Djava.net.preferIPv4Stack=true +ENV LAUNCHER_CONF ./conf/jetty.xml ./conf/jetty-requestlog.xml + +CMD java \ + -Dnexus-work=${SONATYPE_WORK} -Dnexus-webapp-context-path=${CONTEXT_PATH} \ + -Xms${MIN_HEAP} -Xmx${MAX_HEAP} \ + -cp 'conf/:lib/*' \ + ${JAVA_OPTS} \ + org.sonatype.nexus.bootstrap.Launcher ${LAUNCHER_CONF} From 35ee678d3464819ebdcbeec7c0541863ec61853f Mon Sep 17 00:00:00 2001 From: "mathieu.grzybek" Date: Wed, 18 Sep 2019 14:53:22 +0200 Subject: [PATCH 04/10] [sonar] Use proxy-aware Centos --- sonar/Dockerfile.tmpl | 64 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 64 insertions(+) create mode 100644 sonar/Dockerfile.tmpl diff --git a/sonar/Dockerfile.tmpl b/sonar/Dockerfile.tmpl new file mode 100644 index 0000000..bec7f79 --- /dev/null +++ b/sonar/Dockerfile.tmpl @@ -0,0 +1,64 @@ +# +# Creates a docker container with SonarQube, incl. several plugins +# + +FROM centos:7 + +LABEL maintainer="Marcel Birkner " +LABEL maintainer="Mathieu Grzybek + +ENV JAVA_OPTS "$JAVA_OPTS -Duser.country=%%COUNTRY%% -Duser.language=%%LANGUAGE%% -Duser.timezone=%%TIMEZONE%%" + +# Proxy variable if needed +ENV HTTP_PROXY=%%HTTP_PROXY%% + +# Set the JAVA_HOME variable to make it clear where Java is located +ENV JAVA_HOME /usr/lib/jvm/java-1.8.0 + +ENV SONAR_VERSION 5.6.3 +ENV SONARQUBE_HOME /opt/sonarqube + +# Plugin Versions +ENV SONAR_JAVA_PLUGIN 4.2 +ENV SONAR_WEB_PLUGIN 2.4 +ENV SONAR_SCM_GIT_PLUGIN 1.0 + +RUN INSTALL_PKGS="java-1.8.0-openjdk.x86_64" && \ + echo "proxy=$HTTP_PROXY" >> /etc/yum.conf && \ + yum -y --setopt=tsflags=nodocs install $INSTALL_PKGS && \ + rpm -V $INSTALL_PKGS && \ + yum clean all && \ + localedef -f UTF-8 -i en_US en_US.UTF-8 + +# Http port +EXPOSE 9000 + +# H2 Database port +EXPOSE 9092 + +# Install packages necessary +RUN yum -y install unzip && yum clean all + +# Add SonarQube binaries from Nexus Repository +ADD https://sonarsource.bintray.com/Distribution/sonarqube/sonarqube-${SONAR_VERSION}.zip $SONARQUBE_HOME/sonarqube-${SONAR_VERSION}.zip + +# Unpack SonarQube Zip +RUN set -x \ + && unzip $SONARQUBE_HOME/sonarqube-${SONAR_VERSION}.zip \ + && mv sonarqube-${SONAR_VERSION}/* $SONARQUBE_HOME \ + && rm $SONARQUBE_HOME/sonarqube-${SONAR_VERSION}.zip + +# Add plugins +RUN mkdir -p $SONARQUBE_HOME/extensions/plugins/ +ADD http://central.maven.org/maven2/org/sonarsource/java/sonar-java-plugin/${SONAR_JAVA_PLUGIN}/sonar-java-plugin-${SONAR_JAVA_PLUGIN}.jar $SONARQUBE_HOME/extensions/plugins/sonar-java-plugin-${SONAR_JAVA_PLUGIN}.jar +ADD http://central.maven.org/maven2/org/sonarsource/sonar-web-plugin/sonar-web-plugin/${SONAR_WEB_PLUGIN}/sonar-web-plugin-${SONAR_WEB_PLUGIN}.jar $SONARQUBE_HOME/extensions/plugins/sonar-web-plugin-${SONAR_WEB_PLUGIN}.jar +ADD http://central.maven.org/maven2/org/codehaus/sonar-plugins/sonar-scm-git-plugin/${SONAR_SCM_GIT_PLUGIN}/sonar-scm-git-plugin-${SONAR_SCM_GIT_PLUGIN}.jar $SONARQUBE_HOME/extensions/plugins/sonar-scm-git-plugin-${SONAR_SCM_GIT_PLUGIN}.jar +COPY run.sh $SONARQUBE_HOME + +WORKDIR $SONARQUBE_HOME + +VOLUME ["$SONARQUBE_HOME/data","$SONARQUBE_HOME/conf","$SONARQUBE_HOME/logs"] + +RUN chmod -R 777 $SONARQUBE_HOME + +CMD ["/opt/sonarqube/run.sh"] From da1816b14ae67d4766316587a86e8250ff051894 Mon Sep 17 00:00:00 2001 From: "mathieu.grzybek" Date: Wed, 18 Sep 2019 14:53:29 +0200 Subject: [PATCH 05/10] [Templating] Old files cleanup --- jenkins/Dockerfile | 45 ----------------------------------- nexus/Dockerfile | 56 ------------------------------------------- sonar/Dockerfile | 59 ---------------------------------------------- 3 files changed, 160 deletions(-) delete mode 100644 jenkins/Dockerfile delete mode 100644 nexus/Dockerfile delete mode 100644 sonar/Dockerfile diff --git a/jenkins/Dockerfile b/jenkins/Dockerfile deleted file mode 100644 index 7e73e25..0000000 --- a/jenkins/Dockerfile +++ /dev/null @@ -1,45 +0,0 @@ -FROM jenkins/jenkins:lts - -USER root -RUN apt-get update \ - && apt-get install -y sudo curl\ - && apt-get install -y libltdl7\ - && rm -rf /var/lib/apt/lists/* -RUN echo "jenkins ALL=NOPASSWD: ALL" >> /etc/sudoers - -# getting the docker-cli -# --- Attention: docker.sock needs to be mounted as volume in docker-compose.yml -# see: https://issues.jenkins-ci.org/browse/JENKINS-35025 -# see: https://get.docker.com/builds/ -# see: https://wiki.jenkins-ci.org/display/JENKINS/CloudBees+Docker+Custom+Build+Environment+Plugin#CloudBeesDockerCustomBuildEnvironmentPlugin-DockerinDocker -RUN curl -sSL -o /bin/docker https://get.docker.io/builds/Linux/x86_64/docker-latest -RUN chmod +x /bin/docker - -USER jenkins - -# installing specific list of plugins. see: https://github.com/jenkinsci/docker#preinstalling-plugins -COPY plugins.txt /usr/share/jenkins/plugins.txt -RUN /usr/local/bin/install-plugins.sh < /usr/share/jenkins/plugins.txt - -# Adding default Jenkins Seed Job -COPY jobs/job-dsl-seed-job.xml /usr/share/jenkins/ref/jobs/job-dsl-seed-job/config.xml - -############################################ -# Configure Jenkins -############################################ -# Jenkins settings -COPY config/config.xml /usr/share/jenkins/ref/config.xml - -# Jenkins Settings, i.e. Maven, Groovy, ... -COPY config/hudson.tasks.Maven.xml /usr/share/jenkins/ref/hudson.tasks.Maven.xml -COPY config/hudson.plugins.groovy.Groovy.xml /usr/share/jenkins/ref/hudson.plugins.groovy.Groovy.xml -COPY config/maven-global-settings-files.xml /usr/share/jenkins/ref/org.jenkinsci.plugins.configfiles.GlobalConfigFiles.xml - -# SSH Keys & Credentials -COPY config/credentials.xml /usr/share/jenkins/ref/credentials.xml -COPY config/ssh-keys/cd-demo /usr/share/jenkins/ref/.ssh/id_rsa -COPY config/ssh-keys/cd-demo.pub /usr/share/jenkins/ref/.ssh/id_rsa.pub - -# tell Jenkins that no banner prompt for pipeline plugins is needed -# see: https://github.com/jenkinsci/docker#preinstalling-plugins -RUN echo 2.0 > /usr/share/jenkins/ref/jenkins.install.UpgradeWizard.state diff --git a/nexus/Dockerfile b/nexus/Dockerfile deleted file mode 100644 index 8faf139..0000000 --- a/nexus/Dockerfile +++ /dev/null @@ -1,56 +0,0 @@ -# -# Creates a docker container with Nexus Artifact Repository -# - -FROM centos:7 - -MAINTAINER Marcel Birkner - -ENV SONATYPE_WORK /sonatype-work -ENV NEXUS_VERSION 2.14.1-01 -ENV NEXUS_HOME /opt/sonatype/nexus/ - -RUN INSTALL_PKGS="java-1.8.0-openjdk.x86_64" && \ - yum -y --setopt=tsflags=nodocs install $INSTALL_PKGS && \ - rpm -V $INSTALL_PKGS && \ - yum clean all && \ - localedef -f UTF-8 -i en_US en_US.UTF-8 - -# Install packages necessary -RUN yum -y install unzip && yum clean all - -ADD https://download.sonatype.com/nexus/oss/nexus-${NEXUS_VERSION}-bundle.zip nexus-${NEXUS_VERSION}-bundle.zip - -# Extract Nexus -RUN set -x \ - && unzip nexus-${NEXUS_VERSION}-bundle.zip \ - && mkdir -p ${NEXUS_HOME} \ - && cp -r nexus-${NEXUS_VERSION}/* ${NEXUS_HOME} \ - && rm -rf nexus-${NEXUS_VERSION}-bundle.tar.gz \ - && rm -rf nexus-${NEXUS_VERSION} - -RUN groupadd -r nexus -g 3001 && \ - useradd -u 3001 -r -g nexus -m -d ${SONATYPE_WORK} -s /bin/bash -c "Nexus Run User" nexus - -VOLUME ${SONATYPE_WORK} - -EXPOSE 8081 - -WORKDIR /opt/sonatype/nexus - -RUN INSTALL_PKGS="createrepo" && \ - yum -y --setopt=tsflags=nodocs install $INSTALL_PKGS && \ - rpm -V $INSTALL_PKGS && \ - yum clean all - -ENV CONTEXT_PATH / -ENV MAX_HEAP 768m -ENV MIN_HEAP 256m -ENV JAVA_OPTS -server -XX:MaxPermSize=192m -Djava.net.preferIPv4Stack=true -ENV LAUNCHER_CONF ./conf/jetty.xml ./conf/jetty-requestlog.xml -CMD java \ - -Dnexus-work=${SONATYPE_WORK} -Dnexus-webapp-context-path=${CONTEXT_PATH} \ - -Xms${MIN_HEAP} -Xmx${MAX_HEAP} \ - -cp 'conf/:lib/*' \ - ${JAVA_OPTS} \ - org.sonatype.nexus.bootstrap.Launcher ${LAUNCHER_CONF} diff --git a/sonar/Dockerfile b/sonar/Dockerfile deleted file mode 100644 index 084e112..0000000 --- a/sonar/Dockerfile +++ /dev/null @@ -1,59 +0,0 @@ -# -# Creates a docker container with SonarQube, incl. several plugins -# - -FROM centos:7 - -MAINTAINER Marcel Birkner - -ENV JAVA_OPTS "$JAVA_OPTS -Duser.country=DE -Duser.language=de -Duser.timezone=Europe/Berlin" - -# Set the JAVA_HOME variable to make it clear where Java is located -ENV JAVA_HOME /usr/lib/jvm/java-1.8.0 - -ENV SONAR_VERSION 5.6.3 -ENV SONARQUBE_HOME /opt/sonarqube - -# Plugin Versions -ENV SONAR_JAVA_PLUGIN 4.2 -ENV SONAR_WEB_PLUGIN 2.4 -ENV SONAR_SCM_GIT_PLUGIN 1.0 - -RUN INSTALL_PKGS="java-1.8.0-openjdk.x86_64" && \ - yum -y --setopt=tsflags=nodocs install $INSTALL_PKGS && \ - rpm -V $INSTALL_PKGS && \ - yum clean all && \ - localedef -f UTF-8 -i en_US en_US.UTF-8 - -# Http port -EXPOSE 9000 - -# H2 Database port -EXPOSE 9092 - -# Install packages necessary -RUN yum -y install unzip && yum clean all - -# Add SonarQube binaries from Nexus Repository -ADD https://sonarsource.bintray.com/Distribution/sonarqube/sonarqube-${SONAR_VERSION}.zip $SONARQUBE_HOME/sonarqube-${SONAR_VERSION}.zip - -# Unpack SonarQube Zip -RUN set -x \ - && unzip $SONARQUBE_HOME/sonarqube-${SONAR_VERSION}.zip \ - && mv sonarqube-${SONAR_VERSION}/* $SONARQUBE_HOME \ - && rm $SONARQUBE_HOME/sonarqube-${SONAR_VERSION}.zip - -# Add plugins -RUN mkdir -p $SONARQUBE_HOME/extensions/plugins/ -ADD http://central.maven.org/maven2/org/sonarsource/java/sonar-java-plugin/${SONAR_JAVA_PLUGIN}/sonar-java-plugin-${SONAR_JAVA_PLUGIN}.jar $SONARQUBE_HOME/extensions/plugins/sonar-java-plugin-${SONAR_JAVA_PLUGIN}.jar -ADD http://central.maven.org/maven2/org/sonarsource/sonar-web-plugin/sonar-web-plugin/${SONAR_WEB_PLUGIN}/sonar-web-plugin-${SONAR_WEB_PLUGIN}.jar $SONARQUBE_HOME/extensions/plugins/sonar-web-plugin-${SONAR_WEB_PLUGIN}.jar -ADD http://central.maven.org/maven2/org/codehaus/sonar-plugins/sonar-scm-git-plugin/${SONAR_SCM_GIT_PLUGIN}/sonar-scm-git-plugin-${SONAR_SCM_GIT_PLUGIN}.jar $SONARQUBE_HOME/extensions/plugins/sonar-scm-git-plugin-${SONAR_SCM_GIT_PLUGIN}.jar -COPY run.sh $SONARQUBE_HOME - -WORKDIR $SONARQUBE_HOME - -VOLUME ["$SONARQUBE_HOME/data","$SONARQUBE_HOME/conf","$SONARQUBE_HOME/logs"] - -RUN chmod -R 777 $SONARQUBE_HOME - -CMD ["/opt/sonarqube/run.sh"] From 0262ead7e14a275747426f608dd64f959dc34882 Mon Sep 17 00:00:00 2001 From: "mathieu.grzybek" Date: Wed, 18 Sep 2019 14:57:58 +0200 Subject: [PATCH 06/10] [makefile] add status target --- Makefile | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/Makefile b/Makefile index 3ebdd6e..fa956a1 100644 --- a/Makefile +++ b/Makefile @@ -8,6 +8,7 @@ LANGUAGE=$(shell echo $$LANG | awk -F. '{print $$1}' | awk -F_ '{print $$2}') TIMEZONE=$(shell timedatectl | awk '/Time zone/ {print $$3}') ############################################################################## + .PHONY: help # This help message help: @grep '^.PHONY: .* #' Makefile \ @@ -55,6 +56,10 @@ clean: down ############################################################################## +.PHONY: status # Get stack status "docker-compose ps" +status: + @docker-compose ps + .PHONY: up # Start "docker-compose up" up: prepare @docker-compose up From b9fe812342621919b34cd31a331a1988edfa33ef Mon Sep 17 00:00:00 2001 From: "mathieu.grzybek" Date: Wed, 18 Sep 2019 17:55:32 +0200 Subject: [PATCH 07/10] [nexus] use local nexus deployment --- docker-compose.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docker-compose.yml b/docker-compose.yml index bd01c5c..088b4ca 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -10,7 +10,7 @@ volumes: services: nexus: - build: ./docker-nexus3 + build: ./nexus restart: always ports: - "18081:8081" From 2ade8d9d8f356b36a37f5cae001a3e1493ce8319 Mon Sep 17 00:00:00 2001 From: "mathieu.grzybek" Date: Fri, 20 Sep 2019 16:42:25 +0200 Subject: [PATCH 08/10] [traefik] publish services using a reverse-proxy --- docker-compose.yml | 32 +++++++++++++++++++++++--------- nexus/Dockerfile.tmpl | 2 +- 2 files changed, 24 insertions(+), 10 deletions(-) diff --git a/docker-compose.yml b/docker-compose.yml index 088b4ca..72b43b3 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -9,20 +9,31 @@ volumes: jenkins-data: services: + traefik: + image: traefik:montdor + restart: always + command: --accesslog --api --api.insecure=true --log --providers.docker=true --providers.docker.exposedbydefault=false + ports: + - "80:80" + - "443:443" + - "8080:8080" + networks: + - prodnetwork + volumes: + - /var/run/docker.sock:/var/run/docker.sock:ro nexus: build: ./nexus restart: always - ports: - - "18081:8081" networks: - prodnetwork volumes: - nexus-data:/nexus-data + labels: + - "traefik.enable=true" + - "traefik.http.routers.nexus.rule=Host(`localhost`) && PathPrefix(`/nexus/`)" jenkins: build: ./jenkins restart: always - ports: - - "18080:8080" networks: - prodnetwork volumes: @@ -36,22 +47,21 @@ services: - NEXUS_PORT=8081 - SONAR_PORT=9000 - SONAR_DB_PORT=5432 + - JENKINS_OPTS=--prefix=/jenkins/ + labels: + - "traefik.enable=true" + - "traefik.http.routers.jenkins.rule=Host(`localhost`) && PathPrefix(`/jenkins`)" sonardb: networks: - prodnetwork restart: always image: postgres:9.6 - ports: - - "5432:5432" environment: - POSTGRES_USER=sonar - POSTGRES_PASSWORD=sonar sonar: image: sonarqube restart: always - ports: - - "19000:9000" - - "19092:9092" networks: - prodnetwork depends_on: @@ -60,6 +70,10 @@ services: - SONARQUBE_JDBC_URL=jdbc:postgresql://sonardb:5432/sonar - SONARQUBE_JDBC_USERNAME=sonar - SONARQUBE_JDBC_PASSWORD=sonar + - sonar.web.context=/sonar + labels: + - "traefik.enable=true" + - "traefik.http.routers.sonar.rule=Host(`localhost`) && PathPrefix(`/sonar/`)" ########################################################################################## # DISABLED: GitLab takes too much memory and CPU. Demo uses GitHub repositories instead. diff --git a/nexus/Dockerfile.tmpl b/nexus/Dockerfile.tmpl index 4a0f1c4..08b8d17 100644 --- a/nexus/Dockerfile.tmpl +++ b/nexus/Dockerfile.tmpl @@ -43,7 +43,7 @@ EXPOSE 8081 WORKDIR /opt/sonatype/nexus -ENV CONTEXT_PATH / +ENV CONTEXT_PATH /nexus ENV MAX_HEAP 768m ENV MIN_HEAP 256m ENV JAVA_OPTS -server -XX:MaxPermSize=192m -Djava.net.preferIPv4Stack=true From d7711212783d2e46eeaadee3d2184dadffe1584b Mon Sep 17 00:00:00 2001 From: "mathieu.grzybek" Date: Mon, 23 Sep 2019 13:23:39 +0200 Subject: [PATCH 09/10] [nexus] add a TODO for Nexus3 and proxy --- docker-compose.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/docker-compose.yml b/docker-compose.yml index 72b43b3..471fc8a 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -22,6 +22,8 @@ services: volumes: - /var/run/docker.sock:/var/run/docker.sock:ro nexus: + # Nexus3 uses chef-solo. HTTP_PROXY env is not used. + # TODO: deal with Nexus3 and proxies. build: ./nexus restart: always networks: From e80ddf2803a584d77366b1807e5b39451e6ac0c2 Mon Sep 17 00:00:00 2001 From: "mathieu.grzybek" Date: Fri, 27 Sep 2019 11:43:21 +0200 Subject: [PATCH 10/10] [Templating] Set virtualhost from an env variable --- .gitignore | 1 + Makefile | 14 ++++-- docker-compose.yml.tmpl | 99 +++++++++++++++++++++++++++++++++++++++++ 3 files changed, 111 insertions(+), 3 deletions(-) create mode 100644 .gitignore create mode 100644 docker-compose.yml.tmpl diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..1120be9 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +docker-compose.yml diff --git a/Makefile b/Makefile index fa956a1..482f492 100644 --- a/Makefile +++ b/Makefile @@ -45,14 +45,22 @@ prepare: nexus/Dockerfile.tmpl > nexus/Dockerfile \ || true + # docker-compose: Set traefik virtualhost + @test -z ${TRAEFIK_VIRTUALHOST} \ + && sed "s/%%TRAEFIK_VIRTUALHOST%%/localhost/" \ + docker-compose.yml.tmpl > docker-compose.yml \ + || sed "s/%%TRAEFIK_VIRTUALHOST%%/${TRAEFIK_VIRTUALHOST}/" \ + docker-compose.yml.tmpl > docker-compose.yml + .PHONY: clean # Stop and remove temporary files clean: down + @docker-compose rm + @rm -f \ jenkins/Dockerfile \ nexus/Dockerfile \ - sonar/Dockerfile - - @docker-compose rm + sonar/Dockerfile \ + docker-compose.yml ############################################################################## diff --git a/docker-compose.yml.tmpl b/docker-compose.yml.tmpl new file mode 100644 index 0000000..112ab10 --- /dev/null +++ b/docker-compose.yml.tmpl @@ -0,0 +1,99 @@ +version: '3' + +networks: + prodnetwork: + driver: bridge + +volumes: + nexus-data: + jenkins-data: + +services: + traefik: + image: traefik:montdor + restart: always + command: --accesslog --api --api.insecure=true --log --providers.docker=true --providers.docker.exposedbydefault=false + ports: + - "80:80" + - "443:443" + - "8080:8080" + networks: + - prodnetwork + volumes: + - /var/run/docker.sock:/var/run/docker.sock:ro + nexus: + # Nexus3 uses chef-solo. HTTP_PROXY env is not used. + # TODO: deal with Nexus3 and proxies. + build: ./nexus + restart: always + networks: + - prodnetwork + volumes: + - nexus-data:/nexus-data + labels: + - "traefik.enable=true" + - "traefik.http.routers.nexus.rule=Host(`%%TRAEFIK_VIRTUALHOST%%`) && PathPrefix(`/nexus/`)" + jenkins: + build: ./jenkins + restart: always + networks: + - prodnetwork + volumes: + - /var/run/docker.sock:/var/run/docker.sock + - /usr/bin/docker:/usr/bin/docker + - jenkins-data:/var/lib/jenkins/ + depends_on: + - nexus + - sonar + environment: + - NEXUS_PORT=8081 + - SONAR_PORT=9000 + - SONAR_DB_PORT=5432 + - JENKINS_OPTS=--prefix=/jenkins/ + labels: + - "traefik.enable=true" + - "traefik.http.routers.jenkins.rule=Host(`%%TRAEFIK_VIRTUALHOST%%`) && PathPrefix(`/jenkins`)" + sonardb: + networks: + - prodnetwork + restart: always + image: postgres:9.6 + environment: + - POSTGRES_USER=sonar + - POSTGRES_PASSWORD=sonar + sonar: + image: sonarqube + restart: always + networks: + - prodnetwork + depends_on: + - sonardb + environment: + - SONARQUBE_JDBC_URL=jdbc:postgresql://sonardb:5432/sonar + - SONARQUBE_JDBC_USERNAME=sonar + - SONARQUBE_JDBC_PASSWORD=sonar + - sonar.web.context=/sonar + labels: + - "traefik.enable=true" + - "traefik.http.routers.sonar.rule=Host(`%%TRAEFIK_VIRTUALHOST%%`) && PathPrefix(`/sonar/`)" + +########################################################################################## +# DISABLED: GitLab takes too much memory and CPU. Demo uses GitHub repositories instead. +# +# gitlab: +# image: gitlab/gitlab-ce:latest +# restart: always +# networks: +# - prodnetwork +# environment: +# GITLAB_OMNIBUS_CONFIG: | +# # external_url 'https://gitlab.example.com' +# # Add any other gitlab.rb configuration here, each on its own line +# ports: +# - "10080:80" +# - "10443:443" +# - "10022:22" +# volumes: +# - /opt/gitlab/config:/etc/gitlab +# - /opt/gitlab/logs:/var/log/gitlab +# - /opt/gitlab/data:/var/opt/gitlab