Skip to content

Commit 0f9eae9

Browse files
authored
Merge pull request #127 from neonexus/master
Added tmux.sh and self-update.sh scripts.
2 parents cae1886 + 91726b6 commit 0f9eae9

File tree

7 files changed

+451
-131
lines changed

7 files changed

+451
-131
lines changed

.ncurc

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// This allows us to "lock" Chai into v4.
22

33
{
4-
"reject": ["chai"]
4+
"reject": ["chai", "eslint"]
55
}

CHANGELOG.md

+8-1
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,18 @@
11
# Changelog
22

3+
## [v5.3.0](https://github.com/neonexus/sails-react-bootstrap-webpack/compare/v5.2.3...v5.3.0) (2024-04-22)
4+
### Features
5+
6+
* Added TMUX and self-update scripts.
7+
* Updated README for the new scripts, and Aiven.io mention.
8+
* Updated dependencies.
9+
310
## [v5.2.3](https://github.com/neonexus/sails-react-bootstrap-webpack/compare/v5.2.2...v5.2.3) (2024-04-09)
411
### Features
512

613
* Fixed issue with setup not setting DB SSL correctly.
714
* Fixed npm audit issues.
8-
* Fixed meta data issue with Favicons.
15+
* Fixed metadata issue with Favicons.
916
* Updated dependencies.
1017

1118
## [v5.2.2](https://github.com/neonexus/sails-react-bootstrap-webpack/compare/v5.2.1...v5.2.2) (2024-01-24)

README.md

+159-4
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
# sails-react-bootstrap-webpack
22

33
[![Travis CI status](https://img.shields.io/travis/com/neonexus/sails-react-bootstrap-webpack.svg?branch=release&logo=travis)](https://app.travis-ci.com/github/neonexus/sails-react-bootstrap-webpack)
4-
[![Sails version](https://img.shields.io/badge/dynamic/json?url=https%3A%2F%2Fraw.githubusercontent.com%2Fneonexus%2Fsails-react-bootstrap-webpack%2Fv5.2.3%2Fpackage.json&query=%24.dependencies.sails&label=Sails&logo=sailsdotjs)](https://sailsjs.com)
5-
[![React version](https://img.shields.io/badge/dynamic/json?url=https%3A%2F%2Fraw.githubusercontent.com%2Fneonexus%2Fsails-react-bootstrap-webpack%2Fv5.2.3%2Fpackage.json&query=%24.devDependencies.react&label=React&logo=react)](https://react.dev)
6-
[![Bootstrap version](https://img.shields.io/badge/dynamic/json?url=https%3A%2F%2Fraw.githubusercontent.com%2Fneonexus%2Fsails-react-bootstrap-webpack%2Fv5.2.3%2Fpackage.json&query=%24.devDependencies.bootstrap&label=Bootstrap&logo=bootstrap&logoColor=white)](https://getbootstrap.com)
7-
[![Webpack version](https://img.shields.io/badge/dynamic/json?url=https%3A%2F%2Fraw.githubusercontent.com%2Fneonexus%2Fsails-react-bootstrap-webpack%2Fv5.2.3%2Fpackage.json&query=%24.devDependencies.webpack&label=Webpack&logo=webpack)](https://webpack.js.org)
4+
[![Sails version](https://img.shields.io/badge/dynamic/json?url=https%3A%2F%2Fraw.githubusercontent.com%2Fneonexus%2Fsails-react-bootstrap-webpack%2Fv5.3.0%2Fpackage.json&query=%24.dependencies.sails&label=Sails&logo=sailsdotjs)](https://sailsjs.com)
5+
[![React version](https://img.shields.io/badge/dynamic/json?url=https%3A%2F%2Fraw.githubusercontent.com%2Fneonexus%2Fsails-react-bootstrap-webpack%2Fv5.3.0%2Fpackage.json&query=%24.devDependencies.react&label=React&logo=react)](https://react.dev)
6+
[![Bootstrap version](https://img.shields.io/badge/dynamic/json?url=https%3A%2F%2Fraw.githubusercontent.com%2Fneonexus%2Fsails-react-bootstrap-webpack%2Fv5.3.0%2Fpackage.json&query=%24.devDependencies.bootstrap&label=Bootstrap&logo=bootstrap&logoColor=white)](https://getbootstrap.com)
7+
[![Webpack version](https://img.shields.io/badge/dynamic/json?url=https%3A%2F%2Fraw.githubusercontent.com%2Fneonexus%2Fsails-react-bootstrap-webpack%2Fv5.3.0%2Fpackage.json&query=%24.devDependencies.webpack&label=Webpack&logo=webpack)](https://webpack.js.org)
88

99
[//]: # ([![Codecov](https://img.shields.io/codecov/c/github/neonexus/sails-react-bootstrap-webpack?logo=codecov)](https://codecov.io/gh/neonexus/sails-react-bootstrap-webpack))
1010

@@ -18,6 +18,10 @@ A virtual start-up in a box!
1818

1919
NOTE: You will need access to a MySQL / MariaDB database for the setup. If you want to use a different datastore, you'll need to configure it manually.
2020

21+
[Aiven.io](https://aiven.io) has FREE (no CC required) secure MySQL (5 GB), and Redis (1 GB). Both require use of SSL, and can be restricted to specified IPs. (If you are having trouble finding the
22+
FREE instances, you need to select Digital Ocean as the cloud provider.) Use my [referral link](https://console.aiven.io/signup?referral_code=mk36ekt3wo1dvij7joon) to signup, and you'll get $100
23+
extra when you start a trial (trial is NOT needed for the free servers).
24+
2125
```shell
2226
npx drfg neonexus/sails-react-bootstrap-webpack my-new-site
2327
cd my-new-site
@@ -58,6 +62,9 @@ npm run start OR npm run ngrok
5862
* [Sails-Style Configuration](#sails-style-configuration)
5963
* [Script Options](#script-options)
6064
* [Support for `sails-hook-autoreload`](#support-for-sails-hook-autoreload)
65+
* [Getting Setup Remotely](#getting-setup-remotely)
66+
* [What is TMUX?](#what-is-tmux)
67+
* [A simple walkthrough for a self-updating VM](#a-simple-walkthrough-for-a-self-updating-vm)
6168
* [What About SEO?](#what-about-seo)
6269
* [Useful Links](#useful-links)
6370

@@ -530,6 +537,154 @@ For example: `./ngrok.js token=AUTHTOKEN1` > `NGROK_AUTHTOKEN=AUTHTOKEN2 ./ngork
530537
If you would like to use [`sails-hook-autoreload`](https://npmjs.com/package/sails-hook-autoreload), just install it: `npm i sails-hook-autoreload --save-dev`. The config
531538
file [`config/autoreload.js`](config/autoreload.js) is already pre-configured for this repo.
532539

540+
## Getting setup remotely
541+
542+
There are a lot of ways to go about remote deployments; many automated, some not so much. For the sake of argument, let's say you want to set up a remote server by hand. It would be nice if said
543+
server (or servers if behind a load-balancer), could do a `git pull`, `npm install`, and an asset build if need be `npm run build`. It would also be great if you could see the progress, or even
544+
just the console of the Node server.
545+
546+
That's what the [`self-update.sh`](self-update.sh) and [`tmux.sh`](tmux.sh) shell scripts are for. Note, they are both defaulted to `bash`, but should work just fine in `zsh`.
547+
548+
### What is TMUX?
549+
550+
In simplest terms, TMUX is a "terminal multiplexer". It lets you switch between programs in one terminal, detach them (they keep running in the background) and reattach them to a different terminal.
551+
552+
In other words, it adds a lot of magic to the terminal. One of the most useful things, is being able to run programs in the background, but still being able to see the console output later (as
553+
it is still running). It runs on most Linux-y distros, including macOS.
554+
555+
[Check out their "Getting Started" docs](https://github.com/tmux/tmux/wiki/Getting-Started) for more on what you can do.
556+
557+
To install (remember: on the remote machine, not your local machine), it's most likely `sudo INSTALLER install tmux`. Amazon Linux is `sudo yum install tmux`, Ubuntu is `sudo apt-get install tmux`.
558+
559+
### A simple walkthrough for a self-updating VM
560+
561+
For this guide, I'm going to be using Amazon Linux as the basis; it's a great default if using AWS. However, most of these steps can easily be adapted.
562+
563+
It should also be noted, this is by no means the only way to set up remote servers; nor is it a thorough guide. This is just a quick-n-dirty, get off the ground running without a lot of tooling, kind
564+
of guide. There are PLENTY of automated deployment managers and documentation out there. This is fairly open-ended; it is assumed you know how to do a portion of basic remote server management.
565+
566+
#### Getting Started
567+
568+
Spin up a new instance at the smallest size possible (as of this writing, `t4g.nano` is the smallest) and SSH into it and follow along.
569+
570+
#### Lack of Memory
571+
572+
While the smallest instance size will certainly not have enough RAM to support an asset build, it is plenty for running our Node server.
573+
574+
To make it so the instance CAN handle an asset build (despite its lack of memory), you'll want to create a swapfile. I use 4 GB swapfiles, as that seems to be more than enough head-room for asset
575+
building, however, you can most likely get away with just 2G.
576+
577+
First, create the file, and allocate the space:
578+
```shell
579+
sudo fallocate -l 4G /swapfile
580+
```
581+
582+
Make it readable / writable only from ROOT:
583+
```shell
584+
sudo chmod 600 /swapfile
585+
```
586+
587+
Make it a proper swapfile:
588+
```shell
589+
sudo mkswap /swapfile
590+
```
591+
592+
Tell the OS to actually use the swapfile:
593+
```shell
594+
sudo swapon /swapfile
595+
```
596+
597+
Edit the `fstab` table to make this swapfile permanent:
598+
```shell
599+
sudo nano /etc/fstab
600+
```
601+
602+
Add this to the bottom of the `fstab` and save:
603+
```shell
604+
/swapfile swap swap defaults 0 0
605+
```
606+
607+
#### Get the basics installed
608+
609+
Now that we have the lack of memory issue dealt with, let's get the 3 bits of software installed that we for sure need: `git`, `node` and `tmux`:
610+
611+
```shell
612+
sudo yum install git nodejs tmux
613+
```
614+
615+
#### Setup server to be authenticated for `git pull`
616+
617+
This is going to assume you have a repo setup with GitHub, but the keygen is pretty much universal.
618+
619+
Generate SSH key:
620+
```shell
621+
ssh-keygen -t ed25519 -C [email protected]
622+
```
623+
624+
Copy the public key:
625+
```shell
626+
cat ~/.ssh/id_ed25519.pub
627+
```
628+
629+
Save it as a ["deploy key"](https://docs.github.com/v3/guides/managing-deploy-keys/#deploy-keys). (Or however you need to save it in your repo to allow `git pull` on the remote server).
630+
631+
#### Clone your repo
632+
633+
Now that you have the server's public key saved in your repo, you should be able to clone your repo on the remote server:
634+
635+
```shell
636+
git clone [email protected]:USERNAME/REPO.git myapp
637+
```
638+
639+
#### Make sure everything works
640+
641+
Now, you'll want to `cd myapp`, and `npm install`.
642+
643+
Now, before you can actually start the server for a dry-run, you need to decide how you are going to store the server's credentials (user/pass for datastores and the like). It is recommended you use
644+
the [environment variables](#environment-variables), but it is also possible to run the [interactive setup](#interactive-setup), and generate a `local.js`.
645+
646+
#### Give it a spin
647+
648+
You should now be able to `sudo npm run lift:prod` (recommended for all remote environments, even DEV). `sudo` is needed on Amazon Linux, because it required ROOT permissions to open ports.
649+
650+
If everything is working as intended... congrats (or so you thought)! Now that you have everything working; it's time to get the server to update / rebuild / start itself.
651+
652+
#### Final stretch
653+
654+
Now you need to decide how you are going to have the `tmux.sh` script run on startup. The easiest way would be to just install `cronie`:
655+
656+
```shell
657+
sudo yum install cronie
658+
```
659+
660+
Enable the service:
661+
```shell
662+
sudo systemctl enable crond.service
663+
```
664+
665+
Start said service:
666+
```shell
667+
sudo systemctl start crond.service
668+
```
669+
670+
Now edit the `crontab` to run the script at `@reboot`:
671+
672+
```shell
673+
@reboot cd myapp; ./tmux.sh
674+
```
675+
676+
#### Have you tried turning it off and on again?
677+
678+
```shell
679+
sudo reboot
680+
```
681+
682+
Now re-login to the instance. You should be able to `tmux attach` and see the Sails console.
683+
684+
#### Now save that image!
685+
686+
Now you should create an AMI from that server. You should be able to terminate the running instance, and spin up a new one using your new custom AMI, and everything should just work.
687+
533688
## What about SEO?
534689

535690
I recommend looking at [prerender.io](https://prerender.io). They offer a service (free up to 250 pages) that caches the end result of a JavaScript-rendered view (React, Vue, Angular), allowing search

0 commit comments

Comments
 (0)