Skip to content

Tips for Developing in Docker

Colin Payne-Rogers edited this page Nov 17, 2020 · 7 revisions

This page will help developers work with their local docker environment.

Setup

Refer to the docker README.md for a detailed setup explanation. This page assumes you have both cveawg and mongo containers running locally.

Populating MongoDB in Docker

Populating the mongo docker container can be done from a shell inside the cveawg container, the same way a local environment can be populated, once prerequisites are met.

Copy Static Fixtures into the Container

The current docker setup does not copy or mount static fixtures from cve-services/datadump/pre-population/. A hot fix to copy this data in cve-services/docker/Dockerfile.dev will be implemented after the initial production rollout. Until then, the following command will copy that data into the cveawg container:

docker cp datadump/ cveawg:/app/datadump`

Run the Population Script inside the Container

The /app folder inside the cveawg container is a subset of the cve-services repository. A shell inside the container has access to the application's Node environment. The following command, from outside the container, will run the container's dev population script:

docker exec -it cveawg npm run populate:dev

One can also open a shell inside the container, then run the script:

docker exec -it cveawg /bin/sh
npm run populate:dev

Running Mocha Tests in Docker

Once one understands the process for populating the mongo container, any additional task that is familiar in a local environment becomes a pattern on the same theme to run that task in Docker. For example, the following will run tests in the running docker environment:

docker exec -it cveawg npm run test

Aliases to Streamline Development

Noting the pattern for developing in docker, here is a set of aliases that one could add to their ~/.bashrc to streamline their local development process:

alias cveawg='docker exec -it cveawg'
alias cveawgdb='docker exec -it mongo'
alias cveawg-sh='cveawg /bin/sh'
alias cveawg-mongo='cveawgdb mongo'
alias cveawg-populate='cveawg npm run populate:dev'
alias cveawg-test='cveawg npm run test'

Clone this wiki locally