Skip to content

snoek09/laravel-ecs-demo

 
 

Repository files navigation

Laravel on ECS Demo

Build and run with docker-compose (local)

$ docker-compose up --build

Build assets

$ docker-compose run --rm nodejs bash -c "npm install && npm run dev"

docker login (with latest awscli)

$ aws ecr get-login-password --region ${AWS_DEFAULT_REGION}) | docker login --username AWS --password-stdin xxxxxxxxxxxx.dkr.ecr.{$AWS_DEFAULT_REGION}.amazonaws.com

Build and push docker to AWS ECR (Elastic Container Registry)

Create ECR repository

Create 2 repositories for nginx and php-fpm. Like below:

  • aws ecr create-repository --repository-name laravel-ecs-demo/nginx
  • aws ecr create-repository --repository-name laravel-ecs-demo/php-fpm

Build nodejs and assets(js/css)

$ docker build -t nodejs -f docker/nodejs/Dockerfile .
$ docker run --rm -v $(pwd):/build -w /build nodejs npm install
$ docker run --rm -v $(pwd):/build -w /build nodejs npm run dev

Build php-fpm/nginx

$ docker build -t ${REPOSITORY_URI_PHP_FPM}:latest -f docker/php-fpm/Dockerfile .
$ docker build -t ${REPOSITORY_URI_NGINX}:latest -f docker/nginx/Dockerfile .

Add tags

$ docker tag ${REPOSITORY_URI_PHP_FPM}:latest ${REPOSITORY_URI_PHP_FPM}:$IMAGE_TAG
$ docker tag ${REPOSITORY_URI_NGINX}:latest ${REPOSITORY_URI_NGINX}:$IMAGE_TAG

Push docker image

$ docker push ${REPOSITORY_URI_PHP_FPM}:latest
$ docker push ${REPOSITORY_URI_PHP_FPM}:$IMAGE_TAG
$ docker push ${REPOSITORY_URI_NGINX}:latest
$ docker push ${REPOSITORY_URI_NGINX}:$IMAGE_TAG

Create Task definition

namelaravel-ecs-demo
Launch typeEC2

Add php-fpm container

name php-fpm
image (uri) ${AWS_ACCOUNT_ID}.dkr.ecr.${AWS_DEFAULT_REGION}.amazonaws.com/php-fpm:latest
working directory /app
memory 300

Add nginx container

name nginx
image (uri) ${AWS_ACCOUNT_ID}.dkr.ecr.${AWS_DEFAULT_REGION}.amazonaws.com/nginx:latest
port mapping tcp 80:80
memory 300
links php-fpm

Create ECS Cluster

namelaravel-ecs-demo-cluster
cluster compatibilityEC2 Linux + Networking
EC2 Instance typet3.medium
Provisioning modelOn Demand
Number of instances1

Create ALB (Application load balancer)

Availability Zone(Choose from VPC of ECS Cluster)
ListenersHTTP 80
Target instances(Choose from Availability Zone)

Create Service in ECS Cluster

Launch typeEC2
Task definitionlaravel-ecs-demo
Clusterlaravel-ecs-demo-cluster
Service namelaravel-ecs-demo
Service typeREPLICA
Load balancer typeApplication Load Balancer
Container to load balancenginx:80:80
Listener port80:HTTP
Target Group(Choose of ALB)

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • PHP 90.0%
  • Blade 4.2%
  • Python 3.5%
  • Other 2.3%