Skip to content

Commit

Permalink
Merge pull request #123 from panoratech/docker-compose-monorepo-upgrade
Browse files Browse the repository at this point in the history
feat: Fully Dockerized Monorepo Turbo
  • Loading branch information
rflihxyz authored Dec 6, 2023
2 parents 80498ff + c0461d0 commit 30157a0
Show file tree
Hide file tree
Showing 6 changed files with 11,725 additions and 35 deletions.
8 changes: 8 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
pg_data/
node_modules/

apps/webapp/node_modules
apps/webapp/dist

packages/api/node_modules
packages/api/dist
52 changes: 42 additions & 10 deletions apps/webapp/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,16 +1,48 @@
# build stage
FROM node:20-alpine as build-stage
# run directly from the repo root directory
# docker build -f ./apps/webapp/Dockerfile .
FROM node:20-alpine AS base
# =======================================================================
FROM base AS builder
RUN apk add --no-cache libc6-compat
RUN apk update

# Set pnpm
ENV PNPM_HOME="/pnpm"
ENV PATH="$PNPM_HOME:$PATH"
RUN corepack enable

WORKDIR /app
COPY package*.json ./
RUN npm install
RUN pnpm add -g turbo
COPY . .
RUN npm run build
RUN turbo prune webapp --docker
RUN ls -la ./out/full/apps/webapp

# =======================================================================
# Add lockfile and package.json's of isolated subworkspace
FROM base AS installer
RUN apk add --no-cache libc6-compat
RUN apk update
# Set pnpm
ENV PNPM_HOME="/pnpm"
ENV PATH="$PNPM_HOME:$PATH"
RUN corepack enable

WORKDIR /app

# First install the dependencies (as they change less often)
COPY .gitignore .gitignore
COPY --from=builder /app/out/json/ .
COPY --from=builder /app/out/pnpm-lock.yaml ./pnpm-lock.yaml
RUN pnpm install

# Build the project
COPY --from=builder ./app/out/full/ .
RUN pnpm turbo run build --filter=webapp...

# ========================================================================
FROM nginx:stable-alpine as runner

# production stage
FROM nginx:stable-alpine as production-stage
COPY --from=build-stage /app/dist/ /usr/share/nginx/html
RUN ls -la /usr/share/nginx/html
RUN ls -la /usr/share/nginx/html
COPY --from=installer ./app/apps/webapp/dist/ /usr/share/nginx/html

EXPOSE 80
CMD ["nginx", "-g", "daemon off;"]
10 changes: 7 additions & 3 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ version: '3.8'
services:

postgres:
image: postgres:14.6
image: postgres:16.1
environment:
POSTGRES_USER: ${POSTGRES_USER}
POSTGRES_PASSWORD: ${POSTGRES_PASSWORD}
Expand All @@ -16,7 +16,9 @@ services:
- ./packages/api/scripts/init.sql:/docker-entrypoint-initdb.d/init.sql

api:
build: ./packages/api
build:
context: ./
dockerfile: ./packages/api/Dockerfile
environment:
DATABASE_URL: postgresql://${POSTGRES_USER}:${POSTGRES_PASSWORD}@${POSTGRES_HOST}:5432/${POSTGRES_DB}?ssl=false
DISTRIBUTION: ${DISTRIBUTION}
Expand All @@ -29,7 +31,9 @@ services:
- postgres

webapp:
build: ./packages/webapp
build:
dockerfile: ./apps/webapp/Dockerfile
context: ./
restart:
unless-stopped
ports:
Expand Down
Loading

0 comments on commit 30157a0

Please sign in to comment.