Friday, January 25, 2019

How To Build CI/CD Pipeline via Wercker in K8S

Requirement

We try to build an sample CI/CD pipeline to increase efficiency of development and deployment.It is also core part of devops methodology. With power of OKE(Oracle Kubernets Engine) and Wercker (Cloud based CI/CD tool Oracle acquired),"We can automatically build, test and deploy their applications, end-to-end, all the way from source to production in a repeatable transparent manner." Quote from Oracle CloudNative Lab Wercker Guide. More details please refer Wercker Doc

Preparation

  • Create Github account link
  • We can use github account Oauth to login Wercker
  • Login Github,create a new private repository in Github. ie iridize-oci-oke-project
  • Login Wercker via github sign-in, authorize wercker to access github .
    • On top right, click "add application"
    • Select user and SCM using the github account
    • Find the new private repository we just created
    • Let Wercker add deployment key for this private repository in github
    • In the first page of wercker, choose language or just create default wercker.yml
    • Copy and paste the wercker.yml into the Github repository
    • You would see a build is triggered in wercker as it detects a change in the repository

Implementation Steps On the Cloud

Create CI/CD for Postgresql Docker Image
  • Generate wercker.yml
box: postgres:9.3
build:
   steps:
      - internal/docker-build:
        dockerfile: Postgres-Dockerfile
        image-name: postgresimage
        
      - internal/docker-push:
        # specify the image to be pushed - this is the one we created earlier
        image-name: postgresimage
        username: $OCIRUSERNAME # Registry username
        password: $OCIRPASSWORD # Registry password
        registry: https://iad.ocir.io/v2
        repository: $IRIDIZEREPO
        tag: $VERSION
  • Copy the Postgres-dockerfile
FROM postgres:9.3
RUN mkdir -p /var/lib/postgresql-static-test/data
ENV PGDATA /var/lib/postgresql-static-test/data
  • Add Application environment variables in app.wercker.com
Application environment variables screenshot
  • Do a test update on Postgres-dockerfile or wercker.yml , the CI/CD pipeline will start automatically. rebuild the docker images and deploy it to OCIR without intervention

Implementation Steps Locally via CLI

  • Download Wercker CLI locally. More details refer doc
    • In linux where has docker running,download CLI via below command
    curl -L https://s3.amazonaws.com/downloads.wercker.com/cli/stable/linux_amd64/wercker -o /usr/local/bin/wercker
    chmod u+x /usr/local/bin/wercker
    
  • Use "wercker build" Please refer more details in wercker doc

No comments: