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

ci: fix containerfile build for monorepo layout #170

Merged
merged 1 commit into from
Aug 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions .dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,13 @@


# nextjs files
!apps/*/src/
!apps/*/public/
!apps/*/.next/
!apps/*/*.ts
!apps/
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The line !apps/*/src/ looks to me like it should be sufficient to get the apps/web/src/* directory allowed, but it wasn't working. To resolve, I added !apps/ and I'm calling it a day.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I completely assumed that !apps/*/src would expand to include any subdirectories so great catch!

!apps/*/*.js
!apps/*/*.json
!apps/*/*.ts
!apps/*/.next/
!apps/*/public/
!apps/*/src/

!public/
!src/
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/container.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ jobs:
with:
context: .
platforms: linux/amd64
file: Containerfile
file: apps/web/Containerfile
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The Containerfile moved, but the build "content" did not: the context remains the repo root.

push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ node_modules
.env.development.local
.env.test.local
.env.production.local
.envrc
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I use a local .envrc file sometimes to test connecting a locally-built container to a remote DB URL.


# Testing
coverage
Expand Down
17 changes: 10 additions & 7 deletions apps/web/Containerfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,22 @@ LABEL maintainer="[email protected]"

# provide pnpm globally for dep installing and building
FROM alpine AS base
ENV NEXT_TELEMETRY_DISABLED=1
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Porting this no-telem env var across all build stages...

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lol, great catch. Very obnoxious to keep track of.

ENV PNPM_HOME="/pnpm"
ENV PATH="$PNPM_HOME:$PATH"
RUN corepack enable pnpm
RUN pnpm install turbo --global

# prune package structure + code into out/
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
ENV NEXT_TELEMETRY_DISABLED=1
# Check https://github.com/nodejs/docker-node/tree/b4117f9333da4138b03a546ec926ef50a31506c3#nodealpine
# to understand why libc6-compat might be needed.
RUN apk update
RUN apk add --no-cache libc6-compat
# Set working directory
WORKDIR /app
COPY . .
COPY . /app
WORKDIR /app/apps/web
RUN turbo prune --scope=cuiloa-app --docker

# Install and build app
Expand All @@ -26,7 +29,7 @@ RUN apk update
WORKDIR /app

# Disable build time telemetry.
ENV NEXT_TELEMETRY_DISABLED 1
ENV NEXT_TELEMETRY_DISABLED=1

# grab dependencies
COPY .gitignore .gitignore
Expand All @@ -45,7 +48,7 @@ FROM alpine AS runner
WORKDIR /app

# Disable telemetry.
ENV NEXT_TELEMETRY_DISABLED 1
ENV NEXT_TELEMETRY_DISABLED=1

# Don't run production as root
RUN addgroup --system --gid 1001 nodejs
Expand All @@ -59,6 +62,6 @@ COPY --from=installer /app/apps/web/package.json .
# https://nextjs.org/docs/advanced-features/output-file-tracing
COPY --from=installer --chown=nextjs:nodejs /app/apps/web/.next/standalone ./
COPY --from=installer --chown=nextjs:nodejs /app/apps/web/.next/static ./apps/web/.next/static
COPY --from=installer --chown=nextjs:nodejs /app/apps/web/public ./apps/web/public
# COPY --from=installer --chown=nextjs:nodejs /app/apps/web/public ./apps/web/public
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AFAICT the ./apps/web/public/ dir doesn't exist and doesn't need to exist: the app works well without it.


CMD node apps/web/server.js
Loading