-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdeploy.sh
More file actions
executable file
·47 lines (40 loc) · 1.71 KB
/
deploy.sh
File metadata and controls
executable file
·47 lines (40 loc) · 1.71 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#! /bin/bash
# エラーで処理中断
set -ex
APP_NAME=bestcode
EB_BUCKET=elasticbeanstalk-ap-northeast-1-195500977316
NAMESPACE=toyokappa
CONTAINER_REGISTRY=195500977316.dkr.ecr.ap-northeast-1.amazonaws.com
SHA1=$1
ENV=$2
BUILD_NO=$3
if [ -n "$ENV" -a "$ENV" = "production" ]; then
RAILS_MEMORY=600
SIDEKIQ_MEMORY=200
NGINX_MEMORY=128
NGINX_TAG=latest
elif [ -n "$ENV" -a "$ENV" = "staging" ]; then
RAILS_MEMORY=600
SIDEKIQ_MEMORY=200
NGINX_MEMORY=128
NGINX_TAG=release
fi
DOCKERRUN_FILE=Dockerrun.aws.json
BUNDLE=${SHA1}-${APP_NAME}-${ENV}-bundle.zip
VERSION_LABEL=${APP_NAME}-${ENV}-${SHA1}-${BUILD_NO}
sed "s/<TAG>/${SHA1}/" < Dockerrun.aws.json.template > ${DOCKERRUN_FILE}
sed -i -e "s/<APP_NAME>/${APP_NAME}/g" ${DOCKERRUN_FILE}
sed -i -e "s/<NAMESPACE>/${NAMESPACE}/g" ${DOCKERRUN_FILE}
sed -i -e "s/<RAILS_ENV>/${ENV}/g" ${DOCKERRUN_FILE}
sed -i -e "s/<CONTAINER_REGISTRY>/${CONTAINER_REGISTRY}/g" ${DOCKERRUN_FILE}
sed -i -e "s/<RAILS_MEMORY>/${RAILS_MEMORY}/g" ${DOCKERRUN_FILE}
sed -i -e "s/<SIDEKIQ_MEMORY>/${SIDEKIQ_MEMORY}/g" ${DOCKERRUN_FILE}
sed -i -e "s/<NGINX_MEMORY>/${NGINX_MEMORY}/g" ${DOCKERRUN_FILE}
sed -i -e "s/<NGINX_TAG>/${NGINX_TAG}/g" ${DOCKERRUN_FILE}
zip ${BUNDLE} -r ${DOCKERRUN_FILE} .ebextensions # <-- ここでSource Bundleをつくっています。
aws s3 cp ${BUNDLE} s3://${EB_BUCKET}/${BUNDLE}
aws elasticbeanstalk create-application-version --region ap-northeast-1 --application-name ${APP_NAME} \
--version-label ${VERSION_LABEL} --source-bundle S3Bucket=${EB_BUCKET},S3Key=${BUNDLE}
# Update Elastic Beanstalk environment to new version
aws elasticbeanstalk update-environment --region ap-northeast-1 --environment-name ${APP_NAME}-${ENV} \
--version-label ${VERSION_LABEL}