This repository contains two distict sections of code in directories Terraform and Docker.
The Terraform directory container the Infrastructure as Code (IaC) Terraform files to build the Azure resource infrastructure for the CraftCMS Docker image to run in. This code uses the Azurerm Provider to create Azure resources.
The Docker portion of the repository is for creating a Docker image containing an installation of CraftCMS which will run in the Azure Web App Service in Azure deployed by the Terraform section of the repository.
Craft is a flexible, user-friendly CMS for creating custom digital experiences on the web and beyond.
In technical terms, it’s a self-hosted PHP application backed by a MySQL or Postgres database. Read more in the official documentation.
The CraftCMS source code can be found here craftcms/cms
. This repository uses a sample project for its installation which can be found here for further updates craftcms/craft
.
TODO: Guide users through getting your code up and running on their own system. In this section you can talk about:
- Installation process
- Software dependencies
- Latest releases
- API references
-
Build the docker image with Docker file
docker build . --no-cache --build-arg php_version=8.3 --build-arg ubuntu_version=24.14 --progress plain --tag craftcms:latest
-
Tag the Docker image to be pushed to the Azure container registry
docker tag craftcms:latest [CONTAINER-REGISTRY-NAME].azurecr.io/craftcms:latest
-
Get an access token required to authrnticate to container registry
TOKEN=$(az acr login --name [CONTAINER-REGISTRY-NAME] --expose-token --output tsv --query accessToken) docker login [CONTAINER-REGISTRY-NAME].azurecr.io --username 00000000-0000-0000-0000-000000000000 --password-stdin <<< $TOKEN
-
Push new tagged image to the Azure container registry
docker push [CONTAINER-REGISTRY-NAME].azurecr.io/craftcms:latest
- For
Terraform
the sakteaterraformstate storage account will need to have the IP address added to the firewall when running Terraform commands.
terraform init -reconfigure -backend-config='.backend/dev.azurerm.tfbackend' -var-file='.backend/dev.tfvars'<br />
terraform init -reconfigure -backend-config='.backend/stage.azurerm.tfbackend' -var-file='.backend/stage.tfvars'<br />
terraform init -reconfigure -backend-config='.backend/prod.azurerm.tfbackend' -var-file='.backend/prod.tfvars'<br />
terraform plan -out 'plan.tfplan' -var-file='.backend/dev.tfvars'<br />
terraform plan -out 'plan.tfplan' -var-file='.backend/stage.tfvars'<br />
terraform plan -out 'plan.tfplan' -var-file='.backend/prod.tfvars'<br />
terraform apply 'plan.tfplan'
terraform plan -out 'plan.tfplan' -var-file='.backend/stage.tfvars' -destroy
terraform apply 'plan.tfplan'
-
Need to manually configure logging for each environment with diagnostic settings etc.
-
Need to configure the CraftCMS database
- Do a MySQL Workbench or command line dump export of the craftcms database
- Do an import using the dump file on the new environment craftcms database
- If the database was named different than the database used for the export you will need to edit the dump file and change the exported database name references to the import database name
-
Copy the container image tag from one environment to another or build and deploy a new one the the new environment
-
Update Docker credentials for the web app environment variables for the new environment
-
Update settings in CraftCMS that contain references to the copied environment such as file system paths for assets
-
Create assets folder on the storage account files container