Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Docker support with development and production configurations and… #5

Merged
merged 1 commit into from
Jan 14, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions .docker/Dockerfile.dev
Original file line number Diff line number Diff line change
@@ -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"]
38 changes: 21 additions & 17 deletions Dockerfile → .docker/Dockerfile.prod
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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"]
ENTRYPOINT ["/app/scripts/prod-entrypoint.sh"]
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
10 changes: 3 additions & 7 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ services:
dev:
build:
context: .
dockerfile: Dockerfile
dockerfile: .docker/Dockerfile.dev
develop:
watch:
- action: sync
Expand All @@ -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
Expand All @@ -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:
Expand Down
4 changes: 2 additions & 2 deletions packages/api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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\"",
Expand Down
15 changes: 0 additions & 15 deletions scripts/type-check.sh

This file was deleted.

Loading