diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..9b49524 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,15 @@ +node_modules +Dockerfile* +docker-compose* +.dockerignore +.git +.gitignore +README.md +LICENSE +.vscode +Makefile +helm-charts +.env +.editorconfig +.idea +coverage* \ No newline at end of file diff --git a/apps/web/bun.lockb b/apps/web/bun.lockb new file mode 100755 index 0000000..081a12b Binary files /dev/null and b/apps/web/bun.lockb differ diff --git a/apps/web/init.sql b/apps/web/init.sql new file mode 100644 index 0000000..9f441d8 --- /dev/null +++ b/apps/web/init.sql @@ -0,0 +1,4 @@ +-- REPLACE janedoe with your mysql user in the .env + +GRANT CREATE ON *.* TO 'janedoe'@'%'; +GRANT ALL PRIVILEGES ON *.* TO 'janedoe'@'%'; diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..c5c656f --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,74 @@ +version: '3.8' +services: + db: + image: mysql:8.4 + container_name: mysql + restart: always + env_file: + - ./apps/web/.env + ports: + - '3306:3306' + healthcheck: + test: ['CMD-SHELL', 'mysqladmin ping -h 127.0.0.1 --password="$$(cat /run/secrets/db-password)" --silent'] + interval: 3s + retries: 5 + start_period: 30s + volumes: + - mysql-data:/var/lib/mysql + - ./apps/web/sql/init.sql:/docker-entrypoint-initdb.d/init.sql + + prisma: + build: + context: . + dockerfile: ./web.Dockerfile + container_name: prisma + env_file: + - ./apps/web/.env + ports: + - '5555:5555' + working_dir: /app + volumes: + - ./apps/web/:/app + depends_on: + db: + condition: service_healthy + command: sh -c "bunx prisma generate && bunx prisma migrate dev && bunx prisma studio" + + web: + build: + context: . + dockerfile: ./web.Dockerfile + container_name: web + platform: linux/amd64 + working_dir: /app + stdin_open: true + tty: true + volumes: + - ./apps/web/:/app + - /app/node_modules + - /app/ui + - /app/eslint-config + - /app/tslint-config + ports: + - "3000:3000" + env_file: + - ./apps/web/.env + depends_on: + - prisma + command: sh -c "bun run dev" + + storybook: + build: + context: . + dockerfile: ./web.Dockerfile + ports: + - "3000:3000" + env_file: + - ./apps/web/.env + depends_on: + - prisma + command: sh -c "bun run dev:storybook" + +volumes: + mysql-data: + diff --git a/package.json b/package.json index 287182d..1bac092 100644 --- a/package.json +++ b/package.json @@ -33,6 +33,7 @@ "turbo": "^2.0.14", "typescript": "^5.4.5" }, + "trustedDependencies": ["prisma", "esbuild"], "engines": { "node": ">=18" }, diff --git a/web.Dockerfile b/web.Dockerfile new file mode 100644 index 0000000..c43a547 --- /dev/null +++ b/web.Dockerfile @@ -0,0 +1,35 @@ +# Set Bun and Node version +ARG BUN_VERSION=1.1.13 +ARG NODE_VERSION=20.12.2 +FROM imbios/bun-node:${BUN_VERSION}-${NODE_VERSION}-slim AS base + +WORKDIR /usr/src/app + +FROM base AS install +RUN mkdir -p /temp/dev +WORKDIR /temp/dev +COPY ./apps/web/package.json ./apps/web/bun.lockb ./ +COPY ./packages/eslint-config/ ./node_modules/@repo/eslint-config/ +COPY ./packages/typescript-config/ ./node_modules/@repo/typescript-config/ +COPY ./packages/ui/ ./node_modules/@repo/ui/ +COPY ./apps/web/prisma/ ./prisma/ +# TODO: Remove the || true to use trustedDependencies so bun +# can install the dependencies without error +# RUN bun install +# RUN bun install --frozen-lockfile || true +# RUN bun pm trust --all + +# FROM base AS prerelease +# COPY --from=install /temp/dev/node_modules node_modules +# COPY --from=install /temp/dev/prisma prisma +# COPY . . + +# FROM base AS release +# COPY --from=install /temp/dev/node_modules node_modules +# COPY --from=prerelease /usr/src/app/index.ts . +# COPY --from=prerelease /usr/src/app/package.json . + +# COPY ./apps/web/ . + + +# CMD ["bun", "run", "dev"] \ No newline at end of file