Skip to content

Commit

Permalink
use bun
Browse files Browse the repository at this point in the history
  • Loading branch information
xcodeassociated committed Oct 11, 2024
1 parent 0e7f396 commit cbca5f4
Show file tree
Hide file tree
Showing 6 changed files with 62 additions and 9,948 deletions.
15 changes: 15 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
node_modules
Dockerfile*
docker-compose*
.dockerignore
.git
.gitignore
README.md
LICENSE
.vscode
Makefile
helm-charts
.env
.editorconfig
.idea
coverage*
24 changes: 7 additions & 17 deletions .github/workflows/build-and-test.yml
Original file line number Diff line number Diff line change
@@ -1,43 +1,33 @@
name: NodeJS with Webpack
name: Bun Build with Docker

on:
push:
branches: ['main', 'release/*']
branches: ['**']
pull_request:
branches: ['**']

jobs:
build:
runs-on: ubuntu-latest

strategy:
matrix:
node-version: [18.x]

steps:
- uses: actions/checkout@v4

- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node-version }}
- uses: oven-sh/setup-bun@v2

- name: Install dependencies
run: npm install
run: bun install --frozen-lockfile

- name: Run the tests
run: npm test
run: bun run test

- name: Build
run: npm run build
run: bun run build
env:
CI: false

docker:

runs-on: ubuntu-latest
needs: build

steps:
- name: Checkout
uses: actions/checkout@v4
Expand All @@ -56,4 +46,4 @@ jobs:
context: .
push: true
platforms: linux/amd64, linux/arm64
tags: xcodeassociated/softeno-nextjs-website:latest
tags: xcodeassociated/nextjs-template:latest
75 changes: 22 additions & 53 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,67 +1,36 @@
FROM node:18-alpine AS base
# Stage 1: Build the application
FROM oven/bun:1.1-slim as builder

Check warning on line 2 in Dockerfile

View workflow job for this annotation

GitHub Actions / docker

The 'as' keyword should match the case of the 'from' keyword

FromAsCasing: 'as' and 'FROM' keywords' casing do not match More info: https://docs.docker.com/go/dockerfile/rule/from-as-casing/

# Install dependencies only when needed
FROM base AS deps
# Check https://github.com/nodejs/docker-node/tree/b4117f9333da4138b03a546ec926ef50a31506c3#nodealpine to understand why libc6-compat might be needed.
RUN apk add --no-cache libc6-compat
# Set working directory
WORKDIR /app

# Install dependencies based on the preferred package manager
COPY package.json yarn.lock* package-lock.json* pnpm-lock.yaml* ./
RUN \
if [ -f yarn.lock ]; then yarn --frozen-lockfile; \
elif [ -f package-lock.json ]; then npm ci; \
elif [ -f pnpm-lock.yaml ]; then corepack enable pnpm && pnpm i --frozen-lockfile; \
else echo "Lockfile not found." && exit 1; \
fi
# Copy the package and lock file
COPY package.json bun.lockb ./

# Install dependencies using Bun
RUN bun install

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

# Next.js collects completely anonymous telemetry data about general usage.
# Learn more here: https://nextjs.org/telemetry
# Uncomment the following line in case you want to disable telemetry during the build.
# ENV NEXT_TELEMETRY_DISABLED 1

RUN \
if [ -f yarn.lock ]; then yarn run build; \
elif [ -f package-lock.json ]; then npm run build; \
elif [ -f pnpm-lock.yaml ]; then corepack enable pnpm && pnpm run build; \
else echo "Lockfile not found." && exit 1; \
fi

# Production image, copy all the files and run next
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

RUN addgroup --system --gid 1001 nodejs
RUN adduser --system --uid 1001 nextjs
# Build the application
RUN bun next build

COPY --from=builder /app/public ./public
# Stage 2: Run the application
FROM oven/bun:1.1-alpine as runner

Check warning on line 20 in Dockerfile

View workflow job for this annotation

GitHub Actions / docker

The 'as' keyword should match the case of the 'from' keyword

FromAsCasing: 'as' and 'FROM' keywords' casing do not match More info: https://docs.docker.com/go/dockerfile/rule/from-as-casing/

# Set the correct permission for prerender cache
RUN mkdir .next
RUN chown nextjs:nodejs .next
# Set environment variables (optional, based on your app)
ENV NODE_ENV=production
ENV PORT=3000

# Automatically leverage output traces to reduce image size
# https://nextjs.org/docs/advanced-features/output-file-tracing
COPY --from=builder --chown=nextjs:nodejs /app/.next/standalone ./
COPY --from=builder --chown=nextjs:nodejs /app/.next/static ./.next/static
# Set working directory
WORKDIR /app

USER nextjs
# Copy built files from the builder stage
COPY --from=builder /app ./

# Expose port
EXPOSE 3000

ENV PORT 3000

# server.js is created by next build from the standalone output
# https://nextjs.org/docs/pages/api-reference/next-config-js/output
CMD HOSTNAME="0.0.0.0" node server.js
# Start the application
CMD ["bun", "next", "start"]
Binary file added bun.lockb
Binary file not shown.
Loading

0 comments on commit cbca5f4

Please sign in to comment.