Skip to content

Commit

Permalink
♻️ build with docker and copy missing static files
Browse files Browse the repository at this point in the history
  • Loading branch information
Fredkiss3 committed Sep 12, 2024
1 parent 5882fa8 commit c2e9c2e
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 41 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: 21 additions & 22 deletions docker/Dockerfile.prod
Original file line number Diff line number Diff line change
Expand Up @@ -17,31 +17,28 @@ RUN \
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

##### RUNNER

FROM node:20-alpine3.19 AS runner
WORKDIR /app

# ARG SESSION_SECRET
# ARG DATABASE_URL
# ARG GITHUB_CLIENT_ID
# ARG GITHUB_SECRET
# ARG GITHUB_PERSONAL_ACCESS_TOKEN
# ARG KV_PREFIX
# ARG NEXT_PUBLIC_VERCEL_URL="localhost:3000"
# ARG REDIS_HTTP_URL="http://webdis:7379"
# ARG REDIS_HTTP_USERNAME
# ARG REDIS_HTTP_PASSWORD
# ARG GITHUB_REDIRECT_URI="http://localhost:3000/api/auth/callback"

# ENV NEXT_PUBLIC_VERCEL_URL=$NEXT_PUBLIC_VERCEL_URL
# ENV SESSION_SECRET=$SESSION_SECRET
# ENV DATABASE_URL=$DATABASE_URL
# ENV GITHUB_CLIENT_ID=$GITHUB_CLIENT_ID
# ENV GITHUB_REDIRECT_URI=$GITHUB_REDIRECT_URI
# ENV GITHUB_SECRET=$GITHUB_SECRET
# ENV GITHUB_PERSONAL_ACCESS_TOKEN=$GITHUB_PERSONAL_ACCESS_TOKEN
# ENV REDIS_HTTP_URL=$REDIS_HTTP_URL
ENV REDIS_HTTP_USERNAME=user
ENV REDIS_HTTP_PASSWORD=password

Expand All @@ -56,7 +53,9 @@ RUN adduser --system --uid 1001 nextjs
# Don't forget to put the build cache in the artifact
COPY --from=deps /app/node_modules ./node_modules

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

COPY . .

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

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

0 comments on commit c2e9c2e

Please sign in to comment.