Skip to content

Jenkins

Create docker-compose.yml

docker-compose.yml

YAML
version: '3.7'
services:
  jenkins:
    image: jenkins/jenkins:lts
    privileged: true
    user: root
    ports:
      - 8081:8080
      - 50000:50000
    container_name: jenkins
    volumes:
      - ./jenkins_data:/var/jenkins_home
      - /var/run/docker.sock:/var/run/docker.sock
      - /usr/local/bin/docker:/usr/local/bin/docker

docker-compose.yml | updated | swarm

YAML
version: '3.7'

services:


  jenkins:
    image: harbor.kafana.dev/kafana/jenkins:2023-07-03
    deploy:
      placement:
        constraints:
          - node.role==manager
      replicas: 1
      restart_policy:
        condition: on-failure
      resources:
        limits:
          memory: 3072M
    ports:
      - 4004:8080
    volumes:
      - ./persistent-cache:/persistent-cache
      - ./volume-caches/build-cache/composer:/.composer
      - ./volume-caches/build-cache/composer:/home/docker/.composer
      - ./volume-caches/build-cache/node/npm:/.npm
      - ./volume-caches/build-cache/node/npm:/home/docker/.npm
      - ./volume-caches/build-cache/node/gyp:/.node-gyp
      - ./volume-caches/build-cache/node/cache:/.cache
      - ./volume-caches/build-cache/node/config:/.config
      - ./volume-caches/build-cache/bower/local:/.local
      - ./volume-caches/build-cache/bower/local:/home/docker/.local
      - ./jenkins_home:/var/jenkins_home
      - /var/run/docker.sock:/var/run/docker.sock
      - /usr/bin/docker-compose:/usr/bin/docker-compose
      - /usr/bin/docker:/usr/bin/docker
      - ./known_hosts:/var/jenkins_home/.ssh/known_hosts
    networks:
      - durbok-net

networks:
  durbok-net:
    external: true

volumes:
  persistent-cache:

Dockerfile

Maintain jenkins version by building custom docker image using jenkins original dockerfile

Docker
FROM jenkins/jenkins:lts

USER root
RUN apt-get update \
      && apt-get upgrade -y \
      && apt-get install -y sudo libltdl-dev ssh rsync zip \
      && rm -rf /var/lib/apt/lists/*

RUN curl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o "awscliv2.zip" && \
    unzip awscliv2.zip && \
    ./aws/install && \
    rm -rf awscliv2.zip

RUN echo "jenkins ALL=NOPASSWD: ALL" >> /etc/sudoers

# Fixes socket permissions within build containers
RUN groupadd -for -g 998 docker
RUN usermod -aG docker jenkins

USER jenkins

Build:

Bash
docker build -t harbor.kafana.dev/kafana/jenkins:$(date +%F) .