diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..52a79f5 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,9 @@ +Dockerfile +.dockerignore +node_modules +npm-debug.log +README.md +.next +!.next/static +!.next/standalone +.git \ No newline at end of file diff --git a/.env b/.env index b4d9f3a..15f9205 100644 --- a/.env +++ b/.env @@ -1 +1 @@ -API_URL=http://localhost:5183 \ No newline at end of file +API_URL=http://localhost:8080 \ No newline at end of file diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 82f00eb..dc88f59 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -15,50 +15,22 @@ jobs: - name: Checkout uses: actions/checkout@v4 - - name: Setup Node - uses: actions/setup-node@v4 - with: - node-version: '20' - cache: yarn - - - name: Restore cache - uses: actions/cache@v4 - with: - path: | - .next/cache - # Generate a new cache whenever packages or source files change. - key: ${{ runner.os }}-nextjs-${{ hashFiles('**/package-lock.json', '**/yarn.lock') }}-${{ hashFiles('**.[jt]s', '**.[jt]sx') }} - # If source files changed but packages didn't, rebuild from a prior cache. - restore-keys: | - ${{ runner.os }}-nextjs-${{ hashFiles('**/package-lock.json', '**/yarn.lock') }}- - - - name: Install dependencies - run: yarn install --immutable - - - name: Build - run: yarn build - env: - NODE_ENV: production - SENTRY_AUTH_TOKEN: ${{ github.event_name == 'push' && secrets.SENTRY_AUTH_TOKEN || '' }} - SENTRY_DSN: ${{ secrets.SENTRY_DSN }} - NEXT_PUBLIC_SENTRY_DSN: ${{ secrets.NEXT_PUBLIC_SENTRY_DSN }} - - name: Set up Docker Buildx uses: docker/setup-buildx-action@v3 - if: ${{ github.ref == 'refs/heads/master' }} - name: Log in to Docker Hub uses: docker/login-action@v3 - if: ${{ github.ref == 'refs/heads/master' }} with: username: ${{ secrets.DOCKER_USERNAME }} password: ${{ secrets.DOCKER_PASSWORD }} - name: Build and push Docker image uses: docker/build-push-action@v5 - if: ${{ github.ref == 'refs/heads/master' }} with: - push: true + push: ${{ github.ref == 'refs/heads/master' }} tags: benscobie/student-loan-repayment-calculator:latest context: . file: 'docker/Dockerfile.linux.amd64' + secrets: | + SENTRY_AUTH_TOKEN: ${{ github.event_name == 'push' && secrets.SENTRY_AUTH_TOKEN || '' }} + NEXT_PUBLIC_SENTRY_DSN: ${{ secrets.NEXT_PUBLIC_SENTRY_DSN }} diff --git a/docker/Dockerfile.linux.amd64 b/docker/Dockerfile.linux.amd64 index f618f53..968152d 100644 --- a/docker/Dockerfile.linux.amd64 +++ b/docker/Dockerfile.linux.amd64 @@ -1,18 +1,39 @@ -# Production image, copy all the files and run next -FROM node:20-alpine AS runner +FROM node:20-alpine AS base + +FROM base AS deps +RUN apk add --no-cache libc6-compat +WORKDIR /app + +COPY package.json yarn.lock .yarnrc.yml ./ +COPY .yarn/releases ./.yarn/releases +RUN yarn install --immutable + +FROM base AS builder +WORKDIR /app + +ARG NEXT_PUBLIC_SENTRY_DSN + +COPY --from=deps /app/node_modules ./node_modules +COPY . . + +ENV NEXT_TELEMETRY_DISABLED 1 + +RUN --mount=type=secret,id=SENTRY_AUTH_TOKEN \ + SENTRY_AUTH_TOKEN=$(cat /run/secrets/SENTRY_AUTH_TOKEN) \ + NEXT_PUBLIC_SENTRY_DSN=$NEXT_PUBLIC_SENTRY_DSN \ + yarn build + +FROM base AS runner WORKDIR /app -ENV NODE_ENV=production -# Uncomment the following line in case you want to disable telemetry during runtime. -ENV NEXT_TELEMETRY_DISABLED=1 +ENV NEXT_TELEMETRY_DISABLED 1 +ENV NODE_ENV production RUN addgroup --system --gid 1001 nodejs RUN adduser --system --uid 1001 nextjs -# You only need to copy next.config.js if you are NOT using the default configuration -COPY next.config.js ./ -COPY public ./public -COPY package.json ./package.json +COPY --from=builder /app/public ./public +COPY --from=builder /app/package.json ./package.json # Set the correct permission for prerender cache RUN mkdir .next @@ -20,14 +41,14 @@ RUN chown nextjs:nodejs .next # Automatically leverage output traces to reduce image size # https://nextjs.org/docs/advanced-features/output-file-tracing -COPY --chown=nextjs:nodejs .next/standalone ./ -COPY --chown=nextjs:nodejs .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 EXPOSE 3000 -ENV PORT=3000 -ENV HOSTNAME="0.0.0.0" +ENV PORT 3000 +ENV HOSTNAME "0.0.0.0" CMD ["node", "server.js"] \ No newline at end of file diff --git a/next.config.js b/next.config.js index 0591d0a..378e13e 100644 --- a/next.config.js +++ b/next.config.js @@ -34,7 +34,7 @@ module.exports = withSentryConfig(module.exports, { // https://github.com/getsentry/sentry-webpack-plugin#options // Suppresses source map uploading logs during build - silent: true, + silent: false, org: 'none-rai', project: 'slrc-frontend', // For all available options, see: