Skip to content

Commit

Permalink
add dockerfile
Browse files Browse the repository at this point in the history
  • Loading branch information
seadfeng committed Aug 23, 2024
1 parent 867d876 commit 34b7b46
Show file tree
Hide file tree
Showing 12 changed files with 1,275 additions and 1,545 deletions.
74 changes: 74 additions & 0 deletions .docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
FROM node:20-alpine AS base

# 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
WORKDIR /app

RUN node -v

# Install dependencies based on the preferred package manager
COPY package.json yarn.lock* package-lock.json* pnpm-lock.yaml* ./
RUN ls -la
RUN \
if [ -f yarn.lock ]; then yarn --frozen-lockfile; \
elif [ -f package-lock.json ]; then npm ci; \
elif [ -f pnpm-lock.yaml ]; then yarn global add pnpm && pnpm i --frozen-lockfile; \
else echo "Lockfile not found." && exit 1; \
fi


# Rebuild the source code only when needed
FROM base AS builder
WORKDIR /app
COPY --from=deps /app/node_modules ./node_modules
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 npm run build

RUN ls -la /app/.next/standalone

# If using npm comment out above and use below instead
# RUN npm run build

# 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

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

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

# 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

RUN ls -la /app

USER nextjs

EXPOSE 3000

ENV PORT 3000
# set hostname to localhost
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
CMD ["node", "server.js"]
6 changes: 6 additions & 0 deletions .docker/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@

## Docker Build

```sh
sh ./bin/docker.sh
```
1 change: 1 addition & 0 deletions .docker/compose/.env
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
NEXT_PUBLIC_GA_ID=
7 changes: 7 additions & 0 deletions .docker/compose/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
services:
app:
extends:
file: services.yml
service: app
ports:
- 127.0.0.1:3000:3000
4 changes: 4 additions & 0 deletions .docker/compose/services.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
services:
app:
image: ghcr.io/seadfeng/font-generator:latest
env_file: .env
10 changes: 10 additions & 0 deletions .docker/compose/update_and_restart.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#!/usr/bin/env bash

# Pull the latest images
docker compose pull

# Rebuild and start the app
docker compose up -d --no-deps --build app

# Clean up unused Docker resources
docker system prune -f
24 changes: 24 additions & 0 deletions .github/workflows/docker-build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
name: "Docker Build CI"
on:
push:
branches: ["main"]
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout Repository
uses: actions/checkout@v3

- name: Set up QEMU
uses: docker/setup-qemu-action@v3

- name: Setup Docker Buildx
id: docker_buildx
uses: docker/setup-buildx-action@v3

- name: Docker Build
run: |
echo ${{ secrets.DOCKER_LOGIN }} | docker login ghcr.io -u ${{ github.actor }} --password-stdin
docker buildx create --use
docker buildx inspect --bootstrap
docker buildx build --push -t ghcr.io/${{ github.repository }}:latest -f .docker/Dockerfile .
15 changes: 15 additions & 0 deletions bin/docker.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#!/bin/bash

VERSION=$(node -p "require('./package.json').version")
APP=$(node -p "require('./package.json').name")

echo "Build: ${APP}.${VERSION}"

docker buildx build \
--no-cache \
--build-arg VERSION=$VERSION \
-t ${APP}:$VERSION \
-f .docker/Dockerfile \
.

docker tag ${APP}:$VERSION ${APP}:latest
9 changes: 8 additions & 1 deletion bin/transforms.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import fonts from "@/fonts";
import { fonts, superFonts } from "@/fonts";
import fs from 'fs';
import path from 'path';

Expand All @@ -17,6 +17,13 @@ Object.keys(fonts).forEach((fontKey) => {
Array.from(normalChars).map((char, index) => {
transforms[fontKey][char] = Array.from(currentChars)[index]
})
if (fontKey in superFonts) {
transforms[fontKey] = {
...transforms[fontKey],
...superFonts[fontKey]
}
}

}
});

Expand Down
1 change: 1 addition & 0 deletions next.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import nextIntlPlugin from "next-intl/plugin";
const withNextIntl = nextIntlPlugin("./src/i18n.ts");

const nextConfig = {
output: 'standalone',
eslint: {
dirs: ["src"],
},
Expand Down
Loading

0 comments on commit 34b7b46

Please sign in to comment.