diff --git a/Dockerfile b/Dockerfile index 4e5bc80..92c9f67 100644 --- a/Dockerfile +++ b/Dockerfile @@ -13,20 +13,25 @@ RUN bun install --frozen-lockfile # Copy source code COPY . . -# RUN DB Migrations and build -RUN bun run db:migrate && bun run build +# Build the application +RUN bun run build # Production stage -FROM debian:bookworm-slim +# FROM debian:bookworm-slim -WORKDIR /app +# WORKDIR /app -# Copy only the compiled binary from builder -COPY --from=builder /app/server . +# # Copy only the compiled binary from builder +# COPY --from=builder /app/server . -# Expose the port your app runs on -EXPOSE 3000 +# # Expose the port your app runs on +# EXPOSE 3000 -# Run the binary -CMD ["./server"] +# # Copy the entrypoint script +# COPY entrypoint.sh . +# Make the entrypoint script executable +RUN chmod +x ./entrypoint.sh + +# Set the entrypoint +ENTRYPOINT ["./entrypoint.sh"] \ No newline at end of file diff --git a/docker-compose.yml b/docker-compose.yml index e363536..2adf7e1 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -6,8 +6,10 @@ services: ports: - "${SERVER_PORT}:${SERVER_PORT}" depends_on: - - db - - minio + db: + condition: service_healthy + minio: + condition: service_healthy environment: NODE_ENV: production DATABASE_URL: ${DATABASE_URL} @@ -22,6 +24,12 @@ services: - "${DB_PORT}:5432" volumes: - postgres_data:/var/lib/postgresql/data + healthcheck: + test: ["CMD-SHELL", "pg_isready -U ${DB_USER} -d ${DB_NAME}"] + interval: 10s + timeout: 5s + retries: 5 + start_period: 10s minio: image: minio/minio:latest diff --git a/entrypoint.sh b/entrypoint.sh new file mode 100644 index 0000000..628bb4d --- /dev/null +++ b/entrypoint.sh @@ -0,0 +1,9 @@ +#!/bin/sh +set -e + +# Run migrations +bun run db:migrate + +# Start the application +echo "Starting the application..." +./server \ No newline at end of file