Jenkins+Docker (docker-compose)

The goal of this article is to recreate the manual steps from the previous part with a yml template and docker-compose.

Required files:

WorkDir
    └── Dockerfile
    └── docker-compose.yml
    └── secrets
      └── JENKINS_USER
      └── JENKINS_PASS

We will be using local file secrets with this approach

Dockerfile:

FROM jenkins/jenkins:lts

ENV JAVA_OPTS="-Djenkins.install.runSetupWizard=false"

COPY ./csrf.groovy /usr/share/jenkins/ref/init.groovy.d/csrf.groovy
COPY ./basic.security.groovy /usr/share/jenkins/ref/init.groovy.d/basic.security.groovy
COPY ./basic.security002.groovy /usr/share/jenkins/ref/init.groovy.d/basic.security002.groovy
COPY ./plugins_list.txt /usr/share/jenkins/ref/plugins_list.txt

EXPOSE 8080
EXPOSE 50000

Here’s what our docker-compose.yml will look like:

version: '3.7'
services:
  jenkins:
    restart: unless-stopped
    user: root
    build: .
    image: jmaster:latest
    ports:
      - "8080:8080"
      - "50000:50000"
    volumes:
      - ./jenkins_data:/var/jenkins_home
      - /var/run/docker.sock:/var/run/docker.sock
    secrets:
      - jenkins-username
      - jenkins-password
    environment:
    - HOME=/var/jenkins_home
      - JENKINS_HOME=/var/jenkins_home
      - JAVA_OPTS=
          -Djenkins.install.runSetupWizard=false
          -Djava.awt.headless=true
      - PLUGINS=
          matrix-auth
          docker-plugin
    entrypoint: /bin/bash
    command:
      - -c
      - |-
          /usr/local/bin/install-plugins.sh $${PLUGINS}
          /sbin/tini -- /usr/local/bin/jenkins.sh          
secrets:
  jenkins-username:
    file: ./secrets/JENKINS_USER
  jenkins-password:
    file: ./secrets/JENKINS_PASS

November 6, 2019   (v.16c40e0)