CICD Pipeline Part2
Category : DevOps Tag : streamlit docker 101series
June 1, 2021, midnight

Short Description :
CICD explanation. Part 2 focuses on how to create CICD script using travis and setup AWS EB
source : datak

<h2>About</h2><p>In&nbsp;<a href="https://datak.biz/blog/detail/43/" target="_blank">Part 1</a>, we reviewed how to create `Dockerfile` using streamlit application. In the part2, we will review how to use CI service, travis and how to create CICD script through AWS elastic beanstalk service.</p><h2>What is Travis?</h2><p>Travis is a hosted continuous integration service and is used to build and test software projects directly connected to github. This enables automation from git repo to pushing to application cloud server with test and other script integrated such as docker build. Travis also holds environmental variables and passes to the script</p><h2>CI Script</h2><p>Script for Travis CI is build in `.travis.yml` right under project directly. Below is the script used for the project.</p><pre># shell script cd &lt;project directly&gt; vim .travis.yml</pre><pre># .travis.yml #specify main language language: generic #superuser permission sudo: required services: &nbsp;&nbsp;&nbsp;&nbsp;- docker #no test script this time #deploy info deploy: &nbsp;&nbsp;&nbsp;&nbsp;provide: elasticbeanstalk &nbsp;&nbsp;&nbsp;&nbsp;region: "us-west-2"&nbsp;&nbsp;&nbsp;&nbsp;#from AWS URL &nbsp;&nbsp;&nbsp;&nbsp;app: "docker-st-efmc"&nbsp;&nbsp;&nbsp;&nbsp;#same name from AWS &nbsp;&nbsp;&nbsp;&nbsp;env: "dockerstefmc-env"&nbsp;&nbsp;&nbsp;&nbsp;#environment name from AWS &nbsp;&nbsp;&nbsp;&nbsp;bucket_name: &lt;your bucket name&gt;&nbsp;&nbsp;&nbsp;&nbsp;#search from S3 in AWS &nbsp;&nbsp;&nbsp;&nbsp;bucket_path: "docker-st-efmc"&nbsp;&nbsp;&nbsp;&nbsp;#same name as the App &nbsp;&nbsp;&nbsp;&nbsp;on: &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;branch: master&nbsp;&nbsp;&nbsp;&nbsp;#master branch in github to trigger the scripts run &nbsp;&nbsp;&nbsp;&nbsp;access_key_id: $AWS_ACCESS_KEY&nbsp;&nbsp;&nbsp;&nbsp;#to be passed from travis &nbsp;&nbsp;&nbsp;&nbsp;secret_access_key: $AWS_SECRET_KEY&nbsp;&nbsp;&nbsp;&nbsp;#to be passed from travis </pre><p><br></p><h2>Travis setup</h2><p>Go to `travis-ci.com` and login and authenticate your github repo, then you will see all of github repo in travis dashboard</p><p><img src="/media/django-summernote/2021-06-02/980bf198-0a48-4e6e-a450-1ca44c0ec095.png" style="width: 100%;"></p><p><br></p><p><br></p><p><br></p><h2>What is AWS Elastic Beanstalk?</h2><p>AWS Elastic Beanstalk is an orchestration service offered by AWS for deploying applications which orchestrates various AWS services, including EC2, S3, and load balancers. In this blog we are using dingle docker container for a deployment, but EB can scale to multiple container used by docker-compose which will be documented in the near future.</p><h2>Elastic Beanstalk setup</h2><ul><li>Login to AWS</li><li>At search box, search `Elastic Beanstalk`</li><li>At EB page, `create a new environment` at top right button</li><li>Select `web server environment` then `Select` button</li><li><img src="/media/django-summernote/2021-06-02/394e52a0-9f4c-4c60-8bb4-fdc4dcc0daea.png" style="width: 100%;"><br></li><li>Fill out app info accordingly. Note that select `docker` at platform, and select `Docker running on 64bit Amazon Linux` so AWS searches `Dockerfile` at project directory. Push `Configure more options` at bottom</li><li><img src="/media/django-summernote/2021-06-02/e16cacb4-7e92-4f68-a50c-73c4ef48f13d.png" style="width: 100%;"></li><li>Make sure that you select `single instance` (free tier eligible) if you prefer minimum scaling and minimum cost. Finally push `Create environment`</li><li><img src="/media/django-summernote/2021-06-02/78e0e048-8643-4cbc-aaec-e53c987557ab.png" style="width: 100%;"></li><li>Region will be seen at environment app page. Go to environment at left pane and push your environment name. You will find your region at the docker URL. My case is "us-west-2".</li><li><img src="/media/django-summernote/2021-06-02/5450089e-398f-4384-a3ed-b35ef8c6e07c.png" style="width: 100%;"><br></li><li>Bucket list can be found at S3. At AWS app search box, type `S3`. Amazon S3 is an acronym of `Simple Storage Service` and is the service offered by AWS that provides object storage through a web service interface. S3 uses the same scaleble storage infrastructure that Amazon.com uses to run its EC services.</li><li><img src="/media/django-summernote/2021-06-02/fd99dee3-3726-4f34-81d1-6cc3c2af4386.png" style="width: 100%;"><br></li></ul><h3>IAM security in AWS</h3><ul><li>IAM is centralized access control for AWS services. IAM stands for Identify and Access Management. Need to create a policy that applies to the application, actually travis needs secret key with a certain roll so travis deploy and make changes in AWS. Go to AWS search box and type `IAM` to go to IAM page.</li><li>Go to `Users` at left pane and push `Add User` button.&nbsp;</li><li>Fill out user name and select `Programmatic Access` then push `Next: Permissions`</li><li><img src="/media/django-summernote/2021-06-02/28fa74f9-adbf-4741-b7b6-91661b85ab84.png" style="width: 100%;"></li><li>Select `Attach existing policies directly`. And filter by `elasticbeanstalk` and select `administrato access` then push `Next: Tags`</li><li><img src="/media/django-summernote/2021-06-02/ed60326a-3cf2-48cc-92a4-1d05531c9f4f.png" style="width: 100%;"><br></li><li>No tag is needed</li><li>Copy the Access Key ID and Secret Acces key to use in the Travis Variables Set up</li></ul><p><br></p><h2>Environmental Variables in Travis</h2><p>In travis web site, go to your actual project which is exact same git repo name from github. Open `More options` at right top pull down, and select `Settings`.</p><p><img src="/media/django-summernote/2021-06-02/91a1ff70-d1ee-41d6-88ee-b17bedba0392.png" style="width: 100%;"></p><p>Under `Environment Variables`, you can create your own variables with the password. Push `Add` to save.</p>


<< Back to Blog Posts
Back to Home

Related Posts

Docker 101 : Basic Commands
Nov 28 2020
Basic commands for docker operation, such as build, run, and going into container etc.
CICD Pipeline Part1
Jun 1 2021
CICD explanation. Part 1 focuses on how to locally create a docker container using python streamlit
CICD Pipeline Part3
Jun 2 2021
CICD explanation. Part3 includes demo on CICD pipeline automation
CICD Pipeline Part4
Jun 2 2021
CICD explanation. Part4 includes sub-domain assignment using google domain



© DATAK 2024