Install nvm (which installs npm and nodejs) and mongo.
Install node modules. You also need to create the mongo storage folder.
npm install
mkdir -p data-node/db
Maybe you will need to increase the number of file watchers, with:
echo fs.inotify.max_user_watches=524288 | sudo tee -a /etc/sysctl.conf && sudo sysctl -p
To run a development server with a database :
npm run dev
This starts a mongod instance on the 27017
port. For more info, look at package.json
.
Connect to http://localhost:9000/
.
First, to secure the server, you need to setup the SSH keys. Then configure the firewall UFW.
Install docker and docker compose. To have docker working properly, you may need to add the user to the docker group. Don't forget to logout and login to apply the effect.
sudo groupadd docker
sudo usermod -aG docker $USER
Setup the DNS server correctly, and update the domain name in init-letsencrypt.sh
.
The DNS configuration needs to be done, which can take up to 48h, before you can go to the next step.
Initialize the Let's Encrypt configuration.
In case this does not work, you can re-run the command.
Maybe remove the certbot/
directory, just to be sure.
This comes from this tutorial.
./init-letsencrypt.sh
You may need to change the permission of the ./certbot
folder.
sudo chown -R $USER certbot
Update the .env
file.
cp sample.env .env
You should be able to start the server:
docker-compose up
Sometimes, there are errors that the certificate is self signed.
Just delete the certbot
folder, make sure the containers are down, and start again.
To create a new admin user, just register a new user at POST /auth/register
, the first user will be granted admin access.
To setup the deployement pipeline, generate a set of RSA keys with ssh-keygen
.
Go on Gitlab to repo -> Settings -> CI -> Environment Var
. Set the environment
variable SSH_DEPLOY_KEY
to the private key generated (e.g: ./id_rsa
).
Then SSH to the server, go to the ~/.ssh/authorized_keys
file.
Add a line with the exact public key (e.g: ./id_rsa.pub
).
The configuration for the continuous integration is done !
You can just push in the master branch. The CI Gitlab pipeline should deploy the code correctly.
The Gitlab CI pipeline is configured in gitlab-ci.yml
. It first connect in SSH to the server, using the RSA key given
in Gitlab environment variable configuration. Then, it pulls the last version of the code, build the containers, then
up the docker-compose file.
To ssh to the server, use the RSA keys. The root user is root
and the regular user is api
.
The backend repository is located in /home/api/clapback-backend
.