This repo deploys a LAMP stack to AWS.
Before we can deploy the rest of the project we need a bucket for storing the terraform state and ECR repositories for the container images.
AWS_PROFILE=ktacct AWS_DEFAULT_REGION=us-east-2 aws cloudformation deploy \
--template-file cloudformation/lamp-prereq.yaml \
--stack-name "lamp-prereq"
Logical ID | Type |
---|---|
ECRbase | AWS::ECR::Repository |
ECRweb | AWS::ECR::Repository |
S3Bucket | AWS::S3::Bucket |
Use the make command to build the php image to be run in AWS. You have to specify the tag you want to use for the image. This build used the public docker-hub apache tag of php. This image was also mirrored to ECR in case of dockerhub rate limit issues.
make mirror-base tag=202209151750
Requirements:
- Terraform Installed (
tfenv use 1.2.9
)
Once the image is uploaded to ECR, create a settings.auto.tfvars
with the image uri in the ./terraform
directory.
Example settings.auto.tfvars
img_uri = "<ACCOUNT_NUMBER>.dkr.ecr.us-east-2.amazonaws.com/lamp/web:<TAG-HERE>"
./terraform
Directory:
./terraform
├── main.tf
├── outputs.tf
├── settings.auto.tfvars
├── variables.tf
└── versions.tf
Check Terraform plan:
AWS_PROFILE=ktacct AWS_DEFAULT_REGION=us-east-2 make plan
Deploy Terraform:
AWS_PROFILE=ktacct AWS_DEFAULT_REGION=us-east-2 make apply
- Build and push new image
make push tag=202209152305
- Update
settings.auto.tfvars
file with new tag
img_uri = "487169596959.dkr.ecr.us-east-2.amazonaws.com/lamp/web:202209152248"
- Terraform apply to update the ECS service and task definition
AWS_PROFILE=ktacct AWS_DEFAULT_REGION=us-east-2 make apply