Create a CI/CD on aws for play framework project using sbt

Dileep
2 min readJan 7, 2020

--

CodeBuild

First you have to create a project on codebuild.

  • Write name of project.
  • Provide your source of code (github, gitlab etc..).
  • Select your enviroment ( you can select default ubuntu environment or you can setup your own docker container ).
  • Create your new service rule ( or you can use your older service rule).
  • Put your buildspec.yml file in root folder of your project or you can insert build command manually ( I just put my buildspec.yml below).
version: 0.2env:
variables:
TEST_ENV_VARIABLE: prodArtifacts
phases:
install:
runtime-versions:
java: openjdk8

commands:
- export OLDDIR=$PWD
- export GIT_ALLOW_PROTOCOL="ssh"
- cd
- if [ ! -d ".ssh" ]; then mkdir .ssh; fi
- cd .ssh
- aws s3 cp s3://bucketname/foldername/id_rsa .
- chmod 400 id_rsa
- aws s3 cp s3://bucketname/foldername/id_rsa.pub .
- aws s3 cp s3://bucketname/foldername/known_hosts .
- eval `ssh-agent`
- ssh-add id_rsa
- cd $OLDDIR
- git clone git@gitlab.com:username/repo.git
- cd repo
#install sbt
- echo "deb https://dl.bintray.com/sbt/debian /" | tee -a /etc/apt/sources.list.d/sbt.list
- apt-get update
- apt-get install sbt
- apt-get install unzip
build:
commands:
- echo Build started on `date`
- sbt clean dist # generate build
post_build:
commands:
- cd target
- cd universal
- unzip logistics-0.0.1-SNAPSHOT.zip -d .
- rm logistics-0.0.1-SNAPSHOT.zip
- cd logistics-0.0.1-SNAPSHOT
artifacts:
type: NONE
base-directory: "repo/target/universal/logistics-0.0.1-
SNAPSHOT/"
files:
- '**/*'
  • We use git lab as project repo but aws doesn’t give any option to fetch code repo from gitlab. so i just create a repo in codecommit ( aws version control tool) and create buildspec.yml and put it in master ( choose source as code commit and use master branch for code pull).
  • I just used ssh in buildspec.yml file for a private repo.

CodePipeline

  • Open your code pipeline and create a new project and choose your bucket to upload your artifacts.
  • Choose your source provider
  • Choose code build as a building tool. specify your region and select your project name
  • Select where you want to deploy your artifacts. (i deployed on elastic beanstalk).
  • At last, create your pipeline and your CI/CD is ready.
Code Pipeline
  • Run your code pipeline. it will fetch your code from source and build. Upload your artifacts on s3 and deployed it on EBS.

Thanks.

--

--

Dileep
Dileep

Written by Dileep

Passionate about coding, cyber security | Software Engineer | IIT Roorkee.

No responses yet