DevOps Training
  • DevOps
  • What is DevOps
    • What DevOps Look like
    • Why DevOps Needed
    • DevOps Automation Tools
    • DevOps Principles
  • cloud computing
    • How DevOps links with Cloud Computing
    • What is cloud computing?
      • Platform as a service (PaaS)
      • Infrastructure as a service (IaaS)
      • Software as a service (SaaS)
      • Function as a Service
      • SaaS, PaaS, IaaS
  • Version Control
    • Git as Version Control
      • Setting up Remote Repo
      • Git Hooks
      • github vs gitlab vs bitbucket
      • Quick Recap Git
  • DevOps #01 Continuous Integration
    • Continuous Integration & Continuous Delivery
      • Understanding CI Tools
      • Prerequisite
      • Continuous Integration
      • CI Tools
      • Travis-CI
        • Travis CI with S3
        • Static Site Build S3
        • Beanstalk with AWS CLI
          • Elastic Beanstalk with Travis CI
        • Travis using Code Deploy EC2
          • Github and Code Deploy
          • Travis CI with Code Deploy
      • Gitlab-CI
        • CI Setup for application
        • Gitlab Runners on EC2
        • CI Integration with AWS
          • Deploying App using Gitlab CI
          • Gitlab CI with AWS S3
          • Gitlab CI with ECS
          • CI Integration with EC2
            • Update and Clean Gitlab.yml
        • Install Gitlab on EC2
      • CI/CD using Jenkins CI
        • Jenkins Build on EC2
        • Jenkins Build EC2 Ubuntu
        • Jenkins CI/CD
          • Create a Build Item
          • Create a Build Pipleine
            • Pipeline Using Docker
            • Pipeline Examples
          • Jenkins CI with S3
            • Jenkins CI - S3
          • Jenkins CI with EC2
    • Jenkins CI Cluster Mode
    • AWS Code Pipeline CI/CD
      • AWS CI/CD Tools
        • AWS Code Build
        • AWS Code Deploy to Beanstalk
        • AWS Code Deploy to EC2
        • AWS Pipeline - Example CI/CD
  • Docker
    • Docker
      • Docker for Developers
        • Install and setup
        • Docker Commands
        • Docker Images Container
        • Docker Architecture
    • Docker Demos
      • Node JS Container
    • Docker-compose
      • Using Docker Compose
      • Docker Compose Demo
  • AWS Quick Refresh
    • AWS Quick Recap - Videos
    • AWS Quick Recap
  • AWS Architecture - Lab
    • Application Deployment - 01
    • Application Deployment - 02
    • Application 3 tier Architecture
  • Basic Networking
    • Computer Networking for Beginners
      • Basic of Networking
      • Networking Protocols
      • OSI Model
      • Network address and Host address
      • Subnetting Type
    • Network Architecture
    • Networking Layers OSI Model
    • Internet protocol
      • CIDR and subnetting
        • Examples
      • AWS VPC Subnets
  • VPC and Networking
    • AWS VPC
    • VPC Demo
      • Bastion Host | Jump Server
  • AWS Components
    • AWS Components In Depth
      • AWS Storage
        • AWS EBS
        • AWS Cloudfront
        • AWS S3
      • AWS Compute
        • ECS
        • AWS VPC
          • VPC Components
        • AWS EC2
        • AWS ELB
          • Application Load balancer
            • Example
        • AWS EC2 Auto Scaling
          • Demo
        • AWS Route 53
        • AWS Lambda Serverless
          • AWS Lambda Serverless Computing
  • Assignments
    • Assignment 01-Node JS app on EC2
    • Assignment 02-Node JS with Mysql
    • Assignment-03
  • Microservices
    • Microservices Architecture
      • Docker and Docker-Compose
      • Docker-Compose Example 01
      • Docker-Compose Example 02
      • Hand-on | Building Microservices
    • Architecture Components
  • AWS ECS
    • AWS ECS
      • Introduction of ECS
Powered by GitBook
On this page
  • S3
  • CloudFront
  • IAM
  • TravisCI

Was this helpful?

  1. DevOps #01 Continuous Integration
  2. Continuous Integration & Continuous Delivery
  3. Travis-CI

Travis CI with S3

PreviousTravis-CINextStatic Site Build S3

Last updated 5 years ago

Was this helpful?

TravisCI is free only in open source projects. It is an easy to use and highly popular service. Using GitHub, we will be able to manage the Continuous Deployment process. For this, we will use Amazon’s S3 and CloudFront services.

pipeline setup for travis CI/CD Setup

S3

Now, as a first step, we should create a bucket in S3 service and edit its policy to make it public.

You can add this code using the editor. Be sure to change the example-bucketfield to your bucket name.

Then, enable static website hosting in the properties area.

You now have a public S3 bucket. By the way, don’t forget change the index document field to your root HTML file name. Finally S3 bucket is ready, let’s it ready CloudFront now.

{
    "Version": "2012-10-17",
    "Statement": [
        {
            "Sid": "AllowPublicRead",
            "Effect": "Allow",
            "Principal": {
                "AWS": "*"
            },
            "Action": [
                "s3:AbortMultipartUpload",
                "s3:DeleteObject",
                "s3:GetObject",
                "s3:GetObjectAcl",
                "s3:PutObject",
                "s3:PutObjectAcl"
            ],
            "Resource": "arn:aws:s3:::bucket/*"
        }
    ]
}

CloudFront

Next step, you have to open the CloudFront service and create a new distribution.

In this area, you should edit the Origin Domain Name field to choose name of S3 Bucket’s you want to use and must be write into Default Root Object field your root HTML file name. This will take some time to be ready. Don’t worry. Don’t forget the Distribution ID, we will need it. Please, take a note.

IAM

Using IAM, to access S3 and CloudFront from the TravisCI we need to allow. So we need to add AmazonS3FullAccess and CloudFrontFullAccesspermissions our account.

TravisCI

We need to create a .travis.yml file and we will configure this file. We’re going to need some secret keys, we need to add them on the Travis.

Our .travis.yml file should be as shown below:

warnings_are_errors: false
language: node_js
node_js:
  - '10'
  - node
install:
- yarn global add travis-ci-cloudfront-invalidation
- yarn
script:
- CI=false yarn build
deploy:
  provider: s3
  access_key_id: $AWS_ACCESS_ID
  secret_access_key: $AWS_SECRET_ID
  bucket: 'catchtheday.com'
  local_dir: build
  region: us-west-2
  skip_cleanup: true
  on:
    branch: master
after_deploy:
  - travis-ci-cloudfront-invalidation -a $AWS_ACCESS_ID -s $AWS_SECRET_ID -c $CF_ID -i '/*' -b $TRAVIS_BRANCH -p $TRAVIS_PULL_REQUEST

Why did we use the travis-ci-cloudfront-invalidation package? You can read this source for the answer:

Search for the keywords to learn more about each warning.
To ignore, add // eslint-disable-next-line to the line before.
File sizes after gzip:
  65.1 KB  build/static/js/2.5e5cab2f.chunk.js
  2.67 KB  build/static/js/main.f4d26a5b.chunk.js
  1.74 KB  build/static/css/main.e818454e.chunk.css
  762 B    build/static/js/runtime~main.a8a9905a.js
The project was built assuming it is hosted at the server root.
You can control this with the homepage field in your package.json.
For example, add this to build it for GitHub Pages:
  "homepage" : "http://myname.github.io/myapp",
The build folder is ready to be deployed.
You may serve it with a static server:
  yarn global add serve
  serve -s build
Find out more about deployment here:
  https://bit.ly/CRA-deploy
Done in 13.69s.
The command "CI=false yarn build" exited with 0.
dpl_0
2.45s$ rvm $(travis_internal_ruby) --fuzzy do ruby -S gem install dpl
Successfully installed dpl-1.10.11
1 gem installed
8.57s
dpl.1
Installing deploy dependencies
Successfully installed jmespath-1.4.0
Successfully installed aws-eventstream-1.0.3
Successfully installed aws-sigv4-1.1.0
Successfully installed aws-sdk-core-2.11.304
Successfully installed aws-sdk-resources-2.11.304
Successfully installed aws-sdk-2.11.304
Successfully installed mime-types-data-3.2019.0331
Successfully installed mime-types-3.2.2
Successfully installed dpl-s3-1.10.11
9 gems installed
Logging in with Access Key: ****************&&&&
Beginning upload of 12 files with 5 threads.
dpl.2
Preparing deploy
dpl.3
Deploying application
uploading "index.html" with {:content_type=>"text/html"}
uploading "static/js/runtime~main.a8a9905a.js.map" with {:content_type=>""}
uploading "asset-manifest.json" with {:content_type=>"application/json"}
uploading "precache-manifest.a945bef9e23e3fdfdd3a5bc84ed1654a.js" with {:content_type=>"application/javascript"}
uploading "service-worker.js" with {:content_type=>"application/javascript"}
uploading "static/js/main.f4d26a5b.chunk.js" with {:content_type=>"application/javascript"}
uploading "static/js/main.f4d26a5b.chunk.js.map" with {:content_type=>""}
uploading "static/js/runtime~main.a8a9905a.js" with {:content_type=>"application/javascript"}
uploading "static/js/2.5e5cab2f.chunk.js" with {:content_type=>"application/javascript"}
uploading "static/js/2.5e5cab2f.chunk.js.map" with {:content_type=>""}
uploading "static/css/main.e818454e.chunk.css.map" with {:content_type=>""}
uploading "static/css/main.e818454e.chunk.css" with {:content_type=>"text/css"}
after_deploy
0.47s$ travis-ci-cloudfront-invalidation -a $AWS_ACCESS_ID -s $AWS_SECRET_ID -c $CF_ID -i '/*' -b $TRAVIS_BRANCH -p $TRAVIS_PULL_REQUEST
2019-06-27T08:27:13.419Z - error: Error invalidating CloudFront Cache: {"message":"User: arn:aws:iam::736998360651:user/testCI is not authorized to perform: cloudfront:CreateInvalidation","code":"AccessDenied","time":"2019-06-27T08:27:13.416Z","requestId":"5d5c67a7-98b5-11e9-b947-ed27eb0a7763","statusCode":403,"retryable":false,"retryDelay":68.32954804381812}
Done. Your build exited with 0.

https://docs.aws.amazon.com/en_us/AmazonS3/latest/dev/example-bucket-policies.html
https://docs.aws.amazon.com/en_us/AmazonS3/latest/dev/using-with-s3-actions.html
Logonpm: travis-ci-cloudfront-invalidationnpm
LogoGitHub - tkssharma/DevOpsTraining: DevOpsTrainingGitHub