diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..1380c2e --- /dev/null +++ b/.dockerignore @@ -0,0 +1,2 @@ +node_modules +.next \ No newline at end of file diff --git a/.github/workflows/lighthouse.yml b/.github/workflows/lighthouse.yml index fc903ca..03e5c8d 100644 --- a/.github/workflows/lighthouse.yml +++ b/.github/workflows/lighthouse.yml @@ -7,6 +7,8 @@ jobs: # Build job build-and-test: runs-on: ubuntu-latest + env: + LIGHTHOUSE: 'true' steps: - name: Checkout uses: actions/checkout@v3 diff --git a/Dockerfile.prod b/Dockerfile.prod new file mode 100644 index 0000000..e884575 --- /dev/null +++ b/Dockerfile.prod @@ -0,0 +1,31 @@ +# Builder Stage +FROM node:18-alpine AS builder + +WORKDIR /app + +COPY package*.json ./ + +RUN npm ci + +COPY . . + +RUN npm run build + +# Production Stage + +FROM node:18-alpine AS production + +WORKDIR /app + +# Copy the built artifacts from the builder stage +COPY --from=builder /app/.next/standalone ./ +COPY --from=builder /app/.next/static ./.next/static +COPY --from=builder /app/public ./public + +# Set the environment variables (if needed) +ENV NODE_ENV=production +ENV NEXT_TELEMETRY_DISABLED=1 + +EXPOSE 3000 + +CMD ["node", "server.js"] \ No newline at end of file diff --git a/next.config.js b/next.config.js index 8ee7474..9f3d15d 100644 --- a/next.config.js +++ b/next.config.js @@ -4,15 +4,15 @@ const path = require('path'); * @type {import('next').NextConfig} */ const nextConfig = { - output: 'export', + output: process.env.LIGHTHOUSE ? 'export' : 'standalone', reactStrictMode: true, swcMinify: true, images: { loader: 'custom', loaderFile: './akamai-loader.js', }, - basePath: '/dibbs-site', - assetPrefix: '/dibbs-site', + basePath: process.env.NODE_ENV === 'production' ? '/dibbs-site' : '', + assetPrefix: process.env.NODE_ENV === 'production' ? '/dibbs-site' : '', sassOptions: { includePaths: [ path.join(__dirname, './', 'node_modules', '@uswds', 'uswds', 'packages'), diff --git a/package.json b/package.json index 6455784..36e896f 100644 --- a/package.json +++ b/package.json @@ -8,7 +8,9 @@ "start": "next start", "lint": "next lint", "prepare": "husky", - "fmt": "prettier --write ." + "fmt": "prettier --write .", + "docker-build-prod": "docker build -f Dockerfile.prod -t dibbs-site:prod .", + "docker-run-prod": "docker run -p 3000:3000 dibbs-site:prod" }, "lint-staged": { "**/*": "prettier --write --ignore-unknown" diff --git a/src/app/utils/constants.ts b/src/app/utils/constants.ts index 57f628d..5d69f69 100644 --- a/src/app/utils/constants.ts +++ b/src/app/utils/constants.ts @@ -1,3 +1,3 @@ -const basePath = '/dibbs-site'; +const basePath = process.env.NODE_ENV === 'production' ? '/dibbs-site' : ''; export { basePath };