From b3e02394ac6030c9cca8fa7f4943cad5ce622b35 Mon Sep 17 00:00:00 2001 From: dswbx Date: Tue, 3 Dec 2024 08:51:30 +0100 Subject: [PATCH] added an initial docker image --- .gitignore | 4 +++- docker/Dockerfile | 28 ++++++++++++++++++++++++++++ docker/README.md | 36 ++++++++++++++++++++++++++++++++++++ 3 files changed, 67 insertions(+), 1 deletion(-) create mode 100644 docker/Dockerfile create mode 100644 docker/README.md diff --git a/.gitignore b/.gitignore index a513830..9727332 100644 --- a/.gitignore +++ b/.gitignore @@ -20,8 +20,10 @@ packages/media/.env **/*/*.db **/*/*.db-shm **/*/*.db-wal +**/*/.tmp .npmrc /.verdaccio .idea .vscode -.git_old \ No newline at end of file +.git_old +docker/tmp \ No newline at end of file diff --git a/docker/Dockerfile b/docker/Dockerfile new file mode 100644 index 0000000..d0df2e9 --- /dev/null +++ b/docker/Dockerfile @@ -0,0 +1,28 @@ +# Stage 1: Build stage +FROM node:20 as builder + +WORKDIR /app + +# Install & copy required cli +RUN npm install --omit=dev bknd +RUN mkdir /output && cp -r node_modules/bknd/dist /output/dist + +# Stage 2: Final minimal image +FROM node:20-alpine + +WORKDIR /app + +# Install pm2 and libsql +RUN npm install -g pm2 +RUN echo '{"type":"module"}' > package.json +RUN npm install @libsql/client + +# Create volume and init args +VOLUME /data +ENV DEFAULT_ARGS "--db-url file:/data/data.db" + +# Copy output from builder +COPY --from=builder /output/dist ./dist + +EXPOSE 1337 +CMD ["pm2-runtime", "dist/cli/index.js run ${ARGS:-${DEFAULT_ARGS}}"] \ No newline at end of file diff --git a/docker/README.md b/docker/README.md new file mode 100644 index 0000000..48e498e --- /dev/null +++ b/docker/README.md @@ -0,0 +1,36 @@ +# Official `bknd` Docker image +The docker image intentially doesn't copy any data into the image for now, so you can copy the +Dockerfile and build the image anywhere. + +## Building the Docker image +To build the Docker image, run the following command: + +```bash +docker build -t bknd . +``` + +## Running the Docker container +To run the Docker container, run the following command: + +```bash +docker run -p 1337:1337 bknd +``` + +You can pass the same CLI arguments (see [Using the CLI](https://docs.bknd.io/cli) guide) to the +docker container as you'd do with +`npx bknd +run`, +like so: + +```bash +docker run -p 1337:1337 -e ARGS="--db-url file:/data/data.db" bknd +``` +Or connect to a remote turso database: +```bash +docker run -p 1337:1337 -e ARGS="--db-url libsql://.turso.io --db-token " bknd +``` + +To mount the data directory to the host, you can use the `-v` flag: +```bash +docker run -p 1337:1337 -v /path/to/data:/data bknd +``` \ No newline at end of file