updated pipeline

I’ve updated this blog to use a new Jekyll theme, as well as the CICD pipeline for automated delivery. I hacked together a method of replacing the ECS Container task without the load balancer, though it may result in badly cached responses. Still looking for the best way to handle this without paying Amazon extra load balancing fees.

The updated pipeline includes the following:

  1. AWS CodeCommit Lambda trigger on push to master
  2. AWS Lambda triggers AWS CodeBuild project
  3. AWS CodeBuild project uses the following buildspec.yml
  4. AWS CodeBuild builds the container, uploads to the AWS ECR, stops the current task, and purges CloudFront

CAVEAT: AWS CodeBuild Ubuntu Docker builder uses Ubuntu 14.04 LTS. Unfortunately I need Ruby 2.1+ for some Jekyll dependencies.

Below it uses rbenv as a method to install Ruby 2.3+. The problem is the build process takes ~6 minutes due to the apt dependencies and the installation of Ruby 2.3. My plan at this point is to build a new base container that is includes all of these, and use Docker multi-stage build process to make this faster.

version: 0.2

      - echo Logging in to Amazon ECR...
      - $(aws ecr get-login --region $AWS_DEFAULT_REGION)
      - echo Build started on `date`
      - echo Running apt-get update
      - apt-get update
      - apt-get install git-core curl zlib1g-dev build-essential libssl-dev libreadline-dev libyaml-dev libsqlite3-dev sqlite3 libxml2-dev libxslt1-dev libcurl4-openssl-dev python-software-properties libffi-dev -qq
      - git clone https://github.com/rbenv/rbenv.git ~/.rbenv
      - export PATH="$HOME/.rbenv/bin:$PATH"
      - eval "$(rbenv init -)"
      - git clone https://github.com/rbenv/ruby-build.git ~/.rbenv/plugins/ruby-build
      - export PATH="$HOME/.rbenv/plugins/ruby-build/bin:$PATH"
      - rbenv install 2.3.1
      - rbenv global 2.3.1
      - gem install jekyll jekyll-paginate
      - echo Building Jekyll site
      - jekyll build
      - echo Building the Docker image...
      - docker build -t $IMAGE_REPO_NAME:latest .
      - echo Build completed on `date`
      - echo Pushing the Docker image...
      - docker push $AWS_ACCOUNT_ID.dkr.ecr.$AWS_DEFAULT_REGION.amazonaws.com/$IMAGE_REPO_NAME:$IMAGE_TAG
      - echo Stopping current task
      - aws ecs stop-task --task `aws ecs list-tasks --cluster cluster --output text | awk '{print $2}'`
      - echo Sleeping for 30 seconds
      - sleep 30
      - echo Configuring AWS CloudFront Preview
      - aws configure set preview.cloudfront true
      - echo Purging CloudFront cache
      - aws cloudfront create-invalidation --distribution-id $DISTRIBUTION_ID --path '/*'
Ryan Gravlin's Picture

About Ryan Gravlin

Over 25 years experience as a system operator.

Miami, FL https://dbag.tech