Skip to content

Commit

Permalink
feat: docker
Browse files Browse the repository at this point in the history
  • Loading branch information
seaerchin committed Aug 14, 2024
1 parent d3229ea commit 3853119
Show file tree
Hide file tree
Showing 5 changed files with 114 additions and 1 deletion.
35 changes: 35 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@

# dependencies
node_modules/
.pnp
.pnp.js
.yarn/install-state.gz

# misc
.DS_Store
*.pem

# debug
npm-debug.log*
yarn-debug.log*
yarn-error.log*

# local env files
.env*.local

# vercel
.vercel

# typescript
*.tsbuildinfo
next-env.d.ts

# Storybook logs
build-storybook.log

# Turbo repo logs
.turbo

# Build artifacts
dist/

46 changes: 46 additions & 0 deletions apps/studio/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
FROM node:22-alpine AS base

FROM base AS builder
RUN apk update
RUN apk add --no-cache libc6-compat

# Set working directory
WORKDIR /app
# Replace <your-major-version> with the major version installed in your repository. For example:
# RUN npm i -g turbo@^2
RUN npm install -g turbo@^2
COPY . .

# Generate a partial monorepo with a pruned lockfile for a target workspace.
# Assuming "web" is the name entered in the project's package.json: { name: "web" }
RUN turbo prune isomer-studio --docker

# Add lockfile and package.json's of isolated subworkspace
FROM base AS installer
RUN apk update
RUN apk add --no-cache libc6-compat
WORKDIR /app

# First install the dependencies (as they change less often)
COPY --from=builder /app/out/json/ .
RUN npm ci

# Build the project
COPY --from=builder /app/out/full/ .
RUN npx turbo run build --filter=isomer-studio...

FROM base AS runner
WORKDIR /app

# Don't run production as root
RUN addgroup --system --gid 1001 nodejs
RUN adduser --system --uid 1001 nextjs
USER nextjs

# Automatically leverage output traces to reduce image size
# https://nextjs.org/docs/advanced-features/output-file-tracing
COPY --from=installer --chown=nextjs:nodejs /app/apps/studio/.next/standalone ./
COPY --from=installer --chown=nextjs:nodejs /app/apps/studio/.next/static ./apps/studio/.next/static
COPY --from=installer --chown=nextjs:nodejs /app/apps/studio/public ./apps/studio/public

CMD ["node", "apps/studio/server.js"]
1 change: 1 addition & 0 deletions apps/studio/next.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ const ContentSecurityPolicy = `
*/
/** @type {import("next").NextConfig} */
const config = {
output: "standalone",
reactStrictMode: true,
/**
* Dynamic configuration available for the browser and server.
Expand Down
4 changes: 3 additions & 1 deletion apps/studio/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,13 @@
"setup": "run-s --print-label db:setup db:sleep migrate:dev db:seed",
"setup:test": "run-s --print-label db:setup db:sleep migrate generate",
"teardown": "docker compose down",
"predev": "run-s migrate",
"dev": "next dev",
"prebuild": "run-s generate migrate",
"prebuild": "run-s generate",
"build": "next build",
"build:theme": "npx chakra-cli tokens src/theme/index.ts",
"build:preview-tw": "NODE_ENV=production npx tailwindcss build -i src/styles/tailwind.css -o public/assets/css/preview-tw.css && prettier --write public/assets/css/preview-tw.css",
"prestart": "npm run migrate",
"start": "next start",
"format": "prettier --check . --ignore-path ../../.gitignore",
"format:fix": "prettier --write . --ignore-path ../../.gitignore",
Expand Down
29 changes: 29 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
version: "3"

services:
studio:
ports:
- 3000:3000
build:
context: .
dockerfile: ./apps/studio/Dockerfile
depends_on:
- postgres
# NOTE: try to restart container if it's stopped.
# if manual stop, restarts on next enter
restart: always
env_file:
- .env
postgres:
image: postgres:latest
ports:
- 5432:5432
environment:
- POSTGRES_DB=app
- POSTGRES_USER=root
- POSTGRES_PASSWORD=root
volumes:
- postgres-volume:/var/lib/postgresql/data

volumes:
postgres-volume:

0 comments on commit 3853119

Please sign in to comment.