Giter Site home page Giter Site logo

jenkins-terraform-microservice's Introduction

jenkins-terraform-microservice

A demo project of a (Java) microservice, deployed via a Jenkins pipeline to AWS ElasticBeanstalk provisioned by terraform scripts.

The deployment pipeline looks like this: Pipeline

Goals

  • Staging and production environments
  • Infrastructure is defined in the same repository as the microservice application code
  • Minimal boilerplate needed to reduce repetition in each microservice

Set up

Create a Github Organization Folder in your jenkins instance and configure the github organization name. You can use mine (ulich) or you can fork the repository and configure your name. If you get "Github Quota Exceeded" messages, you should configure credentials and provide your Github username + Api Key.

Jenkins will now scan the github organization for any repository with a Jenkinsfile in it and it should create a job named jenkins-terraform-microservice.

Make sure your jenkins instance is able to connect to AWS by either using IAM roles if your jenkins instance is running on an ec2 instance or by setting up the aws cli with your secret key.

Jenkins pipeline

The Jenkinsfile uses a utility method from ulich/jenkins-pipeline-library.

This is what happens inside the pipeline (pseudo-code):

build_app

# deploy to staging
# -----------------

terraform init
terraform workspace select default
terraform plan -out staging-planfile
if (staging-planfile contains changes) {
    wait_for_approval "check the console output of the terraform plan"
    terraform apply staging-planfile
}
eb deploy


wait_for_approval "check that staging still works"


# deploy to prod
# --------------

terraform workspace select prod
terraform plan -out prod-planfile
if (prod-planfile contains changes) {
    wait_for_approval "check the console output of the terraform plan"
    terraform apply prod-planfile
}
eb deploy

Terraform

The infrastructure folder contains terraform scripts that define the infrastructure needed for this microservice. It uses a terraform module to reduce the amount of code needed in each microservice repository.

You could define additional resources needed for the microservice (database instances, etc.) in this folder.

You are maybe wondering where the provider or S3 state bucket configuration is. It is generated by the Jenkins pipeline#generateTerraformConfig method in order to reduce the boilerplate needed in each microservice.

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.