How to install node js on gocd agent? - node.js

While running node js app on gocd build pipeline i am get make sure npm install can be run on this agent.
How to install node js on gocd server to run test.

make sure npm install can be run on this agent. &
How to install node js on gocd server to run test."
Both are completely two different things. You might have to spend little more time on understanding differences in responsibilities of GoCD server and Agent.
On a brief note you do not need to install nodejs on gocd server to run tests. All the tasks are run by "GoCD Agents". So you can go and manually install nodejs on GoCD agent (or) you can use nodejs docker container as agent which will have nodejs by default.

Related

Running Vue JS project in Docker

I have already built a few VueJs applications for myself. Now I am working with a team. One backend and me frontend.
Now I'm wondering how do I include the environment in the repository. Until today I always had node on my local machine. With nvm I could also jump between versions on the local machine. But now I want future colleagues who will develop the app to have the same environment. So work with the same node and npm version. I thought this could be done with a dockerfile or docker-compose.yml. Then I can log into the container and run the npm run build for example.
Question But how does it work with npm run dev? Do I have access with the browser to the port that is assigned in the container of the Vue app?

Package and run nodejs application in an offline server

I'm currently using NextJS and to run a production build, I use npm run build followed by npm run start. This all works well on my local machine.
However, I need to deploy this app on an offline machine where I may not have an internet connection to install all the node packages.
I've taken a look at npm pkg and npm pack utilities, but not quite sure which is the best one to use in the context of a nextjs app.
Would appreciate any advice on the best way to do this.
Edit: thinking along the lines of how I would build my maven project and have a .jar output which I can use to deploy to any other machine as a single deployable file.

Use npm install to deploy a node application?

Say I have a node.js application (some web server for the manner of sake). So I have a directory structure with a src which contains my code and a package.json which includes some metadata about my project and all the packages needed to run it. So I run npm install to get all the packages and run node server.js to run the application.
I have a CI pipeline for my application that upon PR to master runs tests, and if succeeds, merges to master. The next step I want is to deploy the application on a server.
This means that eventually I need my source code plus all the dependencies on the server, and run node server.js.
Is it correct to publish my application as a package (as part of the CI pipeline), and then on the server run npm install to fetch it? Or is npm installing packages only makes sense for packages that serve as some functionality for other applications?
The reason I doubt this is that when you run npm install (at least on a directory with a package.json) you get all the packages in the node_modules directory, which makes me believe that the second option I stated is true.
NOTE
The application is running on a Windows server, no Dockers.

Is it mandatory for each deployment to production for remove node modules and run npm install?

I use vuetify (vue)
Is it mandatory for each deployment to production for remove node modules and run npm install? Or just run npm run build?
I have two option :
Option 1 : Every deployment, I run the npm run build directly
Option 2 :
Delete the contents of dist folder
Delete node_modules folder
npm install
npm run build
Which is the best option?
npm install
This command installs a package, and any packages that it depends on. If the package has a package-lock or shrinkwrap file, the installation of dependencies will be driven by that, with an npm-shrinkwrap.json taking precedence if both files exist. See package-lock.json and npm-shrinkwrap.
If you did not install or update the package before releasing the project, you do not need to execute npm install, otherwise, you need to execute it to ensure that dependent packages on the production environment is consistent with your local dependent package version.
If you are using an automatic build deployment tool like jenkins, for convenience you can execute the install command before each build. It's okay.
Imagine more environments, not just a production:
development
testing1
staging
uat
production
Can we upload the npm run build result (compressed js) or node_modules to our git repository? ANSWER IS NOT!!. So if you need to have a version of your app running in any of these environments, you must to execute npm run build. And this command needs the classic npm run install. I think this last sentence, answer your question.
(ADVICE) Docker to the rescue
assumption 1 your client-side app (vue) is not complex(no login, no session, no logout, etc ), you could publish it using a basic nginx, apache, basic-nodejs.
assumption 2 you are able to have one more server for docker private repository. Also if you are in google, amazon o azure, this service is ready to use, of course a payment is required
In one line, with docker you must execute just one time npm install and npm run build. Complete flow is:
developer push some changes to the git repository
manually or automatically a docker build in launched.
inside Dockerfile, npm install and npm run build is executed. Also a minimal server with nodejs (example) is configured pointing to your builded assets
your new docker image is uploaded to your docker private repository
that's all
If your quality assurance team needs to perform some tests to your new app, just a docker image download is required. If everything is ok, you pass to the next stage (staging or uat) or production. Steps will be the same: just download the docker image.
Optimizations
Use docker stages to split build and start steps
If your app does not have complex flows(no login, no session, no logout, etc ), replace node basic server with a simple nginx
I need login and logout
In this case, nginx or apache does not helps you because they are a simple static servers.
You could use a minimal nodejs code like this:
https://github.com/jrichardsz/nodejs-static-pages/blob/master/server.js
Adding /login , /logout, etc
Or use my server:
https://github.com/utec/geofrontend-server
which has a /login, /logout and other cool features for example: How are you planning to pass your backend api urls to your vue app in any of your environments?.

Jenkins and NodeJS

So I have a MEAN application up and running and Im looking into a continuous integration solution. I have successfully gotten Jenkins up and running with web hooks that grab my project from a bitbucket repo when a merge happens to master.
Right now I do not have any tests so Jenkins just runs some shell commands that 'deploys' the server. Which is great. My goal would be to have this run tests and fail a deploy if they fail.
So my problem is that the build never completes. My goal would be to when it completes it will keep the server running or deploy it and keep it running.
Here are the shell commands I run one the build is kicked off.
npm install
npm install bower
bower install
npm install grunt-cli
grunt prod
node server
And it successfully runs the server and such but it just hangs up after the node server command is executed
How do I make it so Jenkins sees this as successful and then deploys it? I have crawled the internet with no much luck.
EDIT:
So looking at some docs and such. I would need to configure my tests to run when the build gets ran. If there are not tests then it passes (by default)... So what I need is when that happens, jenkins needs to run a deploy script. After looking around in jenkins I am still unable to figure out how to do so.
EDIT #2
So moving those shell script out of the build allows it to finish and is 'successful' since no tests are present. I see that jenkins keeps the project in a workspace directory. Is there a way to get jenkins to deploy from there or some kind of other application to deploy that build in that workspace?
Thanks
So what I ended up doing was something simple but im not sure if its best practice..
Jenkins has the webhook to my bitbucket repo and watches for pulls into master. This then kicks off my jenkins build which it runs
npm install bower
bower install
npm install grunt-cli
grunt prod
which builds the project. Then I installed nodemon which watches the last "successful build" folder run the server from there. When it gets refreshed the server restarts. This seems to run pretty smoothly so far.

Resources