This is a quickstart repository you can fork to develop and deploy Craft CMS on Kubernetes on AWS/GCP/DO with Porter.
This quickstart guide connects Craft CMS to a PostgreSQL database deployed on Porter. You can connect Craft CMS instances deployed on Porter to any external databases, but Porter lets you deploy a PostgreSQL instance in just one click. If you want to connect to a database that's deployed via Porter, please follow this guide. To seed the deployed database with existing data, you can use Porter's Remote Execution feature to run psql
commands inside the deployed database.
To allow users to easily reuse the same set of environment variables across deployments, Porter supports Environment Groups. In this guide, we will be deploying two services for Craft CMS that use the same set of environment variables - we recommend you to store these as an environment group for convenience.
- Navigate to the Environment Group tab. Create a new environment group by loading in from a file or manually inputting the variables.
- Ensure that all environment variables outlined below are included. Your
DATABASE
environment variables must match the config of the database you are trying to connect to. If you're trying to connect to a database on Porter, see this guide for more details.
NODE_ENV=production
APP_ID=
SECURITY_KEY=
DATABASE_HOST=
DATABASE_PORT=5432
DATABASE_NAME=
DATABASE_USERNAME=
DATABASE_PASSWORD=
- Create an account on Porter.
- One-click provision a Kubernetes cluster in a cloud provider of your choice, or connect an existing cluster if you already have a cluster.
- Fork this repository.
- We will launch two separate services:
web
andconsole
. From the Launch tab, navigate to Web Service > Deploy from Git Repository. Select the forked repository andweb.Dockerfile
from the root directory. Click Continue. - Configure the port to
8080
, load in the environment variables from the Environment Group you created in the previous section, then hit deploy. - Next we will deploy a
console
service. Navigate to Worker > Deploy from Git Repository from the launch tab. Select the forked repository andconsole.Dockerfile
from the root directory. Load in the same set of environment variables as those used forweb
service, then hit deploy. - Porter will now automatically handle CI/CD for your Craft CMS deployments whenever you push to the forked repository.
To develop, clone this repository to your local environment and run docker-compose -f docker-compose.yml up --build
from the root directory.
To propagate your changes to the production environment, you need to run php craft migrate/all
and php craft project-config/apply
in one of your deployed services. You can do this via Porter's Remote Execution feature. This feature works in a similar way as ssh
and allows you to run commands inside a deployment.
After you've successfully deployed your changes, you can run these commands to propagate your changes.
porter run [DEPLOYMENT_NAME] -- php craft migrate/all
porter run [DEPLOYMENT_NAME] -- php craft project-config/apply
Alternatively, if you want to open up an interactive shell instance in the deployment to run other commands, run:
porter run [DEPLOYMENT_NAME] -- sh
Join the Porter Discord community if you have any questions. For contributions/suggestions to docs, please open an issue in our open source repository.