├── .DS_Store ├── README.md ├── _config.yml ├── aws-eb-setup.md ├── aws-ecs-setup.md ├── configure-jenkins-ecs-eb.md ├── containerize-springboot-microservice.md ├── images ├── aws_eb.png ├── aws_ecs.png ├── configure_build_triggers.png ├── configure_gitlab_connections.png ├── configure_gitlab_webhooks.png └── configure_scm.png └── jenkins-gitlab-setup.md /.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/eajitesh/Continuous-Delivery-Microservices-AWS/55e0151b777d66f0d91790aa85cefc8998acf88b/.DS_Store -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Deep Dive into Continuous Delivery of Microservices on AWS 2 | 3 | The goal of this project is to enable developers play with continuous delivery of microservices on [Awazon Web Services (AWS)](https://aws.amazon.com/) cloud. Those planning to do **startups** could get tips and code samples to get started with development, testing and releasing (continuously deploying) the software thereby gaining the competitive edge for their products. 4 | 5 | The project would demonstrate some of the following: 6 | 7 | 1. Developers check-in the code into the code repository such as GitLab. 8 | 2. GitLab webhook triggers the Jenkins job 9 | 3. Jenkins job starts with getting code from repository, build the code, run the unit tests/integration 10 | 4. Once build and tests run successfully, Jenkins build the image for microservices and push the same to either of Dockerhub or [AWS ECR (EC2 Container Registry)](https://aws.amazon.com/ecr/). 11 | 5. After the docker image for microservices is pushed to the image repository, following is done to deploy microservices (would run within containers) on [AWS EC2 Container Service (ECS) Cluster](http://docs.aws.amazon.com/AmazonECS/latest/developerguide/ECS_clusters.html) or [AWS Elastic Beanstalk (EB)](http://docs.aws.amazon.com/elasticbeanstalk/latest/dg/Welcome.html). 12 | - **AWS ECS Cluster**: For deploying to ECS cluster, a new task definition is registered and the ECS service is updated. As a result of updating ECS service, the container using microservices image (pulled from image repository) gets started. 13 | - **AWS Elastic Beanstalk**: For deploying the microservices on AWS EB, the execution of EB Cli command related with deployment is executed which leads to starting of container (with microservice image) on EC2 instance on AWS EB environment. 14 | 15 | 16 | This project is intended to provide information related with some of the following topics. 17 | ``` 18 | 1. Setup Gitlab and Jenkins 19 | 2. Setup Dockerhub, AWS ECR 20 | 3. Containerize Springboot Microservice 21 | 4. Continuous Delivery using AWS ECS 22 | 5. Continuous Delivery using AWS Elastic Beanstalk 23 | ``` 24 | ## Setup Gitlab and Jenkins 25 | 26 | The first step is to get setup with the development envitonment. We shall use Docker images for GitLab and Jenkins and, Docker-compose for starting/commissioning the environment. Once environment is commissioned, it would be required to login into both GitLab and Jenkins to do some of the following: 27 | 28 | 1. **GitLab**: Ceate code repository 29 | 30 | 2. **Jenkins**:Install plugins,configure system, create job, configure job  etc.   31 | 32 | Read further details on this page, [Jenkins Gitlab with Docker Containers](https://github.com/eajitesh/Continuous-Delivery-Microservices-AWS/blob/master/jenkins-gitlab-setup.md) 33 | 34 | ## Setup Dockerhub and AWS account     35 | 36 | Next step is to create your account with image repository such as Dockerhub and AWS ECR. 37 | 38 | 1. **Dockerhub**: Go to [Dockerhub](http://www.dockerhub.com) and get signed up. You will be using this credentials from within Jenkins to login to Dockerhub and push the images. 39 | 2. **AWS**: Go to [AWS](http://www.aws.com) and get signed up. 40 | 41 | ## Containerize Springboot Microservice 42 | 43 | Springboot can be used to create microservice and Docker containers can be used to containerize them. Read further details on this page, [Containerize Springboot Microservice](https://github.com/eajitesh/Continuous-Delivery-Microservices-AWS/blob/master/containerize-springboot-microservice.md) 44 | 45 | ## Continuous Delivery of Microservices on AWS using AWS ECS 46 | 47 | [AWS EC2 Container Service (ECS)](http://docs.aws.amazon.com/AmazonECS/latest/developerguide/Welcome.html) is a highly scalable container management service which is used to start, stop and run microservices within Docker containers on AWS EC2 instances. In this project, it is demonstrated as to how to deploy container-based microservices using CLI commands from within Jenkins. As part of getting setup with ECS, following needs to be done: 48 | 49 | 1. Create a repository (EC2 Repository - ECR) 50 | 2. Create a task definition 51 | 3. Create an ECS cluster 52 | 4. Create a service 53 | 54 | Following represents the **solution architecture** of deploying microservices on AWS using AWS ECS. 55 | 56 | ![Solution Architecture - Microservices to AWS ECS](images/aws_ecs.png) 57 | 58 | Read further details on this page, [Continuous Delivery of Microservices with AWS ECS](https://github.com/eajitesh/Continuous-Delivery-Microservices-AWS/blob/master/aws-ecs-setup.md) 59 | 60 | ## Continuous Delivery of Microservices on AWS using AWS Elastic Beanstalk 61 | 62 | [AWS Elastic Beanstalk](https://aws.amazon.com/documentation/elastic-beanstalk/) service is used to deploy and scale web applications and services developed with Java, .NET, PHP, Nodejs, Python, Ruby, Go and Docker on servers such as Apache, Tomcat, Nginx etc. All one is required to do is simply upload their code and Elastic Beanstalk does some of the following aspect of deployment: 63 | 64 | - Capacity provisioning 65 | - Load balancing 66 | - Auto-scaling 67 | - Application-health monitoring 68 | 69 | Following represents the **solution architecture** of deploying microservices on AWS using AWS Elastic Beanstalk based on single container docker configurations. Note that Docker platform for Elastic Beanstalk supports two generic configurations such as single container and multicontainer. 70 | 71 | ![Solution Architecture - Microservices to AWS Elastic Beanstalk](images/aws_eb.png) 72 | 73 | Read further details on this page, [Continuous delivery of Microservices on AWS using AWS Elastic Beanstalk](https://github.com/eajitesh/Continuous-Delivery-Microservices-AWS/blob/master/aws-eb-setup.md) 74 | 75 | -------------------------------------------------------------------------------- /_config.yml: -------------------------------------------------------------------------------- 1 | theme: jekyll-theme-cayman -------------------------------------------------------------------------------- /aws-eb-setup.md: -------------------------------------------------------------------------------- 1 | # Continuous Delivery of Microservices on AWS using AWS Elastic Beanstalk 2 | 3 | [AWS Elastic Beanstalk](https://aws.amazon.com/documentation/elastic-beanstalk/) service can be used to deploy and scale applications and services (from docker containers) developed with Java, .NET, PHP, Nodejs, Python, Ruby, Go etc on servers such as Apache, Tomcat, Nginx etc. Docker containers provide the flexibility of selecting one's runtime environment of choice including platform, programming language, app/services dependencies, and also, configuring the environment appropriately. All one is required to do is simply push the docker image to the image repository, and deploy the container. Elastic Beanstalk service, then, takes care of different aspects of deployment such as capacity provisioning, load balancing, auto-scaling, application/service health monitoring etc. 4 | 5 | Docker platform for Elastic Beanstalk has two generic configurations such as following: 6 | - Single container Docker 7 | - Multicontainer Docker 8 | 9 | We shall try and cover the use cases for both the configuration types. 10 | 11 | ## Single Container Docker 12 | 13 | Before getting into details of single container docker configurations for Elastic Beanstalk, lets quickly look into the solution architecture for deploying microservices on AWS using AWS Elastic Beanstalk. 14 | 15 | ### Solution Architecture 16 | 17 | Following represents the **solution architecture** of deploying microservices on AWS using AWS Elastic Beanstalk using single container docker configurations. 18 | 19 | ![Solution Architecture - Microservices to AWS Elastic Beanstalk](images/aws_eb.png) 20 | 21 | In the above diagram, pay attention to some of the following: 22 | 23 | 1. Code is checked into code repository such as Gitlab 24 | 2. Webhook configured in GitLab triggers the Jenkins job 25 | 3. Jenkins job starts executing which results in following steps: 26 | - Retrieve the microservice artifacts from Gitlab 27 | - Build the microservice 28 | - Run the tests such as unit and integration tests 29 | - Build the image if all of the above steps are successful 30 | - Push the image to image repository such as Dockerhub or AWS ECR 31 | - Deploy using AWS Elastic Beanstalk CLI command 32 | 33 | ### Single Docker Container Configuration 34 | 35 | Following steps need to be taken to get setup with Elastic Beanstalk to deploy application/services/microservices from docker containers based on single docker container configuration: 36 | 37 | 1. Create a Beanstalk application using [AWS console for creating new application](http://console.aws.amazon.com/elasticbeanstalk/home#/newApplication). Pay attention to some of the following while creating the application. 38 | - Select environment as Web Server environment. 39 | - On environment type page, select configuration as "Docker" (and not Multi-container Docker) and environment type as "Load balancing, auto scaling" 40 | - Continue with choosing default in each step. In "Application version", you may choose to upload the Dockerfile or Dockerrun.aws.json. Later, the same Dockerfile or Dockerrun.aws.json can be uploaded using "eb deploy" command as part of Jenkins build post-steps. 41 | 2. Install Elastic Beanstalk command line interface (EB CLI). EB CLI provides a set of commands for creating, updating and monitoring environments from a local repository. 42 | 3. Go to the project folder consisting of Dockerrun.aws.json or Dockerfile (for single docker container configuration). Use "eb init" command to choose some of the following: 43 | - Region 44 | - Access key and secret key 45 | - Select an application (created earlier using EB console). 46 | - Select a keypair (one which was selected while creating the application using EB console) 47 | 48 | With above steps followed, one should be all set to execute the following command from the project folder. 49 | ``` 50 | eb deploy 51 | ``` 52 | Make sure that project folder consists of either Dockerfile or Dockerrun.aws.json. In the code below, image is retrieved from Dockerhub. Note the AWSEBDockerrunVersion as "1". For multi-container configuration, the value becomes "2". 53 | ``` 54 | { 55 | "AWSEBDockerrunVersion": 1, 56 | "Image": { 57 | "Name": "ajitesh/springboot-web-app", 58 | "Update": "true" 59 | }, 60 | "Ports": [ 61 | { 62 | "ContainerPort": "8080" 63 | } 64 | ], 65 | "Logging": "/var/log" 66 | } 67 | ``` 68 | ## Configure Jenkins Post-steps 69 | 70 | Jenkins post-steps can be configured to achieve following: 71 | 72 | ### Pushing images to Dockerhub; Deploy to Elastic Beanstalk 73 | 74 | ``` 75 | # Build the docker image 76 | sudo docker build -t ImageName:tag /var/jenkins_home/workspace/SpringBootApp 77 | 78 | # Login into Dockerhub; dockerhubLogin and dockerhubPassword is login and password respectively for dockerhub.com 79 | sudo docker login -u="dockerhubLogin" -p="dockerhubPassword" 80 | 81 | # Push docker image into Dockerhub 82 | sudo docker push ImageName:tag 83 | 84 | # EB Deploy; Go to the project folder and execute the command, "eb deploy" 85 | cd /var/jenkins_home/workspace/awsebdemo 86 | eb deploy 87 | ``` 88 | In above code samples, note some of the following: 89 | - **ImageName:tag** should be replaced with image such as ajitesh/springboot-web-app:latest. 90 | 91 | ## Reference 92 | 93 | - [Elastic Beanstalk Archtectural Overview](http://docs.aws.amazon.com/elasticbeanstalk/latest/dg/concepts.concepts.architecture.html) 94 | - [Deploying Elastic Beanstalk Applications from Docker Containers](http://docs.aws.amazon.com/elasticbeanstalk/latest/dg/create_deploy_docker.html) 95 | - [Single Container Docker Configuration](http://docs.aws.amazon.com/elasticbeanstalk/latest/dg/create_deploy_docker_image.html) 96 | - [Multicontainer Docker Environments](http://docs.aws.amazon.com/elasticbeanstalk/latest/dg/create_deploy_docker_ecs.html) 97 | - [EB CLI Commands](http://docs.aws.amazon.com/elasticbeanstalk/latest/dg/eb-cli3-getting-started.html) 98 | - [Elastic Beanstalk FAQs](https://aws.amazon.com/elasticbeanstalk/faqs/) 99 | 100 | -------------------------------------------------------------------------------- /aws-ecs-setup.md: -------------------------------------------------------------------------------- 1 | # Continuous Delivery of Microservices with AWS ECS 2 | 3 | [AWS EC2 Container Service (ECS)](http://docs.aws.amazon.com/AmazonECS/latest/developerguide/Welcome.html) is a highly scalable container management service which is used to start, stop and run microservices within Docker containers on a cluster of AWS EC2 instances. In this project, it is demonstrated as to how to deploy container-based microservices using CLI commands from within Jenkins. In order to achieve the same, following needs to be done: 4 | 5 | 1. Setup ECS Service 6 | - Create a repository (EC2 Repository - ECR) 7 | - Create a task definition 8 | - Create an ECS cluster 9 | - Create a service 10 | 2. Configure Jenkins build Post-steps 11 | 12 | **Note**: For the demonstration purpose, both **Gitlab** and **Jenkins** are setup within **Docker Containers**. In real world scenario, Gitlab and Jenkins may get setup within different VMs. 13 | 14 | Before getting into the setup details, let us try and understand the solution architecture related with achieving continuous delivery of microservices with AWS ECS. 15 | 16 | ## Solution Architecture 17 | 18 | Following represents the solution architecture of deploying microservices using AWS ECS. 19 | 20 | ![Solution Architecture - Microservices to AWS ECS](https://github.com/eajitesh/Continuous-Delivery-Microservices-AWS/blob/master/images/aws_ecs.png) 21 | 22 | In above diagram, pay attention to some of the following: 23 | 24 | 1. Code is checked into code repository such as Gitlab 25 | 2. Webhook configured in GitLab triggers the Jenkins job 26 | 3. Jenkins job starts executing which results in following steps: 27 | - Retrieve the microservice artifacts from Gitlab 28 | - Build the microservice 29 | - Run the tests such as unit and integration tests 30 | - Build the image if all of the above steps are successful 31 | - Push the image to image repository such as Dockerhub or AWS ECR 32 | - Register task definition with AWS ECS 33 | - Update AWS ECS 34 | 35 | ## Setup ECS Service 36 | 37 | Before configuring steps into Jenkins, following needs to be setup using AWS ECS console. 38 | 39 | ### Create an Image Repository with AWS ECR 40 | 41 | First step is getting setup with AWS ECR. Following command needs to be executed in order to create an ECR repository. 42 | ``` 43 | # Login into ECR 44 | aws configure 45 | aws ecr get-login 46 | docker built -t ImageName . 47 | docker tag ImageName:tag AWS_ECR_URL/ImageName:tag 48 | docker push AWS_ECR_URL/ImageName:tag 49 | ``` 50 | Note some of the following with above command: 51 | - **AWS_ECR_URL** is of the format https://__aws_account_id__.dkr.ecr.__region__.amazonaws.com. One can get the value of Account id by logging into console and going to My Account page. Region information can be found from the [region and availability zones page](http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/using-regions-availability-zones.html) 52 | - **aws configure** command is used to setup AWS CLI installation. The command would require one to enter credentials and config information before one starts working with their AWS services. The command would require one to enter details for access key ID, secret access key, default region name and default output format. However, as we need to achieve this without entering details at the prompt, following needs to be done in order to achieve the promptless command such as **aws configure --profile default** 53 | - Create a folder, **.aws** in the home. 54 | - Create a file named as **config** within above folder, **.aws**, with following content. One could get access key id and secret access key information by logging into the AWS console and accessing "My Security Credentials". 55 | ``` 56 | [default] 57 | aws_access_key_id=AKXXIXXYXX4X4XXXXJRY 58 | aws_secret_access_key=DyxxxxxxeqQyxyyyyytXcwwthbbCxaaaa8Qi0y 59 | region=us-west-2 60 | output=json 61 | ``` 62 | - **aws ecr get-login** command is used to get the login prompt which needs to be executed further to login (start authenticated session) into AWS ECR and thereafter, push the image. 63 | - Other commands are usual commands to push the docker image to the AWS ECR image repository. 64 | 65 | Executing above commands leads to user entering the details at the prompt. If one wants to achieve the same without prompt, from within Jenkins, the same could be achieved using following command which is a combination of commands to achieve promptless execution. 66 | 67 | ``` 68 | yes "" | aws configure --profile default ; aws ecr get-login > awslogin.sh ; sudo sh awslogin.sh 69 | ``` 70 | One can observe that executing command such as "aws ecr get-login" leads to output of command such as following which needs to be executed for successfully logging in. The command below is sent to awslogin.sh file as shown in the command and then awslogin.sh is executed. 71 | ``` 72 | docker login -u AWS -p SomeRandomPasswordStringSentByAWS -e none https://**aws_account_id**.dkr.ecr.**region**.amazonaws.com 73 | ``` 74 | 75 | ### Create a Task Definition 76 | 77 | Next step is to create a task definition. Command such as following could be used to create the task definition: 78 | 79 | ``` 80 | aws ecs register-task-definition --family TaskDefinitionFamily --container-definitions "[{\"name\":\"ContainerName\",\"image\":\"ImageName:tag\",\"memory\":300,\"portMappings\":[{\"hostPort\":0,\"containerPort\":8080,\"protocol\":\"tcp\"}]}]" 81 | ``` 82 | In above command, note the following two aspects: 83 | - **TaskDefinitionFamily** is the name of family for a task definition, which allows you to track multiple versions of the same task definition. The family is used as a name for your task definition. 84 | - **ContainerName** which is the name of the container. 85 | - **container-definitions** which is used to provide information related with one or more containers which will be started as a result of executing task based on the task definition. 86 | 87 | One may want to login and access the AWS console at Services/EC2 Container Service/Task Definitions and try and create task definition to understand different aspects of task definition creation. Further details in relation with register-task-definition can be found on this page, [register-task-definition](http://docs.aws.amazon.com/cli/latest/reference/ecs/register-task-definition.html). 88 | 89 | ### Create an ECS Cluster 90 | 91 | As this is one time activity, one may want to use AWS console at Services/EC2 Container Service/Clusters to create the cluster. It is pretty straight forward and very easy to create the cluster. 92 | 93 | ### Create/Update the Service 94 | 95 | Once done with creating cluster, one will be required to update ECS service. update-service command is used to modify the task definition and deploy a new version of the service. 96 | ``` 97 | aws ecs update-service --cluster ClusterName --service ServiceName --task-definition TaskDefinitionName --desired-count 2 98 | ``` 99 | In above code snippet, note some of the following: 100 | - **TaskDefinitionName** is name of the task definition. The family and revision (family:revision ) or full Amazon Resource Name (ARN) of the task definition to run in your service. If a revision is not specified, the latest ACTIVE revision is used. If you modify the task definition with update-service , Amazon ECS spawns a task with the new version of the task definition and then stops an old task after the new version is running. 101 | - **ClusterName** is name of the ECS cluster 102 | - **ServiceName** is name of the service 103 | - **desired-count** is used to configure number of instantiations of the task to place and keep running in your service. 104 | 105 | Further details in relation with update-service command can be found on this page, [update-service](http://docs.aws.amazon.com/cli/latest/reference/ecs/update-service.html). 106 | 107 | 108 | ## Configure Jenkins Post-steps 109 | 110 | Jenkins post-steps can be configured to achieve following: 111 | 112 | ### Pushing images to Dockerhub; Register task definition; Update ECS 113 | 114 | ``` 115 | # Build the docker image 116 | sudo docker build -t ImageName:tag /var/jenkins_home/workspace/SpringBootApp 117 | 118 | # Login into Dockerhub; dockerhubLogin and dockerhubPassword is login and password respectively for dockerhub.com 119 | sudo docker login -u="dockerhubLogin" -p="dockerhubPassword" 120 | 121 | # Push docker image into Dockerhub 122 | sudo docker push ImageName:tag 123 | 124 | # Login using AWS CLI 125 | yes "" | aws configure --profile default ; aws ecr get-login > awslogin.sh ; sudo sh awslogin.sh 126 | 127 | # Register task definition` 128 | aws ecs register-task-definition --family TaskDefinitionFamily --container-definitions "[{\"name\":\"ContainerName\",\"image\":\"ImageName:tag\",\"memory\":300,\"portMappings\":[{\"hostPort\":0,\"containerPort\":8080,\"protocol\":\"tcp\"}]}]" 129 | 130 | # Update service 131 | aws ecs update-service --cluster ClusterName --service ServiceName --task-definition TaskDefinitionName --desired-count 2 132 | ``` 133 | In above code samples, note some of the following: 134 | - **ImageName:tag** is the image name. For example, ajitesh/springboot-web-app:latest. 135 | - **TaskDefinitionFamily** is the name of family for a task definition, which allows you to track multiple versions of the same task definition. The family is used as a name for your task definition. 136 | - **ContainerName** which is the name of the container. 137 | - **ClusterName** is the name of the ECS cluster 138 | - **ServiceName** is the name of the service 139 | 140 | ### Pushing images to ECR; Register the task definition ; Update the ECS service 141 | ``` 142 | # Login into AWS 143 | yes "" | aws configure --profile default ; aws ecr get-login > awslogin.sh ; sudo sh awslogin.sh 144 | 145 | # Build the docker image 146 | sudo docker build -t ImageName /var/jenkins_home/workspace/SpringBootApp 147 | 148 | # Tag the image; Push docker image into AWS ECR 149 | sudo docker tag ImageName:tag 153819127898.dkr.ecr.us-west-2.amazonaws.com/ImageName:tag 150 | sudo docker push AWS_ECR_URL/ImageName:tag 151 | 152 | # Register task definition` 153 | aws ecs register-task-definition --family TaskDefinitionFamily --container-definitions "[{\"name\":\"ContainerName\",\"image\":\"ImageName:tag\",\"memory\":300,\"portMappings\":[{\"hostPort\":0,\"containerPort\":8080,\"protocol\":\"tcp\"}]}]" 154 | 155 | # Update service 156 | aws ecs update-service --cluster ClusterName --service ServiceName --task-definition TaskDefinitionName --desired-count 2 157 | ``` 158 | 159 | ## Reference 160 | 161 | - [What is Amazon EC2 Container Service?](http://docs.aws.amazon.com/AmazonECS/latest/developerguide/Welcome.html) 162 | - [AWS CLI Commands](http://docs.aws.amazon.com/cli/latest/reference/) 163 | - [AWS ECS CLI Commands](http://docs.aws.amazon.com/cli/latest/reference/ecs/) 164 | - [Using the Amazon ECS Command Line Interface](http://docs.aws.amazon.com/AmazonECS/latest/developerguide/ECS_CLI.html) 165 | -------------------------------------------------------------------------------- /configure-jenkins-ecs-eb.md: -------------------------------------------------------------------------------- 1 | ## Configure Jenkins for Deploying Microservices on AWS ECS, Elastic Beanstalk 2 | 3 | 4 | -------------------------------------------------------------------------------- /containerize-springboot-microservice.md: -------------------------------------------------------------------------------- 1 | # Containerize Springboot Microservice 2 | 3 | Check out this sample project, [Springboot Microservice](https://github.com/eajitesh/Spring-Boot-Web-App-Template) which represents REST endpoints written using @RestController annotation. 4 | 5 | Following code represents the Dockerfile which is used to build the docker image for this microservice. 6 | 7 | ``` 8 | FROM frolvlad/alpine-oraclejdk8:slim 9 | VOLUME /tmp 10 | ADD target/demo-0.0.1-SNAPSHOT.jar app.jar 11 | RUN sh -c 'touch /app.jar' 12 | ENV JAVA_OPTS="" 13 | ENTRYPOINT [ "sh", "-c", "java $JAVA_OPTS -Djava.security.egd=file:/dev/./urandom -jar /app.jar" ] 14 | ``` 15 | 16 | Following represents a REST endpoint. Pay attention to usage of @RestController annotation. 17 | 18 | ``` 19 | package com.example; 20 | 21 | import org.springframework.beans.factory.annotation.Autowired; 22 | import org.springframework.web.bind.annotation.RequestMapping; 23 | import org.springframework.web.bind.annotation.RequestMethod; 24 | import org.springframework.web.bind.annotation.RequestParam; 25 | import org.springframework.web.bind.annotation.RestController; 26 | 27 | @RestController 28 | public class DoctorSearchController { 29 | 30 | @Autowired 31 | DoctorService docService; 32 | 33 | @RequestMapping(value="/doctors", method=RequestMethod.GET, produces="application/json") 34 | public DoctorList searchDoctor(@RequestParam(value="location", required=false) String location, 35 | @RequestParam(value="speciality", required=false) String speciality) { 36 | DoctorList docList = docService.find(location, speciality); 37 | return docList; 38 | } 39 | } 40 | ``` 41 | -------------------------------------------------------------------------------- /images/aws_eb.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/eajitesh/Continuous-Delivery-Microservices-AWS/55e0151b777d66f0d91790aa85cefc8998acf88b/images/aws_eb.png -------------------------------------------------------------------------------- /images/aws_ecs.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/eajitesh/Continuous-Delivery-Microservices-AWS/55e0151b777d66f0d91790aa85cefc8998acf88b/images/aws_ecs.png -------------------------------------------------------------------------------- /images/configure_build_triggers.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/eajitesh/Continuous-Delivery-Microservices-AWS/55e0151b777d66f0d91790aa85cefc8998acf88b/images/configure_build_triggers.png -------------------------------------------------------------------------------- /images/configure_gitlab_connections.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/eajitesh/Continuous-Delivery-Microservices-AWS/55e0151b777d66f0d91790aa85cefc8998acf88b/images/configure_gitlab_connections.png -------------------------------------------------------------------------------- /images/configure_gitlab_webhooks.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/eajitesh/Continuous-Delivery-Microservices-AWS/55e0151b777d66f0d91790aa85cefc8998acf88b/images/configure_gitlab_webhooks.png -------------------------------------------------------------------------------- /images/configure_scm.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/eajitesh/Continuous-Delivery-Microservices-AWS/55e0151b777d66f0d91790aa85cefc8998acf88b/images/configure_scm.png -------------------------------------------------------------------------------- /jenkins-gitlab-setup.md: -------------------------------------------------------------------------------- 1 | # Set up Jenkins-Gitlab 2 | 3 | Following are some of the key aspects of configuring Jenkins and GitLab and integrating them such that an event in GitLab will result in invocation of a Jenkins job using WebHooks. 4 | 5 | - Installing Jenkins Plugins 6 | - Configuring Jenkins 7 | - Configuring GitLab 8 | - Setup Jenkins/GitLab within Docker Containers 9 | 10 | ## Installing Jenkins Plugins 11 | 12 | Following are some of the plugins which is required to achieve the Jenkins/Gitlab integration, building Maven projects etc. 13 | 14 | - Gitlab, git client, git plugin 15 | - Maven integration plugin 16 | - You may choose to work with AWS plugins such as AWS ECS, AWS ECR plugins etc; However, the same could be achieved using shell script as a build post-steps. 17 | 18 | ## Configuring Jenkins 19 | 20 | Following needs to be configured within Jenkins for integrating with GitLab: 21 | 22 | - Go to Manage Jenkins/Configure System page 23 | - Configure Gitlab connections appropriately. The diagram below represents the same. 24 | 25 | ![Gitlab Connection Configuration](images/configure_gitlab_connections.png) 26 | 27 | - Go to Project dashboard. Click on Configure. 28 | - Configure "Source Code Management" appropriately as shown in the diagram below. 29 | 30 | ![Source Code Management Configuration](images/configure_scm.png) 31 | 32 | - Configure "Build Triggers" appropriately as shown in the diagram below. 33 | 34 | ![Build Triggers Configuration](images/configure_build_triggers.png) 35 | 36 | 37 | ## Configuring Gitlab 38 | 39 | A Webhook needs to be created for triggering Jenkins job based on one or more types of events which can be configured appropriately at the time of creating WebHooks. Go to project page in GitLab. Click on "Integrations" link which shows up as one of the link options in vertical menu which appears by clicking on settings button found on top right part of the page. 40 | 41 | ![Gitlab Webhooks Configuration](images/configure_gitlab_webhooks.png) 42 | 43 | 44 | ## Setup Jenkins/GitLab within Docker Containers 45 | 46 | The project was executed with GitLab and Jenkins installed in seperate containers. Following docker-compose.yml file could be used to setup both Jenkins and Gitlab in seperate containers. 47 | ``` 48 | version: '2' 49 | 50 | networks: 51 | prodnetwork: 52 | driver: bridge 53 | 54 | services: 55 | jenkins: 56 | image: jenkins 57 | ports: 58 | - "18080:8080" 59 | networks: 60 | - prodnetwork 61 | volumes: 62 | - /var/run/docker.sock:/var/run/docker.sock 63 | - /usr/local/bin/docker:/usr/bin/docker 64 | - /opt/jenkins/:/var/lib/jenkins/ 65 | depends_on: 66 | - gitlab 67 | 68 | gitlab: 69 | image: gitlab/gitlab-ce 70 | restart: always 71 | networks: 72 | - prodnetwork 73 | environment: 74 | GITLAB_OMNIBUS_CONFIG: | 75 | # external_url 'https://gitlab.example.com' 76 | # Add any other gitlab.rb configuration here, each on its own line 77 | ports: 78 | - "80:80" 79 | - "443:443" 80 | - "2222:22" 81 | volumes: 82 | - /opt/gitlab/config:/etc/gitlab 83 | - /opt/gitlab/logs:/var/log/gitlab 84 | - /opt/gitlab/data:/var/opt/gitlab 85 | ``` 86 | In case of running this docker-compose file on Linux/Ubuntu, change the volume under jenkins from "- /usr/local/bin/docker:/usr/bin/docker" to "- /usr/bin/docker:/usr/bin/docker" 87 | 88 | ## Jenkins Image with AWS & EB Utility 89 | 90 | To be able to access the AWS and EB CLI commands from Jenkins, you may need to include the code for installing them in Jenkins Dockerfile. 91 | 92 | Get the docker image for Jenkins with AWS & EB CLI utility from this page, [Docker image for Jenkins with AWS & EB CLI Utility](https://github.com/eajitesh/docker). 93 | 94 | This image also takes care of the issues such as (add jenkins to Sudoers file etc) in relation with executing Docker commands from within Jenkins as part of Post-steps. 95 | --------------------------------------------------------------------------------