Kick off the infrastructure and application projects in one command.
This command will execute the following tasks sequentially:
-
Initialise the terraform modules (
terraform init
) -
Create the ECR container registry for the docker image (
terraform apply -auto-approve -var-file=main.tfvars -target=module.container_registry
) -
Build a fresh copy of the wordpress image and push it to the ECR created in step 2. (
make update-wp
) -
Create the rest of the infrastructure modules
-
Wait until the Load Balancer is provisioned and an extra time for the target group listeners to be ready. (
make wait-lb
)
Usage:
make kick-n-run
# accept the confirmation typing "y"
Requirements:
- docker client
Check for the required images used during the other commands and pull them if they are not present.
It checks first if the image is pulled or not, so it is safe to call it multiple times.
Images pulled:
Usage:
make pull-required-images
This script will generate the terraform module documentation based on your input/output variables.
Usage:
make docs-terraform
It uses terraform-docs to read .tf
files and generate the document.
The script use the docker image with the bin installed so you don't need to install nothing in your machine.
This script will loop though
terraform/modules
directory and create/replace the file aREADME.md
for every module.
You can customize the output with a config file. Follow this link for more details.
Here a sample file .terraform-docs.yml
file:
formatter: markdown document
header-from: doc.md
sections:
hide:
- providers
- requirements
This script will:
- format the document as
markdown document
- inject the content of
doc.md
intoREADME.md
- hide the sections:
providers
andrequirements
Authenticate the docker client with the ECR registry.
Usage:
make ecr-login
Requirements:
- docker client
Environment variables
Name | Description |
---|---|
AWS_DEFAULT_REGION | the default aws region where the ECR is located. |
DOCKER_REGISTRY_URL | the repository url where the docker image is located Example: AWS_ACCOUNT_ID.dkr.ecr.AWS_REGION.amazonaws.com/REPOSITORY_NAME |
Build a new docker image
Usage:
make build-wp
Requirements:
- docker client
Environment variables
Name | Description |
---|---|
DOCKER_REPOSITORY | the name of the repository used to retrieve the images pushed into the repository. |
Push the recent built image to the ECR repository.
It will authenticate with the ECR first before run this command:
make ecr-login
The image will be tagget using the repo commit sha
and latest
alias. It will also use the ECR repository prefix. For example:
097922957456.dkr.ecr.ap-southeast-2.amazonaws.com/devops-wp:6eb88c0
Requirements:
- docker client
Environment variables:
Name | Description |
---|---|
DOCKER_REPOSITORY | the name of the repository used to retrieve the images pushed into the repository. |
AWS_DEFAULT_REGION | the default aws region where the ECR is located. |
DOCKER_REGISTRY_URL | the repository url where the docker image is located Example: AWS_ACCOUNT_ID.dkr.ecr.AWS_REGION.amazonaws.com/REPOSITORY_NAME |
Execute the commands in order:
It will create a new ECS task definition and trigger the rolling update of the tasks.
Usage:
# in the root directory
make deploy-wp
List of operations:
- Fetch the latest task definition deployed into the ECS. So any update in the task definition url will be reused for the next deployment.
- Fetch the latest image deployed into the ECR Repository.
- Update the
task-definition.json
with the new image tag. - Register the new task-definition with the ECS.
- Update the ECS service with the new task-definition revision and force the deploment of new tasks.
Requirements:
- docker client
- AWS CLI
- sed
Environment variables:
Name | Description |
---|---|
PROJECT_NAME | the name of the project, used to locate the ECS service for the task definition registration. |
DOCKER_REPOSITORY | the name of the repository used to retrieve the images pushed into the repository. |
DOCKER_REGISTRY_URL | the repository url where the docker image is located Example: AWS_ACCOUNT_ID.dkr.ecr.AWS_REGION.amazonaws.com/REPOSITORY_NAME |
Initialise the terraform modules and execute the terraform plan.
The plan will be output as terraform-plan
inside the terraform
folder.
It will use the file terraform/main.tfvars
for input variables.
Usage:
make tf-ci-plan
Requirements:
- docker client
Run terraform apply (with auto-approve) using the terraform plan file terraform-plan
.
It will use the file terraform/main.tfvars
for input variables.
Usage:
make tf-ci-apply
Requirements:
- docker client
Run terraform destroy (with auto-approve) using the terraform/main.tfvars
as input variables
make tf-ci-remove
Requirements:
- docker client
Run tf-ci-plan and tf-ci-apply
Usage:
make tf-all
Check the identity of the AWS user profile. Used mostly for test/debugging purposes.
Usage:
make aws-caller-identity
Wait until the Load Balancer is ready to receive requests.
🧯 TODO: change the code due to S3 state compatibility
This command will check that the following files exists in .github
:
- secrets: key-value field with secrets
- .env: key-value with list of environment variables
It will exit an error if those files do not exits.
Simulate github action execution when:
- a
pull-request
tomerge
was created - changes were made in
docker
folder
make ga-test-pr-build-wp
Workflow: on-pr-build-wp.yml
Simulate github action execution when:
- a
push
tomerge
was initiated - changes were made in
docker
folder
make ga-test-push-deploy-wp
Workflow: on-push-deploy-wp.yml