A starting point for automating the creation of microservices and all its Ops costs with a single click.
Having a way of rapidly creating and deploying microservices is a prerequisite if you want to do serious microservices. It should be easy, so that we can focus on business, the thing that makes us unique.
This project serves as a starting point for automating all the operational setup cost associated to creating new microservices with a single click.
The central pieces of this solution are Docker, Jenkins, the Jenkins Job-DSL plugin and Gogs (it should be easy for you to adapt it to work with any other Git Server though, like GitHub or BitBucket).
We use Docker to run Jenkins and Gogs. Jenkins itself has access to Docker in a Docker-outside-of-Docker approach, i.e. we map the host's Docker socket, so that containers started by Jenkins will be siblings.
We have prepared two repositories into Gogs (our Git server):
One of the pipelines is the create_microservice pipeline that fulfills the promise of creating microservices with one click. What it does:
The microservice's pipeline anatomy:
Both the create_microservice pipeline and the microservice's pipeline again are easy for you to adapt and extend to your needs.
Good examples of extending the create_microservice pipeline are adding steps to create metrics dashboards and monitoring alerts for your new microservice.
An obvious example of adapting the microservice's pipeline is changing how / where it deploys the service.
Let's get hands on next!
Clone this repository
Run ./run.sh (the first time it might take a couple of minutes since it needs to build the Jenkins docker image)
Now you got Jenkins and Gogs running (the repositories on Gogs can be explored at http://localhost:3000/explore/repos if you'd like)
Browse to Jenkins at http://localhost:8080
Run the seed job (the first time it might take a few seconds because it downloads libs and runs tests before effectively updating the jobs)
Go to the all_pipelines view (or create_microservice view, but all_pipelines is especially good because you can see everything that will happen)
Run the create_microservice pipeline (provide a service name, i.e. good_service and the port that it shall listen to, e.g. 8000)
Wait for the pipeline to finish and for the seed job to run again
Voilà! You have a brand new pipeline for your microservice. Trigger it to get your microservice up and running
After the deployment is done, you can check your microservice echo Hello World! (e.g. http://localhost:8000)
Enjoy and maybe create some more microservices :)
Now that you have a solution for easily creating microservices, one thing will happen: you WILL create lots of microservices. And in order to be able to maintain them, you'll need the proper mindset. A few tips:
Note there is quite some Inception here, so just remember to carry your totem with you and have fun! :)
If you would like to help making this project better, see the CONTRIBUTING.md.
Send any other comments, flowers and suggestions to André Schaffer and Tommy Tynjä.
This project is distributed under the MIT License.