PM2 deploy folder structure - how to use / configure - node.js

I'm deploying a node application using PM2 and nvm as described in the pm2 documentation. I observe the resulting folder structure, and I'm questionning myself about why it is as it is, and if there is some way to configure it.
My ecosystem.config.js just contains the minimun information to connect to git (bitbucket) and check out the project, that's why I think it's not worth to put it here.
This is the folder structure I obtain running pm2 deploy production setup:
source/
.git // git root
*.* // all checked out projet files
shared/
pids/ // empty folder, pids are in ~/.pm2/pids
logs/ // empty folder, logs are in ~/.pm2/logs
current/ // symlink to /source
.deploys // git commit ids
My questions are:
What is /current for ? navigating directly to /source will give the same result. In a capistrano deployment, where I have several releases checked out, having a symlink makes sense, since it allows to rollback instantly, but here I don't see how it could be useful.
What if I would only keep a subfolder of /source in the webroot ? Is there a way to configure this ? Maybe I'm still too much thinking in 'Apache mode', and there is no need for this ?

This github issue very well describes my problem (and others) ;
https://github.com/Unitech/pm2-deploy/issues/27#issue-49186558
The answer to my question is simpler that I hoped:
the symlink of the current/ folder misses its purpose.
there is no way to configure pm2 deploy in a more detailed way.

Related

Install drupal project with drupal in a subdirectory

My customer a has production environment with the following folder structure:
- www
|- maresmuseum
where I only have access to these two empty folders, being the "maresmuseum" the public_folder.
I've deployed my Drupal 9 site with composer, like the project-recommended way does, you know: placing the index.php along many other core related folders & files in "maresmuseum" folder, and /vendor, /tmp and many other private stuff in the "www" folder.
As a result, I can access my website through a url like this: https://example.com/maresmuseum (I'm quite sure my customer has a .htaccess rule somewhere to accomplish that, don't you?)
Given this production scenario, and having in mind I work with DDEV on local, I want to install this site on my local machine so I can access it with a url like this: https://example.local/maresmuseum.
Of course, all inner pages of this site must follow this url pattern, something like this:
https://example.local/maresmuseum/about-us
https://example.local/maresmuseum/contact, etc..
How should I configure DDEV to accomplish that?
Thanks in advance.
I'm sure there are many ways to do this. Here's one way to do it using nginx configuration changes.
I used https://blog.rebootr.nl/drupal-8-in-a-subdirectory-with-nginx/
ddev config --composer-root=maresmuseum --project-type=drupal9 --webserver-type=nginx-fpm --docroot=maresmuseum/web --create-docroot --web-working-dir=/var/www/html/maresmuseum (This sets up to put composer.json in maresmuseum)
Install Drupal 9: ddev composer create drupal/recommended-project --no-install
ddev composer require drush/drush
Install project, or load db, or whatever, maybe ddev exec vendor/bin/drush si -y demo_umami --account-pass=admin
Edit the .ddev/nginx_full/nginx-site.conf to remove the #ddev-generated and replace the location stanza, example in https://gist.github.com/rfay/5248e5f75bf3e27d84965bfdfc69c240#file-nginx-site-conf
Edit the maresmuseum/sites/default/settings.php to add the stanza suggested in the article to the bottom, example in https://gist.github.com/rfay/5248e5f75bf3e27d84965bfdfc69c240#file-settings-php
ddev restart && ddev launch /maresmuseum
https://<project>.ddev.site/maresmuseum will work fine (as it will without the directory).
I had some trouble with browser cache, so you'll want to pay attention to that.

How can I clone a git repository on a server automatically to another folder on every commit

I have a simple express.js-powered API running on an ubuntu server with pm2. The server.js and the other files are in /var/www/node/api/.
On this server, at /srv/git-repos/api.git/ is my git repository, where I commit new changes from my local machine.
The Question is, is it possible, that every time I commit new changes to the server, it recognizes this, and clones my repository to let's say /var/www/node/api-dev/(which will then be available at dev.example.com, this could be made possible with nginx, so there is no problem) and restarts my pm2 instance with pm2 restart api.
Because then I would test, if my changes work on the server, and when they do, I just can copy the content of /var/www/node/api-dev to /var/www/node/api manually.
Or is there another, better workflow? It's just a small API on which I will make many changes because I want to develop it for the needs of my frontend.
Thanks for your answers and suggestions, I hope it's understandable what I want to archive.
git commit
git clone <repo> ../api-dev
pm2 restart api
Save it as c.sh and run with ./c.sh or add to your .bashrc

Folder structure to deploy app on EC2 instance

I am setting up a new React app on EC2 instance (ubuntu). I have installed nodeJS and npm and I am able to build my app successfully.
Issue is my code is in /var/www/html folder and my site example.com is pointed to this folder.
when I run
npm run build
It builds a folder under /html like /html/build now my app runs on example.com/build. Resources for these files comes from example.com/static/style.css etc but they actually reside under example.com/build/static
I can edit asset-manifest.json and change the path but thats not appropriate solution as I need to get rid of /build folder for production
I am not super familiar with deployments to EC2 but this looks like you just need to either copy the entire contents of your app inside var/www/html, or you need to tell apache or nginx to look to the right folder (in this case /build)
For example, with apache you probably have a file inside /etc/apache2/sites-enabled/ that is pointing to /var/www/html, you could change that to /var/www/html/build and restart apache.
You can check this for examples on how to write these configurations https://gist.github.com/rambabusaravanan/578df6d2486a32c3e7dc50a4201adca4

How to host and access files on a Netlify site

I am using Netlify to host a github repo and am trying to find a way to host additional files on the domain.
( If you don't know what Netlify is check it out. It's a fast dirty and free version of AWS code deploy as far as I understand. (Disclaimer have not used AWS code deploy))
Example
Base Domain:
https://physiome-test.netlify.com/
Load a 3D model from
https://physiome-test.netlify.com/3Dmodels/heart/fullheart.json
Does anyone know if this is possible? I understand that they only provide 'static sites' but I don't see why that couldn't include file storage so that one doesn't have to worry about CORS
Netlify will host all static content in the folder you tell it to on deploy. You are currently telling Netlify to put your whole repository into the site starting at the root of the repository. This is causing issues with your relative paths.
You can go to any path in your repository at this time on your site and get a returned response of the file.
Solution:
Build your site into one build location and have Netlify deploy that location to the site. Any path relative to the root path of the location will be the root of your site.
1. Put the body assets under your simple_heart/models directory at simple_heart/models/body
2. netlify.toml (root of your repository)
[build]
command = "cp -r ./simple_heart ./build && npm run build"
publish = "build"
3. Fix your index.html in the simple_heart to reflect the relative paths from the root of simple_heart which will now be the root of your site with the build assets physiomeportal.js and physiomeportal.min.js at the root of your site.
note: To see this, run the command from the root of your site on a local build.

db.* files in /home from Perforce?

I see several db.* files in my /home directory, and it seems they come from perforce. For example, some files are db.archmap, db.bodtext, db.change, db.changex
Are these files useful? Can I delete them? They are making my /home directory messy
You have started a server using your home directory as the Perforce server's P4ROOT folder. Those files are files that are generated from starting the server and cannot be deleted unless you want to hose your server installation. It's not clear to me how you've started the server instance, so I'll try and cover multiple bases with my answer.
If you want to start up the server under your own account, you should set the P4ROOT environment variable and point it to where you want the server to store its files. Alternatively, when you start the server, you can specify the root folder on the command line using the -r option:
p4d -r /home/mark/p4server
which would put the server's files into the directory called 'p4server' off of my home directory.
Typically it is best to run the perforce server using a user that is dedicated to running perforce. I use a user called 'perforce'. I set P4ROOT (and other variables) in that users environment. If you cannot use a separate user, it might be easier to use the -r command line option that I mentioned above.
Those files are only server files, not client files. So it is safe to delete them, but if you start the server back up it will recreate them. So you might want to uninstall the server.
Unless you are running a beta version, they have p4sandbox coming soon(maybe in the beta, I forget) which MAY create those files. I don't have a beta version, so I can't verify what new files the client may or may not create.
You can check the documentation here to see what these files do/are for.

Resources