Skip to content

Instantly share code, notes, and snippets.

@edcote
Last active October 3, 2018 03:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save edcote/0dfd1f9f26c628ba1a3dbb2860ebd7dd to your computer and use it in GitHub Desktop.
Save edcote/0dfd1f9f26c628ba1a3dbb2860ebd7dd to your computer and use it in GitHub Desktop.
Jenkins and Docker

Goal

  • To deploy riscv-ci on docker, with preserved data.

    mkdir -p docker/riscv-ci cd docker/riscv-ci

Docker and Jenkins setup

  • Create an image on top of the Jenkins image with log, cache directories and java opts
# <workdir>docker/riscv-ci/Dockerfile

FROM jenkins/jenkins:lts

USER root

# Environment
ENV HOME /root
ENV JENKINS_HOME /root/jenkins
ENV JAVA_OPTS="-Xmx8192m"

# Filesystem setup
RUN mkdir -p $JENKINS_HOME
RUN mkdir /var/log/jenkins
RUN mkdir /var/cache/jenkins
RUN chown -R jenkins:jenkins /var/log/jenkins
RUN chown -R jenkins:jenkins /var/cache/jenkins

# Set timezone
RUN echo "America/Los_Angeles" > /etc/timezone && \
    dpkg-reconfigure --frontend noninteractive tzdata && \
    date

USER jenkins
  • Create the data image
# <workdir>/docker/riscv-ci/Dockerfile-data

FROM ubuntu:17.10

# Create the jenkins user
RUN useradd -d "/var/jenkins_home" -u 1000 -m -s /bin/bash jenkins

# Create the folders and volume mount points
RUN mkdir -p /var/log/jenkins
RUN chown -R jenkins:jenkins /var/log/jenkins
VOLUME ["/var/log/jenkins", "/var/jenkins_home"]
USER jenkins
CMD ["echo", "Hello from data container"]
  • Build docker images
cd <workdir>/docker/riscv-ci/Dockerfile-data
docker build --tag riscv-ci-data -f Dockerfile-data .
docker build --tag riscv-ci      -f Dockerfile      .
  • Run commands inside container. Example (bash): docker run -it <dockerfile> bash

  • Run Jenkins on port 8080: docker run -p 8080:8080 <dockerfile>

When something goes wrong

  • stop all containers: docker kill $(docker ps -q)
  • remove all containers: docker rm $(docker ps -a -q)
  • remove all docker images: docker rmi $(docker images -q)

References

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment