To compile (or set up CI) an Angularjs Fullstack application, below factors you need to take care:
- source code
- install node, ruby, and compass
- install npm packages(labs). if you need to run tests, Dev packages will need to be considered as well.
- install grunt cli, install bower
- bower install
- grunt build (this has so many complex compile such as minimize html, js and css)
- run test (if test is needed)
To build a deployable archive for hosting, then you need to :
- install node
- install npm in the host machine
- appy ENVs
- copy /dist
CI and CD, ideally, we should compile and test with a CI docker image(a base image with above node, bower, ruby, grunt...) then hold the generated "/dist" and use it for CD (so "/dist" should be a volume). Then in CD, we should have another CD docker image(same base image as CI, but with runtime packages only: node) then COPY "/dist" and other operations as i described above. The whole reason of have a CI docker image and same base CD image is to use CI image for compile and generate"/dist" to avoid to use the "/dist" which is generated by your host machine. Your host machine may use different OS and environment settings so it may generate something funny for your CD docker image. This is less likely because we are compiling front end html, js and css. However above settings is still highly recommended.
For development, ideally we should use the same Docker image as developing environment in all developers machine for coding. Nobody should use their host machine to run their code. But i am still struggling with Docker's performance on PCs. Ideally, we should have a docker image run grunt serve and volume to host machine's src folder, the docker node server will automatically detect my code changes and load my new code..... But i never successfully run "grunt serve", i suspect it is due to docker container poor performance.
My docker container doesn't have enough power to compile the code. So i have to use the host machine to compile the code, and use /dist in docker later (and run npm again in docker etc. as i describe above)....
Below list explains in detail:
- You need to run mongo first and use --link to run Node to link with this mongo instance.
- --link will put a group of ENVs into Node docker, but null of them can be used directly by angularjs fullstack framework (very easy to understand, because docker is not made for nodejs, so database link doesn't follow node/mongo's convention ). In short, you have to change developement.js and production.js in server/config/environment, to change mongo url
- Use docker container to run grunt is too heavy to a docker. So some time, run "grunt serve" or "grunt build" failed.(just stop and hang in some stage, never finish)
- So i will
- compile (grunt build) on the host machine
- and build a docker image and copy the "output" (/dist)
- I didn't run grunt on the image/container, so it didn't not run local.env.js to setup ENVs, So i have to setup ENVs myself. In docker, you can have a .env file which will be automatically picked by "docker build".
- However, can i use Node packages from host machine, the answer is NO. Because Node libs have OS specific implementation. We have to run "npm" again to get right libs for you docker image OS.
- Can we use Bower packages? answer is yes. because bower packages are front end js and css which are not OS specific.
- start the container by:
docker run --rm --link mongo:MONGO \
--env-file .env \
-p 8080:8080 --name xxx xxx node dist/server/app.js