This is a simple setup and deploy scripts to run a server with Nginx, Node and SSL enabled.
- Have your code in a GitHub repository
- Have a server running somewhere (I use Digital Ocean)
- Have a domain with
A
record pointing to your server IP
- Copy the script to your box using:
scp box/speed_run_deploy.sh root@server_ip:~/speed_run_deploy.sh
- Log into your server
ssh root@server_ip
Obs: Assuming you're logging in as
root
, the script will create a deployer user.
- Run the script and follow the instructions!
bash speed_run_deploy.sh
It will install Nginx, PM2, Node.js, setup SSL and Firewall for you.
- Exit the box
- (From your machine) Copy the public key (it was created in ~/.ssh/deployer.pub in your machine):
cat ~/.ssh/deployer.pub | pbcopy
- Go to https://github.com/settings/keys
- Click 'Add new SSH' Key and paste the contents in public key field
- Copy the private key contents (it was created in ~/.ssh/deployer in your machine):
cat ~/.ssh/deployer | pbcopy
-
Push your code to Github
-
Copy the repository URL
-
Go to
https://github.com/<YOUR GITHUB USER>/<YOUR REPO NAME>/settings/secrets/actions
-
Create secret
SSH_PRIVATE_KEY
and paste the private key contents -
Create secret:
SERVER_IP
as -
Create secret:
SERVER_USER
as -
SSH into your server using the deployer user:
ssh -i ~/.ssh/deployer deployer@<YOUR SERVER IP>
- Clone your repository into
/var/www/<DOMAIN NAME>
git clone https://github.com/<YOUR GITHUB USER>/<YOUR REPO NAME>.git /var/www/<DOMAIN NAME>
Done! Every merge to main branch will be deployed.
- Commit something to the
main
branch (or the one you selected in setup) - The action will run automatically, wait until it finishes
- Access your domain and there you have it!
This is a Next.js project bootstrapped with create-next-app. You may use the boilerplate as is, it works!
You just need the following files if you want just the deploy script:
.github/actions/deploy.yaml
.github/workflows/deploy-prod.yaml
box/speed_run_deploy.sh
You will also need to edit speed_run_deploy.sh
because it creates a deploy.sh
script that you may want to edit.
Cheers,
Thiago V Ricieri
- System Thinker @ Systematic Success
- Maker @ Making of a Maker
- Engineering Manager, Apps @ Pluto TV / Paramount Global
- Founder @ Ghost Ship & Co.
- Digital Nomad @ Threads, X.com, LinkedIn, GitHub, Instagram, Website