Skip to content

Commit

Permalink
♻️ build image outside of docker
Browse files Browse the repository at this point in the history
  • Loading branch information
Fredkiss3 committed Sep 13, 2024
1 parent 70a7df0 commit 6ed42b4
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 49 deletions.
38 changes: 19 additions & 19 deletions .github/workflows/build-and-push-images.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,25 +19,25 @@ jobs:
steps:
- name: Checkout
uses: actions/checkout@v4
# - name: Cache nextjs build output
# uses: actions/cache@v4
# with:
# path: ${{ github.workspace }}/.next/cache
# key: ${{ runner.os }}-nextjs-${{ hashFiles('**/pnpm -lock.yaml') }}-${{ hashFiles('**/*.js', '**/*.mjs', '**/*.jsx', '**/*.ts', '**/*.tsx') }}
# restore-keys: |
# ${{ runner.os }}-nextjs-${{ hashFiles('**/pnpm-lock.yaml') }}-
# - uses: pnpm/action-setup@646cdf48217256a3d0b80361c5a50727664284f2
# with:
# version: 8.15.9
# - name: Use Node.js version 20.x
# uses: actions/setup-node@v2
# with:
# node-version: 20.x
# cache: 'pnpm'
# - name: Build app with node
# run: |
# FORCE_COLOR=true pnpm install --shamefully-hoist --strict-peer-dependencies=false --frozen-lockfile
# FORCE_COLOR=true SKIP_ENV_VALIDATION=1 pnpm run build
- name: Cache nextjs build output
uses: actions/cache@v4
with:
path: ${{ github.workspace }}/.next/cache
key: ${{ runner.os }}-nextjs-${{ hashFiles('**/pnpm -lock.yaml') }}-${{ hashFiles('**/*.js', '**/*.mjs', '**/*.jsx', '**/*.ts', '**/*.tsx') }}
restore-keys: |
${{ runner.os }}-nextjs-${{ hashFiles('**/pnpm-lock.yaml') }}-
- uses: pnpm/action-setup@646cdf48217256a3d0b80361c5a50727664284f2
with:
version: 8.15.9
- name: Use Node.js version 20.x
uses: actions/setup-node@v2
with:
node-version: 20.x
cache: 'pnpm'
- name: Build app with node
run: |
FORCE_COLOR=true pnpm install --shamefully-hoist --strict-peer-dependencies=false --frozen-lockfile
FORCE_COLOR=true SKIP_ENV_VALIDATION=1 pnpm run build
- name: Set up QEMU
uses: docker/setup-qemu-action@v2
- name: Set up Docker Buildx
Expand Down
43 changes: 13 additions & 30 deletions docker/Dockerfile.prod
Original file line number Diff line number Diff line change
Expand Up @@ -7,32 +7,10 @@ WORKDIR /app

# Install dependencies based on the preferred package manager

COPY package.json yarn.lock* package-lock.json* pnpm-lock.yaml\* ./
COPY package.json pnpm-lock.yaml ./
COPY ./patches ./patches

RUN \
if [ -f yarn.lock ]; then yarn --frozen-lockfile; \
elif [ -f package-lock.json ]; then npm ci; \
elif [ -f pnpm-lock.yaml ]; then yarn global add pnpm && pnpm install --shamefully-hoist --strict-peer-dependencies=false --frozen-lockfile; \
else echo "Lockfile not found." && exit 1; \
fi

##### BUILDER
FROM node:20-alpine3.19 AS builder


WORKDIR /app
COPY --from=deps /app/node_modules ./node_modules
COPY . .

ENV NEXT_TELEMETRY_DISABLED 1

RUN \
if [ -f yarn.lock ]; then yarn build; \
elif [ -f package-lock.json ]; then npm run build; \
elif [ -f pnpm-lock.yaml ]; then yarn global add pnpm@8 && SKIP_ENV_VALIDATION=1 pnpm run build; \
else echo "Lockfile not found." && exit 1; \
fi
RUN yarn global add pnpm@8 && pnpm install --shamefully-hoist --strict-peer-dependencies=false --frozen-lockfile

##### RUNNER

Expand All @@ -50,13 +28,18 @@ ENV NEXT_TELEMETRY_DISABLED=1
RUN addgroup --system --gid 1001 nodejs
RUN adduser --system --uid 1001 nextjs

COPY . .

COPY --from=deps /app/node_modules ./node_modules

COPY --from=builder --chown=nextjs:nodejs /app/.next ./.next
COPY --from=builder --chown=nextjs:nodejs /app/.next/static ./.next/standalone/static
COPY ./custom-incremental-cache-handler.mjs ./.next/custom-incremental-cache-handler.mjs
COPY ./public/ ./public/
COPY ./drizzle/ ./drizzle/

COPY ./migrate.mjs .
COPY ./next.config.mjs .
COPY ./package.json .
COPY ./custom-incremental-cache-handler.mjs .

COPY --chown=nextjs:nodejs .next/standalone ./
COPY --chown=nextjs:nodejs .next/static ./.next/static


USER nextjs
Expand All @@ -65,4 +48,4 @@ ENV PORT=80
ENV NODE_ENV=production
ENV HOSTNAME=0.0.0.0

CMD ["sh", "-c", "npm run db:migrate-docker && npm run start"]
CMD ["sh", "-c", "node migrate.mjs && node server.js"]

0 comments on commit 6ed42b4

Please sign in to comment.