I was working with an On-Prem server and I had to install AWS CodeDeploy Agent to get the CI & CD Pipeline. CodeDeploy uses ruby version 2.x. Ubuntu 16.04 and above, ships with ruby 2.3 as default and CodeDeploy just doesn't work. So, I thought why not write it in GoLang. Go is best suited for this job. No dependencies at all. Just a binary file that runs as a service.
################################################################
####################### DEBIAN PACKAGE #########################
################################################################
wget - no-cache -O - https://api.bintray.com/users/miradnanali/keys/gpg/public.key | sudo apt-key add -
echo "deb [arch=amd64] https://dl.bintray.com/miradnanali/S3CodeDeployerDebian bionic main" > /etc/apt/sources.list.d/s3-codedeployer.list
echo "deb [arch=amd64] https://dl.bintray.com/miradnanali/S3CodeDeployerDebian artful main" > /etc/apt/sources.list.d/s3-codedeployer.list
echo "deb [arch=amd64] https://dl.bintray.com/miradnanali/S3CodeDeployerDebian zesty main" > /etc/apt/sources.list.d/s3-codedeployer.list
echo "deb [arch=amd64] https://dl.bintray.com/miradnanali/S3CodeDeployerDebian xenial main" > /etc/apt/sources.list.d/s3-codedeployer.list
echo "deb [arch=amd64] https://dl.bintray.com/miradnanali/S3CodeDeployerDebian trusty main" > /etc/apt/sources.list.d/s3-codedeployer.list
echo "deb [arch=amd64] https://dl.bintray.com/miradnanali/S3CodeDeployerDebian buster main" > /etc/apt/sources.list.d/s3-codedeployer.list
echo "deb [arch=amd64] https://dl.bintray.com/miradnanali/S3CodeDeployerDebian stretch main" > /etc/apt/sources.list.d/s3-codedeployer.list
echo "deb [arch=amd64] https://dl.bintray.com/miradnanali/S3CodeDeployerDebian jessie main" > /etc/apt/sources.list.d/s3-codedeployer.list
echo "deb [arch=amd64] https://dl.bintray.com/miradnanali/S3CodeDeployerDebian wheezy main" > /etc/apt/sources.list.d/s3-codedeployer.list
$ apt-get install s3-code-deployer
################################################################
########################## RPM PACKAGE #########################
################################################################
rpm --import https://api.bintray.com/users/miradnanali/keys/gpg/public.key
sudo echo "
[s3-code-deployer]
name=s3-code-deployer
baseurl=https://api.bintray.com/content/miradnanali/S3CodeDeployerRPM
gpgkey=https://api.bintray.com/users/miradnanali/keys/gpg/public.key
gpgcheck=0
enabled=1
repo_gpgcheck=1
" > /etc/yum.repos.d/s3-code-deployer.repo
sudo yum update
sudo yum install -y s3-code-deployer
revision_check_duration: 10 // in minutes
aws:
accessKey: YOUR_AWS_ACCESS_KEY
secretKey: YOUR_AWS_SECRET_KEY
bucket: YOUR_AWS_DEPLOYMENT_BUCKET
region: YOUR_AWS_REGION
deployments:
- application: staging.example.com
environment: staging
destination: /var/www/html/staging.example.com
s3_revision_file: example.com/staging.tar.gz
- application: www.example.com
environment: production
destination: /var/www/html/www.example.com
s3_revision_file: example.com/prod.tar.gz
You'll have to create two shell-scripts inside a deployment/scripts folder, located inside your application root folder. Below is an example. Upon successful deployment the s3-code-deployer will auto run these two scripts if they are available. You can write your migration, assets compression and other commands in it.
application_root
- deployment
- scripts
- BeforeInstall.sh
- AfterInstall.sh