Frontend Deployment Guide
The guide describes how to deploy frontend packages using npm http-server and the distribution package. A example of the script to automate this process can be found in frontend-ec2-instance.sh.
Initialize an Ubuntu 18.04 instance
Install npm Install http-server
Retrieve front end distributions from s3 or deployment package
The distributions for cms frontend should be available from a provided s3 bucket or included in a deployment package. It will consist of a bundle that can be served statically from a npm http-server.
Create a systemd unit that will start up the http-server
This will start the http-server and serve the contents of the bundle on the pre-defined port
Post-Deployment Instructions
- To update the frontend service, simply restart the service with the new distribution package
- Certificates can be provided in the http-server start up command to enable ssl
frontend-ec2-instance.sh
#! /bin/bash
# Run commands as root user
sudo su
# Install npm and http-server
apt-get update
yes | apt install npm
npm install --global http-server
# Install aws cli
yes | apt install awscli
mkdir dist
# Create deploy script
echo '
#!/bin/bash
aws s3 sync ###S3_URL### /root/dist
http-server -p 80 /root/dist
' >> ~/deploy-frontend.sh
chmod u+x ~/deploy-frontend.sh
# Create system service
echo '
Description=Start Http Server
[Service]
User=root
ExecStart=/root/deploy-frontend.sh
Restart=on-failure
RestartSec=5s
[Install]
WantedBy=multi-user.target
' >> /etc/systemd/system/frontend.service
systemctl enable frontend.service
systemctl start frontend.service