pm2+ not showing versioning when using ecosystem file - node.js

I'm using PM2+ to manage my NodeJS deployments.
Usually, when I deploy an application with pm2 start src/app.js, I get details about versioning like in the screenshot below. However, when I deploy using an ecosystem file I only get N/A:
PM2 normally extracts this information directly using vizion.
But since it didn't work with the ecosystem file, I specified the GitHub repository directly just like the documentation stated.
This is my current pm2-services.json ecosystem-file:
{
"apps": [
{
"name": "my-node-app",
"cwd": "./my-node-app-repo-folder",
"script": "src/app.js",
"env": {
"NODE_ENV": "production"
},
"repo": "https://github.com/MyUserName/MyNodeAppRepo.git",
"ref": "origin/master"
}
]
}
For the ref field, I also tried putting refs/remotes/origin/master, remotes/origin/master and master.
Sadly none of them worked (I made sure they are correct using git show-ref).
Additional info:
NodeJS Version: v15.11.0
NPM Version: 7.6.3
PM2 Version: 4.5.6 (latest, by the time of writing this)
So, how do I get the Versioning field to display correctly?
Note: This isn't really an issue but rather a minor inconvenience. I just want to know what I'm doing wrong.

Related

Node.js live debugging in VSCode doesn't work

I have a small project (but issue also appears on the one created by npx create-react-app my-app). I use VsCode and developing inside container (https://code.visualstudio.com/docs/remote/containers) . Dockerfile is very minimal:
ARG VARIANT="16-bullseye"
FROM mcr.microsoft.com/vscode/devcontainers/javascript-node:0-${VARIANT}
devcontainer.json has, almost, just defaults:
{
"name": "Node.js",
"build": {
"dockerfile": "Dockerfile",
"args": { "VARIANT": "16-bullseye" }
},
"settings": {},
"extensions": [
"dbaeumer.vscode-eslint"
],
"remoteUser": "node"
}
To debug, I run npm start , then I (for the 1st time) i click on Debug URl.
On macOS everything works, including file monitoring, so when I change js file, npm is recompiling instantly.
On Windows 11 however, the last part doesn't work - I need to stop and start npm manually, to have changes implement.
I've even tried to remove .vscode directory from my profile - no change here...
Any idea what is going on? Why it does work on macOS and doesn't work on Windows ?
I have the same extensions on both systems...I just can't find what is going on with Windows machine...
EDIT: the issue seems to be related to "Remote Development" extension for vscode . Issue is present only when using this extension on Windows. So I've opened a bug there: https://github.com/microsoft/vscode-remote-release/issues/6633

AWS Toolkit + VSCode local testing

I'm trying to figure out how to use AWS toolkit for vscode. I go to the AWS extension and click Create New SAM Application, point to project directory and it creates a hello world function. Above it, it says Add Debug Configuration. I click that, choose nodejs 12.x and save the launch.json, but I don't get the run option. It still says Add Debug Configuration for some reason. How can I run my lambda functions locally in the console?
The launch.json file generates, but I can never run the code.
launch.json
{
"configurations": [
{
"type": "aws-sam",
"request": "direct-invoke",
"name": "new test:app.lambdaHandler (nodejs12.x)",
"invokeTarget": {
"target": "code",
"projectRoot": "new test/hello-world",
"lambdaHandler": "app.lambdaHandler"
},
"lambda": {
"runtime": "nodejs12.x",
"payload": {},
"environmentVariables": {}
}
}
]
}
I also tried navigating to the hello-world directory in terminal and executing node app.js, but it doesn't return anything
What am I doing wrong? I appreciate the help!
Make sure you have SAM CLI install in local, here are the instructions for installation https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/serverless-sam-cli-install.html
Then run the command sam local start-api.
You should be able to access the api at http://127.0.0.1:3000/hello
You can also do the same via vscode by selecting Run > Run without debugging (shortcut: ctrl + F5)

Using NodeJS development dependencies in Heroku review-app post-deploy step

I have a (demo) application hosted on Heroku. I've enabled Heroku's "review app" feature to spin up new instances for pull request reviews. These review instances all get a new MongoDB (on mLab) provisioned for them through Heroku's add-on system. This works great.
In my repository, I've defined some seeder scripts to quickly get a test database up and running. Running yarn seed (or npm run seed) will fill the database with test data. This works great during development, and it would be perfect for review apps as well. I want to execute the seeder command in the postdeploy hook of the Heroku review app, which can be done by specifying it under the environment.review section of the app.json file. Like so:
{
"name": "...",
"addons": [
"mongolab:sandbox"
],
"environments": {
"review": {
"addons": [
"mongolab"
],
"scripts": {
"postdeploy": "npm run seed"
}
}
}
}
The problem is, the seeder script relies on some development-only dependencies (faker, ts-node [this is a TypeScript project], and mongo-seeding) to execute. And these dependencies are not available in the postdeploy phase of an Heroku app.
I also don't think that "compiling" the typescript in the regular build step is the best idea. This seeder script is only used in development (and review apps). Besides, I'm not sure that would resolve the issue with missing dependencies like faker.
How would one go about this? Any tricks I'm missing?
Can I maybe skip Heroku's step where it actively deletes development dependencies? But only for review apps? Or even better, can I "exclude" just the couple of dependencies I need, and only for review apps?
The Heroku docs indicate that when the NODE_ENV variable contains anything but "production", the devDependencies will not be removed after the build step.
To make sure this only happens for Heroku review apps, you can set the NODE_ENV variable under the environments.review section of the app.json file. The following config should do the trick:
{
"name": "...",
"addons": [
"mongolab"
],
"environments": {
"review": {
"addons": [
"mongolab:sandbox"
],
"env": {
"NODE_ENV": "development"
},
"scripts": {
"postdeploy": "npm run seed"
}
}
}
}

Zeit builds failing - Error: No output directory named "build" found

As of 1/5/20 all of my builds are failing that are deployed on Now. I was getting the warning that node 8.x was no longer supported so I specified an engine version of 12.x in my package.json, this successfully stopped the warning from popping during deployment but I'm still receiving the following error
Error: No output directory named "build" found.
I thought maybe a recent change I pushed was causing this but going back and redeploying old deployments that built successfully now received this error. I'm wondering if something on the Now platform changed that I wasn't aware of because it does not seem that code I've pushed recently was the catalyst for this error.
It's also very odd since right before this error the deployment log shows the following
Creating an optimized production build...
Compiled successfully.
File sizes after gzip:
207.04 KB build/static/js/2.7d84160a.chunk.js
11.64 KB build/static/js/main.65999b58.chunk.js
1.24 KB build/static/css/main.cacda93c.chunk.css
762 B build/static/js/runtime~main.a8a9905a.js
The project was built assuming it is hosted at the server root.
You can control this with the homepage field in your package.json.
For example, add this to build it for GitHub Pages:
"homepage" : "http://myname.github.io/myapp",
The build folder is ready to be deployed.
So it looks like the build folder is created but now for some reason now can't find it.
My now.json looks like this
{
"version": 2,
"name": "appname",
"public": false,
"builds": [
{ "src": "package.json", "use": "#now/static-build" },
{ "src": "index.js", "use": "#now/node-server" }
]
}
Any idea why my deployments would suddenly start failing in the last day?
Classic case of finding the solution as soon as I post on stackoverflow...
Not sure which tutorial I followed when first spinning this up but in my package.json I had my now-build script set to
react-scripts build && mv build dist
I removed the last bit of that so now my now-build script is simply
react-scripts build
and all is well again.
I couldn't really tell you why I set this, I just blindly followed the tutorial. For the past 4 months, this has worked, not sure why yesterday it started throwing errors, oh well.

Rollback pm2 deploy to specific commit

I would like to know how to use pm2 to "rollback" a recent code change.
Our team's change process requires us to have a "rollback" plan in the case of a problem with a deploy. We normally just document that the rollback plan will be to git checkout CHANGESET to go back to the previous version of the code while we fix the issue and test it in dev.
How can I achieve a similar rollback using pm2? Our new-ish deploy process is pm2 deploy production and my ecosystem.json is included below. Currently both UAT and production use origin/master as the "ref". I was thinking maybe to use a tag or something, but not sure the best approach. Perhaps I should just continue to do a git checkout COMMIT in these rare rollback cases, but looking for other ideas.
{
"apps": [{ blah... }],
"deploy": {
"UAT": {
"user": "USER_HERE",
"host": ["IP_HERE", "IP_HERE"],
"ref": "origin/master",
"repo": "git#github.com:USER/REPO.git",
"path": "/home/USER/node",
"post-deploy": "bash ./update.sh"
},
"production": {
"user": "USER_HERE",
"host": ["IP_HERE", "IP_HERE"],
"ref": "origin/master",
"repo": "git#github.com:USER/REPO.git",
"path": "/home/USER/node",
"post-deploy": "bash ./update.sh"
}
}
The tool pm2 deploy provides the command revert. So, you can do:
pm2 deploy ecosystem.json revert
This "rollback" your app to the previous deploy. You can specify also how many last deployment revert to.
See also the command [ref] combined with list, curr or prev:
https://github.com/Unitech/PM2/blob/0.14.7/ADVANCED_README.md#deployment-options

Resources