From 0e905c42f0f9eb87e8e8c89b9ed54d75ac4d265f Mon Sep 17 00:00:00 2001 From: Felipe Fink Grael Date: Tue, 23 Jan 2024 13:58:57 -0300 Subject: [PATCH] build: Change frontend build to production configuration --- .github/workflows/build-frontend.yaml | 4 +++- frontend/Dockerfile | 25 ++++++++++--------------- frontend/next.config.js | 4 +++- 3 files changed, 16 insertions(+), 17 deletions(-) diff --git a/.github/workflows/build-frontend.yaml b/.github/workflows/build-frontend.yaml index 0ebdae3..aae5b6b 100644 --- a/.github/workflows/build-frontend.yaml +++ b/.github/workflows/build-frontend.yaml @@ -22,7 +22,9 @@ jobs: - uses: actions/checkout@v4 - name: Build image - run: docker build frontend/ --file frontend/Dockerfile --tag $IMAGE_NAME --label "runnumber=${GITHUB_RUN_ID}" + run: docker build frontend/ --file frontend/Dockerfile --tag $IMAGE_NAME --label "runnumber=${GITHUB_RUN_ID}" --build-arg "NEXT_PUBLIC_CARTESI_NODE_URL=$NEXT_PUBLIC_CARTESI_NODE_URL" + env: + NEXT_PUBLIC_CARTESI_NODE_URL: ${{ vars.NEXT_PUBLIC_CARTESI_NODE_URL }} - name: Log in to registry run: echo "${{ secrets.GITHUB_TOKEN }}" | docker login ghcr.io -u $ --password-stdin diff --git a/frontend/Dockerfile b/frontend/Dockerfile index d4ec2cb..7fcad5d 100644 --- a/frontend/Dockerfile +++ b/frontend/Dockerfile @@ -28,11 +28,10 @@ WORKDIR /app COPY --from=deps /app/node_modules ./node_modules COPY . . - +ARG NEXT_PUBLIC_CARTESI_NODE_URL ENV NEXT_TELEMETRY_DISABLED 1 -# FIXME: uncomment this for production -# RUN npm run build +RUN npm run build # Production image, copy all the files and run next FROM base AS runner @@ -41,17 +40,15 @@ LABEL org.opencontainers.image.source https://github.com/prototyp3-dev/world-arc WORKDIR /app -# FIXME: uncomment this for production -# ENV NODE_ENV production + +ENV NODE_ENV production ENV NEXT_TELEMETRY_DISABLED 1 RUN addgroup --system --gid 1001 nodejs RUN adduser --system --uid 1001 nextjs -# FIXME: uncomment this for production -# COPY --from=builder /app/public ./public -RUN chown -R nextjs:nodejs /app -COPY --from=builder --chown=nextjs:nodejs /app/ ./ + +COPY --from=builder /app/public ./public # Set the correct permission for prerender cache RUN mkdir .next @@ -59,9 +56,8 @@ RUN chown nextjs:nodejs .next # Automatically leverage output traces to reduce image size # https://nextjs.org/docs/advanced-features/output-file-tracing -# FIXME: uncomment this for production -# COPY --from=builder --chown=nextjs:nodejs /app/.next/standalone ./ -# COPY --from=builder --chown=nextjs:nodejs /app/.next/static ./.next/static +COPY --from=builder --chown=nextjs:nodejs /app/.next/standalone ./ +COPY --from=builder --chown=nextjs:nodejs /app/.next/static ./.next/static USER nextjs @@ -73,6 +69,5 @@ ENV HOSTNAME "0.0.0.0" # server.js is created by next build from the standalone output # https://nextjs.org/docs/pages/api-reference/next-config-js/output -# FIXME: uncomment this for production -# CMD ["node", "server.js"] -CMD ["npm", "run", "dev"] +CMD ["node", "server.js"] + diff --git a/frontend/next.config.js b/frontend/next.config.js index 767719f..445e35f 100644 --- a/frontend/next.config.js +++ b/frontend/next.config.js @@ -1,4 +1,6 @@ /** @type {import('next').NextConfig} */ -const nextConfig = {} +const nextConfig = { + output: 'standalone' +} module.exports = nextConfig