Skip to content

Commit

Permalink
Merge pull request #38 from hackerspace-ntnu/lighthouse
Browse files Browse the repository at this point in the history
Lighthouse
  • Loading branch information
ZeroWave022 authored Sep 20, 2024
2 parents 00319d2 + 7820cd0 commit 2c43b1d
Show file tree
Hide file tree
Showing 11 changed files with 198 additions and 30 deletions.
5 changes: 3 additions & 2 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
# should be updated accordingly.

# General
NEXT_TELEMETRY_DISABLED="true"
NODE_ENV="development"
NEXT_PUBLIC_SITE_URL="http://localhost:3000"

Expand All @@ -28,8 +29,8 @@ STORAGE_PASSWORD="password"
STORAGE_NAME="images"

# Auth
FEIDE_CLIENT_ID=
FEIDE_CLIENT_SECRET=
FEIDE_CLIENT_ID=" "
FEIDE_CLIENT_SECRET=" "
FEIDE_AUTHORIZATION_ENDPOINT="https://auth.dataporten.no/oauth/authorization"
FEIDE_TOKEN_ENDPOINT="https://auth.dataporten.no/oauth/token"
FEIDE_USERINFO_ENDPOINT="https://auth.dataporten.no/openid/userinfo"
58 changes: 58 additions & 0 deletions .github/workflows/code-quality.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
name: Code Quality

on:
pull_request:
workflow_dispatch:

jobs:
lint-format:
name: Lint & Format
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Setup Biome
uses: biomejs/setup-biome@v2
with:
version: latest
- name: Run Biome
run: biome ci .
performance-audit:
name: Performance Audit
runs-on: ubuntu-latest
env:
NEXT_TELEMETRY_DISABLED: true
NODE_ENV: "production"
NEXT_PUBLIC_SITE_URL: "http://localhost:3000"
DATABASE_HOST: "localhost"
DATABASE_PORT: "5432"
DATABASE_USER: "user"
DATABASE_PASSWORD: "password"
DATABASE_NAME: "database"
STORAGE_HOST: "localhost"
STORAGE_PORT: "9000"
STORAGE_USER: "user"
STORAGE_PASSWORD: "password"
STORAGE_NAME: "images"
FEIDE_CLIENT_ID: " "
FEIDE_CLIENT_SECRET: " "
FEIDE_AUTHORIZATION_ENDPOINT: "https://auth.dataporten.no/oauth/authorization"
FEIDE_TOKEN_ENDPOINT: "https://auth.dataporten.no/oauth/token"
FEIDE_USERINFO_ENDPOINT: "https://auth.dataporten.no/openid/userinfo"
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Setup bun
uses: oven-sh/setup-bun@v2
with:
bun-version: latest
- name: Install Dependencies
run: bun install --frozen-lockfile
- name: Build
run: bun run build
- name: Run Lighthouse
env:
LHCI_GITHUB_APP_TOKEN: ${{ secrets.LHCI_GITHUB_APP_TOKEN }}
run: |
bun add -g @lhci/cli@0.13.x
lhci autorun
17 changes: 0 additions & 17 deletions .github/workflows/lint.yml

This file was deleted.

81 changes: 76 additions & 5 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,17 +1,88 @@
FROM imbios/bun-node:20-slim
FROM imbios/bun-node:22-slim AS base

# Install dependencies only when needed
FROM base AS deps

WORKDIR /app

COPY package.json bun.lockb ./
ENV NODE_ENV=production

RUN bun install --production --frozen-lockfile
# Install dependencies
COPY package.json bun.lockb ./
RUN bun install --frozen-lockfile

# Rebuild the source code only when needed
FROM base AS builder
WORKDIR /app
COPY --from=deps /app/node_modules ./node_modules
COPY . .

ENV NODE_ENV=production
ENV NEXT_TELEMETRY_DISABLED=1
ENV SKIP_ENV_VALIDATION=true

# Set environment variables during the build
ARG NEXT_PUBLIC_SITE_URL
ARG DATABASE_USER
ARG DATABASE_PASSWORD
ARG DATABASE_HOST
ARG DATABASE_PORT
ARG DATABASE_NAME
ARG STORAGE_HOST
ARG STORAGE_PORT
ARG STORAGE_USER
ARG STORAGE_PASSWORD
ARG STORAGE_NAME
ARG FEIDE_CLIENT_ID
ARG FEIDE_CLIENT_SECRET
ARG FEIDE_AUTHORIZATION_ENDPOINT
ARG FEIDE_TOKEN_ENDPOINT
ARG FEIDE_USERINFO_ENDPOINT

ENV NEXT_PUBLIC_SITE_URL=$NEXT_PUBLIC_SITE_URL
ENV DATABASE_USER=$DATABASE_USER
ENV DATABASE_PASSWORD=$DATABASE_PASSWORD
ENV DATABASE_HOST=$DATABASE_HOST
ENV DATABASE_PORT=$DATABASE_PORT
ENV DATABASE_NAME=$DATABASE_NAME
ENV STORAGE_HOST=$STORAGE_HOST
ENV STORAGE_PORT=$STORAGE_PORT
ENV STORAGE_USER=$STORAGE_USER
ENV STORAGE_PASSWORD=$STORAGE_PASSWORD
ENV STORAGE_NAME=$STORAGE_NAME
ENV FEIDE_CLIENT_ID=$FEIDE_CLIENT_ID
ENV FEIDE_CLIENT_SECRET=$FEIDE_CLIENT_SECRET
ENV FEIDE_AUTHORIZATION_ENDPOINT=$FEIDE_AUTHORIZATION_ENDPOINT
ENV FEIDE_TOKEN_ENDPOINT=$FEIDE_TOKEN_ENDPOINT
ENV FEIDE_USERINFO_ENDPOINT=$FEIDE_USERINFO_ENDPOINT

# Build the application
RUN bunx next build


# Production image, copy all the files and run next
FROM base AS runner
WORKDIR /app

ENV NODE_ENV=production
RUN bun run build
ENV NEXT_TELEMETRY_DISABLED=1
ENV SKIP_ENV_VALIDATION=true

RUN addgroup --system --gid 1002 nodejs && \
adduser --system --uid 1002 nextjs

COPY --from=builder /app/public ./public

# Set the correct permission for prerender cache
RUN mkdir .next && chown nextjs:nodejs .next

# Automatically leverage output traces to reduce image size
COPY --from=builder --chown=nextjs:nodejs /app/.next/standalone ./
COPY --from=builder --chown=nextjs:nodejs /app/.next/static ./.next/static

USER nextjs

EXPOSE 3000

ENTRYPOINT [ "bun", "run", "start" ]
# server.js is created by next build from the standalone output
CMD ["bun", "run", "server.js"]
Binary file modified bun.lockb
Binary file not shown.
17 changes: 17 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,23 @@ services:
build:
context: .
dockerfile: Dockerfile
args:
- NEXT_PUBLIC_SITE_URL
- DATABASE_HOST
- DATABASE_PORT
- DATABASE_USER
- DATABASE_PASSWORD
- DATABASE_NAME
- STORAGE_HOST
- STORAGE_PORT
- STORAGE_USER
- STORAGE_PASSWORD
- STORAGE_NAME
- FEIDE_CLIENT_ID
- FEIDE_CLIENT_SECRET
- FEIDE_AUTHORIZATION_ENDPOINT
- FEIDE_TOKEN_ENDPOINT
- FEIDE_USERINFO_ENDPOINT
ports:
- "3000:3000"
db:
Expand Down
37 changes: 37 additions & 0 deletions lighthouserc.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
ci:
collect:
url:
- 'http://localhost:3000/en'
- 'http://localhost:3000/en/events'
- 'http://localhost:3000/en/news'
- 'http://localhost:3000/en/news/1'
- 'http://localhost:3000/en/about'
startServerCommand: 'bun run start'
upload:
target: 'temporary-public-storage'
assert:
preset: 'lighthouse:recommended'
assertions:
first-contentful-paint:
- error
- maxNumericValue: 2000
aggregationMethod: optimistic
interactive:
- error
- maxNumericValue: 5000
aggregationMethod: optimistic
bf-cache: 'off'
csp-xss: 'off'
identical-links-same-purpose: 'off'
total-byte-weight: 'off'
color-contrast: 'off'
heading-order: 'off'
mainthread-work-breakdown: 'off'
bootup-time: 'off'
largest-contentful-paint: 'off'
dom-size: 'off'
render-blocking-resources: 'off'
server-response-time: 'off'
uses-responsive-images: 'off'
maskable-icon: 'off'
installable-manifest: 'off'
4 changes: 1 addition & 3 deletions next-sitemap.config.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import { env } from '@/env';

/** @type {import('next-sitemap').IConfig} */
const config = {
siteUrl: env.NEXT_PUBLIC_SITE_URL,
siteUrl: process.env.NEXT_PUBLIC_SITE_URL ?? '',
generateRobotsTxt: true,
generateIndexSitemap: false,
};
Expand Down
5 changes: 4 additions & 1 deletion next.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ await import('./src/env.js');
const withNextIntl = nextIntl('./src/lib/locale/i18n.ts');

/** @type {import("next").NextConfig} */
const config = {};
const config = {
reactStrictMode: true,
output: 'standalone',
};

export default withNextIntl(config);
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"private": true,
"type": "module",
"scripts": {
"prepare": "lefthook install",
"prepare": "if [ \"$NODE_ENV\" != \"production\" ]; then lefthook install; fi",
"postbuild": "next-sitemap",
"prebuild": "next telemetry disable",
"build": "next build",
Expand Down
2 changes: 1 addition & 1 deletion src/server/s3/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,6 @@ const s3 =
if (env.NODE_ENV !== 'production') globalForS3.s3 = s3;

const buckets = env.STORAGE_NAME.split(',');
const imageBucket = buckets[0] as string;
const imageBucket = buckets[0];

export { s3, endpoint, imageBucket, PutObjectCommand, DeleteObjectCommand };

0 comments on commit 2c43b1d

Please sign in to comment.