From 9b1a7e0b825d189d1058ae418996e66622b07978 Mon Sep 17 00:00:00 2001 From: jesus mejuto Date: Tue, 16 Jan 2024 11:30:56 +0100 Subject: [PATCH] feature/265 Containerize with docker This PR makes it possible to run the project with one command ``` pnpm docker-dev ``` Once the update to v14 is done (https://github.com/shadcn-ui/taxonomy/pull/253) I would be happy to add testing to it, so we can mock email sending and test the features of the app. I hope it is useful. Thanks --- README.md | 8 ++++++++ docker-run.sh | 7 +++++++ docker/Dockerfile | 10 ++++++++++ docker/docker-compose.yml | 39 +++++++++++++++++++++++++++++++++++++++ package.json | 3 ++- 5 files changed, 66 insertions(+), 1 deletion(-) create mode 100755 docker-run.sh create mode 100644 docker/Dockerfile create mode 100644 docker/docker-compose.yml diff --git a/README.md b/README.md index 040a609d..c9b736a9 100644 --- a/README.md +++ b/README.md @@ -67,6 +67,8 @@ If you have some suggestions, feel free to create an issue. ## Running Locally +### With pnpm + 1. Install dependencies using pnpm: ```sh @@ -85,6 +87,12 @@ cp .env.example .env.local pnpm dev ``` +### With Docker and docker compose + +```sh +pnpm docker-dev +``` + ## License Licensed under the [MIT license](https://github.com/shadcn/taxonomy/blob/main/LICENSE.md). diff --git a/docker-run.sh b/docker-run.sh new file mode 100755 index 00000000..34d5dd23 --- /dev/null +++ b/docker-run.sh @@ -0,0 +1,7 @@ +#!/bin/sh -e + +OPTS="-f ./docker/docker-compose.yml" + +docker-compose $OPTS down --volumes +docker-compose $OPTS up -d db +docker-compose $OPTS up -d web diff --git a/docker/Dockerfile b/docker/Dockerfile new file mode 100644 index 00000000..4dbd3da6 --- /dev/null +++ b/docker/Dockerfile @@ -0,0 +1,10 @@ +FROM node:20 as base +RUN npm install -g pnpm + +COPY ../ /app +WORKDIR /app + +FROM base as base_build + +RUN sh -c 'yes | pnpm install' + diff --git a/docker/docker-compose.yml b/docker/docker-compose.yml new file mode 100644 index 00000000..48eaa434 --- /dev/null +++ b/docker/docker-compose.yml @@ -0,0 +1,39 @@ +version: "3.7" + +services: + web: + build: + target: base_build + context: ../ + dockerfile: ./docker/Dockerfile + args: + - BUILDKIT_INLINE_CACHE=1 + ports: + - "3000:3000" + working_dir: /app + volumes: + - ../:/app + - ./.env.local:/app/.env.local + command: [ + "pnpm", + "dev" + ] + + db: + image: mysql:5.7 + restart: always + environment: + MYSQL_DATABASE: 'db' + MYSQL_USER: 'user' + MYSQL_PASSWORD: 'password' + MYSQL_ROOT_PASSWORD: 'password' + ports: + - '3306:3306' + expose: + - '3306' + volumes: + - my-db:/var/lib/mysql + +# Names our volume +volumes: + my-db: diff --git a/package.json b/package.json index 00460d22..c77fcbd5 100644 --- a/package.json +++ b/package.json @@ -13,7 +13,8 @@ "start": "next start", "lint": "next lint", "preview": "next build && next start", - "postinstall": "prisma generate" + "postinstall": "prisma generate", + "docker-dev": "./docker-run.sh" }, "dependencies": { "@editorjs/code": "^2.8.0",