-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(deploy) add cotainers redis and kafka e adjust dockerfile and g…
…ithub action
- Loading branch information
1 parent
c447a27
commit d0eb45a
Showing
3 changed files
with
119 additions
and
89 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,76 +1,42 @@ | ||
FROM node:20-alpine AS builder | ||
# Stage 1: Base image | ||
FROM node:20-alpine AS base | ||
WORKDIR /app | ||
ENV PNPM_HOME="/pnpm" | ||
ENV PATH="$PNPM_HOME:$PATH" | ||
RUN apk add --no-cache openssl | ||
RUN corepack enable | ||
|
||
# Define build argument | ||
# Adicionando DATABASE_URL como argumento e variável de ambiente | ||
ARG DATABASE_URL | ||
ENV DATABASE_URL=${DATABASE_URL} | ||
|
||
WORKDIR /app | ||
|
||
RUN corepack enable && corepack prepare pnpm@latest --activate | ||
|
||
# Copy root package.json and workspace files | ||
COPY package.json pnpm-workspace.yaml pnpm-lock.yaml ./ | ||
|
||
# Copy API package.json | ||
COPY apps/api/package.json ./apps/api/ | ||
# Stage 2: Development dependencies | ||
FROM base AS dependencies | ||
COPY apps/api/package.json pnpm-lock.yaml pnpm-workspace.yaml ./ | ||
COPY packages ./packages | ||
COPY config ./config | ||
|
||
# Install dependencies | ||
RUN pnpm install --frozen-lockfile | ||
|
||
# Copy source code | ||
COPY apps/api ./apps/api | ||
|
||
# Build the application | ||
WORKDIR /app/apps/api | ||
COPY apps/api/prisma ./prisma | ||
COPY apps/api/tsup.config.ts ./ | ||
RUN pnpm install | ||
RUN pnpm prisma generate | ||
|
||
# Stage 3: Build | ||
FROM base AS builder | ||
COPY --from=dependencies /app/node_modules ./node_modules | ||
COPY --from=dependencies /app/node_modules/prisma ./node_modules/prisma | ||
COPY . . | ||
RUN pnpm build | ||
|
||
# Generate Prisma Client in builder stage | ||
RUN pnpm prisma generate --schema=./prisma/schema.prisma | ||
|
||
FROM node:20-alpine | ||
|
||
ARG DATABASE_URL | ||
ENV DATABASE_URL=${DATABASE_URL} | ||
ENV NODE_ENV=production | ||
|
||
RUN addgroup -S appgroup && adduser -S appuser -G appgroup | ||
RUN apk add --no-cache openssl | ||
|
||
WORKDIR /app | ||
|
||
RUN corepack enable && corepack prepare pnpm@latest --activate | ||
|
||
# Copy necessary files | ||
COPY --from=builder /app/package.json ./ | ||
COPY --from=builder /app/pnpm-workspace.yaml ./ | ||
COPY --from=builder /app/pnpm-lock.yaml ./ | ||
COPY --from=builder /app/apps/api/package.json ./apps/api/ | ||
COPY --from=builder /app/apps/api/dist ./apps/api/dist | ||
COPY --from=builder /app/packages ./packages | ||
COPY --from=builder /app/config ./config | ||
# Stage 4: Production | ||
FROM base AS runner | ||
COPY --from=builder /app/dist ./dist | ||
COPY --from=builder /app/node_modules ./node_modules | ||
COPY --from=builder /app/apps/api/node_modules ./apps/api/node_modules | ||
COPY --from=builder /app/apps/api/prisma ./apps/api/prisma | ||
|
||
# Important: Copy the generated Prisma Client | ||
COPY --from=builder /app/node_modules/.prisma ./node_modules/.prisma | ||
COPY --from=builder /app/node_modules/@prisma ./node_modules/@prisma | ||
|
||
# Install production dependencies | ||
RUN pnpm install --prod --frozen-lockfile | ||
|
||
# Set correct permissions | ||
RUN chown -R appuser:appgroup /app | ||
|
||
USER appuser | ||
|
||
WORKDIR /app/apps/api | ||
COPY apps/api/package.json ./ | ||
COPY apps/api/prisma ./prisma/ | ||
|
||
# Generate Prisma Client again in production stage | ||
RUN pnpm prisma generate --schema=./prisma/schema.prisma | ||
# Gera o Prisma Client novamente no ambiente final | ||
RUN npx prisma generate && npx prisma db push | ||
|
||
EXPOSE 3333 | ||
|
||
CMD ["pnpm", "start"] | ||
CMD ["pnpm", "start"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters