GithubHelp home page GithubHelp logo

uvsmtid / turbo-banyan Goto Github PK

View Code? Open in Web Editor NEW
0.0 1.0 0.0 128 KB

Demo CI/CD pipeline defined via AWS CloudFormation for a service with REST API and MySQL database.

License: MIT License

Shell 11.12% Dockerfile 0.60% Java 87.80% TSQL 0.48%
aws ci ci-cd cd cd-pipeline cicd mysql rest rest-api cfn

turbo-banyan's Introduction

What is this?

This is a demo service with:

  • REST interface
  • MySQL backend database
  • AWS CloudFormation to provision its CI/CD pipeline

Follow sections from trivial to complex:

You may want to jump directly to C.

Depending on the section - Git, Java, Maven, Docker, AWS CLI, ... are assumed functional on the local machine.

Configuration before the start

Ultimately, the demo is about CI/CD pipeline in AWS integrated with github.com.

The following steps explain and prepare parameters for aws-cnf-stack.conf configuration file.

  • Specify your AWS account and please stick with specific AWS region.

    AWS_ACCOUNT="243535590163"
    

    Obviously, the IAM user under this account (for aws CLI configuration) needs necessary permissions.

    This demo was only tested in the following region (preferred as aws-cfn-stack.yaml template may lack additional Mappings):

    AWS_REGION="ap-southeast-1"
  • Use your own github.com account to be watched by the pipeline.

    Make a fork of this repository:

    https://github.com/uvsmtid/turbo-banyan

    Your github.com account will subsequently be referenced via this environment variable (replace uvsmtid):

    GIT_HUB_ACCOUNT="uvsmtid"
  • Generate new API token on github.com and store it in AWS Secrets Manager.

    The name of the secret will be stored in this environment variable:

    GIT_HUB_API_TOKEN_SECRET_NAME="turbo-banyan-github-token"

    NOTE: https://docs.aws.amazon.com/codepipeline/latest/userguide/update-change-detection.html

    The token and webhook require the following GitHub scopes:

    • repo - used for full control to read and pull artifacts from public and private repositories into a pipeline.
    • admin:repo_hook - used for full control of repository hooks.

    Create the token: https://github.com/settings/tokens

    Store token value into AWS secret (replace 0000000000000000000000000000000000000000):

    # NOTE: this command has issues of being extremely slow to execute (up to few minutes).
    aws \
        secretsmanager \
        create-secret \
        --region "${AWS_REGION}" \
        --name "${GIT_HUB_API_TOKEN_SECRET_NAME}" \
        --secret-string '{"token":"0000000000000000000000000000000000000000"}'

A: Start via sources

If started via sources, the service uses embedded in-memory database.

  • Start the service (in one terminal):

    mvn clean test && mvn exec:java \
        -Dspring.profiles.active=local-dev \
        --projects=turbo-banyan-student-service
  • Test the service (in another terminal):

    root_url="http://localhost:8080/"
    ./run-test-requests.sh "${root_url}"

    Or use Swagger UI: http://localhost:8080/swagger-ui/

B: Start via images

If started via images, the service requires available MySQL instance with initialised database.

TODO: Consider managing both Docker instances via docker-compose.

  • Start a database instance:

    docker run \
        --name mysql-instance \
        --rm \
        -p 3306:3306 \
        -p 33060:33060 \
        -e MYSQL_ROOT_HOST='%' \
        -e MYSQL_ROOT_PASSWORD=root_turbo_banyan_password \
        -d mysql:latest

    Please wait - MySQL startup normally takes around 30 sec.

  • Init the database:

    docker exec \
        mysql-instance \
        mysql \
        -hlocalhost \
        -uroot \
        -proot_turbo_banyan_password \
        -e "$(cat turbo-banyan-student-service/src/main/resources/database/init-database.sql)"
  • Build a service image:

    mvn package
  • Run a service image:

    docker run \
        --rm \
        -p 8080:8080 \
        -e SPRING_DATASOURCE_URL='jdbc:mysql://localhost:3306/turbo_banyan_database' \
        -e SPRING_DATASOURCE_USERNAME='turbo_banyan_username' \
        -e SPRING_DATASOURCE_PASSWORD='turbo_banyan_password' \
        --network=host \
        uvsmtid/turbo-banyan-student-service:latest
    
  • Test the service:

    root_url="http://localhost:8080/"
    ./run-test-requests.sh "${root_url}"

    Or use Swagger UI: http://localhost:8080/swagger-ui/

C: Start via CI/CD

Check configuration before the start.

  • Create the pipeline:

    TODO: Consider modifying script to merge create and update operations into one (e.g. push)

    ./aws-cfn-stack.sh create

    Monitor provisioning of the pipeline - it may take several minutes:

    https://console.aws.amazon.com/cloudformation

    If changes are necessary, use update command subsequently:

    ./aws-cfn-stack.sh update
  • Push a commit (e.g. modify readme.md) to trigger the pipeline:

    echo "" >> readme.md && \
    git add . && \
    git commit -m "Add empty new line to readme.md" && \
    git push origin

    Monitor pipeline execution - it may take several minutes:

    https://console.aws.amazon.com/codesuite/codepipeline/pipelines

  • Test the service:

    Find DNS name of the relevant balancer in DNSName field:

    source aws-cfn-stack.conf
    
    aws elbv2 \
        describe-load-balancers \
        --region "${AWS_REGION}"

    Use the DNS name as hostname for the root_url:

    root_url="http://${load_balancer_dns_name}/"
    ./run-test-requests.sh "${root_url}"

    Or use Swagger UI: http://${load_balancer_dns_name}/swagger-ui/

Tear down CI/CD

  • Delete the pipeline:

    ./aws-cfn-stack.sh delete

References


turbo-banyan's People

Contributors

uvsmtid 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.