I've deployed an app (node js backned and react on frontend) via a bitbucket pipeline to Azure. It executes without any errors.
pipelines:
branches:
master:
- step:
name: Install, build, test & deploy
caches:
- node
script: # Modify the commands below to build your repository.
- apt-get update || true && apt-get install zip
- cd backend && npm ci && npm run build && cd ../frontend && npm ci && npm run build && cd ../
- mv frontend/build backend/dist/
- cd backend && zip -r build-$BITBUCKET_BUILD_NUMBER.zip *
- curl -v -X POST -u $DEPLOY_USER:$DEPLOY_PASSWORD https://$DEPLOY_URL.scm.azurewebsites.net/api/zipdeploy -T "build-$BITBUCKET_BUILD_NUMBER.zip"
my package json
"scripts": {
"build": "npm run build:app",
"build:app": "tsc",
"dev": "NODE_ENV=development tsnd --respawn --transpileOnly ./index.ts",
"lint": "tslint -c tslint.json './**/*.ts'",
"lint:fix": "tslint -c tslint.json './**/*.ts' --fix",
"start": "NODE_ENV=production node dist/server.js",
"start:staging": "NODE_ENV=staging ts-node ./index.ts",
"test": "echo \"Error: no test specified\" && exit 1"
},
The site gives a 403 with "You do not have permission to view this directory or page."
I've downloaded the logs (diagnostic dump) from https://xxx.scm.azurewebsites.net/ but I don't find any errors.
Im running this on windows in Azure and Mac locally. Probably something wrong there. Can I somehow see the output from when then node app starts? Or how can I debug this?
Starting the web app:
403 generally shows up in Appservice when ever the application has not started. To fix this, in your app service click on Advanced Tools under Development Tools
This opens up a window with an option on top of the header - Bash. Click on that.
By default it will be in home directory. Now, using cd navigate to site -> wwwroot
here, you should be able to see all your files if properly deployed. Now issue the command npm start (or any custom command)
Monitoring Logs:
In your webapp under monitoring, you have Log Stream just click on that and you should be able to see the live logs.
You can give a restart on web app once these changes are done.
Lastly, under configuration check if you have provided a start up command for the app service in General Settings. If its node, hope you have given process.env.PORT to get the available port. Hope this helps!
Related
I am using Dockerfile for Nodejs project but its returning Connection refused error
When I run the app without Docker it works absolutely fine.
Command I use to build and run the docker container is as follows:
docker build -t myapp .
docker run -it -p 8080:8080 myapp
Running above command runs without any error but when I hit http://localhost:8080/test-url it fails
My dockerfile is as follows:
FROM node:16.16.0-alpine
ADD . /opt
COPY . .
RUN npm install
EXPOSE 8080
RUN chmod +x /opt/deploy.sh
RUN apk update && apk add bash
CMD ["/bin/bash", "/opt/deploy.sh"]
And my package.json is as follows (truncated to show only script):
"scripts": {
"start": "DEBUG=app* node index.js",
"build": "rimraf build && babel-node ./src --out-dir build/src && npm run docs",
"dev": "DEBUG=app* nodemon --exec babel-node index.js",
"lint": "eslint 'index.js' 'src/**/*.js' 'src/index.js'",
"docs": "apidoc -i src/ -o public/docs",
"prepare": "husky install",
"lint-staged": "lint-staged"
},
For development I use following command which works fine::
npm run dev
For deploymeent I run deploy.sh which has env variables and final command as ::
npm run build
npm run start
Even when I am trying http://localhost:8080/test-url by loging into docker interactive terminal it returns same error - Connection Refused
Your Port mapping looks right to me. Did you check your firewall? Maybe it is blocking the connection. It could also be helpful to test, if you can run an NGINX-Container on Port 8080. That way you can check if it is a general configuration-problem with Docker or a specific problem of your Image.
Also, did you try to set your node server to listen to 0.0.0.0 instead of localhost? I'm not sure how Docker handles IPs in the Containers, but I was thinking maybe it is called by it's internal ip. If that is the case and your server listens to localhost only, it shouldn't accept the connection.
I hope one of these things can point you in the right direction.
I'm having that problem where I'm trying to deploy Express and React boilerplate app like one app on Azure App Services. Locally everything works normaly, but when I try to deploy the whole thing, I see ":( Application Error " screen. I think it has to do something with the way my "scripts" inside server's package.json are set...(deploying only express server without client files works just fine). Here I'm trying to let Azure execute the build command once the app is deployed and not before that:
"scripts": {
"start": "cd client && npm run build && cd ../ && node server",
"test": "echo something"
},
Probably I'm missing something crucial for Azure (I'm a beginner).I've read a lot and followed many tutorials but nothing seems to solve my problem. I'll really appreciate it if someone can give me a hand. Thank you!
Link to my github repo : https://github.com/Ivailo663/finalExpressApp
"scripts": { "start": "cd client && npm run build && cd ../ && node server", "test": "echo something" }
This script will work if you already have all the modules your app needed, but if you don't have the modules, you need to install them first.
However, it is recommended that you build the client locally or use pipline to deploy the build folder to azure.
We are working on nodeJs/ExpressJs we have configured multiple .env files for development and production and pointing it to package.json for different execution process, we have naming conversation issues at scripts.
Whenever we run npm run prod it takes to preprod configuration. what could be the issues?
Update: we have figured that the suffix of the script key is the same in the next script, after update/rename preprod to preProd the both runs fine. but why?
Eg :
"scripts": {
"dev": "clear; env-cmd -f ./config/hostedDev.env nodemon --exec babel-node index.js",
"prod": "clear; env-cmd -f ./config/prod.env nodemon --exec babel-node index.js",
"preprod": "clear; env-cmd -f ./config/preprod.env nodemon --exec babel-node index.js"
},
Apparently the issue is with the word 'pre'.
If you would have noticed it runs both preprod and prod commands (pre running first).
If you change the script name to 'postprod' the postprod script will run later.
So, I guess npm uses 'pre' as to run before the 'prod' script and then running 'prod' script itself.
I'm running for the first time my Next.js app with a custom server.js on Elastic BeanStalk with 64bit Amazon Linux/4.11.0.
After the creation on the application, the environment and the deploy with the eb-cli I received a warning into the EB dashboard Environment health has transitioned from Degraded to Severe.
I changed the Node command into the config to npm run deploy. Nothing changed.
Here's my package.json.
"scripts": {
"start": "pm2 start server.js -i max",
"build": "next build",
"dev": "nodemon --exec babel-node server.js",
"start-next": "next start",
"deploy": "NODE_ENV=production next build && pm2 start server.js -i max",
"test": "echo \"Error: no test specified\" && exit 1"
},
I connected to the eb instance with eb ssh and after I've located the project dir I tried to execute npm run build but an error happened.
> NODE_ENV=production next build && pm2 start server.js -i max
> Build error occurred
Error: > Build directory is not writeable. https://err.sh/zeit/next.js/build-dir-not-writeable
at build (/var/app/current/node_modules/next/dist/build/index.js:1:6361)
at <anonymous>
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! webreader-client#1.0.0 deploy: `NODE_ENV=production next build && pm2 start server.js -i max`
npm ERR! Exit status 1
I've created a .next directory with sudo but the error is still raised.
Docs:
https://github.com/zeit/next.js/blob/master/errors/build-dir-not-writeable.md
After spending nearly 4 hours on the phone with AWS support, their solution was as follows:
create a folder/file in the root of your project: .ebextensions/00_dir_permission.config
commands:
01_set_file_permissions:
command: "chmod 777 -R /tmp"
Of course this is less than ideal, but for some reason right now in EB permissions have changed such that you are not able to kick off the build without tweaking on permissions like this. Hoping this changes soon.
I was getting this same error locally and after about an hour of troubleshooting, I realized I had my node version set wrong. Seems like next 9.4 doesn't support version 9 of node. I updated to version 12 and it's working without issue.
I trying to deploy a website which works flawlessly on my local Budo server. I'm trying to deploy it to Google App Engine, but I don't have enough knowledge about node.js and package.json to specify the configurations to run my website on App Engine.
My app has the following scripts running in my package.json file:
"scripts": {
"start": "budo main.js:dist/bundle.js --live --host localhost",
"watch": "watchify main.js -v --debug -o dist/bundle.js",
"prep": "yarn && mkdirp dist",
"build": "browserify main.js -o dist/bundle.js",
"lint": "eslint main.js --fix",
"deploy": "yarn build && uglifyjs dist/bundle.js -c -m -o dist/bundle.min.js"
},
I know the simple commands to deploy the server and the surrounding configurations of the Google Cloud Platform, but I don't know how to change my dependencies to work on the App Engine.
When I deploy the current setup I simply get 503 connection error.
So how do I port this to a setup that will work in production?