Last active
August 29, 2015 14:17
-
-
Save sgykfjsm/c6b9a73f0cfb7b3c6df0 to your computer and use it in GitHub Desktop.
Docker用のカスタムAMIを使うためにダミーのアプリケーションに仕込んでおく.ebextensions
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--- | |
commands: | |
01-yum-security-update: | |
command: /usr/bin/yum update -y --security --bugfix --skip-broken | |
ignoreErrors: true | |
02-backup-original-hooks: | |
command: /bin/cp -vpRP /opt/elasticbeanstalk/hooks /opt/elasticbeanstalk/hooks.org | |
ignoreErrors: true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--- | |
files: | |
"/etc/init/sample-docker-app.conf" : | |
mode: 755 | |
owner: root | |
group: root | |
content: | | |
description "Elastic Beanstalk Docker Container sample-docker-app" | |
start on started docker | |
stop on stopping docker | |
respawn | |
script | |
# "play-scala-intro" is *exmaple*. This must be replaced with real container name. | |
CONTAINER_NAME="play-scala-intro" | |
# Wait for docker to finish starting up first. | |
FILE=/var/run/docker.sock | |
while [ ! -e ${FILE} ]; do | |
sleep 2 | |
done | |
DOCKER_APP_FILE=/etc/elasticbeanstalk/.aws_beanstalk.current-container-id | |
CONTAINER_ID=$(docker ps --no-trunc -a| grep ${CONTAINER_NAME} | cut -d" " -f1) | |
if ! docker ps | grep -q ${CONTAINER_ID} ; then | |
docker start ${CONTAINER_ID} > ${DOCKER_APP_FILE} | |
fi | |
NGINX_UPSTREAM_IP=$(docker inspect ${CONTAINER_ID} | jq ".[0].NetworkSettings.IPAddress" --raw-output) | |
# "9000" is *example*. This must be replaced with real application settings. | |
NGINX_UPSTREAM_PORT=9000 | |
DOCKER_PORT_FILE=/etc/elasticbeanstalk/.aws_beanstalk.container-port | |
if ! cat /etc/nginx/conf.d/elasticbeanstalk-nginx-docker-upstream.conf | grep -q $NGINX_UPSTREAM_IP; then | |
sed -i.$(date '+%Y%m%d%H%M%S.%Z') \ | |
"s/server.*;/server ${NGINX_UPSTREAM_IP}:${NGINX_UPSTREAM_PORT};/" \ | |
/etc/nginx/conf.d/elasticbeanstalk-nginx-docker-upstream.conf | |
service nginx restart | |
fi | |
echo ${NGINX_UPSTREAM_PORT} > ${DOCKER_PORT_FILE} | |
mkdir -p /var/log/eb-docker/containers/eb-current-app | |
docker logs -f ${CONTAINER_ID} > /var/log/eb-docker/containers/eb-current-app/${CONTAINER_ID:0:12}-stdouterr.log 2>&1 | |
exec docker wait ${CONTAINER_ID} | |
end script | |
post-stop script | |
CONTAINER_ID=$(docker ps --no-trunc | grep 'play-scala-intro' | cut -f1 -d' ') | |
if [ -n "${CONTAINER_ID}" ] ; then | |
docker stop ${CONTAINER_ID} | |
fi | |
end script |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--- | |
commands: | |
01-modified-hooks-restartappserver-enact: | |
command: | | |
/bin/sed -i \ | |
-e "/^stop_upstart_service eb-docker/a stop_upstart_service sample-docker-app || true" \ | |
-e "s/^start_upstart_service eb-docker/start_upstart_service sample-docker-app/" \ | |
/opt/elasticbeanstalk/hooks/restartappserver/enact/01restart.sh | |
ignoreErrors: true | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--- | |
commands: | |
01-run-dummy-app: | |
command: | | |
/usr/bin/docker ps -a | grep -q 'play-scala-intro' || \ | |
/usr/bin/docker run -d \ | |
-p 22812:2812 \ | |
--name play-scala-intro \ | |
-v /etc/localtime:/etc/localtime:ro \ | |
sgykfjsm/play-scala-intro | |
cwd: /home/ec2-user | |
ignoreErrors: false |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--- | |
files: | |
"/opt/elasticbeanstalk/hook/appdeploy/enact/99run-dummy.sh" : | |
mode: 755 | |
owner: root | |
group: root | |
content: | | |
#!/bin/bash | |
set -e | |
. /opt/elasticbeanstalk/hooks/common.sh | |
/opt/elasticbeanstalk/hook/restartappserver/enact/01restart | |
"/opt/elasticbeanstalk/hook/configdeploy/post/99run-dummy.sh" : | |
mode: 755 | |
owner: root | |
group: root | |
content: | | |
#!/bin/bash | |
set -e | |
. /opt/elasticbeanstalk/hooks/common.sh | |
# TODO: pickup config update | |
/opt/elasticbeanstalk/hook/restartappserver/enact/01restart |
実験的なものなので、これを実運用で使ってはならない。
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
これがダメなところ