Skip to content

Instantly share code, notes, and snippets.

@jjamor
Created July 19, 2017 11:42
Show Gist options
  • Save jjamor/71e00d7f34fc683b4bcf1237907dc7d7 to your computer and use it in GitHub Desktop.
Save jjamor/71e00d7f34fc683b4bcf1237907dc7d7 to your computer and use it in GitHub Desktop.

CI/CD

Branches

  • Feature_X is current feature
  • Devel is integration
  • Release is preproduction
  • Master is production
  • Master:tag X is release X

Workflow

  • Create new branch Feature_X from Devel
git checkout -b <current_feature>
  • Work on the feature
    • Run tests locally
    • Commit often
git add <files>
git commit -m <message>
  • Merge often with Devel

    • Fix conflicts, add files and commit.
    • At least once each day
    • Mandatory regression tests
    • Mandatory integration test
    • Optional image creation
    • Optional end-to-end tests with containers
  • Merge with Release when the sprint finishes

    • Mandatory image creation
    • Mandatory integration tests
    • Optional end-to-end tests with containers
  • Replace Master with Release

    • Tag release branch with release number
    • Merge with master
    • Tag alias docker image with latest

Preparing project

git clone https://github.com/ciberado/picalculator

Maven important plugins

Creating images with Dockerfile

  • With docker:
docker build --tag capside/picalculator:0.0.3 .
  • With maven:
mvn clean package docker:build
  • With hub: Docker Hub Automatic Build

Jenkins in a container

  • Jenkins in a container is GOOD
  • A container using Docker is BAD
  • A container working with external Docker [is FINE]

Jenkins with Docker (Dockerfile)

FROM jenkins:1.651.1

USER root
RUN wget -qO- https://get.docker.com/ | sh
RUN apt-get update \
      && apt-get install -y sudo \
      && rm -rf /var/lib/apt/lists/*
RUN echo "jenkins ALL=NOPASSWD: ALL" >> /etc/sudoers 
       
USER jenkins
COPY plugins.txt /usr/share/jenkins/plugins.txt
RUN /usr/local/bin/plugins.sh /usr/share/jenkins/plugins.txt

Test Docker outside Docker

docker run -it -rm -v /var/run/docker.sock:/var/run/docker.sock custom-jenkins /bin/bash
$> sudo docker ps
$> exit

Launch Jenkins in Docker with Docker

docker run -d --name jenkins  \
	-v /var/run/docker.sock:/var/run/docker.sock \
	-p 8080:8080 -p 50000:50000 \
	custom-jenkins

Configure Jenkins

  • Jenkins admin -> System configuration
    • Install java
    • Instal Maven (Beware! 3.5 is NOT compatible)
  • Jenkins admin -> Install plugins
    • Git plugin
    • Credentials (maybe already installed)
    • Credentials Binding
    • Plain Credentials
  • Reboot

Secrets creation

  • Credentials -> Global -> Add credentials
    • Kind=Secret text, Scope=Global, Secret=, Id=dockerpassword
  • Credentials -> Global -> Add credentials
    • Kind=Secret text, Scope=Global, Secret=, Id=dockerusername

Project creation

  • Type: maven
  • Git: https://github.com/ciberado/picalculator
  • Check use secret text
    • Binding añadir secret text: variable=dockerpassword, credentials=dockerpassword
    • Binding añadir secret text: variable=dockerusername, credentials=dockerusername
  • Goals: clean package
  • Post build (only if successful build):
sudo docker login -u $dockerusername -p $dockerpassword
sudo docker build -t $dockerusername/pi:$POM_VERSION .
sudo docker push $dockerusername/pi:$POM_VERSION		
  • Save & Build now
  • Test with
docker run -it -p 8081:8080 capside/pi:0.0.3-SNAPSHOT

Tools and links

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