Coder Social home page Coder Social logo

tomcat_maven_app's Introduction

CI-CD with Docker

Here is the step by step instructions to host a highly available website.

Pre-requisites

  1. Create an account in dockerhub
  2. Machine with Jenkins up and running
  3. An agent with docker running
  4. Install the git and java in Agent
  5. Add this Agent to Jenkins with the label called docker
  6. Edit the Agent's Security Group Inbound rules by allowing traffic on 8080, 8081, 8082 custom ports.

Creating Nginx Loadbalancer

Execute the following on agent

  1. Create a directory called nginx and change into it.
  2. Create a file called nginx.conf with following contents
upstream backend {
    server GATEWAYIP:8081;
    server GATEWAYIP:8082;
}

server {
    location / {
       proxy_pass http://backend;
    }
}
  1. Get the Docker default gateway IP by running below command on docker agent.
GATEWAY=$(docker network inspect bridge | grep -i gateway | awk '{print $2}' | sed -e 's/,$//' -e 's/^"//' -e 's/"$//')
  1. Replace the GATEWAYIP with the gateway ip.
sed -i 's/GATEWAYIP/'"$GATEWAY"'/g' nginx.conf
  1. Confirm the GATEWAYIP is replaced with the actual ip address in nginx.conf.
  2. Create a Dockerfile with following content
FROM nginx
LABEL owner=loki
LABEL desc="Nginx LoadBalancer"
RUN rm -rf /etc/nginx/conf.d/default.conf
COPY ./nginx.conf /etc/nginx/conf.d/default.conf
  1. Create the docker image. Pls replace the registry with your registry
docker build -t lokeshkamalay/nginx:latest .
  1. Store the image in Dockerhub
docker push lokeshkamalay/nginx:latest

Creating a Jenkins Pipeline

  1. Setup a Jenkins Pipeline job with Pipeline Script from SCM
  2. Choose repo as https://github.com/lokeshkamalay/tomcat_maven_app.git
  3. Ensure the agent running docker is configured with the label docker
  4. Create a credential with the name of docker-hub and input docker hub username and password.
  5. Run the Job

Results

  1. Confirm the job has run successful
  2. Access your website with the Agent's Public IP on port 8080. website

tomcat_maven_app's People

Contributors

lokeshkamalay avatar

Stargazers

 avatar  avatar

Watchers

 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.