Valist
Search…
Setup: Nodejs / MongoDB
This demonstrates how one can configure a service running a Nodejs webserver and connects to MongoDB.
It also demonstrates how to copy data to a database with two steps. The first step's result is cached so that it does not need to run the next time this is started.

valist.yml

1
services:
2
app:
3
path: app
4
public: true
5
port: 8080
6
cmd: node /app.js
7
depends_on:
8
- mongo
9
environment:
10
- MONGODB_URL=mongodb://mongo:27017/test
11
mongo:
12
image: mongo:4.0
13
steps:
14
- name: mongodump
15
path: mongodump
16
out: /dump
17
cache: true
18
- name: load
19
service: mongo
20
copy:
21
- mongodump:/
22
cmd: mongorestore /dump
23
Copied!
From this configuration, we can see the following:
    In this configuration, we have two services, "app" and "mongo". We also have two steps used to setup the staging environment.
    About the service "app":
      It will run a web server listening on port 8080.
      The code is defined in the directory "app" where there is also a Dockerfile. The name of the Dockerfile is just "Dockerfile" so there is no need to specify the path to the file.
      The option public is set to true so that it is possible to reach this server from the web.
      It is also dependent on the service "mongo" and will not start before that service is started.
      The service "app" has an environment variable called MONGODB_URL which is used to connect to the mongo service. The host "mongo" in the URL is used to connect to the mongo service. Services can connect to each other using their name as the host.
    About the service "mongo"
      It is using an existing image so it does not need to be built.
    About the step "mongodump"
      It is not refering to a service or image. Instead, its code is defined under the specified path ./mongodump where there is also a Dockerfile with the name "Dockerfile".
      When running the default command specified in the Dockerfile, it will output files in a directory at path /dump.
      The output will be cached so that this step does not need to run every time this staging environment is created.
    About the step "load"
      It is running a command on the service "mongo". Because of this, it is implicitly dependent on that service to run and we don't need to specify this using "depends_on". It will therefore run after the service "mongo" is started.
      It will copy the output from the step "mongodump" and place them in its root directory.
      After the files are copied, it will run the specified command to populate the MongoDB database.
Last modified 1yr ago
Copy link
Contents
valist.yml