Dockerizes a Node.js service and deploys it to a remote server using a CI/CD workflow implemented with GitHub Actions.
The Node.js service is a web app with two routes: a home "/" route and a "/secret" route which has basic authentication requiring a "username" and "password".
The workflow dockerizes the Node.js web app and deploys it a remote server via SSH making use of github secrets. This project creates a digital ocean droplet running Ubuntu for the remote server.
- Terraform version 1.14+
- Ansible version 2.16+
- Node.js version 18.19.1+
- Npm
Prerequisites:
- An SSH key pair (generate by running the
ssh-keygencommand) - DigitalOcean Personal Access Token
Run these commands from within the project directory or folder to setup the server:
Bash:
npm install
cd terraform
terraform init
# This command requests a personal access token (do_token) and the filepath of a public SSH key (pub_key). Enter them to continue
terraform apply
cd ../ansible
ansible-playbook -i inventory.ini setup.yml
CMD and Powershell:
npm install
cd terraform
terraform init
# This command requests a personal access token (do_token) and the filepath of a public SSH key (pub_key). Enter them to continue
terraform apply
cd ..\ansible
ansible-playbook -i inventory.ini setup.yml
For running the workflow:
- Fork this repository.
- Add the remote server's public ip address as "HOST" and the matching private SSH key (not the filepath) as "KEY" as secrets in the repository
- Add a "SECRET_MESSAGE", "USERNAME" and "PASSWORD" as secrets in the repository naming them as stated.
- Make some non functional change/s to one or more of the project's files (make a change to this README.md file for example) and commit the changes to the repository making sure the action is enabled.
The workflow should be able to be seen running in the actions tab of the repository.
To access the Node.js web app after the workflow has run, go to the public ip of the remote server using a modern browser (run terraform output to see the ip).