this is ready for deploy Aws ecs fargate template
-
AWS account.
-
aws cli installed.
- Installing ecs cli
config // nginx and php-fpm configuration
ops // json definitions for aws roles and processes
site // app files
.gitignore //ready to use with bedrock from roots.io
buidspec.yml // code build instructions
*.Dockerfile // both of the dockers that will be build at the process. YOU SHOULD CHANGE THEIR FROM SECTION.
README.md // here i am
mkdir ${name-of-your-project}
cd ${name-of-your-project}
git clone https://github.com/amitrahav/wordpress-ecs-template.git ./
- create two ECR repositories: one for php-app and one for nginx:
create-repository --repository-name ${applicationName}-${environment}-fpm && create-repository --repository-name ${applicationName}-${environment}-nginx
.
- change all
{}
content at ops/codePipelineServiceRole.json create codePipeline service role byaws iam create-role --role-name ${applicationName}-${environment} --assume-role-policy-document file://ops/codePipelineServiceRole.json
- modify ops/codePipeline.json with the correct name for your app. create new codePipeline using aws cli
aws codepipeline create-pipeline --cli-input-json file://ops/codePipeline.json
or manually.
- change all
{}
content at ops/lambdaServiceRole.json create service role byaws iam create-role --role-name arn:aws:iam::${accountId}:role/updateECSImage-service-role --assume-role-policy-document file://ops/codePiplineServiceRole.json
- zip lambda file
zip ops/lambda.zip ops/lambda.py
- deploy lambda function
aws lambda create-function --function-name updateECSImage --zip-file fileb://ops/lambda.zip --handler lambda.handler --runtime python2,7 --role arn:aws:iam::${accountId}:role/updateECSImage-service-role
- change all
{}
content at ops/ecsTaskExecutionRole.json create service role byaws iam create-role --role-name arn:aws:iam::${accountId}:role/ecsTaskExecutionRole file://ops/ecsTaskExecutionRole.json
. - change all
{}
content at ops/task-definition.json and register the taskaws ecs register-task-definition --cli-input-json file://ops/task-definition.json
- create cluster if doesn't exists
aws ecs create-cluster --cluster-name "${application-name}"
- create service
aws ecs create-service --service-name ${app name}-${environment}-service --task-definition {task-definition family name} --desired-count 1
(you can use any other desired count)
- add declarative loadBalancer security groups, target group and https configuration.
It's recommended to use bedrock.
cd site
composer create-project roots/bedrock ./
before initial commit you Should add php-fpm docker image path to fpm.Dockerfile (line 1). I Use Wp-Engine as php-fpm container.
-
dockerBuild install dependencies and create 2 docker image and push them into ECR repo.
-
Nginx and PHP-FPM configuration (from config/ folder) being copied to the containers.
-
With the help of a simple lambda function (ops/lambda.py), i updated ECS service, and reDeployed it.