Skip to content

beyowi/semaphore-demo-cicd-kubernetes

 
 

Repository files navigation

A Companion Demo for the CI/CD with Docker and Kubernetes Book

Run it in your workstation

$ docker-compose up --build
$ curl -w "\n" -X PUT -d "firstName=al&lastName=pacino" 127.0.0.1:3000/person
$ curl -w "\n" 127.0.0.1:3000/all

CI/CD Pipelines

The CI/CD workflow is as follows:

  1. Build docker image w/cache.
  2. Run tests inside docker images.
  3. Push image to docker registry.
  4. Perform canary deployment.
  5. Run functional test and migration in canary deployment.
  6. One-click production/stable deployment.

Workflow

Configure Semaphore

  1. Fork this repository
  2. Clone it to your machine
  3. Sign up for Semaphore and install sem cli.
  4. Add the project to Semaphore:
$ sem init

Deploy to the cloud

Cloud services required:

  • Kubernetes Cluster (recommended 3 nodes) called semaphore-demo-cicd-kubernetes
  • PostgreSQL Database in the same region and VPC as the cluster.

Open the relevant pipeline files at .semaphore and fill in the environment variables for the blocks. Uncomment the desired promotion on .semaphore/semaphore.yml.

Create Secrets

Create DB connection secret:

    $ sem create secret db-params \e
        -e DB_USER=YOUR_DB_USERNAME \
        -e DB_PASSWORD=YOUR_DB_PASSWORD \
        -e DB_HOST=YOUR_DB_IP \
        -e DB_PORT=YOUR_DB_PORT (5432) \
        -e DB_SCHEMA=YOUR_DB_SCHEMA (postgres) \
        -e DB_SSL=true|false (empty)

Depending on the cloud provider, you’ll need to create different secrets.

AWS

  • Create an IAM User with Administrator permissions. Create a secret with the access id and the Kubernetes kubeconfig file:
$ sem create secret aws-key \
    -e AWS_ACCESS_KEY_ID=YOUR_AWS_ACCESS_ID \
    -e AWS_SECRET_ACCESS_KEY=YOUR_AWS_SECRET_KEY \
    -f YOUR_KUBECONFIG.yml:/home/semaphore/aws-key.yml

Google Cloud

  • Create a project called semaphore-demo-cicd-kubernetes
  • Create service account and generate a key file. Upload the file to Semaphore:
$ sem create secret gcp-key -f YOUR_KEY_FILE.json:/home/semaphore/gcp-key.json

DigitalOcean

  • Create a project called semaphore-demo-cicd-kubernetes and set it as default.
  • Get your authentication API Token and create a secret for it:
$ sem create secret do-key -e DO_ACCESS_TOKEN=YOUR_DIGITALOCEAN_TOKEN
  • Set the parameter in db-params secret to DB_SSL=true

  • Create a secret to store your DockerHub credentials:

$ sem create secret dockerhub \
    -e DOCKER_USERNAME=YOUR_DOCKERHUB_USER \
    -e DOCKRE_PASSWORD=YOUR_DOCKERHUB_PASSWORD

License

Copyright (c) 2019 Rendered Text

Distributed under the MIT License. See the file LICENSE.md.

About

A Companion Demo for the CI/CD for Docker and Kubernetes Book

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • JavaScript 82.5%
  • Shell 12.1%
  • Dockerfile 5.4%