ºÝºÝߣ

ºÝºÝߣShare a Scribd company logo
AWS/Docker/Rails
? ???
?????
??/??
AWS/Docker/Rails? ??? ??? ??/????
???? ??? ???? ???????.
????
??:???(@negabaro)
???: ?? ??
??:
2011? ??x ?????/JSP ?????? ??(SI)
2013? ???x ??? ????(EC)
2015? ?????x DevOps???? ????(IT???)
2017? ???x ???/DevOps????(?? ??)
??:????(???),??
AWS/Docker/Rails? ???
???????/??
??? ??? ??? ?? ???? ??? ???????.
??? ?????..!
<#>
??
? ?????
? ????
? ??? ??? ??? ??/??? ??? ??? ??
¨C ???? ??
¨C Docker Automation build,deploy
¨C rails?? ??/??
¨C nginx?? ??/??
¨C ? ?
?????
??? ??? ?? ?? ?????..
?????
?????
????? ???
ELB,ALB
?????
DB????
????? elasticsearch
??DB mysql
? ? ???? s3??
?? redis
?? memcached
CDN CloudFront
?????
?????? ???
Middleware?? docker?
??(nginx,unicorn,php-
fpm,td-agent)
AWS ECS? ???? docker
???? ??
??? ?????
????? ??? ?? ??
??? ?? ???in,out?
?????
?????? ???
Web,API Rails? ??
?? ?????(?????? ??)
Docker????? ???? ?? ???? ?????.
??? ??? ????? ???? ????? ????
(??? ??? ?? ?????¡­)
Docker??
??? ????
? ???? ????? ??? ? ??
?????
? ????? ??? ? ?? API
Docker??
???? ????
?? ??
?? ??? ????? ???? ??(tool)
?? ???,???OS, ?? ?? ?? ??? ?? ????? ???? ??? ??
?? ??,?? ?? ???? ?? ?????? ??? ?? ?? ????? ??/??/??
Dockerfile ??? ???? ?? ??? ??? ????? ??
?? ??? ????? ????? ?? ??? ??? ??. ?????? ????? ??? ????(iso
????). ?? ???? git? ??
???(commit),??(branch),????(push),????(pull)? ??
?? ????? docker ??? ???? ??,?? ???? ?? ??? ? ??,???? ???? ?.
?? ?? ?? ???? ???/??/??? ? ?? ?? ?? ??? ???(repository)
??? ??? ???? OS??? ???(Docker hub? ??? ??)
???? ?? ???? ??? ?? ??? ??????? ?? ? ??
?? ??? ??? ???? ???
?????.
Docker??
???? ????
Docker??
???? ???? ?? ????
Base Image
??? ???? xx??? ???? ????? ????
?????.
???=??? ???
Docker??
???? ???? ?? ????
Base Image docker build
??? ???? ?? ???? xx???
??? ???? ????.
CD? ?? = docker build
Docker??
???? ???? ?? ????
Base Image
docker run
docker build
??? ???? ?? CD? CD-ROM?
?? ??????.
CD-ROM? ??? ?? = docker run
Docker??
???? ???? ?? ????
ConainerBase Image
docker run
docker build
xx??? ???????
xx??? ??? ?? =????
Docker??
???? ???? ?? ????
ContainerBase Image
docker run
docker build
Host OS
xx??? ??? ??? ???? CPU i7
7700k, ??? ?? nvidia titan x? ???
???????.
xx?? ??? ??? = Host OS,docker
host,docker server
Docker??
???? ???? ?? ????
Docker repository(Dokcer
Hub,AWS ECR)
??????? ???
docker run
docker build
Host OS
??? xx??? ?? ???? xx??? ????
cd? ???? ?? cd???? ?????.
CD???=Docker repository(docker hub,aws ecr)
CD???? ??=docker push
docker push
Docker??
???? ???? ?? ????
docker builddocker run
docker push
??? docker build? ??
??? docker run,docker push? ????.
??? ??? docker?? ??? ??????
docker ??????? ?? ? ?????.
Docker??
?? ??
Linux Namespaces£º??? ??? ??
Linux cgroups£º??? ??? ??
AUFS£¯Device Mapper Thin Provisioning£º
??/???? ????
Linux iptables£º???,???? ??
???? ??
Docker??
??? ??(??? ??)
? ??? (vmware)
? ????(xen)
? ??? ???? = Solaris Containers,??VZ,
???????(LXC), lmcfty
? ?? ???? = docker
Docker??
??? ??2(????? ??)
? 1983? 4.2BSD?? Chroot ???System Call? ???
? 2000? FreeBSD 4.0?? FreeBSD Jail? ??
? ?? ???? ?? ??? ?? ?? ???(? ??? ??? ? ????)
? Solaris Containers
? ?? docker???(?????? ?? ?? ??!)
? 2008? ??? ??? Linux cgroups? merge?
? LXC ???,??? ?? ?? ?? ?? ??????
??? ??? ??
? Docker 2014? ?? LXC? ????? ???
Docker??
??? ??3(docker??? ??)
? LXC? ???? ??
? 0.9???? ???? libcontainer ??? ??(????
LXC??? ??)
? ?? runC??? ???
? ?? docker? ????? 1.13
Docker??
??? ??
? ?????? ?????? ???? ???? ?????
??? ????
? ??? Control Group(cgroups) ??? ?? CPU? ????,
???? ??????? ??? ? ??? ??, ???
Namespace isolation(?? namespaces)?? ????
??????? ?????, fs??? ?? ??
? ??? ?? ? ???OS? ??
? ?? ??? ???? ??? ??? ????
? Go??? ????
Docker??
??? ??
? ??? ?? ??? OS?? ????? ???
???(portable?)
? Hands ON? ????? ?? ????? ??
? ???? ?? ????? ???
? ???? ??? ?? ? ??
? ??? ???
Docker??
?? ??
? ???? ???? ????? ??? ???? ??? ??
? ?? ???? ?? ??? ??? ??? ? ? ??, ???,
??? ??? ????? ?? ???
? ??? ???? ??? ?????? ????? ????
????? ???? ?? SaaS? PaaS ?? ???? ???
???? ?? ??
? ????? ????? ?? ????? ??? ????
?? ??
? ??.??? ?? ??? ?? ??
Docker??
VM vs Docker? ??
VM? ????,????? Hypervisor? ????? overhead? ??
docker? hypervisor? ???? ?? ??Host OS? ????? VM?? ????? ??
Docker??
Docker vs Chef,Ansible,Puppet
? ??????? docker? ????? ??
? Docker?Immutable Infrastructure? ???
? Bootstrapping?Configuration? ??
? Docker? ????? chef,ansible,puppet?? ???
Docker??
Docker Command
? Docker run
? Docker build
? Docker exec
? Docker rm
? Docker rmi
? ??? ??
??? ???
??? ??/??
??? ??? ??? ??? ????
???? ???????.
Docker? ??? ??
? ???? (rails? DRY??? ?? ??)
? ????? production?? ???? ??? ??
? ????? Chef,ansible?? ?? ?????? ??
? Hot? ?????..
?? ??? ??
? ??,??? ?? ??,??? ?? git??? ????
?? ??
? Wiki? git?? ????? ??
? ????? trello?? xenhub?
? git push? ?? deploy?? ???? ?? ??
???? ??? ??..
? ???? ??
? Docker build,push,deploy
? ???? ??
? ??? ??
? ????
? ?? ??
? ?? ??
? ???
? ???
??? ??? ??? ??/??
???? ??
???? ?? ??? ??? ???
? ? ??????? ??? automation docker build?
???? ?? ??
? ? middleware? docker???? rails_env?? ???
? Docker?? ?? ?? ??? ??????? ????
??
? ??? DRY?? ???? ??
? ????? ?? ?? ??? ??? ??
Directory structure
Rails_env
Middleware
docker
Rails_root rails_root
docker
nginx unicorn
development beta staging productoon shared
memcached redis elasticsearch td-agent mysql base
Dockerfile
docker-
compose.yml
Middleware layer?? ? ?? ?????? rails.env layer? ??(unicorn??? ??)
Mysql? ?? development???? aws RDS? ??? development????? ??
Directory structure ¨C Rails_root
Rails_env
Middleware
docker
Rails_root rails_root
docker
nginx unicorn
development beta staging productoon shared
memcached redis elasticsearch td-agent mysql
Dockerfile
docker-
compose.yml
Rails_root ?? ????? ??? ???????.
Directory structure ¨C docker
Rails_env
Middleware
docker
Rails_root rails_root
docker
nginx unicorn
development beta staging productoon shared
memcached redis elasticsearch td-agent mysql
Dockerfile
docker-
compose.yml
File name description
docker-compose.yml ??? ????? ??? ?? (??development???? ??)
Dockerfile docker build? ??
??? ????? ?? docker?? ???? ???. Docker?????
development???? ??? Dockerfile,docker-compose.yml????.
Directory structure ¨C Middleware
Rails_env
Middleware
docker
Rails_root rails_root
docker
nginx unicorn
development beta staging productoon shared
memcached redis elasticsearch td-agent mysql base
Dockerfile
docker-
compose.yml
Docker ??????? ?????? ????? ?????? ?????.
??? ????? ?? docker image? ???? ???? ????
base????? ????.(base????? ???? ??? ??)
Directory structure ¨C Rails_env
Rails_env
Middleware
docker
Rails_root rails_root
docker
nginx unicorn
development beta staging productoon shared
memcached redis elasticsearch td-agent mysql base
Dockerfile
docker-
compose.yml
Middleware???? ??? ???? ????? ??????.
? ?? ????? ????? ?????? ??? ?? shared?????
????.
Directory structure ¨C Rails_env - environment
?? ?? ??
development ? ????? ????? ??????
??? ??
beta Github ??? ?? ??? ???? ??
staging Production??? ???? ?? ?? ??
???? ??
production ?? ??? ??
Directory structure2 ¨C Docker_build_root
Docker build?
???? ????
Docker_build_root
Rails_env
{development
staging,
production}
files
set_env.sh set._key.sh run_sh.sh
?? ??
??????
??? ??
test Dockerfile
build_docker.s
h
run_docker.sh
push_docker.s
h
deploy
??? ??
Dockerfile docker build? ??
Files???? docker??????? ??? ??(Dockerfile??? files??? ADD?)
build_docker.sh docker build? ???? ???? ??
run_docker.sh docker build? ???? ?????? run?? ??. ?? ???? ?? ????
??(serverspec)
Push_docker.sh Build,test? ?? docker???? aws ecr? push
deploy???? ???? ?? ????(Task Definition file?)? ??
Directory structure2 ¨C Docker build?
???? ????
Docker build?
???? ????
Docker_build_root
Rails_env
{development
staging,
production}
files
set_env.sh set._key.sh run_sh.sh
?? ??
??????
??? ??
test Dockerfile
build_docker.s
h
run_docker.sh
push_docker.s
h
deploy
??? ??
set_env.sh S3?? ????? ??
set_key.sh S3?? ssh key? ??
run_sh.sh ?? ????? ????? ???? ?? shellscript?? ??
build_docker.sh docker build? ???? ???? ??
Other_files ?? ?? ???? ??? ??? ???
???? ??? ???? ??? ????
docker automation build
docker container test by serverspec
docker auto deploy for aws ecs
?? ??
??? ??? ??? ??/??
Docker Automation
Build,Deploy
Docker build
automation docker build? ????? ??? ?? docker build ??? ?? ??
?? ???????.
How to do Docker build
???Docker_root
Rails.env
rails.env layer
{development
staging,
production}
files
set_env.sh set._key.sh run_sh.sh
?? ??
??????
??? ??
Dockerfile build_docker.sh run_docker.sh push_docker.sh deploy
Docker build? ???? ???? ?? build_docker.sh? ??
build_docker.sh??
PR_NUMBER ="${CIRCLE_PR_NUMBER}"
//circlieCI??? ??P.R??? ????? ?? ??
Docker build ¨Ct [ECR-EndPoint]/[ECR-Image]:PR_NUMBER ¨Ct [ECR-EndPoint]/[ECR-
Image] ¨Cfile Dockerfile .
//??P.R??? ??? ??? docker build
Docker repository??? aws ECR? ??
How to do Docker Automaition Build
??? ???
? Docker hub? automation build ??? ??? ?
????? ?????? ???? ?? ??????
?????? ??? ??..
? ??? ????? ??? ??? automation build
??? ???? ??
? ? ??? branch? git push? ???
build,push,test,deploy?? ?? ??? ??? ????
??? ??
How to do Docker Automaition Build
???..??
? Automation Docker Build ? ?? circleCI? ??
? Docker???? ???? ????? ? Middleware??
docker build? ???build_docker.sh??? ???
? circleCI??? git diff???? ???? ??Middleware??
????? ?? ??? ??????? ?? ????
build_docker.sh ??? ?????? ?
How to do Docker Automaition Build
????
? ???? ??? git push -> circleCI?? ??-> git
diff?? build_docker.sh? ???? ???? ?? ->
build ???? ???? ??? build_docker.sh?? ¨C>
run_docker.sh ?? ???? ?? -> serverspec ?? ?? ???? ??test -> ?? ??? -> docker push ->
deploy
? ????
? git push -> circleci -> git diff -> build_docker.sh
How to do Docker Automaition Build
??? ?? ??? ??
? ?? ???? ??? ??? 10?,??? ???? 1??
??
? P.R??? ????? rails??? ??
? circleCI??? ???? rails?? rspec???? 20?? ??
? ??? docker build,run ??? ? ??? rspec? ????
?? ???? ??? ??? ? ???? ?..
? ??. ? ?? ???? merge???? docker ?? build
???? ????? ?
How to do Docker Automaition Build
circle.yml
deployment:
develop:
branch: develop
commands:
- sh docker/run_git_diff.sh:
timeout: 1500
betax:
branch: betax
commands:
- sh docker/run_git_diff.sh:
timeout: 1500
staging:
branch: staging
commands:
- sh docker/run_git_diff.sh:
timeout: 1500
production:
branch: production
commands:
- sh docker/run_git_diff.sh:
timeout: 1500
?? docker?? ??? circleCI?deployment ???
??? ??
?? ????? ???? ??? ??
run_git_diff.sh????? ??? ??? ?? docker
build? ???? ???
How to do Docker Automaition Build
git diff???
#!/bin/sh
changed_files="$(git diff-tree -r --name-only --no-commit-id ORIG_HEAD)¡°
branch_name="${CIRCLE_BRANCH}"
updated_nginx_status=false
updated_unicorn_status=false
updated_td-agent_status=false
updated_rails_status=false
for var in $changed_files
do
if [[ $var =~ ^docker/nginx/$branch_name ]]; then
updated_nginx_status =true
elif [[ $var =~ ^docker/unicorn/$branch_name ]]; then
updated_unicorn_status=true
elif [[ $var =~ ^docker/td-agent/$branch_name ]]; then
updated_td-agent_status =true
else
updated_rails_status=true
fi
done
How to do Docker Automaition Build
git diff???
#!/bin/sh
if [ $updated_nginx_status ]; then
sh docker/nginx/$branch_name/build_docker.sh //docker build
sh docker/nginx/$branch_name/run_docker.sh //docker run
sh docker/nginx/$branch_name/test/run_test.sh //serverspec?? ??? ????? ?? ???
sh docker/nginx/$branch_name/push_docker.sh //???? ??? ??? aws ecr? docker push
else
fi
if [ $updated_unicorn_status ]; then
sh docker/unicorn/$branch_name/build_docker.sh
sh docker/unicorn/$branch_name/run_docker.sh
sh docker/unicorn/$branch_name/test/run_test.sh
sh docker/unicorn/$branch_name/push_docker.sh
else
fi
autumation docker run,test,push? ??? ??
How to do Docker Automaition Build
???? ??? ????
rails_root
docker
nginx
unicorn
development
beta
staging
productoon
shared
memcached
redis
elasticsearch development Build_docker.sh
td-agent production
mysql
base
Dockerfile
docker-
compose.yml
docker/nginx/beta/xx
docker/elasticsearch/d
evelopment/xxx
docker/td-
agent/production/xxx
?? ?? ??? development
branch? merge???
How to do Docker Automaition Build
???? ??? ????
rails_root
docker
nginx
unicorn
development
beta
staging
productoon
shared
memcached
redis
elasticsearch development Build_docker.sh
td-agent production
mysql
base
Dockerfile
docker-
compose.yml
docker/nginx/beta/xx
docker/elasticsearch/
development/xxx
docker/td-
agent/production/xxx
?? ?? ??? development
branch? merge???
Development ????? ???
elasticsearch/development/build_
docker.sh??? ???
How to do Docker Automaition Build
???? ??? ????
rails_root
docker
nginx production build_docker.sh
unicorn
development
beta
staging
productoon build_docker.sh
shared
memcached
redis
elasticsearch development build_docker.sh
td-agent production build_docker.sh
mysql
base
Dockerfile
docker-
compose.yml
docker/nginx/production
/xx
docker/elasticsearch/dev
elopment/xxx
docker/td-
agent/production/xxx
?? ?? ??? production
branch? merge???
docker/unicorn/producti
on/xxx
How to do Docker Automaition Build
???? ??? ????
rails_root
docker
nginx production build_docker.sh
unicorn
development
beta
staging
productoon build_docker.sh
shared
memcached
redis
elasticsearch development build_docker.sh
td-agent production build_docker.sh
mysql
base
Dockerfile
docker-
compose.yml
docker/nginx/production
/xx
docker/elasticsearch/dev
elopment/xxx
docker/td-
agent/production/xxx
?? ?? ??? production
branch? merge???
docker/unicorn/producti
on/xxx
Production ????? ???
nginx,unicorn,td-agent?
build_docker.sh??? ??
???
How to do auto deployment
? ?? ??? AWS ECS? ??? ?? ???????.
? Git push -> circlieci -> git diff -> build_docker.sh -
>run_docker.sh -> run_test.sh -> push_docker.sh ->
create_task_def.sh -> update_task_def.sh
How to do auto deployment
??? ???
? AWS ECS? ???? ?????
? Blue green deployment??? ??? ?? ????
???? ??
? AWS ECS?Minimum healthy percent,Maximum percent??
? ????? ??? ????? ??
? ?????? ???20?? ??? ?? Minimum healthy
percent:50, Maximum percent 100? ????? 10??
????? ?? ??? ????? ??? -> ???
10?? ????? ?? ??? ????? ???? ?
How to do auto deployment
about deploy directory
Docker build?
???? ????
Docker_build_root
Rails_env
{development
staging,
production}
files test deploy
create_task_
def.sh
dynamic_gen
_task_def_js
on.sh
task_def.tem
plate
update_task
_def.sh
??? ??
create_task_def.sh ?? docker build?? ?? ???? ???? task definition??
dynamic_gen_task_def_json.sh task_def.templat? ???? task_def.json??? ??(envsubust??? ??)
task_def.template Dynamic_gen_task_def_json.sh???? ???? ???
update_task_def.sh ??? task_definition?? ??
How to do auto deployment
dynamic_gen_task_def_json.sh + task_def.template
#!/bin/sh
cd docker/unicorn/$BRANCH/deploy/
envsubst '$CIRCLE_PR_NUMBER' < task_def.template > task_def.json
dynamic_gen_task_def_json.sh
{
"containerDefinitions": [ {
"name": "unicorn",
"image": ¡°xx.dkr.ecr.ap-northeast-1.amazonaws.com/xx:${CIRCLE_PR_NUMBER}",
"essential": true,
¡­
task_def.template
How to do auto deployment
create_task_def.sh
#!/bin/sh
cd docker/unicorn/$BRANCH/deploy/
sh dynamic_gen_task_def_json.sh
aws ecs register-task-definition --cli-input-json file://task-def.json
//?? ??? task definition? aws ecs? ??
create_task_def.sh
How to do auto deployment
update_task_def.sh
???? well made?? ecs-deploy? ??? ??????
https://github.com/silinternational/ecs-deploy
TASK_REVISIONS=`aws ecs list-task-definitions --family-prefix [family_name] --status ACTIVE --sort ASC`
//?? family? ??? ?? task definition??? ??
NUM_ACTIVE_REVISIONS=$(echo "$TASK_REVISIONS" | jq ".taskDefinitionArns|length")
//??? task definition? ??? ??
OUTDATED_REVISION_ARN=$(echo "$TASK_REVISIONS" | jq -r ".taskDefinitionArns[NUM_ACTIVE_REVISIONS-1]")
//? ??? -1? ?? task definition??? ?? task def? ARN? ??
aws ecs update-service --cluster [cluaster_name] --service-name [service_name] --task-definition
$OUTDATED_REVISION_ARN
//?? task_def? ?? service????
update_task_def.sh
How to do auto deployment
??
? ???? ??? ??? ????? ??????
? Production?? auto deployment ???? ?????
???? ??? ??????..
??? ??? ??? ??/??
rails????/??
????/ssh key ??
??? ???
? Docker image? portable? ??? ??? ? ???
docker image? ??? ???? ??? ??? ???
?
? ???? docker image?? ??? password??? ssh
key? ?? ???? ??? ????? ??
????/ssh key ??
??
? ????? S3?? ????
? ? ????? ??? ???? ??? ??
? ????? ????,ssh key?? dockerfile???
??? ?? s3?? ???. ??? ??? ???
??? ?
? ?? ???? ???? ??? S3?? ?? ????
??? ??
? S3?? ???? ??? version?? ??
???? ??
???Docker_root
Rails.env
rails.env layer
{development
staging,
production}
files
set_env.sh set._key.sh run_sh.sh
?? ??
??????
??? ??
Dockerfile build_docker.sh run_docker.sh deploy
???? ??
set_env.sh
???? ??? ????? bash ¨Clc ¡°¡± ??? ?? ??
#!/bin/sh
aws s3 cp ¨Cquiet s3://xx/env_[middleware_name]_[rails_env] /etc/profile.d/xx.sh
#ex)aws s3 cp ¨Cquiet s3://xx/env_unicorn_production /etc/profile.d/xx.sh
ex) bash -lc 'bundle exec unicornherder -u unicorn_rails -p /tmp/unicorn.pid -- -c
/unicorn.rb'
??? ??..???? ???..
? ???? docker run xx rails s ? ??? ??
? ??? ??? ??.. ???? ?? ???? ???
?????? ????? ?????? ??
? ???? ????? ?? ??????? ??????
????? ??
? Rails ????? ?? ????? ????? ??
? Supervisord? ???? rails????? ?? ?????
supervisord? ???? ???? ??????? ????
rails???? ??
? ?? graceful?? ????? ??? unicornherder? ??
???? ?? ??
? Rails&docker??? ????? ??? ?? ??? ??
???? ???? ? ??? ??
? ?? ?? ????? bundle install ??? ??
???? ?? ??
??? 3?? ?? ???
bundle install assets_precompile db_migrate
???? ?? ??
??? 3?? ?? ??? ¨C bundle install
Bundle install? ?? RAILS_ENV?????
??(?? ? ??? ??? ?)
Gemfile?? private git repository? ?? ??
ssh key? ??(ssh key? ?? ??..)
??? bundle install? ?? ??????
docker build?? ??? ????? ?
bundle install
???? ?? ??
??? 3?? ?? ??? - bundle install
Bundle install? docker build? ?? ??
Gemfile? ???? bundle install? ???
???? ?? s3? ???? batch? ??
???
Dockerfile???? ?? s3??? ??
???? ??? bundle install? ???
??? ??? ?? ???? ????
bundle install? build? ?? ??(??
??? ?? ????? ?? ?? ???)
bundle install
???? ?? ??
??? 3?? ?? ??? ¨C assets_precompile
assets_precompile? ??? s3? ??
assets_sync?? gem? ???? ???
s3? sync??
sprockets-manifestxx.json??? ???
????? ? ????
assets_precompile
???? ?? ??
??? 3?? ?? ??? ¨C db_migrate
?? ???? ???
??? ?? git diff? ???? migrate
?? ??? ?? ?????
db_migrate??? ?? ??? ????
???..
db_migrate
??? ??? ??? ??/??
nginx?? ??/??
??? ??? nginx ??
? nginx?? ???? ???? ??? ?????
???? ??
? ??? lua script? ????? ??? ?????
??? ?????? ??? ??? ????
? ???? ?? ?????? envsubst ? nginx??
??? ??
? ??. Envsubst????? ???? ???
nginx.conf??? ??
??? ??? nginx ??
envsubst?
apt-get install -y gettext
Ubuntu?? envsubst ?? ??
Envsubst???? ?????? ??? ??? ??
??? ??? nginx ??
???Docker_root
Rails.env
rails.env layer
{development
staging,
production}
files
set_env.sh
dynamic_generate
_nginx.conf.sh
nginx.conf.templa
te
run_sh.sh
?? ??
??????
??? ??
Dockerfile build_docker.sh run_docker.sh deploy
File name description
dynamic_generate_nginx.conf.sh Envsubst??? ????? ??
nginx.conf.template nginx.conf? ??? ?? ??? ??
??? ??? nginx ??
nginx.conf.template
user xxx;
¡­??
geo $http_x_forwarded_for $sidekiq_allow_ip {
default 0;
${OFFICE_GATEWAY} 1;
}
??? ??? nginx ??
dynamic_generate_nginx.conf.sh
#!/bin/sh
####nginx.conf
/bin/bash -c "envsubst '$OFFICE_GATEWAY' < /etc/nginx/nginx.conf.template >
/etc/nginx/nginx.conf && cat /etc/nginx/nginx.conf"
??? ??? nginx ??
? Aws ELB???
? ? ???.. Resolver 10.0.0.2 valid=2s;
ELB/ALB? ??? ???? ???? ???? ? ??
?????ÃûÇ°½â›Q ?? ??? ??
??? ??? ??? ??/??
? ?
?????..
????
???? ?? ??? ?????? ??(?? ?????
??? ????)
?????? logdriver? ???? ?? ???? ?? ???
?? ??
?? ???? ???????? ?????
???? ?? ?????
Aws kinesis agent? ???? AWS Kinesis Firehose? ??
Firehose? ???? s3? ??
AWS Athena? ??
????
logDriver? ???? ?? ???? ??
AWS ECS??? ???? logDriver? ???? ?????? ??
logDriver? td-agent? ?????? ??
Task definition
"logConfiguration": {
"logDriver": "awslogs",
"options": {
"awslogs-group": "rails-actionlog-production",
"awslogs-stream-prefix": "production",
"awslogs-region": "ap-northeast-1"
}
Dockerfile
RUN ln -sf /proc/1/fd/1 /var/log/rails/xx.log
TEST
? ??? ???????? ?? ?????? ?? ????
???? ???? ??
? ?? ??? ??? ?? ??? ??? ???? ??
? ?? ?????? ?? ??? ??? ???? ??? ???
?? ??
? ??:?? ??? ???? ? ???, ??? ??? ????
?? ??? ??? ??
? ???? ??? -> ??? ? ??? serverspec? ?? ??
TEST
Docker build?
???? ????
Docker_build_root
Rails_env
{development
staging,
production}
files
set_env.sh set._key.sh run_sh.sh
?? ??
??????
??? ??
test Dockerfile
build_docker.s
h
run_docker.sh
push_docker.s
h
deploy
test???? ??? serverspec? ????? ??????.
Circleci?? ?? ???? ??? ?????? build,run?
??? ??? ??? ???? ???.
Base ????
Ubuntu:14.04 Ruby:2.3.3 Unicorn:xxx
Unicorn:xxx? build??? ??? ???? ????? ???
?? ??? ???? ?? ??? ??? ??
common
Base ????
rails_root
docker
nginx
unicorn
base
ruby
2.3.1 build_docker.sh
2.3.3 build_docker.sh
php
nginx
unicorn-common
Dockerfile
docker-
compose.yml
Base ????? ?? ?? ???? ??? ?
??????? docker
? ????? production?? ???? ?? ? ??
? ??? ???? ??
? ?? ?? ??? Docker for mac??-> ??? docker-async??
? ??? ????? ???? ?? ???? ?????
? ???..???? ??
? ??? ?? ???? ??? ? ???? ????, ??? ???
? ? ?? ????? ??? ??? ???. ????? ? ?
?? ????? ??????? ??? ?? ???, ? ???
IT??? ??? ??? ?? ?? ? ??
???? ??
? Swarm,Kubernets? , ECS
? ???? ?? ???? ??AWS???? ???
AWS?? ???? AWS ECS??
? ??? ? ???? ??..?????? ECS NOT BAD
???? ??? ?? ? ?? ??
??..
? ?? ?? ??? aws cloudWatch,new relic, bugsang??
? ??? ?????? ???? ???? ??? ???
????..
? ??? ? ??????..@negabaro
?? ????
? ?? ???? ??? ???
? ??? ???? ????? docker pull,push???
????? deploy??? ???
? ??? ?? aws ebs? ??? ??? ????? ??
??? ??? ?
? CoreOS, rancheros, alpine OS?? ??
? Ubuntu?? debian? ???
? ?? docker diet? ???? ??.. ???..base
image???14.04 ???¡­
cron??
? Rails??? rake???? ???? ?? ?????
??
? ?? ??? ??? ??? ??? ??????
docker exec? rake? ???~/.bashrc
export GET_CONTAINER="docker exec -t `docker ps | grep 3000 |grep 3005 |grep admin
| grep unicorn |grep -v redmine | awk '{print $1}'`
crontab -e
30 * * * * source ~/.bashrc;$GET_UNICORN_CONTAINER bash -lc "bundle exec rake
filmarks:xx RAILS_ENV=staging" 1 > /dev/null
Cron??
Lambda?? docker exec rake?? ???? ???
lambda python?? ????? ?? Docker exec rake??
??
EC2 Run Command? ?? ??
#!/bin/bash
yum -y update
curl https://[bucket-name].s3.amazonaws.com/latest/linux_amd64/amazon-ssm-
agent.rpm -o amazon-ssm-agent.rpm
yum install -y amazon-ssm-agent.rpm
http://dev.classmethod.jp/cloud/aws/introduce-to-run-a-command-button-for-linux/
??? ????? EC2RoleforSSM ???? ???
????
[service name]_[rails_env]_[middleware name]
Ex) xxx_staging_unicorn
Staging -> stg
Production -> prod
Developmet -> dev
simple is best..
????
? Locust(http://inokara.hateblo.jp/entry/2016/03/19/033028)
? Jmeter
? ?? ??
AWS ECS userdata?? ?
??? ?? ???? ec2??? ecs agent? ecs????? ???? ?
#!/bin/bash
sudo rm -rf /var/lib/ecs/data/ecs_agent_data.json
echo ECS_CLUSTER=[ECS???? ?] >> /etc/ecs/ecs.config
?? ?
? Docker ???? ???? ?? docker exec ?? ??..
? ? ??? ??? ?? alias??? ???
alias uu="docker exec -it `docker ps | grep unicorn | grep 3000 | awk '{print $1}'`
/bin/bash"
alias nn="docker exec -it `docker ps | grep nginx | grep 80 | awk '{print $1}'` /bin/bash"
alias pp="docker exec -it `docker ps | grep php | grep 80 | awk '{print $1}'` /bin/bash"
alias rr="docker exec -it `docker ps | grep td-agent | awk '{print $1}'` /bin/bash
alias drm='docker rm $(docker ps -aqf "status=exited") 2> /dev/null'
alias drmi='docker rmi $(docker images -aqf "dangling=true") 2> /dev/null'
??? ..??
? ??? ????? ???
? ????? ??? ??? production??? ???? ??? ?
?? ??? ??? ??? ??? ???? ? ???? ?? ??
? ?? ????? docker?, ?docker?? ???.. ???
?????? ?? ??? ???. API?? ???? ?????
??? ??..elasticsearch???? ????? ???? ???
? ??? ??? docker? ?? ??? ??
? ??? ??? ?? ??? ??? ??? ?? ???? ??? ?
Question??
? ??? ??? ?? ?? ??? ??? ????
????? : )
? https://twitter.com/negabaro
? https://www.facebook.com/negabaro
? negabaro@gmail.com
??? ? ?????
?????.
?

More Related Content

What's hot (20)

Docker ?? ? Docker Swarm? ??? ?? ?? ?? A?? Z?? [?????? ????]
Docker ?? ? Docker Swarm? ??? ?? ?? ?? A?? Z?? [?????? ????]Docker ?? ? Docker Swarm? ??? ?? ?? ?? A?? Z?? [?????? ????]
Docker ?? ? Docker Swarm? ??? ?? ?? ?? A?? Z?? [?????? ????]
David Lee
?
Docker?? ?? ???
Docker?? ?? ???Docker?? ?? ???
Docker?? ?? ???
SeongHyun Jeong
?
Enterprise Docker
Enterprise DockerEnterprise Docker
Enterprise Docker
Lee Ji Eun
?
?? ??? ????: ??? ??? ??? 60??? ? ??? ?? ? ????!
?? ??? ????: ??? ??? ??? 60??? ? ??? ?? ? ????!?? ??? ????: ??? ??? ??? 60??? ? ??? ?? ? ????!
?? ??? ????: ??? ??? ??? 60??? ? ??? ?? ? ????!
pyrasis
?
Introduce Docker
Introduce DockerIntroduce Docker
Introduce Docker
Yongbok Kim
?
XECon2015 :: [2-4] ??? - Chak ??? ??? with XE3
XECon2015 :: [2-4] ??? - Chak ??? ??? with XE3XECon2015 :: [2-4] ??? - Chak ??? ??? with XE3
XECon2015 :: [2-4] ??? - Chak ??? ??? with XE3
XpressEngine
?
???? ?? ?? ?? ? ??
???? ?? ?? ?? ? ?????? ?? ?? ?? ? ??
???? ?? ?? ?? ? ??
Daniel Seo
?
??? ??? ??? ?? ????
??? ??? ??? ?? ??????? ??? ??? ?? ????
??? ??? ??? ?? ????
JunSeok Seo
?
Docker ??????????? public v0.1
Docker ??????????? public v0.1Docker ??????????? public v0.1
Docker ??????????? public v0.1
Steve Shim
?
Docker at Deview 2013
Docker at Deview 2013Docker at Deview 2013
Docker at Deview 2013
Jude Kim
?
AWS + Docker in Vingle
AWS + Docker in VingleAWS + Docker in Vingle
AWS + Docker in Vingle
D C
?
???? ?? ?? ???
???? ?? ?? ??????? ?? ?? ???
???? ?? ?? ???
GeunCheolYeom
?
Docker ?? ???? ?? - XE Open seminar #2
Docker ?? ???? ?? - XE Open seminar #2Docker ?? ???? ?? - XE Open seminar #2
Docker ?? ???? ?? - XE Open seminar #2
XpressEngine
?
Docker? ?? ?? ??? ??
Docker? ?? ?? ??? ??Docker? ?? ?? ??? ??
Docker? ?? ?? ??? ??
Dronix
?
Kubernetes on GCP
Kubernetes on GCPKubernetes on GCP
Kubernetes on GCP
Daegeun Kim
?
?? ??? Boot2Docker
?? ??? Boot2Docker?? ??? Boot2Docker
?? ??? Boot2Docker
pyrasis
?
XECon2015 :: [3-4] ??? - Laravel with cloud
XECon2015 :: [3-4] ??? - Laravel with cloudXECon2015 :: [3-4] ??? - Laravel with cloud
XECon2015 :: [3-4] ??? - Laravel with cloud
XpressEngine
?
Introduction to Docker - LOGISPOT
Introduction to Docker - LOGISPOTIntroduction to Docker - LOGISPOT
Introduction to Docker - LOGISPOT
Hosang Jeon
?
Docker Container
Docker ContainerDocker Container
Docker Container
Seung-Hoon Baek
?
Backend Master | 3.4.5 Deploy - Docker Principal
Backend Master | 3.4.5 Deploy - Docker PrincipalBackend Master | 3.4.5 Deploy - Docker Principal
Backend Master | 3.4.5 Deploy - Docker Principal
Kyunghun Jeon
?
Docker ?? ? Docker Swarm? ??? ?? ?? ?? A?? Z?? [?????? ????]
Docker ?? ? Docker Swarm? ??? ?? ?? ?? A?? Z?? [?????? ????]Docker ?? ? Docker Swarm? ??? ?? ?? ?? A?? Z?? [?????? ????]
Docker ?? ? Docker Swarm? ??? ?? ?? ?? A?? Z?? [?????? ????]
David Lee
?
Enterprise Docker
Enterprise DockerEnterprise Docker
Enterprise Docker
Lee Ji Eun
?
?? ??? ????: ??? ??? ??? 60??? ? ??? ?? ? ????!
?? ??? ????: ??? ??? ??? 60??? ? ??? ?? ? ????!?? ??? ????: ??? ??? ??? 60??? ? ??? ?? ? ????!
?? ??? ????: ??? ??? ??? 60??? ? ??? ?? ? ????!
pyrasis
?
XECon2015 :: [2-4] ??? - Chak ??? ??? with XE3
XECon2015 :: [2-4] ??? - Chak ??? ??? with XE3XECon2015 :: [2-4] ??? - Chak ??? ??? with XE3
XECon2015 :: [2-4] ??? - Chak ??? ??? with XE3
XpressEngine
?
???? ?? ?? ?? ? ??
???? ?? ?? ?? ? ?????? ?? ?? ?? ? ??
???? ?? ?? ?? ? ??
Daniel Seo
?
??? ??? ??? ?? ????
??? ??? ??? ?? ??????? ??? ??? ?? ????
??? ??? ??? ?? ????
JunSeok Seo
?
Docker ??????????? public v0.1
Docker ??????????? public v0.1Docker ??????????? public v0.1
Docker ??????????? public v0.1
Steve Shim
?
Docker at Deview 2013
Docker at Deview 2013Docker at Deview 2013
Docker at Deview 2013
Jude Kim
?
AWS + Docker in Vingle
AWS + Docker in VingleAWS + Docker in Vingle
AWS + Docker in Vingle
D C
?
Docker ?? ???? ?? - XE Open seminar #2
Docker ?? ???? ?? - XE Open seminar #2Docker ?? ???? ?? - XE Open seminar #2
Docker ?? ???? ?? - XE Open seminar #2
XpressEngine
?
Docker? ?? ?? ??? ??
Docker? ?? ?? ??? ??Docker? ?? ?? ??? ??
Docker? ?? ?? ??? ??
Dronix
?
?? ??? Boot2Docker
?? ??? Boot2Docker?? ??? Boot2Docker
?? ??? Boot2Docker
pyrasis
?
XECon2015 :: [3-4] ??? - Laravel with cloud
XECon2015 :: [3-4] ??? - Laravel with cloudXECon2015 :: [3-4] ??? - Laravel with cloud
XECon2015 :: [3-4] ??? - Laravel with cloud
XpressEngine
?
Introduction to Docker - LOGISPOT
Introduction to Docker - LOGISPOTIntroduction to Docker - LOGISPOT
Introduction to Docker - LOGISPOT
Hosang Jeon
?
Backend Master | 3.4.5 Deploy - Docker Principal
Backend Master | 3.4.5 Deploy - Docker PrincipalBackend Master | 3.4.5 Deploy - Docker Principal
Backend Master | 3.4.5 Deploy - Docker Principal
Kyunghun Jeon
?

Viewers also liked (8)

Docker ? Linux ?? Linux ???? ????
Docker ? Linux ?? Linux ???? ????Docker ? Linux ?? Linux ???? ????
Docker ? Linux ?? Linux ???? ????
iFunFactory Inc.
?
Ji ?? ?? (???????)
Ji ?? ?? (???????)Ji ?? ?? (???????)
Ji ?? ?? (???????)
beom kyun choi
?
?????? ????? ????
?????? ????? ?????????? ????? ????
?????? ????? ????
beom kyun choi
?
Event source ?????? ????? ?????
Event source ?????? ????? ?????Event source ?????? ????? ?????
Event source ?????? ????? ?????
beom kyun choi
?
?? ?? ??? ??? ??
?? ?? ??? ??? ???? ?? ??? ??? ??
?? ?? ??? ??? ??
beom kyun choi
?
³¾¾±²Ô²Ô±ð¤Ë¤ª¤±¤ë¥Æ¥¹¥È?¥ê¥ê©`¥¹?¥ê¥ê©`¥¹ºó¤Ë¤ä¤Ã¤Æ¤¤¤ëʤÎÉܽé
³¾¾±²Ô²Ô±ð¤Ë¤ª¤±¤ë¥Æ¥¹¥È?¥ê¥ê©`¥¹?¥ê¥ê©`¥¹ºó¤Ë¤ä¤Ã¤Æ¤¤¤ëʤÎÉܽ鳾¾±²Ô²Ô±ð¤Ë¤ª¤±¤ë¥Æ¥¹¥È?¥ê¥ê©`¥¹?¥ê¥ê©`¥¹ºó¤Ë¤ä¤Ã¤Æ¤¤¤ëʤÎÉܽé
³¾¾±²Ô²Ô±ð¤Ë¤ª¤±¤ë¥Æ¥¹¥È?¥ê¥ê©`¥¹?¥ê¥ê©`¥¹ºó¤Ë¤ä¤Ã¤Æ¤¤¤ëʤÎÉܽé
Masataka Kono
?
???? ??
???? ?????? ??
???? ??
beom kyun choi
?
??????? 1???, ????????? ???????
??????? 1???, ????????? ?????????????? 1???, ????????? ???????
??????? 1???, ????????? ???????
Brian Hong
?
Docker ? Linux ?? Linux ???? ????
Docker ? Linux ?? Linux ???? ????Docker ? Linux ?? Linux ???? ????
Docker ? Linux ?? Linux ???? ????
iFunFactory Inc.
?
Event source ?????? ????? ?????
Event source ?????? ????? ?????Event source ?????? ????? ?????
Event source ?????? ????? ?????
beom kyun choi
?
³¾¾±²Ô²Ô±ð¤Ë¤ª¤±¤ë¥Æ¥¹¥È?¥ê¥ê©`¥¹?¥ê¥ê©`¥¹ºó¤Ë¤ä¤Ã¤Æ¤¤¤ëʤÎÉܽé
³¾¾±²Ô²Ô±ð¤Ë¤ª¤±¤ë¥Æ¥¹¥È?¥ê¥ê©`¥¹?¥ê¥ê©`¥¹ºó¤Ë¤ä¤Ã¤Æ¤¤¤ëʤÎÉܽ鳾¾±²Ô²Ô±ð¤Ë¤ª¤±¤ë¥Æ¥¹¥È?¥ê¥ê©`¥¹?¥ê¥ê©`¥¹ºó¤Ë¤ä¤Ã¤Æ¤¤¤ëʤÎÉܽé
³¾¾±²Ô²Ô±ð¤Ë¤ª¤±¤ë¥Æ¥¹¥È?¥ê¥ê©`¥¹?¥ê¥ê©`¥¹ºó¤Ë¤ä¤Ã¤Æ¤¤¤ëʤÎÉܽé
Masataka Kono
?
??????? 1???, ????????? ???????
??????? 1???, ????????? ?????????????? 1???, ????????? ???????
??????? 1???, ????????? ???????
Brian Hong
?

Similar to aws/docker/rails? ??? ??? ??/?? - docker? (20)

Docker osc 0508
Docker osc 0508Docker osc 0508
Docker osc 0508
Open Source Consulting
?
[???????]Docker on Kubernetes v1
[???????]Docker on Kubernetes v1[???????]Docker on Kubernetes v1
[???????]Docker on Kubernetes v1
Ji-Woong Choi
?
[17.01.19] docker introduction (Korean Version)
[17.01.19] docker introduction (Korean Version)[17.01.19] docker introduction (Korean Version)
[17.01.19] docker introduction (Korean Version)
Ildoo Kim
?
Docker & Kubernetes ?? - ???
Docker & Kubernetes ?? - ???Docker & Kubernetes ?? - ???
Docker & Kubernetes ?? - ???
?? ?
?
[????????]???_(?? ?? ??? ???)
[????????]???_(?? ?? ??? ???)[????????]???_(?? ?? ??? ???)
[????????]???_(?? ?? ??? ???)
CONNECT FOUNDATION
?
[9? ?? ???] ??? ????? ??? ????
[9? ?? ???] ??? ????? ??? ????[9? ?? ???] ??? ????? ??? ????
[9? ?? ???] ??? ????? ??? ????
NAVER CLOUD PLATFORM???? ???? ???
?
Introduction to Docker - LOGISPOT
Introduction to Docker - LOGISPOTIntroduction to Docker - LOGISPOT
Introduction to Docker - LOGISPOT
LOGISPOT
?
docker on GCE ( JIRA & Confluence ) - GDG Korea Cloud
docker on GCE ( JIRA & Confluence ) - GDG Korea Clouddocker on GCE ( JIRA & Confluence ) - GDG Korea Cloud
docker on GCE ( JIRA & Confluence ) - GDG Korea Cloud
Jude Kim
?
[221] docker orchestration
[221] docker orchestration[221] docker orchestration
[221] docker orchestration
NAVER D2
?
[???????]Docker on Cloud(Digital Ocean)
[???????]Docker on Cloud(Digital Ocean)[???????]Docker on Cloud(Digital Ocean)
[???????]Docker on Cloud(Digital Ocean)
Ji-Woong Choi
?
Docker? ????? : Docker ?? ???
Docker? ????? : Docker ?? ???Docker? ????? : Docker ?? ???
Docker? ????? : Docker ?? ???
pyrasis
?
[1A6]Docker?? ????? ???? ???????? ????
[1A6]Docker?? ????? ???? ???????? ????[1A6]Docker?? ????? ???? ???????? ????
[1A6]Docker?? ????? ???? ???????? ????
NAVER D2
?
1. Docker Network (1)
1. Docker Network (1)1. Docker Network (1)
1. Docker Network (1)
DEVELOPER.NET
?
docker_quick_start
docker_quick_startdocker_quick_start
docker_quick_start
Sukjin Yun
?
Docker? DevOps?? Serverless? NoOps?? ??
Docker? DevOps?? Serverless? NoOps?? ??Docker? DevOps?? Serverless? NoOps?? ??
Docker? DevOps?? Serverless? NoOps?? ??
Kyuhyun Byun
?
[W3C HTML5 2017] Docker & DevOps?? Serverless & NoOps?? ??
[W3C HTML5 2017] Docker & DevOps?? Serverless & NoOps?? ??[W3C HTML5 2017] Docker & DevOps?? Serverless & NoOps?? ??
[W3C HTML5 2017] Docker & DevOps?? Serverless & NoOps?? ??
??? ???
?
GDGoC_Backend_GoServer_5???? ?????????.pdf
GDGoC_Backend_GoServer_5???? ?????????.pdfGDGoC_Backend_GoServer_5???? ?????????.pdf
GDGoC_Backend_GoServer_5???? ?????????.pdf
dpfls5645
?
??? ?? - ??? ???? ???? :: AWS Container Day
??? ?? - ??? ???? ???? :: AWS Container Day??? ?? - ??? ???? ???? :: AWS Container Day
??? ?? - ??? ???? ???? :: AWS Container Day
Amazon Web Services Korea
?
SOSCON 2017 - Backend.AI
SOSCON 2017 - Backend.AISOSCON 2017 - Backend.AI
SOSCON 2017 - Backend.AI
Joongi Kim
?
[???????]Docker?? ?? ?? 20181113_v3
[???????]Docker?? ?? ?? 20181113_v3[???????]Docker?? ?? ?? 20181113_v3
[???????]Docker?? ?? ?? 20181113_v3
Ji-Woong Choi
?
[???????]Docker on Kubernetes v1
[???????]Docker on Kubernetes v1[???????]Docker on Kubernetes v1
[???????]Docker on Kubernetes v1
Ji-Woong Choi
?
[17.01.19] docker introduction (Korean Version)
[17.01.19] docker introduction (Korean Version)[17.01.19] docker introduction (Korean Version)
[17.01.19] docker introduction (Korean Version)
Ildoo Kim
?
Docker & Kubernetes ?? - ???
Docker & Kubernetes ?? - ???Docker & Kubernetes ?? - ???
Docker & Kubernetes ?? - ???
?? ?
?
Introduction to Docker - LOGISPOT
Introduction to Docker - LOGISPOTIntroduction to Docker - LOGISPOT
Introduction to Docker - LOGISPOT
LOGISPOT
?
docker on GCE ( JIRA & Confluence ) - GDG Korea Cloud
docker on GCE ( JIRA & Confluence ) - GDG Korea Clouddocker on GCE ( JIRA & Confluence ) - GDG Korea Cloud
docker on GCE ( JIRA & Confluence ) - GDG Korea Cloud
Jude Kim
?
[221] docker orchestration
[221] docker orchestration[221] docker orchestration
[221] docker orchestration
NAVER D2
?
[???????]Docker on Cloud(Digital Ocean)
[???????]Docker on Cloud(Digital Ocean)[???????]Docker on Cloud(Digital Ocean)
[???????]Docker on Cloud(Digital Ocean)
Ji-Woong Choi
?
Docker? ????? : Docker ?? ???
Docker? ????? : Docker ?? ???Docker? ????? : Docker ?? ???
Docker? ????? : Docker ?? ???
pyrasis
?
[1A6]Docker?? ????? ???? ???????? ????
[1A6]Docker?? ????? ???? ???????? ????[1A6]Docker?? ????? ???? ???????? ????
[1A6]Docker?? ????? ???? ???????? ????
NAVER D2
?
docker_quick_start
docker_quick_startdocker_quick_start
docker_quick_start
Sukjin Yun
?
Docker? DevOps?? Serverless? NoOps?? ??
Docker? DevOps?? Serverless? NoOps?? ??Docker? DevOps?? Serverless? NoOps?? ??
Docker? DevOps?? Serverless? NoOps?? ??
Kyuhyun Byun
?
[W3C HTML5 2017] Docker & DevOps?? Serverless & NoOps?? ??
[W3C HTML5 2017] Docker & DevOps?? Serverless & NoOps?? ??[W3C HTML5 2017] Docker & DevOps?? Serverless & NoOps?? ??
[W3C HTML5 2017] Docker & DevOps?? Serverless & NoOps?? ??
??? ???
?
GDGoC_Backend_GoServer_5???? ?????????.pdf
GDGoC_Backend_GoServer_5???? ?????????.pdfGDGoC_Backend_GoServer_5???? ?????????.pdf
GDGoC_Backend_GoServer_5???? ?????????.pdf
dpfls5645
?
SOSCON 2017 - Backend.AI
SOSCON 2017 - Backend.AISOSCON 2017 - Backend.AI
SOSCON 2017 - Backend.AI
Joongi Kim
?
[???????]Docker?? ?? ?? 20181113_v3
[???????]Docker?? ?? ?? 20181113_v3[???????]Docker?? ?? ?? 20181113_v3
[???????]Docker?? ?? ?? 20181113_v3
Ji-Woong Choi
?

aws/docker/rails? ??? ??? ??/?? - docker?

  • 1. AWS/Docker/Rails ? ??? ????? ??/?? AWS/Docker/Rails? ??? ??? ??/???? ???? ??? ???? ???????.
  • 2. ???? ??:???(@negabaro) ???: ?? ?? ??: 2011? ??x ?????/JSP ?????? ??(SI) 2013? ???x ??? ????(EC) 2015? ?????x DevOps???? ????(IT???) 2017? ???x ???/DevOps????(?? ??) ??:????(???),??
  • 3. AWS/Docker/Rails? ??? ???????/?? ??? ??? ??? ?? ???? ??? ???????. ??? ?????..! <#>
  • 4. ?? ? ????? ? ???? ? ??? ??? ??? ??/??? ??? ??? ?? ¨C ???? ?? ¨C Docker Automation build,deploy ¨C rails?? ??/?? ¨C nginx?? ??/?? ¨C ? ?
  • 5. ????? ??? ??? ?? ?? ?????..
  • 8. ????? DB???? ????? elasticsearch ??DB mysql ? ? ???? s3?? ?? redis ?? memcached CDN CloudFront
  • 9. ????? ?????? ??? Middleware?? docker? ??(nginx,unicorn,php- fpm,td-agent) AWS ECS? ???? docker ???? ?? ??? ????? ????? ??? ?? ?? ??? ?? ???in,out?
  • 10. ????? ?????? ??? Web,API Rails? ?? ?? ?????(?????? ??)
  • 11. Docker????? ???? ?? ???? ?????. ??? ??? ????? ???? ????? ???? (??? ??? ?? ?????¡­)
  • 12. Docker?? ??? ???? ? ???? ????? ??? ? ?? ????? ? ????? ??? ? ?? API
  • 13. Docker?? ???? ???? ?? ?? ?? ??? ????? ???? ??(tool) ?? ???,???OS, ?? ?? ?? ??? ?? ????? ???? ??? ?? ?? ??,?? ?? ???? ?? ?????? ??? ?? ?? ????? ??/??/?? Dockerfile ??? ???? ?? ??? ??? ????? ?? ?? ??? ????? ????? ?? ??? ??? ??. ?????? ????? ??? ????(iso ????). ?? ???? git? ?? ???(commit),??(branch),????(push),????(pull)? ?? ?? ????? docker ??? ???? ??,?? ???? ?? ??? ? ??,???? ???? ?. ?? ?? ?? ???? ???/??/??? ? ?? ?? ?? ??? ???(repository) ??? ??? ???? OS??? ???(Docker hub? ??? ??) ???? ?? ???? ??? ?? ??? ??????? ?? ? ??
  • 14. ?? ??? ??? ???? ??? ?????. Docker?? ???? ????
  • 15. Docker?? ???? ???? ?? ???? Base Image ??? ???? xx??? ???? ????? ???? ?????. ???=??? ???
  • 16. Docker?? ???? ???? ?? ???? Base Image docker build ??? ???? ?? ???? xx??? ??? ???? ????. CD? ?? = docker build
  • 17. Docker?? ???? ???? ?? ???? Base Image docker run docker build ??? ???? ?? CD? CD-ROM? ?? ??????. CD-ROM? ??? ?? = docker run
  • 18. Docker?? ???? ???? ?? ???? ConainerBase Image docker run docker build xx??? ??????? xx??? ??? ?? =????
  • 19. Docker?? ???? ???? ?? ???? ContainerBase Image docker run docker build Host OS xx??? ??? ??? ???? CPU i7 7700k, ??? ?? nvidia titan x? ??? ???????. xx?? ??? ??? = Host OS,docker host,docker server
  • 20. Docker?? ???? ???? ?? ???? Docker repository(Dokcer Hub,AWS ECR) ??????? ??? docker run docker build Host OS ??? xx??? ?? ???? xx??? ???? cd? ???? ?? cd???? ?????. CD???=Docker repository(docker hub,aws ecr) CD???? ??=docker push docker push
  • 21. Docker?? ???? ???? ?? ???? docker builddocker run docker push ??? docker build? ?? ??? docker run,docker push? ????. ??? ??? docker?? ??? ?????? docker ??????? ?? ? ?????.
  • 22. Docker?? ?? ?? Linux Namespaces£º??? ??? ?? Linux cgroups£º??? ??? ?? AUFS£¯Device Mapper Thin Provisioning£º ??/???? ???? Linux iptables£º???,???? ?? ???? ??
  • 23. Docker?? ??? ??(??? ??) ? ??? (vmware) ? ????(xen) ? ??? ???? = Solaris Containers,??VZ, ???????(LXC), lmcfty ? ?? ???? = docker
  • 24. Docker?? ??? ??2(????? ??) ? 1983? 4.2BSD?? Chroot ???System Call? ??? ? 2000? FreeBSD 4.0?? FreeBSD Jail? ?? ? ?? ???? ?? ??? ?? ?? ???(? ??? ??? ? ????) ? Solaris Containers ? ?? docker???(?????? ?? ?? ??!) ? 2008? ??? ??? Linux cgroups? merge? ? LXC ???,??? ?? ?? ?? ?? ?????? ??? ??? ?? ? Docker 2014? ?? LXC? ????? ???
  • 25. Docker?? ??? ??3(docker??? ??) ? LXC? ???? ?? ? 0.9???? ???? libcontainer ??? ??(???? LXC??? ??) ? ?? runC??? ??? ? ?? docker? ????? 1.13
  • 26. Docker?? ??? ?? ? ?????? ?????? ???? ???? ????? ??? ???? ? ??? Control Group(cgroups) ??? ?? CPU? ????, ???? ??????? ??? ? ??? ??, ??? Namespace isolation(?? namespaces)?? ???? ??????? ?????, fs??? ?? ?? ? ??? ?? ? ???OS? ?? ? ?? ??? ???? ??? ??? ???? ? Go??? ????
  • 27. Docker?? ??? ?? ? ??? ?? ??? OS?? ????? ??? ???(portable?) ? Hands ON? ????? ?? ????? ?? ? ???? ?? ????? ??? ? ???? ??? ?? ? ?? ? ??? ???
  • 28. Docker?? ?? ?? ? ???? ???? ????? ??? ???? ??? ?? ? ?? ???? ?? ??? ??? ??? ? ? ??, ???, ??? ??? ????? ?? ??? ? ??? ???? ??? ?????? ????? ???? ????? ???? ?? SaaS? PaaS ?? ???? ??? ???? ?? ?? ? ????? ????? ?? ????? ??? ???? ?? ?? ? ??.??? ?? ??? ?? ??
  • 29. Docker?? VM vs Docker? ?? VM? ????,????? Hypervisor? ????? overhead? ?? docker? hypervisor? ???? ?? ??Host OS? ????? VM?? ????? ??
  • 30. Docker?? Docker vs Chef,Ansible,Puppet ? ??????? docker? ????? ?? ? Docker?Immutable Infrastructure? ??? ? Bootstrapping?Configuration? ?? ? Docker? ????? chef,ansible,puppet?? ???
  • 31. Docker?? Docker Command ? Docker run ? Docker build ? Docker exec ? Docker rm ? Docker rmi ? ??? ??
  • 32. ??? ??? ??? ??/?? ??? ??? ??? ??? ???? ???? ???????.
  • 33. Docker? ??? ?? ? ???? (rails? DRY??? ?? ??) ? ????? production?? ???? ??? ?? ? ????? Chef,ansible?? ?? ?????? ?? ? Hot? ?????..
  • 34. ?? ??? ?? ? ??,??? ?? ??,??? ?? git??? ???? ?? ?? ? Wiki? git?? ????? ?? ? ????? trello?? xenhub? ? git push? ?? deploy?? ???? ?? ??
  • 35. ???? ??? ??.. ? ???? ?? ? Docker build,push,deploy ? ???? ?? ? ??? ?? ? ???? ? ?? ?? ? ?? ?? ? ??? ? ???
  • 36. ??? ??? ??? ??/?? ???? ??
  • 37. ???? ?? ??? ??? ??? ? ? ??????? ??? automation docker build? ???? ?? ?? ? ? middleware? docker???? rails_env?? ??? ? Docker?? ?? ?? ??? ??????? ???? ?? ? ??? DRY?? ???? ?? ? ????? ?? ?? ??? ??? ??
  • 38. Directory structure Rails_env Middleware docker Rails_root rails_root docker nginx unicorn development beta staging productoon shared memcached redis elasticsearch td-agent mysql base Dockerfile docker- compose.yml Middleware layer?? ? ?? ?????? rails.env layer? ??(unicorn??? ??) Mysql? ?? development???? aws RDS? ??? development????? ??
  • 39. Directory structure ¨C Rails_root Rails_env Middleware docker Rails_root rails_root docker nginx unicorn development beta staging productoon shared memcached redis elasticsearch td-agent mysql Dockerfile docker- compose.yml Rails_root ?? ????? ??? ???????.
  • 40. Directory structure ¨C docker Rails_env Middleware docker Rails_root rails_root docker nginx unicorn development beta staging productoon shared memcached redis elasticsearch td-agent mysql Dockerfile docker- compose.yml File name description docker-compose.yml ??? ????? ??? ?? (??development???? ??) Dockerfile docker build? ?? ??? ????? ?? docker?? ???? ???. Docker????? development???? ??? Dockerfile,docker-compose.yml????.
  • 41. Directory structure ¨C Middleware Rails_env Middleware docker Rails_root rails_root docker nginx unicorn development beta staging productoon shared memcached redis elasticsearch td-agent mysql base Dockerfile docker- compose.yml Docker ??????? ?????? ????? ?????? ?????. ??? ????? ?? docker image? ???? ???? ???? base????? ????.(base????? ???? ??? ??)
  • 42. Directory structure ¨C Rails_env Rails_env Middleware docker Rails_root rails_root docker nginx unicorn development beta staging productoon shared memcached redis elasticsearch td-agent mysql base Dockerfile docker- compose.yml Middleware???? ??? ???? ????? ??????. ? ?? ????? ????? ?????? ??? ?? shared????? ????.
  • 43. Directory structure ¨C Rails_env - environment ?? ?? ?? development ? ????? ????? ?????? ??? ?? beta Github ??? ?? ??? ???? ?? staging Production??? ???? ?? ?? ?? ???? ?? production ?? ??? ??
  • 44. Directory structure2 ¨C Docker_build_root Docker build? ???? ???? Docker_build_root Rails_env {development staging, production} files set_env.sh set._key.sh run_sh.sh ?? ?? ?????? ??? ?? test Dockerfile build_docker.s h run_docker.sh push_docker.s h deploy ??? ?? Dockerfile docker build? ?? Files???? docker??????? ??? ??(Dockerfile??? files??? ADD?) build_docker.sh docker build? ???? ???? ?? run_docker.sh docker build? ???? ?????? run?? ??. ?? ???? ?? ???? ??(serverspec) Push_docker.sh Build,test? ?? docker???? aws ecr? push deploy???? ???? ?? ????(Task Definition file?)? ??
  • 45. Directory structure2 ¨C Docker build? ???? ???? Docker build? ???? ???? Docker_build_root Rails_env {development staging, production} files set_env.sh set._key.sh run_sh.sh ?? ?? ?????? ??? ?? test Dockerfile build_docker.s h run_docker.sh push_docker.s h deploy ??? ?? set_env.sh S3?? ????? ?? set_key.sh S3?? ssh key? ?? run_sh.sh ?? ????? ????? ???? ?? shellscript?? ?? build_docker.sh docker build? ???? ???? ?? Other_files ?? ?? ???? ??? ??? ???
  • 46. ???? ??? ???? ??? ???? docker automation build docker container test by serverspec docker auto deploy for aws ecs ?? ??
  • 47. ??? ??? ??? ??/?? Docker Automation Build,Deploy
  • 48. Docker build automation docker build? ????? ??? ?? docker build ??? ?? ?? ?? ???????.
  • 49. How to do Docker build ???Docker_root Rails.env rails.env layer {development staging, production} files set_env.sh set._key.sh run_sh.sh ?? ?? ?????? ??? ?? Dockerfile build_docker.sh run_docker.sh push_docker.sh deploy Docker build? ???? ???? ?? build_docker.sh? ??
  • 50. build_docker.sh?? PR_NUMBER ="${CIRCLE_PR_NUMBER}" //circlieCI??? ??P.R??? ????? ?? ?? Docker build ¨Ct [ECR-EndPoint]/[ECR-Image]:PR_NUMBER ¨Ct [ECR-EndPoint]/[ECR- Image] ¨Cfile Dockerfile . //??P.R??? ??? ??? docker build Docker repository??? aws ECR? ??
  • 51. How to do Docker Automaition Build ??? ??? ? Docker hub? automation build ??? ??? ? ????? ?????? ???? ?? ?????? ?????? ??? ??.. ? ??? ????? ??? ??? automation build ??? ???? ?? ? ? ??? branch? git push? ??? build,push,test,deploy?? ?? ??? ??? ???? ??? ??
  • 52. How to do Docker Automaition Build ???..?? ? Automation Docker Build ? ?? circleCI? ?? ? Docker???? ???? ????? ? Middleware?? docker build? ???build_docker.sh??? ??? ? circleCI??? git diff???? ???? ??Middleware?? ????? ?? ??? ??????? ?? ???? build_docker.sh ??? ?????? ?
  • 53. How to do Docker Automaition Build ???? ? ???? ??? git push -> circleCI?? ??-> git diff?? build_docker.sh? ???? ???? ?? -> build ???? ???? ??? build_docker.sh?? ¨C> run_docker.sh ?? ???? ?? -> serverspec ?? ?? ???? ??test -> ?? ??? -> docker push -> deploy ? ???? ? git push -> circleci -> git diff -> build_docker.sh
  • 54. How to do Docker Automaition Build ??? ?? ??? ?? ? ?? ???? ??? ??? 10?,??? ???? 1?? ?? ? P.R??? ????? rails??? ?? ? circleCI??? ???? rails?? rspec???? 20?? ?? ? ??? docker build,run ??? ? ??? rspec? ???? ?? ???? ??? ??? ? ???? ?.. ? ??. ? ?? ???? merge???? docker ?? build ???? ????? ?
  • 55. How to do Docker Automaition Build circle.yml deployment: develop: branch: develop commands: - sh docker/run_git_diff.sh: timeout: 1500 betax: branch: betax commands: - sh docker/run_git_diff.sh: timeout: 1500 staging: branch: staging commands: - sh docker/run_git_diff.sh: timeout: 1500 production: branch: production commands: - sh docker/run_git_diff.sh: timeout: 1500 ?? docker?? ??? circleCI?deployment ??? ??? ?? ?? ????? ???? ??? ?? run_git_diff.sh????? ??? ??? ?? docker build? ???? ???
  • 56. How to do Docker Automaition Build git diff??? #!/bin/sh changed_files="$(git diff-tree -r --name-only --no-commit-id ORIG_HEAD)¡° branch_name="${CIRCLE_BRANCH}" updated_nginx_status=false updated_unicorn_status=false updated_td-agent_status=false updated_rails_status=false for var in $changed_files do if [[ $var =~ ^docker/nginx/$branch_name ]]; then updated_nginx_status =true elif [[ $var =~ ^docker/unicorn/$branch_name ]]; then updated_unicorn_status=true elif [[ $var =~ ^docker/td-agent/$branch_name ]]; then updated_td-agent_status =true else updated_rails_status=true fi done
  • 57. How to do Docker Automaition Build git diff??? #!/bin/sh if [ $updated_nginx_status ]; then sh docker/nginx/$branch_name/build_docker.sh //docker build sh docker/nginx/$branch_name/run_docker.sh //docker run sh docker/nginx/$branch_name/test/run_test.sh //serverspec?? ??? ????? ?? ??? sh docker/nginx/$branch_name/push_docker.sh //???? ??? ??? aws ecr? docker push else fi if [ $updated_unicorn_status ]; then sh docker/unicorn/$branch_name/build_docker.sh sh docker/unicorn/$branch_name/run_docker.sh sh docker/unicorn/$branch_name/test/run_test.sh sh docker/unicorn/$branch_name/push_docker.sh else fi autumation docker run,test,push? ??? ??
  • 58. How to do Docker Automaition Build ???? ??? ???? rails_root docker nginx unicorn development beta staging productoon shared memcached redis elasticsearch development Build_docker.sh td-agent production mysql base Dockerfile docker- compose.yml docker/nginx/beta/xx docker/elasticsearch/d evelopment/xxx docker/td- agent/production/xxx ?? ?? ??? development branch? merge???
  • 59. How to do Docker Automaition Build ???? ??? ???? rails_root docker nginx unicorn development beta staging productoon shared memcached redis elasticsearch development Build_docker.sh td-agent production mysql base Dockerfile docker- compose.yml docker/nginx/beta/xx docker/elasticsearch/ development/xxx docker/td- agent/production/xxx ?? ?? ??? development branch? merge??? Development ????? ??? elasticsearch/development/build_ docker.sh??? ???
  • 60. How to do Docker Automaition Build ???? ??? ???? rails_root docker nginx production build_docker.sh unicorn development beta staging productoon build_docker.sh shared memcached redis elasticsearch development build_docker.sh td-agent production build_docker.sh mysql base Dockerfile docker- compose.yml docker/nginx/production /xx docker/elasticsearch/dev elopment/xxx docker/td- agent/production/xxx ?? ?? ??? production branch? merge??? docker/unicorn/producti on/xxx
  • 61. How to do Docker Automaition Build ???? ??? ???? rails_root docker nginx production build_docker.sh unicorn development beta staging productoon build_docker.sh shared memcached redis elasticsearch development build_docker.sh td-agent production build_docker.sh mysql base Dockerfile docker- compose.yml docker/nginx/production /xx docker/elasticsearch/dev elopment/xxx docker/td- agent/production/xxx ?? ?? ??? production branch? merge??? docker/unicorn/producti on/xxx Production ????? ??? nginx,unicorn,td-agent? build_docker.sh??? ?? ???
  • 62. How to do auto deployment ? ?? ??? AWS ECS? ??? ?? ???????. ? Git push -> circlieci -> git diff -> build_docker.sh - >run_docker.sh -> run_test.sh -> push_docker.sh -> create_task_def.sh -> update_task_def.sh
  • 63. How to do auto deployment ??? ??? ? AWS ECS? ???? ????? ? Blue green deployment??? ??? ?? ???? ???? ?? ? AWS ECS?Minimum healthy percent,Maximum percent?? ? ????? ??? ????? ?? ? ?????? ???20?? ??? ?? Minimum healthy percent:50, Maximum percent 100? ????? 10?? ????? ?? ??? ????? ??? -> ??? 10?? ????? ?? ??? ????? ???? ?
  • 64. How to do auto deployment about deploy directory Docker build? ???? ???? Docker_build_root Rails_env {development staging, production} files test deploy create_task_ def.sh dynamic_gen _task_def_js on.sh task_def.tem plate update_task _def.sh ??? ?? create_task_def.sh ?? docker build?? ?? ???? ???? task definition?? dynamic_gen_task_def_json.sh task_def.templat? ???? task_def.json??? ??(envsubust??? ??) task_def.template Dynamic_gen_task_def_json.sh???? ???? ??? update_task_def.sh ??? task_definition?? ??
  • 65. How to do auto deployment dynamic_gen_task_def_json.sh + task_def.template #!/bin/sh cd docker/unicorn/$BRANCH/deploy/ envsubst '$CIRCLE_PR_NUMBER' < task_def.template > task_def.json dynamic_gen_task_def_json.sh { "containerDefinitions": [ { "name": "unicorn", "image": ¡°xx.dkr.ecr.ap-northeast-1.amazonaws.com/xx:${CIRCLE_PR_NUMBER}", "essential": true, ¡­ task_def.template
  • 66. How to do auto deployment create_task_def.sh #!/bin/sh cd docker/unicorn/$BRANCH/deploy/ sh dynamic_gen_task_def_json.sh aws ecs register-task-definition --cli-input-json file://task-def.json //?? ??? task definition? aws ecs? ?? create_task_def.sh
  • 67. How to do auto deployment update_task_def.sh ???? well made?? ecs-deploy? ??? ?????? https://github.com/silinternational/ecs-deploy TASK_REVISIONS=`aws ecs list-task-definitions --family-prefix [family_name] --status ACTIVE --sort ASC` //?? family? ??? ?? task definition??? ?? NUM_ACTIVE_REVISIONS=$(echo "$TASK_REVISIONS" | jq ".taskDefinitionArns|length") //??? task definition? ??? ?? OUTDATED_REVISION_ARN=$(echo "$TASK_REVISIONS" | jq -r ".taskDefinitionArns[NUM_ACTIVE_REVISIONS-1]") //? ??? -1? ?? task definition??? ?? task def? ARN? ?? aws ecs update-service --cluster [cluaster_name] --service-name [service_name] --task-definition $OUTDATED_REVISION_ARN //?? task_def? ?? service???? update_task_def.sh
  • 68. How to do auto deployment ?? ? ???? ??? ??? ????? ?????? ? Production?? auto deployment ???? ????? ???? ??? ??????..
  • 69. ??? ??? ??? ??/?? rails????/??
  • 70. ????/ssh key ?? ??? ??? ? Docker image? portable? ??? ??? ? ??? docker image? ??? ???? ??? ??? ??? ? ? ???? docker image?? ??? password??? ssh key? ?? ???? ??? ????? ??
  • 71. ????/ssh key ?? ?? ? ????? S3?? ???? ? ? ????? ??? ???? ??? ?? ? ????? ????,ssh key?? dockerfile??? ??? ?? s3?? ???. ??? ??? ??? ??? ? ? ?? ???? ???? ??? S3?? ?? ???? ??? ?? ? S3?? ???? ??? version?? ??
  • 72. ???? ?? ???Docker_root Rails.env rails.env layer {development staging, production} files set_env.sh set._key.sh run_sh.sh ?? ?? ?????? ??? ?? Dockerfile build_docker.sh run_docker.sh deploy
  • 73. ???? ?? set_env.sh ???? ??? ????? bash ¨Clc ¡°¡± ??? ?? ?? #!/bin/sh aws s3 cp ¨Cquiet s3://xx/env_[middleware_name]_[rails_env] /etc/profile.d/xx.sh #ex)aws s3 cp ¨Cquiet s3://xx/env_unicorn_production /etc/profile.d/xx.sh ex) bash -lc 'bundle exec unicornherder -u unicorn_rails -p /tmp/unicorn.pid -- -c /unicorn.rb'
  • 74. ??? ??..???? ???.. ? ???? docker run xx rails s ? ??? ?? ? ??? ??? ??.. ???? ?? ???? ??? ?????? ????? ?????? ?? ? ???? ????? ?? ??????? ?????? ????? ?? ? Rails ????? ?? ????? ????? ?? ? Supervisord? ???? rails????? ?? ????? supervisord? ???? ???? ??????? ???? rails???? ?? ? ?? graceful?? ????? ??? unicornherder? ??
  • 75. ???? ?? ?? ? Rails&docker??? ????? ??? ?? ??? ?? ???? ???? ? ??? ?? ? ?? ?? ????? bundle install ??? ??
  • 76. ???? ?? ?? ??? 3?? ?? ??? bundle install assets_precompile db_migrate
  • 77. ???? ?? ?? ??? 3?? ?? ??? ¨C bundle install Bundle install? ?? RAILS_ENV????? ??(?? ? ??? ??? ?) Gemfile?? private git repository? ?? ?? ssh key? ??(ssh key? ?? ??..) ??? bundle install? ?? ?????? docker build?? ??? ????? ? bundle install
  • 78. ???? ?? ?? ??? 3?? ?? ??? - bundle install Bundle install? docker build? ?? ?? Gemfile? ???? bundle install? ??? ???? ?? s3? ???? batch? ?? ??? Dockerfile???? ?? s3??? ?? ???? ??? bundle install? ??? ??? ??? ?? ???? ???? bundle install? build? ?? ??(?? ??? ?? ????? ?? ?? ???) bundle install
  • 79. ???? ?? ?? ??? 3?? ?? ??? ¨C assets_precompile assets_precompile? ??? s3? ?? assets_sync?? gem? ???? ??? s3? sync?? sprockets-manifestxx.json??? ??? ????? ? ???? assets_precompile
  • 80. ???? ?? ?? ??? 3?? ?? ??? ¨C db_migrate ?? ???? ??? ??? ?? git diff? ???? migrate ?? ??? ?? ????? db_migrate??? ?? ??? ???? ???.. db_migrate
  • 81. ??? ??? ??? ??/?? nginx?? ??/??
  • 82. ??? ??? nginx ?? ? nginx?? ???? ???? ??? ????? ???? ?? ? ??? lua script? ????? ??? ????? ??? ?????? ??? ??? ???? ? ???? ?? ?????? envsubst ? nginx?? ??? ?? ? ??. Envsubst????? ???? ??? nginx.conf??? ??
  • 83. ??? ??? nginx ?? envsubst? apt-get install -y gettext Ubuntu?? envsubst ?? ?? Envsubst???? ?????? ??? ??? ??
  • 84. ??? ??? nginx ?? ???Docker_root Rails.env rails.env layer {development staging, production} files set_env.sh dynamic_generate _nginx.conf.sh nginx.conf.templa te run_sh.sh ?? ?? ?????? ??? ?? Dockerfile build_docker.sh run_docker.sh deploy File name description dynamic_generate_nginx.conf.sh Envsubst??? ????? ?? nginx.conf.template nginx.conf? ??? ?? ??? ??
  • 85. ??? ??? nginx ?? nginx.conf.template user xxx; ¡­?? geo $http_x_forwarded_for $sidekiq_allow_ip { default 0; ${OFFICE_GATEWAY} 1; }
  • 86. ??? ??? nginx ?? dynamic_generate_nginx.conf.sh #!/bin/sh ####nginx.conf /bin/bash -c "envsubst '$OFFICE_GATEWAY' < /etc/nginx/nginx.conf.template > /etc/nginx/nginx.conf && cat /etc/nginx/nginx.conf"
  • 87. ??? ??? nginx ?? ? Aws ELB??? ? ? ???.. Resolver 10.0.0.2 valid=2s; ELB/ALB? ??? ???? ???? ???? ? ?? ?????ÃûÇ°½â›Q ?? ??? ??
  • 88. ??? ??? ??? ??/?? ? ? ?????..
  • 89. ???? ???? ?? ??? ?????? ??(?? ????? ??? ????) ?????? logdriver? ???? ?? ???? ?? ??? ?? ?? ?? ???? ???????? ????? ???? ?? ????? Aws kinesis agent? ???? AWS Kinesis Firehose? ?? Firehose? ???? s3? ?? AWS Athena? ??
  • 90. ???? logDriver? ???? ?? ???? ?? AWS ECS??? ???? logDriver? ???? ?????? ?? logDriver? td-agent? ?????? ?? Task definition "logConfiguration": { "logDriver": "awslogs", "options": { "awslogs-group": "rails-actionlog-production", "awslogs-stream-prefix": "production", "awslogs-region": "ap-northeast-1" } Dockerfile RUN ln -sf /proc/1/fd/1 /var/log/rails/xx.log
  • 91. TEST ? ??? ???????? ?? ?????? ?? ???? ???? ???? ?? ? ?? ??? ??? ?? ??? ??? ???? ?? ? ?? ?????? ?? ??? ??? ???? ??? ??? ?? ?? ? ??:?? ??? ???? ? ???, ??? ??? ???? ?? ??? ??? ?? ? ???? ??? -> ??? ? ??? serverspec? ?? ??
  • 92. TEST Docker build? ???? ???? Docker_build_root Rails_env {development staging, production} files set_env.sh set._key.sh run_sh.sh ?? ?? ?????? ??? ?? test Dockerfile build_docker.s h run_docker.sh push_docker.s h deploy test???? ??? serverspec? ????? ??????. Circleci?? ?? ???? ??? ?????? build,run? ??? ??? ??? ???? ???.
  • 93. Base ???? Ubuntu:14.04 Ruby:2.3.3 Unicorn:xxx Unicorn:xxx? build??? ??? ???? ????? ??? ?? ??? ???? ?? ??? ??? ?? common
  • 94. Base ???? rails_root docker nginx unicorn base ruby 2.3.1 build_docker.sh 2.3.3 build_docker.sh php nginx unicorn-common Dockerfile docker- compose.yml Base ????? ?? ?? ???? ??? ?
  • 95. ??????? docker ? ????? production?? ???? ?? ? ?? ? ??? ???? ?? ? ?? ?? ??? Docker for mac??-> ??? docker-async?? ? ??? ????? ???? ?? ???? ????? ? ???..???? ?? ? ??? ?? ???? ??? ? ???? ????, ??? ??? ? ? ?? ????? ??? ??? ???. ????? ? ? ?? ????? ??????? ??? ?? ???, ? ??? IT??? ??? ??? ?? ?? ? ??
  • 96. ???? ?? ? Swarm,Kubernets? , ECS ? ???? ?? ???? ??AWS???? ??? AWS?? ???? AWS ECS?? ? ??? ? ???? ??..?????? ECS NOT BAD ???? ??? ?? ? ?? ??
  • 97. ??.. ? ?? ?? ??? aws cloudWatch,new relic, bugsang?? ? ??? ?????? ???? ???? ??? ??? ????.. ? ??? ? ??????..@negabaro
  • 98. ?? ???? ? ?? ???? ??? ??? ? ??? ???? ????? docker pull,push??? ????? deploy??? ??? ? ??? ?? aws ebs? ??? ??? ????? ?? ??? ??? ? ? CoreOS, rancheros, alpine OS?? ?? ? Ubuntu?? debian? ??? ? ?? docker diet? ???? ??.. ???..base image???14.04 ???¡­
  • 99. cron?? ? Rails??? rake???? ???? ?? ????? ?? ? ?? ??? ??? ??? ??? ?????? docker exec? rake? ???~/.bashrc export GET_CONTAINER="docker exec -t `docker ps | grep 3000 |grep 3005 |grep admin | grep unicorn |grep -v redmine | awk '{print $1}'` crontab -e 30 * * * * source ~/.bashrc;$GET_UNICORN_CONTAINER bash -lc "bundle exec rake filmarks:xx RAILS_ENV=staging" 1 > /dev/null
  • 100. Cron?? Lambda?? docker exec rake?? ???? ??? lambda python?? ????? ?? Docker exec rake?? ?? EC2 Run Command? ?? ?? #!/bin/bash yum -y update curl https://[bucket-name].s3.amazonaws.com/latest/linux_amd64/amazon-ssm- agent.rpm -o amazon-ssm-agent.rpm yum install -y amazon-ssm-agent.rpm http://dev.classmethod.jp/cloud/aws/introduce-to-run-a-command-button-for-linux/ ??? ????? EC2RoleforSSM ???? ???
  • 101. ???? [service name]_[rails_env]_[middleware name] Ex) xxx_staging_unicorn Staging -> stg Production -> prod Developmet -> dev simple is best..
  • 103. AWS ECS userdata?? ? ??? ?? ???? ec2??? ecs agent? ecs????? ???? ? #!/bin/bash sudo rm -rf /var/lib/ecs/data/ecs_agent_data.json echo ECS_CLUSTER=[ECS???? ?] >> /etc/ecs/ecs.config
  • 104. ?? ? ? Docker ???? ???? ?? docker exec ?? ??.. ? ? ??? ??? ?? alias??? ??? alias uu="docker exec -it `docker ps | grep unicorn | grep 3000 | awk '{print $1}'` /bin/bash" alias nn="docker exec -it `docker ps | grep nginx | grep 80 | awk '{print $1}'` /bin/bash" alias pp="docker exec -it `docker ps | grep php | grep 80 | awk '{print $1}'` /bin/bash" alias rr="docker exec -it `docker ps | grep td-agent | awk '{print $1}'` /bin/bash alias drm='docker rm $(docker ps -aqf "status=exited") 2> /dev/null' alias drmi='docker rmi $(docker images -aqf "dangling=true") 2> /dev/null'
  • 105. ??? ..?? ? ??? ????? ??? ? ????? ??? ??? production??? ???? ??? ? ?? ??? ??? ??? ??? ???? ? ???? ?? ?? ? ?? ????? docker?, ?docker?? ???.. ??? ?????? ?? ??? ???. API?? ???? ????? ??? ??..elasticsearch???? ????? ???? ??? ? ??? ??? docker? ?? ??? ?? ? ??? ??? ?? ??? ??? ??? ?? ???? ??? ?
  • 106. Question?? ? ??? ??? ?? ?? ??? ??? ???? ????? : ) ? https://twitter.com/negabaro ? https://www.facebook.com/negabaro ? negabaro@gmail.com