Giter VIP home page Giter VIP logo

jenkins-pipeline's Introduction

Set-up Instructions

  1. Configure the below environment variables.

    • $ export JENKINS_URL=http://<JENKINS HOST>:8081/jenkins
      Port number used here is 8081. It can be changed here according to the configuration in the pipeline-compose.yml file.
    • $ export DOCKER_HOST_PORT=$(stat -c '%g' /var/run/docker.sock)
      This is a required for a hack temporarily. Details are explained below in the 'Build the docker image' section.
    • $ export GIT_REPO_HTTPS_URL="https://github.com/bbideep/springboot-microservices"
      Replace with the appropriate repo URL.
    • $ export GIT_BRANCH="master"
  2. Here, we are using docker secrets to configure the Jenkins Admin username and password. To use docker secrets, we need to initialize docker swarm on the node where Jenkins has to be configured. Run $ docker swarm init to initialize docker swarm.
    Verify that the node is part of the swarm by $ docker node ls.

  3. Run the below commands to populate the secrets. Replace the values as needed.

  • Required to set up Jenkins admin credentials automatically through groovy setup scripts.
    $ echo "your jenkins admin username" | docker secret create admin-username -
    $ echo "your jenkins admin password" | docker secret create admin-password -
  • Required for any AWS CLI/API calls. Ideally, IAM roles should be used.
    $ echo "aws access key" | docker secret create aws-access-key -
    $ echo "aws secret key" | docker secret create aws-secret-key -
  • Required for docker registry login.
    $ echo "docker registry username" | docker secret create docker-reg-user -
    $ echo "docker registry password" | docker secret create docker-reg-pwd -
  • Required for SCM credentials setup.
    $ echo "scm repo username" | docker secret create scm-repo-user -
    $ echo "scm repo password" | docker secret create scm-repo-pwd -
  • Required for Kubernetes secrets setup. $ echo "k8s secret name" | docker secret create k8s-user -
    $ echo "k8s secret token" | docker secret create k8s-pwd -

Note: In case AWS ECR is used, aws ecr get-login --no-include-email can help retrieve the docker login command with the username and password.

Build the docker image

Use the below command to build the docker image and run locally without any image registry. In case you provide a different tag, the pipeline-compose.yml file needs to be updated accordingly.
$ docker build -f Dockerfile -t jenkins-pipeline:latest .

Using docker build --build-arg DOCKER_HOST_PORT=<'docker' group port> -f Dockerfile -t jenkins-pipeline:latest . as a hack for now as I am using the same docker host for demo purpose.
This needs to be fixed to fetch the docker socket group dynamically at container startup.

Build the stack

Deploy 'jenkins' stack:
$ docker stack deploy -c pipeline-compose.yml jenkins

Remove 'jenkins' stack:
$ docker stack rm jenkins

Additional commands cheat sheet

Use commands like the ones below to remove docker secrets:
$ docker secret rm admin-username
$ docker secret rm admin-password

For AWS ECR, below commands can be used to -

  • Retrieve and run docker login command:
    $ DOCKER_LOGIN_CMD=$(aws ecr get-login --no-include-email)
    $ eval $DOCKER_LOGIN_CMD
  • Get the docker login password and use it to create K8S secret:
    $ DOCKER_PWD=$(echo $DOCKER_LOGIN_CMD | awk -F ' ' {'print $6'})
    $ kubectl create secret docker-registry ecr-cred --docker-server=https://<AWS ACCOUNT ID>.dkr.ecr.us-east-1.amazonaws.com --docker-username=AWS --docker-password=$DOCKER_PWD
  • Retrieve base64 encoded contents of the docker config file from the local system.
    $ ENCODED_TOKEN=$(cat ~/.docker/config.json | base64 | tr -d '\n')

jenkins-pipeline's People

Contributors

bbideep avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.