Skip to content

Commit

Permalink
Merge pull request #3024 from LiteFarmOrg/LF-3915-clean-up-docker-com…
Browse files Browse the repository at this point in the history
…pose-up-for-new-contributors

LF-3915 Clean up 'docker compose up' for new contributors
  • Loading branch information
SayakaOno authored Dec 20, 2023
2 parents 338a436 + d15f739 commit 41a29dc
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 19 deletions.
30 changes: 14 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,8 @@ Make sure that your `.env` variables are configured as outlined in the `.env.def

Also see the section below [on using Docker](#docker).

Note: the export server is not usually needed, and so is not started with the other development dependencies. To start it, make sure the the webapp and API are already running, and use the command `docker compose up export`.

<details>
<summary>Instructions for running image, document, and certification services natively</summary>

Expand Down Expand Up @@ -212,13 +214,15 @@ If you are unable to use Docker, please contact a core team member to get instru

To run [ESLint](https://eslint.org/) checks execute `npm run lint`

The [chai.js](https://www.chaijs.com/) and [jest](https://jestjs.io/) libraries automate tests that run real database operations using [JWT](https://jwt.io/introduction). The tests use a dedicated database named `test_farm`, distinct from the `pg-litefarm` database that the app normally uses .
The [chai.js](https://www.chaijs.com/) and [jest](https://jestjs.io/) libraries automate tests that run real database operations using a dedicated database named `test_farm`, distinct from the `pg-litefarm` database that the app normally uses.

You'll want to confirm that you have an empty `test_farm` database (otherwise use your preferred database client to create one) before continuing with the following:

1. In a terminal, navigate to the `packages/api` folder.
2. Execute `npm run migrate:testing:db` to set up the test database.
3. Execute `npm test` to launch the tests. Or, to generate test coverage information, run `npm test -- --coverage .` and then see the `coverage/index.html` file.

While the tests do attempt to clean up after themselves, it's a good idea to periodically use `psql` to `DROP` and `CREATE` the `test_farm` database, followed by the migrations from step 2 above.
While the tests do attempt to clean up after themselves, it's a good idea to periodically use `psql` or your database client to `DROP` and `CREATE` the `test_farm` database, followed by the migrations from step 2 above.

## webapp

Expand Down Expand Up @@ -278,33 +282,27 @@ Use cases in which we currently utilize docker at LiteFarm include:
## Set up

- Go to https://docs.docker.com/get-docker/ and install docker in your local system.
- After installation, the docker CLI will be available where you can run the docker commands.
- create a `.env` file at the root directory of the project i.e. LiteFarm
- Add key-value pairs in the `.env` by referring to the `docker-compose.[ENV].yml` that contains the docker env keys.

## Troubleshooting

1. On Windows: During `npm run nodemon` of `/packages/api` there is an error - possibly with the client variable of knex.

The NODE_ENV variable is not being set properly you will need to adjust the nodemon script in `/packages/api/package.json`.

We hope to improve our `package.json` scripts in the near future.
- After installation, you can run Docker commands using the Docker CLI.
- To build the beta/prod Docker containers (generally used when troubleshooting the build process), you will also need to:
- create a `.env` file at the root directory of the project i.e. LiteFarm
- add key-value pairs in the `.env` by referring to the `docker-compose.[ENV].yml` that contains the docker env keys

## Commands

These commands can be run from the root of the repo.

- `docker compose up` to run all the local development services, OR
- `docker compose up` to start the main development services
- `docker compose up export` to start the process that handles certification document export
- `docker compose up [service names]` to run one or more particular services
- `docker compose down` to stop and remove all containers defined in `docker-compose.yml`
- `docker compose down --volumes` to stop and remove all containers and volumes defined in `docker-compose.yml`
- `docker-compose -f docker-compose.[ENV].yml up --build -d` to build the docker containers in the detach mode.
- `docker-compose -f docker-compose.[ENV].yml up --build` to build the beta/prod docker containers
- `docker ps` to see the list of docker containers in the running state.
- `docker logs --details [containers name]` to view the logs inside the container.

Notes:

- [service names] are db, minio, redis, export_server, and imaginary
- [service names] are db, minio, redis, export, and imaginary
- [container_name] are litefarm-db, litefarm-api and litefarm-web.
- [ENV] are beta and prod

Expand Down
14 changes: 11 additions & 3 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,12 @@ services:
entrypoint: >
/bin/sh -c "
/usr/bin/mc alias set myminio http://minio:9000 myminioadmin myminioadmin;
/usr/bin/mc mb myminio/minio-dev;
/usr/bin/mc anonymous set public myminio/minio-dev;"
if ! /usr/bin/mc ls myminio/minio-dev 2>/dev/null; then
/usr/bin/mc mb myminio/minio-dev;
/usr/bin/mc anonymous set public myminio/minio-dev;
else
echo 'Successfully confirmed the 'minio-dev' bucket is in place';
fi"
redis:
image: redis:7.0-alpine
Expand All @@ -49,8 +53,10 @@ services:
- redis-data:/data
ports:
- 6380:6379
profiles:
- export

export_server:
export:
image: litefarm/node-awscli:0.0.2
restart: unless-stopped
volumes:
Expand All @@ -75,6 +81,8 @@ services:
- 9229:9229 # for debugging
extra_hosts:
- "host.docker.internal:host-gateway"
profiles:
- export

imaginary:
image: h2non/imaginary:1.2.4
Expand Down
3 changes: 3 additions & 0 deletions packages/api/dev.export.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,7 @@ cp ../webapp/public/locales/es/crop.json src/jobs/locales/es
cp ../webapp/public/locales/pt/crop.json src/jobs/locales/pt
cp ../webapp/public/locales/fr/crop.json src/jobs/locales/fr

# Give nodemon time to restart the API
sleep 10

npx nodemon --inspect=0.0.0.0:9229 src/jobs/index.js

0 comments on commit 41a29dc

Please sign in to comment.