I'm trying to "dockerize" our development environment. We have a gulp build system that watches changes to our js/sass/jade files. This is all setup to work just fine outside of docker.
I've created a docker container and I mount my code base into it (using a volume). All the precursor npm installs and bower installs finish successfully. My last step runs gulp and it runs properly and builds but then does not pick up any subsequent changes to any of our js/sass/jade files.
I'm running the build system with the following command:
docker run -it -v $(pwd):/code/ client gulp reset
Does anyone have a similar setup in their development environment? What did you do to get your gulp watch to work and display the building?
EDIT: I guess I could do the gulp build/watch outside of docker and only mount the generated files but I'd rather contain that all inside of docker so that the host machine doesn't need to worry about any dependencies to build/run our app
EDIT2: Here are my dockerfile and docker-compose.yml
#Dockerfile
FROM node:0.12.5
RUN mkdir /code
WORKDIR /code
RUN mkdir client
WORKDIR client
RUN mkdir .tmp
ADD ./client/package.json /code/client/package.json
ADD ./client/bower.json /code/client/bower.json
RUN npm install gulp -g
RUN npm install bower -g
RUN npm install
RUN npm rebuild node-sass
RUN bower --allow-root install
CMD gulp reset
and
client:
build: .
volumes:
- .:/code
I've never been able to get any inotify-based file watcher to ever work over with virtual-box guest additions, and based on this ticket it's unlikely to be available anytime soon. My preferred approach is the following:
Assuming my local source code is in /code
Run my watcher locally on /code
When a change is detected, rsync local /code to remote /code (mounted as a container-only volume) in the container
Example rsync:
docker run --rm --volumes-from sourcecode my/image \
rsync \
--delete \
--recursive \
--safe-links \
--exclude .git --exclude node_modules \
/local/repo/ /container/repo
This avoids lots of issues and allows you to get granular with what you want your container environment to see.
Related
I've always used just npm and never yarn/webpack explicitly. I need to run the code from this repo:
https://github.com/looker-open-source/custom_visualizations_v2
Like a dev server or something to ensure it's serving the files properly but I don't see a "run" like npm run start. Does this just not exist with yarn? It feels like this code should work as is and I shouldn't have to add anything.
EDIT: I've now tried yarn run watch but it just seems to build the code again and not actually host anywhere
npm run somecommand just looks up in the "scripts" field of package.json for the key
somecommand and executes the value in the terminal.
So npm run start basically runs the start script from package.json
The same thing is done using yarn via simply yarn start
In the linked repo, there isn't a start script in the package.json, rather a watch script, so you should be able to run it with the below steps:
yarn to install dependencies after cloning the repo to local (similar to npm install)
yarn watch to start the webpack server (analogous to npm run watch)
Edit:
Turns out the watch command is just setting up webpack to watch for changes and recompile the project every time there is a change.
To run a development server, you will need to add another script preferably with name start and use webpack-dev-server
So the package.json has entries like:
...
"watch": "webpack --config webpack.config.js --watch --progress",
"start": "webpack-dev-server --config webpack.config.js",
...
Then running yarn start should open a dev server at localhost:8080
I have a NodeJS application which has only typescript files in it, no js files. I want to run in on my server in the background.
How can I archive that?
I tried using the npm package called forever but it only works with js files as it doesn't understand the typescript code.
You could use forever in combination with ts-node.
Here is a link to the npm package ts-node
I would suggest using the following command:
forever start -v -c ts-node app.ts
Where -v/--verbose is for turning on the verbose messages from Forever.
And -c is the COMMAND to execute which is default is node
This question is so old and forever now discourages to use it.
For new installations we encourage you to use pm2 or nodemon
Here is a quick tutorial on how to run your Typescript project as a background process.
Install PM2 globally:
npm install pm2 -g
Build your sources with Typescript default config:
tsc
You will have a new directory dist that contains your js files.
pm2 start dist/app.js
Bonus: you can monitor your app with the following command.
pm2 monit
first use
npm install -g ts-node
then use
forever start -v -c ts-node app.ts
it shuld start now
The two production quality recommendations I would make are:
Turn it into a docker container
Write a systemd service
Those are by far the best options. If for some reason this doesn't work:
pm2
supervisord
I am trying to install the http-server, bower, grunt in my windows machine. I tried to install using npm install the install is successful but when, i try to run the command it is saying command not found. I tried closing the command prompt and execute again. Same result. The file are available in appdata folders.
C:\Users\testuser>npm install http-server
+ http-server#0.11.1
updated 1 package in 5.713s
C:\Users\testuser>http-server
'http-server' is not recognized as an internal or external command,
operable program or batch file.
I tried listing the services and the service is installed
C:\Users\testuser>npm list -g --depth=0
C:\Users\testuser\AppData\Roaming\npm
+-- bower#1.8.4
+-- http-server#0.11.1
`-- json-server#0.12.1
I tried searching for similar issues, but could not find the same.
npm install http-server -g
This will install http-server globally so that it may be run from the command line.
I'm going to run react-boilerplate application forever in the server.
I found forever and I'm not sure how I pass parameters to forever. The command to run server is like following:
PORT=80 npm run start:production
Seems like forever start PORT=80 npm run start:production doesn't help me.
One thing is that PORT=80 part is setting the env variable, this kind of command should be in front of other commands. The other thing is that to run npm scripts with forever, you need to use different syntax, so PORT=80 forever start -c "npm run start:production" /path/to/app/dir/.
If you're running forever form the project folder, the path should be ./
Or you can run a react application with pm2 or with nohup
1) install pm2 globally
npm install pm2 -g
2) navigate to the project folder and execute, space is required after --
pm2 start npm -- start
3) to see running instances
pm2 ps
4) to see the other options
pm2 --help
To run with nohup
1) navigate to the project folder
nohup bash -c 'npm start' &
pm2 is superb production process manager for Node. In addition to starting and daemonizing any application, it has a built in load balancer.
Install pm2:
npm install pm2 -g
To add start and add deamon to your app, navigate to the app folder and:
pm2 start app.js
To make pm2 autoboot on server restart:
$ pm2 startup
Then copy and paste the code generated.
For this you will need:
Install forever usingnpm install -g forever
Run the forever command PORT=<YOUR PORT> forever start -c "<command>" ./
Your command can be for example npm start and npm run dev.
Use ./ only if you are in the project folder.
Port means your port number, usually 80 or 443.
I have the following dockerfile
FROM maven:3.3.3-jdk-8
#install node
RUN apt-get update
RUN apt-get -qq update
RUN apt-get install -y nodejs npm
# TODO could uninstall some build dependencies
RUN update-alternatives --install /usr/bin/node node /usr/bin/nodejs 10
# Install packages for envsubst
RUN apt-get update && apt-get upgrade -y --force-yes && rm -rf /var/lib/apt/lists/*;
RUN apt-get update
RUN apt-get install -y gettext-base
# Create app directory
RUN mkdir -p /usr/src/app
WORKDIR /usr/src/app
# cache package.json and node_modules to speed up builds
ADD src src
ADD package.json package.json
ADD node_modules node_modules
ADD pom.xml pom.xml
ADD Gruntfile.js Gruntfile.js
Add gulpfile.js gulpfile.js
ADD settings.xml settings.xml
# Substitute dependencies from environment variables
COPY entrypoint.sh /entrypoint.sh
RUN chmod +x /entrypoint.sh
ENTRYPOINT ["/entrypoint.sh"]
EXPOSE 8000
Here is the entrypoint script
#!/bin/sh
envsubst < "/usr/src/app/src/js/envapp.js" > "/usr/src/app/src/js/app.js"
mvn clean install -DskipTests -s settings.xml
npm start
Note that the line envsubst < "/usr/src/app/src/js/envapp.js" > "/usr/src/app/src/js/app.js" reads the environment and updates the app.js file
I have confirmed that the file is updated by sshing into the container and opening the file
However when I open the app in the browser it appears that it is still reading the old value of the app.js file.
After a lot of debugging I feel that haveing the npm start command still reads an old layer in the docker file. Is there a way that the new changes are picked up in the `npm start line?
I also tried having npm start as an argument to ENTRYPOINT but still have the same effect. Any ideas on what might be wrong?
I also tried forking the image so I copy the files in one image and use this as a base image for the image that does the environment manipultion
But still have the same problem
Here is how I run the docker container
docker run -e "ENVVARIABLE=VALUE" -i <image-name>