From cb29f2024f932ad84beddfe380f9abc18de7c9e3 Mon Sep 17 00:00:00 2001 From: Liam Date: Thu, 16 Nov 2023 13:17:23 +0000 Subject: [PATCH] 7 --- .gitea/workflows/publish.yml | 10 ++++----- Dockerfile | 22 ------------------ apps/node/Dockerfile | 43 ++++++++++++++++++++++++++++++++++++ apps/proxy/Dockerfile | 43 ++++++++++++++++++++++++++++++++++++ 4 files changed, 90 insertions(+), 28 deletions(-) delete mode 100644 Dockerfile create mode 100644 apps/node/Dockerfile create mode 100644 apps/proxy/Dockerfile diff --git a/.gitea/workflows/publish.yml b/.gitea/workflows/publish.yml index fc55c9c..8be8b9d 100644 --- a/.gitea/workflows/publish.yml +++ b/.gitea/workflows/publish.yml @@ -29,16 +29,14 @@ jobs: uses: docker/build-push-action@v4 with: push: true - file: ./Dockerfile + context: ./apps/node + file: ./apps/node/Dockerfile tags: fascinated/proxy:node-latest - build-args: | - APP=node - name: Build and Push (Proxy) uses: docker/build-push-action@v4 with: push: true - file: ./Dockerfile + context: ./apps/proxy + file: ./apps/proxy/Dockerfile tags: fascinated/proxy:proxy-latest - build-args: | - APP=proxy diff --git a/Dockerfile b/Dockerfile deleted file mode 100644 index e65d77b..0000000 --- a/Dockerfile +++ /dev/null @@ -1,22 +0,0 @@ -FROM fascinated/docker-images:node-pnpm-latest - -ARG APP -ENV APP=${APP} - -WORKDIR /usr/src/app - -# Copy the app's sourse -COPY apps/${APP} ./${APP} -COPY apps/${APP}/package.json ./${APP}/package.json - -# Install dependencies -RUN pnpm install --frozen-lockfile --production - -# Build the app -RUN pnpm run build - -# Expose the port -EXPOSE 3000 - -# Run the app -CMD pnpm apps/$APP/dist/index.js \ No newline at end of file diff --git a/apps/node/Dockerfile b/apps/node/Dockerfile new file mode 100644 index 0000000..b17893b --- /dev/null +++ b/apps/node/Dockerfile @@ -0,0 +1,43 @@ +FROM node:18-alpine AS base + +# The web Dockerfile is copy-pasted into our main docs at /docs/handbook/deploying-with-docker. +# Make sure you update this Dockerfile, the Dockerfile in the web workspace and copy that over to Dockerfile in the docs. + +FROM base AS builder +# Check https://github.com/nodejs/docker-node/tree/b4117f9333da4138b03a546ec926ef50a31506c3#nodealpine to understand why libc6-compat might be needed. +RUN apk add --no-cache libc6-compat +RUN apk update +# Set working directory +WORKDIR /app +RUN pnpm install -g turbo +COPY . . +RUN turbo prune node --docker + +# Add lockfile and package.json's of isolated subworkspace +FROM base AS installer +RUN apk add --no-cache libc6-compat +RUN apk update +WORKDIR /app + +# First install 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 and its dependencies +COPY --from=builder /app/out/full/ . +COPY turbo.json turbo.json + +RUN pnpm run build --filter=node... + +FROM base AS runner +WORKDIR /app + +# Don't run production as root +RUN addgroup --system --gid 1001 expressjs +RUN adduser --system --uid 1001 expressjs +USER expressjs +COPY --from=installer /app . + +CMD node apps/node/dist/index.js \ No newline at end of file diff --git a/apps/proxy/Dockerfile b/apps/proxy/Dockerfile new file mode 100644 index 0000000..8cb013f --- /dev/null +++ b/apps/proxy/Dockerfile @@ -0,0 +1,43 @@ +FROM node:18-alpine AS base + +# The web Dockerfile is copy-pasted into our main docs at /docs/handbook/deploying-with-docker. +# Make sure you update this Dockerfile, the Dockerfile in the web workspace and copy that over to Dockerfile in the docs. + +FROM base AS builder +# Check https://github.com/nodejs/docker-node/tree/b4117f9333da4138b03a546ec926ef50a31506c3#nodealpine to understand why libc6-compat might be needed. +RUN apk add --no-cache libc6-compat +RUN apk update +# Set working directory +WORKDIR /app +RUN pnpm install -g turbo +COPY . . +RUN turbo prune proxy --docker + +# Add lockfile and package.json's of isolated subworkspace +FROM base AS installer +RUN apk add --no-cache libc6-compat +RUN apk update +WORKDIR /app + +# First install 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 and its dependencies +COPY --from=builder /app/out/full/ . +COPY turbo.json turbo.json + +RUN pnpm run build --filter=proxy... + +FROM base AS runner +WORKDIR /app + +# Don't run production as root +RUN addgroup --system --gid 1001 expressjs +RUN adduser --system --uid 1001 expressjs +USER expressjs +COPY --from=installer /app . + +CMD node apps/proxy/dist/index.js \ No newline at end of file