読者です 読者をやめる 読者になる 読者になる

かれ4

かれこれ4個目のブログ

S3経由 codedeploy でデプロイするスクリプト

#!/bin/bash

APPLICATION_NAME= #codedeployのapplication name
DEPLOYMENT_GROUP= #codedeployのdeployment group
DEPLOYMENT_CONFIG=CodeDeployDefault.OneAtATime # codedeployのdeployment config
BUCKET= # ソースコードをおいておくS3のバケット
PROFILE=default #aws cli のprofileを指定する場合

## ===========================================
PROJECT_NAME=$(cd $(dirname $0); pwd | perl -pe "s|.*/(.*?)/?|\1|" )
VERSION=$(date '+%Y%m%d%H%M%S')
echo "Project Name = $PROJECT_NAME"
FILENAME=${PROJECT_NAME}-${VERSION}.tar.gz
KEY=${PROJECT_NAME}/$FILENAME

tar zcf  /tmp/${FILENAME} ./
aws --profile ${PROFILE} s3 cp /tmp/${FILENAME}  s3://${BUCKET}/${KEY}
ETag=$(aws --profile ${PROFILE} s3api head-object --bucket ${BUCKET} --key ${KEY} | jq -r .ETag |perl -pe "s/\"(.*?)\"/\1/g") # jq < 1.5対策
echo "uploaded ETAG = ${ETag}"

aws --profile ${PROFILE} deploy \
create-deployment \
--description "deploy with shell. --  ${VERSION}" \
--application-name ${APPLICATION_NAME} \
--deployment-group-name ${DEPLOYMENT_GROUP} \
--deployment-config-name ${DEPLOYMENT_CONFIG} \
--s3-location '{ "bundleType":"tgz", "eTag": "'${ETag}'","bucket": "'${BUCKET}'", "key": "'${KEY}'"}'