diff --git a/.docker/Dockerfile.dev b/.docker/Dockerfile.dev new file mode 100644 index 0000000..ec56d6e --- /dev/null +++ b/.docker/Dockerfile.dev @@ -0,0 +1,27 @@ +# Use the official Bun image as the base image +FROM oven/bun:latest AS bun + +# Set ARGs and ENVs for build +ARG PUBLIC_WEB_API_URL +ENV PUBLIC_WEB_API_URL=$PUBLIC_WEB_API_URL +ENV NODE_ENV=development + +# Set working directory +WORKDIR /app + +# Copy application files and install dependencies +COPY bun.lockb package.json ./ +COPY packages ./packages +RUN bun install + +# Build the frontend +RUN bun run build + +# Copy entrypoint script and set permissions +COPY .docker/scripts/wait-for-it.sh /app/scripts/wait-for-it.sh +COPY .docker/scripts/dev-entrypoint.sh /app/scripts/dev-entrypoint.sh +RUN chmod +x /app/scripts/wait-for-it.sh +RUN chmod +x /app/scripts/dev-entrypoint.sh + +# Set the entrypoint to the start script +ENTRYPOINT ["/app/scripts/dev-entrypoint.sh"] \ No newline at end of file diff --git a/Dockerfile b/.docker/Dockerfile.prod similarity index 61% rename from Dockerfile rename to .docker/Dockerfile.prod index 3e3d04d..486dde9 100644 --- a/Dockerfile +++ b/.docker/Dockerfile.prod @@ -1,10 +1,21 @@ # Use the official Bun image as the base image FROM oven/bun:latest AS bun -# Set ARGs and ENVs +# Set ARGs and ENVs for build ARG PUBLIC_WEB_API_URL -ENV PUBLIC_WEB_API_URL $PUBLIC_WEB_API_URL -ENV NODE_ENV production +ENV PUBLIC_WEB_API_URL=$PUBLIC_WEB_API_URL +ENV NODE_ENV=production + +# Set working directory +WORKDIR /app + +# Copy application files and install dependencies +COPY bun.lockb package.json ./ +COPY packages ./packages +RUN bun install + +# Build the frontend +RUN bun run build # Install dependencies required for Caddy installation RUN apt-get update && apt-get install -y debian-keyring debian-archive-keyring apt-transport-https curl @@ -17,23 +28,16 @@ RUN curl -1sLf 'https://dl.cloudsmith.io/public/caddy/stable/debian.deb.txt' | t RUN apt-get update && apt-get install -y caddy # Copy the Caddyfile into the container and format it -COPY Caddyfile /etc/caddy/Caddyfile +COPY .docker/caddy/Caddyfile /etc/caddy/Caddyfile -# Set the working directory to /app and copy your application files -WORKDIR /app -COPY packages ./packages -COPY scripts ./scripts -COPY bun.lockb ./bun.lockb -COPY package.json ./package.json - -# Install dependencies using Bun -RUN bun install - -# Build the frontend -RUN bun run build +# Copy entrypoint script and set permissions +COPY .docker/scripts/wait-for-it.sh /app/scripts/wait-for-it.sh +COPY .docker/scripts/prod-entrypoint.sh /app/scripts/prod-entrypoint.sh +RUN chmod +x /app/scripts/wait-for-it.sh +RUN chmod +x /app/scripts/prod-entrypoint.sh # Expose ports for the backend and Caddy server EXPOSE 80 443 # Set the entry point to the start script -ENTRYPOINT ["./scripts/prod-entrypoint.sh"] \ No newline at end of file +ENTRYPOINT ["/app/scripts/prod-entrypoint.sh"] \ No newline at end of file diff --git a/Caddyfile b/.docker/caddy/Caddyfile similarity index 100% rename from Caddyfile rename to .docker/caddy/Caddyfile diff --git a/scripts/dev-entrypoint.sh b/.docker/scripts/dev-entrypoint.sh similarity index 100% rename from scripts/dev-entrypoint.sh rename to .docker/scripts/dev-entrypoint.sh diff --git a/scripts/prod-entrypoint.sh b/.docker/scripts/prod-entrypoint.sh similarity index 100% rename from scripts/prod-entrypoint.sh rename to .docker/scripts/prod-entrypoint.sh diff --git a/scripts/wait-for-it.sh b/.docker/scripts/wait-for-it.sh similarity index 100% rename from scripts/wait-for-it.sh rename to .docker/scripts/wait-for-it.sh diff --git a/docker-compose.yml b/docker-compose.yml index 2db611c..c97ccf5 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -27,7 +27,7 @@ services: dev: build: context: . - dockerfile: Dockerfile + dockerfile: .docker/Dockerfile.dev develop: watch: - action: sync @@ -45,23 +45,21 @@ services: - 5173:5173 - 3000:3000 environment: - NODE_ENV: development PUBLIC_API_PORT: 3000 PUBLIC_WEB_API_URL: http://localhost:3000 DATABASE_URL: postgres://postgres:postgres@db:5432/postgres TEST_DATABASE_URL: postgres://test:test@testdb:5433/postgres - entrypoint: ./scripts/dev-entrypoint.sh profiles: [dev] prod: build: context: . - dockerfile: Dockerfile + dockerfile: .docker/Dockerfile.prod args: PUBLIC_WEB_API_URL: http://localhost:5173/api develop: watch: - action: sync+restart - path: ./Caddyfile + path: .docker/caddy/Caddyfile target: /etc/caddy/Caddyfile - action: sync+restart path: ./packages/api @@ -77,10 +75,8 @@ services: ports: - 5173:443 environment: - NODE_ENV: production PUBLIC_API_PORT: 3000 DATABASE_URL: postgres://postgres:postgres@db:5432/postgres - entrypoint: ./scripts/prod-entrypoint.sh profiles: [prod] volumes: db: diff --git a/packages/api/package.json b/packages/api/package.json index db49f3d..a1174ba 100644 --- a/packages/api/package.json +++ b/packages/api/package.json @@ -4,8 +4,8 @@ "private": true, "description": "Backend", "scripts": { - "start": "bun run db:migrate && NODE_ENV=production bun src/app.ts", - "dev": "NODE_ENV=development bun --hot src/app.ts", + "start": "bun src/app.ts", + "dev": "bun --hot src/app.ts", "compile": "tsc -b --noEmit && tsc-alias", "test": "DATABASE_URL=$TEST_DATABASE_URL sh -c \"bun run db:migrate && bun test\"", "test:watch": "DATABASE_URL=$TEST_DATABASE_URL sh -c \"bun run db:migrate && bun test --watch\"", diff --git a/scripts/type-check.sh b/scripts/type-check.sh deleted file mode 100755 index 9a9d7e4..0000000 --- a/scripts/type-check.sh +++ /dev/null @@ -1,15 +0,0 @@ -#!/bin/bash - -# This script is only used to debug typecheck issues locally. -# You can ignore it or delete it. - -echo "Running TypeScript build..." -bunx tsc -b --noEmit -EXIT_CODE=$? - -if [ $EXIT_CODE -ne 0 ]; then - echo "TypeScript build failed with exit code $EXIT_CODE." - exit $EXIT_CODE -fi - -echo "TypeScript build succeeded. $EXIT_CODE" \ No newline at end of file