In the part 03 of this series we got the basic infrastructure ready. Now we can continue to build our Ghost host server on that. Before anything, its best to setup AWS-CLI to use Systems Manager (SSM) so that we can connect to the Ghost host without leaving the terminal. Following the AWS documentation gets us setup in few minutes.
Also we need to have a real domain name for test secure site setup etc. I always use jayforweb.com as my test domain and I use google domains as my domain registrar.
Now we have to setup the followings in our Ghost host.
Route53 hosted zone
Route53 record set
CloudFormation made this easy by providing us some helper scripts. We use cfn-init:file to create configuration files and copy they to the appropriate places. Also we use cfn-init:commands to install and setup Docker, Docker-compose. Below is the new expanded version of our Ghost host resource.
YAML is great, but there is something else, TOML :-) We use a toml file for traefik to make it an opportunity to learn something different. I really like the idea of not having to worry about indentations.
[entryPoints.https.redirect] element in the traefik.toml file redirects all the http traffic to https. [command a] acme.json is used by traefik to setup TLS with LetsEncrypt. We have to use a symlink to add the docker-compose to PATH [command j].
We need to add Route53 hosted zone and the record set with our domain name.
We need to add an alias record as www.jayforweb.com to point to jayforweb.com. I tried to create a record set for that but didn't work. So we will revisit that later.Now its time run our CloudFormation to see what it creates! I deleted my stack to start fresh. Just imagine if we had to delete the resources manually, one by one :-) This is why I love CloudFormation.
Its always handy to know where to look for any errors. On our Ghost host, we can find all the logs under /var/log
cfn-init-cmd.log file is what we should look first. After the deployment our log shows happy faces.
Now we can verify whether our configuration files are in place at /data/traefik. Obviously they should be as we had no errors at all.
The site is up, with one small problem. We have to tweak the acme.json file to get the LetsEncryption working properly. I remember got it working after few tries last time with this site, fewmorewords.com but I dont remember how I did it :-). I will update this post when I work it out. But this is awesome as we got everything as code, no click-ops at all.
We can start up, shut down the site very easily with docker-compose via SSM. We have to make sure to use sudo. Also we should run docker-compose in detached mode [-d flag] when we start up the stack. Have a look at the commands in the below screenshot.
WOW! This became a very long post and thanks for staying with me so far. As always the full code is on github if you want to try this out by yourself.
Subscribe to Few More Words
Get the latest posts delivered right to your inbox