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

feat: Implement docker deployment #111

Open
pieter-berkel opened this issue Jan 9, 2023 · 10 comments
Open

feat: Implement docker deployment #111

pieter-berkel opened this issue Jan 9, 2023 · 10 comments

Comments

@pieter-berkel
Copy link

Describe the feature you'd like to request

I would like to see how to deploy with docker, maybe in the template or at least in the documentation.

Describe the solution you'd like to see

I would like to see a docker example in the documentation.

Additional information

I already tried with the normal turborepo example but this fails because this template uses pnpm.

@juliusmarminge
Copy link
Member

I'd be open for this - however we currently have some issues getting a normal T3 app Docker setup going so I think I'll wait until that one has been resolved before attempting to set it up for monorepos.

Follow it here: t3-oss/create-t3-app#992

@pmioduszewski
Copy link

pmioduszewski commented Mar 8, 2023

Did someone figure it out?

@EkkoKo
Copy link

EkkoKo commented Mar 31, 2023

@pmioduszewski yes! I've created a PR for it right now you can go check it out
#255

Feel free to ask me questions / review it if you think there are stuff that can be written better :)

@oldo
Copy link

oldo commented Apr 28, 2023

Thanks @EkkoKo
By taking a squiz at your PR I was able to resolve issues I was having running in docker. I was going around in circles all morning till I found your work!

@akutruff
Copy link

akutruff commented Nov 8, 2023

I did a bunch of work to dockerize this repo for fly.io. It's all here:

https://github.com/kutruff/fly-t3-turbo

(It's based on EkkOko's PR.)

@raphaelm-gioa
Copy link

What about deploying using SST ? Would that be doable even ?

@bryanjtc
Copy link

Any update on this?

@noxify
Copy link
Contributor

noxify commented Jun 12, 2024

@bryanjtc - i don't think so.

But there is a new medium articel for this topic:
https://fintlabs.medium.com/optimized-multi-stage-docker-builds-with-turborepo-and-pnpm-for-nodejs-microservices-in-a-monorepo-c686fdcf051f

Maybe it helps to get started :)

@bryanjtc
Copy link

I ended up using this Dockerfile from the official turbo docker example
https://github.com/vercel/turbo/blob/main/examples/with-docker/apps/web/Dockerfile
It works perfectly.

@Security2431
Copy link

Security2431 commented Oct 26, 2024

I wanted to share with you a working Dockerfile for creating a create-t3-turbo and Next.js app.

You can find the repository on GitHub at:
https://github.com/Security2431/create-t3-turbo-with-prisma/blob/main/apps/nextjs/Dockerfile

To execute a Dockerfile, open a terminal and run the following command:

docker build -f apps/nextjs/Dockerfile -t create-t3-turbo-with-prisma:latest .

Just in case, sharing the Dockerfile content here:

ARG NODE_VERSION=20
ARG APP_DIRNAME=nextjs
ARG PROJECT=@acme/nextjs

# 1. Alpine image
FROM node:${NODE_VERSION}-alpine AS alpine
RUN apk update
RUN apk add --no-cache libc6-compat

# Setup pnpm and turbo on the alpine base
FROM alpine AS base
RUN corepack enable
# Replace <your-major-version> with the major version installed in your repository. For example:
# RUN npm install [email protected] --global
RUN npm install turbo --global

RUN pnpm config set store-dir ~/.pnpm-store

# 2. Prune projects
FROM base AS pruner
# https://stackoverflow.com/questions/49681984/how-to-get-version-value-of-package-json-inside-of-dockerfile
# RUN export VERSION=$(npm run version)

ARG PROJECT

# Set working directory
WORKDIR /app

# It might be the path to <ROOT> turborepo
COPY . .
 
# Generate a partial monorepo with a pruned lockfile for a target workspace.
# Assuming "@acme/nextjs" is the name entered in the project's package.json: { name: "@acme/nextjs" }
RUN turbo prune --scope=${PROJECT} --docker
 
# 3. Build the project
FROM base AS builder
ARG PROJECT

# Environment to skip .env validation on build
ENV CI=true

WORKDIR /app

# Copy lockfile and package.json's of isolated subworkspace
COPY --from=pruner /app/out/pnpm-lock.yaml ./pnpm-lock.yaml
COPY --from=pruner /app/out/pnpm-workspace.yaml ./pnpm-workspace.yaml
COPY --from=pruner /app/out/json/ .

# First install the dependencies (as they change less often)
RUN --mount=type=cache,id=pnpm,target=~/.pnpm-store pnpm install --frozen-lockfile
 
# Copy source code of isolated subworkspace
COPY --from=pruner /app/out/full/ .

RUN pnpm build --filter=${PROJECT}

# 4. Final image - runner stage to run the application
FROM base AS runner
ARG APP_DIRNAME
 
# Don't run production as root
RUN addgroup --system --gid 1001 nodejs
RUN adduser --system --uid 1001 nextjs
USER nextjs

WORKDIR /app

ENV NODE_ENV=production

COPY --from=builder --chown=nodejs:nextjs /app .
WORKDIR /app/apps/${APP_DIRNAME}

ARG PORT=3000
ENV PORT=${PORT}
EXPOSE ${PORT}

CMD ["pnpm", "start"]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

10 participants