From 4b4b06c24001eb0bdcd5472b5d9a850c9f274e3f Mon Sep 17 00:00:00 2001 From: savareyhano Date: Fri, 6 Dec 2024 22:37:09 +0700 Subject: [PATCH 1/2] feat: dockerize app --- .dockerignore | 3 +++ Dockerfile | 30 ++++++++++++++++++++++++++++++ README.md | 10 ++++++++++ docker-compose.yml | 12 ++++++++++++ 4 files changed, 55 insertions(+) create mode 100644 .dockerignore create mode 100644 Dockerfile create mode 100644 docker-compose.yml diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..9823b66 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,3 @@ +.git +.env +**/node_modules/ diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..3d632ee --- /dev/null +++ b/Dockerfile @@ -0,0 +1,30 @@ +FROM node:23-alpine AS base + +RUN apk add --no-cache sqlite + +WORKDIR /app + +RUN mkdir -p /app/db +RUN sqlite3 /app/db/database.db "VACUUM;" + +COPY ./yarn.lock ./package.json ./ + +RUN yarn install + +COPY ./prisma ./prisma/ + +ENV DATABASE_URL=file:/app/db/database.db + +RUN npx prisma migrate dev --name init + +COPY ./ ./ + +FROM node:23-alpine + +WORKDIR /app + +COPY --from=base ./app ./ + +ENV DATABASE_URL=file:/app/db/database.db + +CMD ["yarn", "dev"] diff --git a/README.md b/README.md index 03bb38d..e6a175c 100644 --- a/README.md +++ b/README.md @@ -55,6 +55,16 @@ npx prisma migrate dev --name init yarn dev ``` +Atau pake docker + +```bash +# jalankan +docker compose up -d + +# untuk mematikan +docker compose down +``` + buka API Documentation [http://localhost:3000/api-docs](http://localhost:3000/api-docs) diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..73302b0 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,12 @@ +services: + app: + build: . + ports: + - '3000:3000' + restart: unless-stopped + environment: + JWT_SECRET: NAKANO_ITSUKI + volumes: + - sqlite_data:/app/db +volumes: + sqlite_data: From d550d87b9c4cf30dd60a2d937dfc0face5aa0dc1 Mon Sep 17 00:00:00 2001 From: Sava Reyhano <32730327+savareyhano@users.noreply.github.com> Date: Thu, 16 Jan 2025 23:02:54 +0700 Subject: [PATCH 2/2] feat: Update Dockerfile --- Dockerfile | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/Dockerfile b/Dockerfile index 3d632ee..81bef4f 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,30 +1,43 @@ +# Base image FROM node:23-alpine AS base +# Install SQLite RUN apk add --no-cache sqlite +# Set working directory inside container WORKDIR /app +# Create database folder and initialize SQLite RUN mkdir -p /app/db RUN sqlite3 /app/db/database.db "VACUUM;" +# Copy package files to install dependencies COPY ./yarn.lock ./package.json ./ +# Install dependencies with Yarn RUN yarn install +# Copy Prisma schema for migrations COPY ./prisma ./prisma/ +# Set DATABASE_URL for Prisma ENV DATABASE_URL=file:/app/db/database.db +# Run Prisma migration to initialize DB RUN npx prisma migrate dev --name init +# Copy the rest of the app files COPY ./ ./ +# Final app image FROM node:23-alpine WORKDIR /app +# Copy app files from base image COPY --from=base ./app ./ ENV DATABASE_URL=file:/app/db/database.db +# Run the app in development mode CMD ["yarn", "dev"]