{"id":362,"date":"2017-04-29T11:33:18","date_gmt":"2017-04-29T02:33:18","guid":{"rendered":"https:\/\/p-corporate-blog-cms.mmmcorp.co.jp\/blog\/2017\/04\/29\/corporate_web_ecs"},"modified":"2022-10-26T10:14:21","modified_gmt":"2022-10-26T01:14:21","slug":"corporate_web_ecs","status":"publish","type":"post","link":"https:\/\/p-corporate-blog-cms.mmmcorp.co.jp\/blog\/2017\/04\/29\/corporate_web_ecs\/","title":{"rendered":"Amazon EC2 Container Service (ECS) \u3068 CircleCI \u3092\u6d3b\u7528\u3057\u305f Docker \u30d9\u30fc\u30b9\u306a\u30b3\u30fc\u30dd\u30ec\u30fc\u30c8\u30b5\u30a4\u30c8"},"content":{"rendered":"
\u4eca\u6708\u306e\u306f\u3058\u3081\u306b\u3001\u5f0a\u793e\u306e\u30b3\u30fc\u30dd\u30ec\u30fc\u30c8\u30b5\u30a4\u30c8\u3092\u4e00\u90e8\u30ea\u30cb\u30e5\u30fc\u30a2\u30eb\u3057\u3066\u3044\u308b\u3002 \u3010\u53c2\u8003URL\u3011\u30d7\u30e9\u30a4\u30d9\u30fc\u30c8\u30ec\u30b8\u30b9\u30c8\u30ea\u306e\u8a8d\u8a3c - Amazon EC2 Container Service<\/a><\/p>\n<\/li>\n \u3053\u308c\u3092\u3001 \u4f8b\u3048\u3070
\u5185\u5bb9\u3060\u3051\u3067\u306f\u306a\u304f\u3001\u30d0\u30c3\u30af\u30a8\u30f3\u30c9\u306e\u30b7\u30b9\u30c6\u30e0\u5074\u3082 AWS OpsWorks<\/a> \u3092\u4f7f\u3063\u3066\u69cb\u7bc9\u3057\u305f\u74b0\u5883\u3078\u30c7\u30d7\u30ed\u30a4\u3057\u3066\u3044\u305f\u3082\u306e\u304b\u3089\u3001 Amazon EC2 Container Service (ECS)<\/a> \u3092\u4f7f\u3063\u305f Docker<\/code> \u30d9\u30fc\u30b9\u306e\u3082\u306e\u3078\u3068\u5909\u66f4\u3057\u3066\u3044\u308b\u3002
\u5f0a\u793e\u3067\u306f\u3001\u3053\u308c\u307e\u3067\u958b\u767a\u74b0\u5883\u3067\u306f Docker<\/code> \u3092\u4f7f\u3063\u3066\u3044\u305f\u304c\u3001\u672c\u756a\u74b0\u5883\u3067\u306e
Docker<\/code> \u904b\u7528\u306f\u3057\u3066\u3044\u306a\u304b\u3063\u305f\u3002\u3000\u3000
\u305d\u308d\u305d\u308d\u672c\u756a\u74b0\u5883\u3067\u3082 Docker<\/code> \u3092\u4f7f\u3063\u305f\u74b0\u5883\u306b\u79fb\u884c\u3057\u305f\u3044\u3068\u601d\u3044\u3001
ECS<\/code> \u74b0\u5883\u3078\u306e\u79fb\u884c\u3092\u884c\u3063\u305f\u3002
\u4eca\u56de\u306f\u3001\u305d\u306e\u79fb\u884c\u306e\u969b\u306e\u30dd\u30a4\u30f3\u30c8\u3092\u307e\u3068\u3081\u3066\u307f\u305f\u3044\u3068\u601d\u3046\u3002<\/p>\nDocker Hub<\/h2>\n
\n
Docker<\/code> \u3092\u4f7f\u3063\u3066\u304a\u308a\u3001Docker Hub<\/a> \u3092\u4f7f\u3063\u3066\u3044\u305f\u306e\u3067\u3001\u305d\u306e\u307e\u307e
ECS<\/code> \u3067\u3082 Docker Hub<\/a> \u3092\u4f7f\u3063\u3066\u3044\u308b(\u4eca\u56de\u306f Amazon EC2 Container Registry (ECR)<\/a> \u306f\u4f7f\u308f\u306a\u3044)<\/li>\n
Ruby on Rails<\/code> \u3067\u7a3c\u50cd\u3057\u3066\u3044\u308b\u5f0a\u793e\u30b3\u30fc\u30dd\u30ec\u30fc\u30c8\u30b5\u30a4\u30c8\u304c\u4e00\u901a\u308a\u52d5\u4f5c\u3059\u308b\u3001\u30d3\u30eb\u30c9\u6e08\u307f\u306e\u30d9\u30fc\u30b9\u3068\u306a\u308b\u30a4\u30e1\u30fc\u30b8\u3092\u7f6e\u304f<\/li>\n
CircleCI<\/code> \u3067\u30c6\u30b9\u30c8\u3092\u5b9f\u884c\u3059\u308b\u969b\u306f\u3001\u305d\u306e\u30d9\u30fc\u30b9\u30a4\u30e1\u30fc\u30b8\u3092
Pull<\/code> \u3057\u3066\u30a2\u30d7\u30ea\u30b1\u30fc\u30b7\u30e7\u30f3\u306e\u30bd\u30fc\u30b9\u3092\u8ffd\u52a0\u3001\u30c6\u30b9\u30c8\u304c\u901a\u3063\u305f\u3089\u3001\u30a2\u30bb\u30c3\u30c8\u30d5\u30a1\u30a4\u30eb\u7fa4\u3092\u30d7\u30ea\u30b3\u30f3\u30d1\u30a4\u30eb\u3057\u3066\u3001\u30c7\u30d7\u30ed\u30a4\u3002\u305d\u3046\u3059\u308b\u3053\u3068\u3067\u30010\u304b\u3089\u30d3\u30eb\u30c9\u3059\u308b\u3088\u308a\u306f\u6642\u9593\u306e\u77ed\u7e2e\u304c\u51fa\u6765\u308b<\/li>\n
AWS ECR<\/code> \u3067\u306f\u306a\u304f\u3066\u3001Docker Hub<\/a> \u3092\u4f7f\u3046\u5834\u5408\u3001
ECS<\/code> \u5bfe\u5fdc
AMI<\/code> \u306e\u5834\u5408\u306f\u4e0b\u8a18\u306e\u3088\u3046\u306b
\/etc\/ecs\/ecs.config<\/code> \u306b\u8ffd\u52a0\u3059\u308b\u5fc5\u8981\u304c\u3042\u308b<\/li>\n<\/ul>\n
ECS_ENGINE_AUTH_TYPE=docker\nECS_ENGINE_AUTH_DATA={"https:\/\/index.docker.io\/v1\/":{"username":"\u30e6\u30fc\u30b6\u30fc\u540d","password":"\u30d1\u30b9\u30ef\u30fc\u30c9","email":"\u30e1\u30fc\u30eb\u30a2\u30c9\u30ec\u30b9"}}<\/code><\/pre>\n
\n
EC2<\/code> \u30a4\u30f3\u30b9\u30bf\u30f3\u30b9\u8d77\u52d5\u6642\u306b\u8ffd\u52a0\u3067\u304d\u308b\u3088\u3046\u306b\u3001
EC2<\/code> \u306e\u30e6\u30fc\u30b6\u30fc\u30c7\u30fc\u30bf\u306b\u8a2d\u5b9a<\/p>\n<\/li>\n<\/ul>\n
#!\/bin\/bash\necho "ECS_ENGINE_AUTH_TYPE=docker" >> \/etc\/ecs\/ecs.config\necho 'ECS_ENGINE_AUTH_DATA={"https:\/\/index.docker.io\/v1\/":{"username":"\u30e6\u30fc\u30b6\u30fc\u540d","password":"\u30d1\u30b9\u30ef\u30fc\u30c9","email":"\u30e1\u30fc\u30eb\u30a2\u30c9\u30ec\u30b9"}}' >> \/etc\/ecs\/ecs.config<\/code><\/pre>\n
\n
CircleCI<\/h2>\n
\n
CircleCI<\/code> \u306e\u30d0\u30fc\u30b8\u30e7\u30f3\u306f\u3001\u30d9\u30fc\u30bf\u4e2d\u306e
2.0<\/code> \u306e\u691c\u8a3c\u304c\u307e\u3060\u51fa\u6765\u3066\u3044\u306a\u3044\u306e\u3067\u3001
1.0<\/code> \u3092\u4f7f\u7528<\/li>\n
2.0<\/code> \u3067\u306f
docker-compose<\/code> \u304c\u4f7f\u3048\u305f\u308a\u3001\u304b\u306a\u308a\u4fbf\u5229\u306b\u306a\u3063\u3066\u3044\u308b\u3088\u3046\u306a\u306e\u3067\u3001\u691c\u8a3c\u304c\u51fa\u6765\u6b21\u7b2c\u305d\u3061\u3089\u306b\u79fb\u884c\u3057\u305f\u3044\u3068\u8003\u3048\u3066\u3044\u308b<\/li>\n
Docker \u30b3\u30f3\u30c6\u30ca\u306e\u30d3\u30eb\u30c9\u3001\u30ad\u30e3\u30c3\u30b7\u30e5<\/h4>\n
\n
tar<\/code> \u30d5\u30a1\u30a4\u30eb\u3068\u3057\u3066\u4fdd\u6301\u3057\u3066\u304a\u304f<\/li>\n
tar<\/code> \u30d5\u30a1\u30a4\u30eb\u3092\u8aad\u307f\u8fbc\u3093\u3067\u3001\u30d3\u30eb\u30c9\u3092\u9ad8\u901f\u5316<\/li>\n
tar<\/code> \u30d5\u30a1\u30a4\u30eb\u304c\u914d\u7f6e\u3055\u308c\u3066\u3044\u308b
~\/docker<\/code> \u30c7\u30a3\u30ec\u30af\u30c8\u30ea\u306f\u30ad\u30e3\u30c3\u30b7\u30e5\u3059\u308b\u8a2d\u5b9a\u3092\u8ffd\u52a0<\/li>\n<\/ul>\n
dependencies:\n cache_directories:\n - "~\/docker"\n\n override:\n - if [[ -e ~\/docker\/image.tar ]]; then docker load -i ~\/docker\/image.tar; fi\n - docker build --rm=false -t app .\n - mkdir -p ~\/docker; docker save app > ~\/docker\/image.tar<\/code><\/pre>\n
\n
\u30c6\u30b9\u30c8\u3067\u4f7f\u3046
MySQL<\/code> \u306f
Docker<\/code> \u30b3\u30f3\u30c6\u30ca\u3092\u4f7f\u308f\u306a\u3044<\/h4>\n
\n
CircleCI<\/code> \u74b0\u5883\u3067\u30c7\u30d5\u30a9\u30eb\u30c8\u3067\u8d77\u52d5\u3059\u308b
MySQL<\/code> \u3092\u4f7f\u3063\u3066\u3001\u30c6\u30b9\u30c8\u3092\u884c\u3046(
DB<\/code> \u306e\u30b3\u30f3\u30c6\u30ca\u306f\u4f5c\u6210\u3057\u306a\u3044)<\/li>\n
MySQL<\/code> \u306b\u63a5\u7d9a\u3059\u308b\u305f\u3081\u3001\u63a5\u7d9a\u7528\u306e\u30e6\u30fc\u30b6\u30fc\u4f5c\u6210\u3092\u884c\u3046<\/li>\n<\/ul>\n
database:\n override:\n - mysql -uroot mysql < scripts\/create_rails_user.sql<\/code><\/pre>\n
scripts\/create_rails_user.sql<\/code> \u306f\u4e0b\u8a18\u306e\u3088\u3046\u306a\u5185\u5bb9\u3002<\/p>\n
GRANT ALL PRIVILEGES ON *.* TO 'rails'@'%' identified by "rails";\nFLUSH PRIVILEGES;<\/code><\/pre>\n
\n
MySQL<\/code> \u306b\u63a5\u7d9a\u3059\u308b\u305f\u3081\u3001\u5916\u90e8\u63a5\u7d9a\u8a2d\u5b9a(
bind-address<\/code> \u306e\u884c\u3092\u30b3\u30e1\u30f3\u30c8\u30a2\u30a6\u30c8)\u3092\u5909\u66f4<\/li>\n<\/ul>\n
machine:\n pre:\n - sudo sed -Ei 's\/^(bind-address|log)\/#&\/' \/etc\/mysql\/mysql.conf.d\/mysqld.cnf<\/code><\/pre>\n
\n
docker run<\/code> \u3067\u3001\u4e0b\u8a18\u306e\u3088\u3046\u306b\u5b9f\u884c<\/li>\n<\/ul>\n
test:\n override:\n - docker run --add-host db:$(ip addr show docker0 | grep "inet\b" | awk '{print $2}' | cut -d\/ -f1) -e RAILS_DATABASE_HOST=db app bundle exec rspec spec<\/code><\/pre>\n
ECS<\/h2>\n
\u30ed\u30b0\u306f\u6a19\u6e96\u51fa\u529b\u3059\u308b\u3088\u3046\u306b<\/h4>\n
\n
CloudWatch<\/code> \u3067\u78ba\u8a8d\u3067\u304d\u308b\u3088\u3046\u306b<\/li>\n<\/ul>\n
unicorn<\/code> \u306e\u8a2d\u5b9a\u30d5\u30a1\u30a4\u30eb
config\/unicorn.rb<\/code> \u306e\u30ed\u30b0\u30d5\u30a1\u30a4\u30eb\u306e\u8a2d\u5b9a\u7b87\u6240\u3092\u30b3\u30e1\u30f3\u30c8\u30a2\u30a6\u30c8\u3057\u3066\u3001\u6a19\u6e96\u51fa\u529b\u306b\u3059\u308b\u3053\u3068\u3067\u3001
ECS<\/code> \u3067\u8a2d\u5b9a\u3057\u3066\u3044\u308b
CloudWatch<\/code> \u306e\u30ed\u30b0\u30b0\u30eb\u30fc\u30d7\u306b\u30ed\u30b0\u30b9\u30c8\u30ea\u30fc\u30e0\u3092\u9001\u4fe1\u3067\u304d\u308b\u3088\u3046\u306b\u306a\u308b\u3002<\/p>\n
# log\n# stderr_path File.expand_path('log\/unicorn.log', ENV['RAILS_ROOT'])\n# stdout_path File.expand_path('log\/unicorn.log', ENV['RAILS_ROOT'])<\/code><\/pre>\n
\n
silinternational\/ecs-deploy<\/a> \u3092\u4f7f\u3063\u3066\u30c7\u30d7\u30ed\u30a4<\/h4>\n