Better Software Development in Team with JavaScript Part 4 (Final)
Last part for a better software development and deployment with JavaScript, I am using philosophy in The Twelve-Factor App. Since I had done the first 9 rules, I will talk about the last 3 rules of 12 factors.
All Parts
Rule #10: Dev/prod parity
Keep development, staging, and production as similar as possible
With docker, this can be achieve by using similar docker-compose.yml
.
In the past, when I was using Ruby on Rails for my project, development and testing was okay, but when comes to deployment, it is a pain to do that.
sample docker-compose.yml
file
version: '3'
services:
app:
build: .
image: testapp
env_file:
.env
Make use of .env
to segregate between development and production, where .env
can store our backend link.
In our node.js, we can simply get the value with process.env.BLABLABLA
with dotenv
packages.
Rule #11: Logs
Treat logs as event streams
Add log record into Dockerfile
In Dockerfile
:
FROM mhartl/alpine-node
COPY index.js
RUN ln -sf /dev/stdout /debug.log
CMD node index.js
this will pipe out debug.log
into /dev/stdout
standard output.
To test out
docker build -t logtest .
docker run -d --name=logtest logtest
docker log -f logtest
docker exec -it logtest cat /debug.log
Rule #12: Admin processes
Run admin/management tasks as one-off processes
Run as one off process with Docker.
Run a ubuntu with bash (--rm flag will remove on exit)
docker run -it --rm ubuntu bash
About Me
I am Lai Weng Han (Johnson), you can find me on Twitter.