Ghost hosting cli is a command line interactive tool to host the Ghost on the AWS cloud with the help of Terraform-CDK. It simplifies the Ghost server deployment by utilizing the AWS infrastructure. It provides the flexibility to host the fresh stack or to plug it into the existing infrastructure.
- Terraform >= 1.1.8
- NodeJS >= 14.17
- AWS account with admin access
Ghost Hosting CLI uses AWS cloud platform, the following parameters are required by default.
AWS access key
AWS secret access key
AWS region
It requires a config.json
file. This config.json
is get's generated while taking input from the user. If this file is already present at the location (from previous deployments), the CLI prompt ask user whether to use the existing configuration or to create new.
Configuration file generation happens only in the deploy stage. Once the config.json
file is ready, the CLI synthesizes Terraform configuration for an application.
After this, rest is handled by terraform to deploy/destroy stacks.
For the deployment, CLI create two stacks:
- Backend stack: S3 backend is used to provide state locking and consistency checking. S3 bucket is used to store the generated state files by the terraform and Dynamo DB table is used for the locking purpose.
- Ghost stack: Once the backend stack is deployed, the deployment for the Ghost stack begins. Changes in the infrastructure plan will be shown to user before deploying/destroying the stack.
Terraform CDK then utilizes the providers and modules specified to generate terraform configuration. This terraform configuration later used for deploying/destroying stacks.
- Existing VPC: You can use the existing VPC by providing subnet ids as comma-separated values otherwise it'll create the new VPC and the subnets.
It expects to have Route53 configured for the domain where you want to host the Ghost. If you want to use the existing VPC, you need to provide the
subnet ids
to launch the ECS tasks (recommend private subnets) andpublic subnet ids
to launch the load balancer (ALB). - Existing Load Balancer: You can use the existing load balancer (ALB) by providing the
load balancer listener ARN
. - Hosting URL: It requires a
Ghost hosting url
where Ghost can be accessed on the web. - Static Website: Refer this to host the static website for the generated content. You can also specify
Static website url
where it will provision the AWS S3 bucket to host the static website. - Existing MySQL Database: The cli requires a MySQL database to store the Ghost configurations along with the content. You can provide the existing DB credentials like DB host, DB name, DB user password, and database name. (otherwise it'll create a new RDS instance).
It comes with the following benefits:
- Easy setup. You don't have to worry about provisioning each of the AWS resources by yourself.
- Make use of the existing infrastructure by providing the existing VPC subnets, load balancer, and database.
- Use this setup to provision and host the static website for the generated content.
- It uses AWS ECS with auto-scaling enabled. So, you don't have to worry about scalability.
- It provides a cost-efficient setup by plugging the existing load balancer and database. Also, it runs on AWS
FARGATE
and utilizes theFARGATE SPOT
resources.
-
Install the package:
npm install -g truesparrow-ghost
-
Deploy Ghost Stack and Backend Stack:
truesparrow-ghost deploy
-
Destroy Ghost and Backend Stack:
truesparrow-ghost destroy
- Clone the repository:
git clone [email protected]:TrueSparrowSystems/ghost-hosting-cli.git
- Install all dependencies:
cd ghost-hosting-cli npm install
- Create build
or
npm run get # fetch required terraform providers and modules npm run build # create a build
npm run watch
- Deploy stacks
npm run dev -- deploy
- Destroy stacks
npm run dev -- destroy
While executing deploy/destroy command, you might get timeout exceptions because of network interruptions. If that is the case, then re-run the command to complete the execution.