From 5bdb710ebc72e0ec81ef759a93218f2d5a092c05 Mon Sep 17 00:00:00 2001 From: Cfp Date: Sun, 22 Jun 2025 15:02:36 +0200 Subject: [PATCH] feat: add docker support --- Dockerfile | 36 ++++++++++++++++++++++++++++++++++++ README.md | 20 +++++++++++++++++++- 2 files changed, 55 insertions(+), 1 deletion(-) create mode 100644 Dockerfile diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..8876b10 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,36 @@ +FROM oven/bun:1-alpine AS base +WORKDIR /usr/src/app + +# install dependencies into temp directory +# this will cache them and speed up future builds +FROM base AS install +RUN mkdir -p /temp/dev +COPY package.json bun.lock /temp/dev/ +RUN cd /temp/dev && bun install --frozen-lockfile + +# install with --production (exclude devDependencies) +RUN mkdir -p /temp/prod +COPY package.json bun.lock /temp/prod/ +RUN cd /temp/prod && bun install --frozen-lockfile --production + +# copy node_modules from temp directory +# then copy all (non-ignored) project files into the image +FROM base AS prerelease +COPY --from=install /temp/dev/node_modules node_modules +COPY . . + +# [optional] tests & build +# ENV NODE_ENV=production +# RUN bun test +# RUN bun run build + +# copy production dependencies and source code into final image +FROM base AS release +COPY --from=install /temp/prod/node_modules node_modules +COPY --from=prerelease /usr/src/app/src src/ +COPY --from=prerelease /usr/src/app/package.json . + +# run the app +USER bun +EXPOSE 3000/tcp +ENTRYPOINT [ "bun", "run", "src/main.ts" ] \ No newline at end of file diff --git a/README.md b/README.md index 599c999..e42f4c4 100644 --- a/README.md +++ b/README.md @@ -29,11 +29,29 @@ You can run this yourself to host your own instance, or contribute to the offici ### Setup -Docker is coming soon! +#### Docker + +1. Build the Docker image: + ```bash + docker build -t trafficcue-server . + ``` +2. Run the Docker container with the required environment variables: + ```bash + docker run -d \ + -p 3000:3000 \ + --add-host host.docker.internal:host-gateway \ + -e DATABASE_URL=postgres://user:password@host:port/database \ + ... # other environment variables as needed \ + trafficcue-server + ``` + or use docker compose as usual. + +#### Local 1. Clone this repository 2. Run `bun install` to install dependencies 3. Launch the app at `src/main.ts` with the environment variables set: + - `DATABASE_URL` (PostgreSQL connection string: `postgres://user:password@host:port/database`) - `GOOGLE_GENERATIVE_AI_API_KEY` (optional, to enable MapAI features. Its free at Google!) - `TANKERKOENIG_API_KEY` (optional, to enable fuel price features. Its free!) - `OIDC_ENABLED` (needs to be enabled for most features requiring authentication)