Skip to content

Commit

Permalink
Fix docker compose, edit documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
Siegrift committed Sep 24, 2023
1 parent 349eaca commit 2ad4b6f
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 7 deletions.
13 changes: 9 additions & 4 deletions packages/api/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,19 @@ pnpm run dev

## Docker

The API is also dockerized. In order to run the API from a docker, run:
The API is also dockerized. Docker needs to publish the port of the server (running inside the docker) to the port on
the host machine. By default, it expects the server is running on port `8090` and publishes it to the `8090` on the
host. To change this, you need to modify both `signed-api.json` configuration and use `PORT` environment variable with
the same value.

In order to run the API from a docker, run:

```bash
# starts the API on port 4000
# Starts the API on port 8090
pnpm run docker:start
# or in a detached mode
# Or in a detached mode
pnpm run docker:detach:start
# optionally specify port
# Optionally specify port (also make sure the same port is specified inside `signed-api.json`)
PORT=5123 pnpm run docker:start
```

Expand Down
15 changes: 13 additions & 2 deletions packages/api/docker/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,18 @@ services:
context: ../../../
dockerfile: ./packages/api/docker/Dockerfile
ports:
- '${PORT:-4000}:${PORT:-4000}'
- '${PORT-8090}:${PORT:-8090}'
environment:
- NODE_ENV=production
- PORT=${PORT:-4000}
volumes:
# Mount the config file path to the container /dist/config folder where the API expects it to be.
#
# Environment variables specified in the docker-compose.yml file are applied to all operations that affect the
# service defined in the compose file, including the build process ("docker compose build"). Docker Compose will
# expect that variable to be defined in the environment where it's being run, and it will throw an error if it is
# not. For this reason we provide a default value.
#
# Docker Compose doesn't allow setting default values based on the current shell's environment, so we can't access
# current working directory and default to "$(pwd)/config". For this reason we default to the config folder
# relative to the docker-compose.yml file.
- ${CONFIG_PATH:-../config}:/usr/src/app/packages/api/dist/config
1 change: 0 additions & 1 deletion packages/api/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,5 @@ export const generateErrorResponse = (
return { statusCode, headers: COMMON_HEADERS, body: JSON.stringify({ message, detail, extra }) };
};

// TODO: Ensure this works in a docker (need to mount the config folder).
export const getConfig = () =>
configSchema.parse(JSON.parse(readFileSync(join(__dirname, '../config/signed-api.json'), 'utf8')));

0 comments on commit 2ad4b6f

Please sign in to comment.