pm2 keep auto restarting on image upload - docker

I am very close to release and while I was testing, I realized my api restarts on image upload, giving me 502 error.
I realized pm2 was restarting on image upload endpoint - since it is not logging any error on api side, it must have been server itself.
while investigating, I realized i had watch option to be true, so I set it to false and expecting all things to work again.
"apps": [
{
"name": "app",
"script": "src/index.js",
"instances": 1,
"autorestart": true,
"watch": false,
"time": true,
"env": {
"NODE_ENV": "production"
}
}
]
}
this is my ecosystem.config.json and my pm2 command is pm2 start ecosystem.config.json --no-daemon
well, pm2 still restarting on every image upload endpoint, giving me same error 502.
I am not physically storing images on my server, i simply save images to s3 buckets.. so image upload file change must be some kind of temp file... can anyone guide me to the right direction?
Thank you.
edit:
Just figured out this silent crash only happens in docker container.. feature works fine when server was ran locally. Still trying to debug it. Also could possibly be sharp image resizing crashing... unsure..
tried sharp.concurrency(1); sharp.cache(false); and setting UV_THREADPOOL_SIZE=1 but no luck

Fixed.
those who are having similar issue.
problem was actually on sharp image resizing library.
the older version library was not compatible with node:alpine.
updating the library to the latest one fixed the problem and the container does not crash anymore.

Related

Playwright tests inside docker fails to load fonts

Currently I have Playwright tests that I am running inside Docker container both locally and in the CI. Unfortunately the tests fail on the CI with screenshot comparison error.
Upon investigation I can see that the fonts on the CI screenshots are different from the ones used to generate the expected images (also run inside docker). But this doesn't happen consistently - sometimes it happens, sometimes it doesn't. Using sharding shows that some shards pass fine and others don't inside the same job run.
Figured it out - after reviewing the trace file - it turned out that the fonts are loaded from our CDN which is on a different domain from the local one inside the Docker container where the tests are running. This results in the following CORS error and the fonts are not applied.
Access to font at 'https://mycdn.com/fonts/my-font.woff2' from origin 'http://localhost:8003' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.
Furthermore this issue was strangely affecting only the tests running on chromium and the ones on webkit.
After some more research I found out this Playwright issue suggesting some parameters when running tests in chromium browser which actually did the job!
So the final solution was to change the chromium configuration to:
{
name: 'chromium',
use: {
browserName: 'chromium',
bypassCSP: true,
launchOptions: {
args: ['--disable-web-security'],
},
},
},

Debug Dockerized Flask app in VSCode not breaking on breakpoints

I followed this tutorial to set up debug in my VSCode.
My launch.json file is below.
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "Python: Remote Attach",
"type": "python",
"request": "attach",
"connect": {
"host": "localhost",
"port": 5678
},
"pathMappings": [
{
"localRoot": "${workspaceFolder}/server/project/views",
"remoteRoot": "/server/project/views"
}
]
}
]
}
My code does break on raised and user uncaught exceptions but it does not break on the breakpoints that I set. The code is reaching the breakpoints and I checked it using print statements, but my breakpoints are not working. VSCode debugger does seem to listen to my docker app (seen in the logs in screenshot) but not sure why it is not breaking at my breakpoints. However, it does give an error saying:
pydev debugger: unable to find translation for:
"/home/vvarma9/DTNetworkRepos/ip2m-metrr/server/project/utils/assessments.py"
in ["/home/vvarma9/DTNetworkRepos/ip2m-metrr/server/project/views/",
"/home/vvarma9/DTNetworkRepos/ip2m-metrr/server/project/views"]
(please revise your path mappings).
Kindly help!
Make sure your local and remote paths are correct. You can check your remote path by logging into the container's terminal. There you can find the absolute path of your "app".
I also cannot tell where you ${workspaceFolder} is actually is. Could be DTNetworkRepos or ip2m-metrr. You will need to make sure you clarify the path.
Also it would help if you posted up your folder stucture, Docker file for the server project and docker compose for all your container projects. Docker file will explain your path on the remote server. Dockerfile & Docker-compose file will ensure us that you have the right cmd or entrypoint for your environment. It may not line up with the tutorial that you set up.

Is there a way to build different projects (different electron-builder file) for electron

We have a white-labeled app built with electron+angular and we want to build 3 different let's say 'flavours' of the app. Except for the UI changes in Angular we have a different electron-builder file with configurations for each project. The problem is that after I build the first one the next one is twice its size (as a .exe) and when I build the third one it's even bigger. It does not matter which I build first, as this is always the case.
I am building these apps with the electron-builder build command, using the --config option to pass a file with configurations.
This is the electron-builder file that I am using (with PROJECT_NAME, PROJECT_APP_ID, and PROJECT_ID changing depending on the project).
"productName": "<PROJECT_NAME>",
"appId": "<PROJECT_APP_ID>",
"directories": {
"output": "release/<PROJECT_ID>"
},
"files": [
"**/*",
"!**/*.ts",
"!*.code-workspace",
"!LICENSE.md",
"!package.json",
"!package-lock.json",
"!src/",
"!e2e/",
"!hooks/",
"!angular.json",
"!_config.yml",
"!karma.conf.js",
"!tsconfig.json",
"!tslint.json"
],
"win": {
"icon": "dist/assets/icons/<PROJECT_ID>"
},
"mac": {
"icon": "dist/assets/icons/<PROJECT_ID>"
},
"linux": {
"icon": "dist/assets/icons/<PROJECT_ID>"
},
}
Am I missing something for electron-builder? I am thinking maybe it keeps a 'cache' or something in a temporary folder and uses that to build on.
I know the question is a bit over the place, but I don't have experience with electron-builder. Any help or suggestion is welcomed.
Some details:
I tried building it from both a windows machine and mac os.
I am using electron-builder v22.9.1
I have tried using different folders for the result, it still didn't work.
[UPDATE] In the script that i use to build these projects, if i delete the directory of the build and then continue with the others, it will work.

exiftool-vendored doesn't return when used in an electron app on Mac?

On Mac, when I run my app from WebStorm, exiftool-vendored works great. However, when I build my app (I use electron-builder) and install it on the same Mac, it never returns, even just trying to get the version:
exiftool.version().then(version => writeBreadcrumb('exif', version))
In other words, no error is raised, and the then is never executed when running an installed version of my app, though it works fine running my app from WebStorm (with cd build && electron .)
What am I doing wrong? Is there an example anywhere of how to use exiftool-vendored in an electron app?
You should take a look at what the docs say about making it work with Electron:
How do you make this work with electron?
Electron is notoriously brittle and buggy, and is not officially supported by this package. Although PhotoStructure uses this package within electron, there's a nontrivial amount of auxiliary support code specific to that project to make it work smoothly.
If you're still anxious to try, here are some things to keep in mind:
Note that this package will spawn exiftool external processes, which means the exiftool-vendored.pl and exiftool-vendored.exe packages should be included in your asarUnpack. SmartUnpack might work, but if it doesn't use a pattern like node_modules/{exiftool-vendored.*}/**/*.
If you're requiring exiftool-vendored from within a webview, you're gonna have a bad time. Many things won't work due to a lack of node compatibility within electron.
__dirname at runtime from within an asar package after webpacking will be invalid, so don't rely on that.
— https://github.com/photostructure/exiftool-vendored.js/wiki/FAQ#how-do-you-make-this-work-with-electron
Since I never found a way to get exiftool-vendored to work with electron on Mac, I accepted the above answer, as essentially a warning to steer clear of exiftool-vendored for electron on Mac.
This answer is included for completeness, for those of us who need exiftool in an electron app for both Mac and Windows:
I used node-exiftool with these settings added in package.json for electron-builder:
"build": {
...
"win": {
...
"extraResources": "exiftoolwin/**/*"
},
"mac": {
...
"extraResources": "exiftool/**/*"
}
}
In the root of my project, I added folders exiftoolwin and exiftool. In exiftoolwin, I put exiftool.exe which I obtained by following the Windows Stand-Alone Executable instructions here, and in my exiftool folder I put exiftool and lib which I obtained by extracting the full perl distribution on Mac, as described on the same page.
Then, in my .jsx (I'm using React):
import exiftool from 'node-exiftool';
const exiftoolFolderAndFile = process.platform === 'win32' ? 'exiftoolwin/exiftool.exe' : 'exiftool/exiftool';
const exiftoolPath = path.resolve(__dirname, '../..', exiftoolFolderAndFile);
const ep = new exiftool.ExiftoolProcess(exiftoolPath);
Then I just use ep as described here.
This is working for us:
add this dependency:
"exiftool-vendored": "^15.2.0",
Update package.json "build" section for mac ( not needed for windows as far as we can see )
"build": {
"mac": {
...
"asarUnpack": [
"node_modules/exiftool-vendored/**" ,
"node_modules/exiftool-vendored.pl/**"
]
}
}

How to restart a dart server which file changes?

I'm running a web server with dart, it starts by:
dart server.dart
When I modified the project files, I hope this server can be restarted automatically. Is there any way to do it? Or is there any useful tool can help?
Not natively in Dart until bug 3310 is implemented. There may well be external tools that will restart the command line when a file changes (open to other answers).
Just ran into this problem developing a dart server. For vscode IDE, following this stackoverflow suggestion I installed the Save and Run Ext extension and modified it for a dart command line program:
{
"saveAndRunExt": {
"commands": [
{
// "match": "\\.(css$|js$|html$)",
"match": ".dart$",
"isShellCommand": false,
"cmd": "workbench.action.debug.restart",
"isAsync": false
},
{
"match": ".dart$",
"isShellCommand": false,
"cmd": "dart.rerunLastTestDebugSession"
}
]
}
}
This will restart the server in debug mode and rerun the last test debug session if any dart file is saved. Both server and test debug sessions work.
Works great for me, at least on initial use of this extension.

Resources