Skip to content

Commit

Permalink
feat: container support
Browse files Browse the repository at this point in the history
  • Loading branch information
besscroft committed May 3, 2024
1 parent 51f6e78 commit 2314604
Show file tree
Hide file tree
Showing 16 changed files with 416 additions and 12 deletions.
10 changes: 10 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
Dockerfile
.dockerignore
node_modules
npm-debug.log
README.md
.next
.git
.idea
.github
.gitignore
36 changes: 36 additions & 0 deletions .github/workflows/build-dev.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
name: Dev Docker Multi-arch Image CI & CD

on:
push:
branches:
- dev

jobs:
build:
name: Running Compile Next Multi-arch Docker Image
runs-on: ubuntu-latest
steps:
- name: Checkout PicImpact
uses: actions/checkout@v4
- name: Get Version
id: get_version
run: echo ::set-output name=VERSION::${GITHUB_REF#refs/tags/}
- name: Login to Docker Hub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
- name: Set up Docker Buildx
id: set_up_buildx
uses: docker/setup-buildx-action@v3
- name: Build and push dev
id: docker_build
uses: docker/build-push-action@v5
with:
context: ./
file: ./Dockerfile
platforms: linux/amd64,linux/arm64
push: true
tags: ${{ secrets.DOCKERHUB_USERNAME }}/picimpact:dev
45 changes: 45 additions & 0 deletions .github/workflows/build-release.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
name: Dev Docker Multi-arch Image CI & CD

on:
push:
tags:
- 'v*'

jobs:
build:
name: Running Compile Next Multi-arch Docker Image
runs-on: ubuntu-latest
steps:
- name: Checkout PicImpact
uses: actions/checkout@v4
- name: Get Version
id: get_version
run: echo ::set-output name=VERSION::${GITHUB_REF#refs/tags/}
- name: Login to Docker Hub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
- name: Set up Docker Buildx
id: set_up_buildx
uses: docker/setup-buildx-action@v3
- name: Build and push latest
id: docker_build
uses: docker/build-push-action@v5
with:
context: ./
file: ./Dockerfile
platforms: linux/amd64,linux/arm64,linux/arm/v7,linux/ppc64le,linux/s390x
push: true
tags: ${{ secrets.DOCKERHUB_USERNAME }}/picimpact:latest
- name: Build and push version
id: docker_build
uses: docker/build-push-action@v5
with:
context: ./
file: ./Dockerfile
platforms: linux/amd64,linux/arm64,linux/arm/v7,linux/ppc64le,linux/s390x
push: true
tags: ${{ secrets.DOCKERHUB_USERNAME }}/picimpact:${{ steps.get_version.outputs.VERSION }}
53 changes: 53 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
FROM node:18-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

COPY package.json pnpm-lock.yaml* .npmrc ./

RUN corepack enable pnpm && pnpm i --frozen-lockfile

FROM base AS builder

WORKDIR /app

COPY --from=deps /app/node_modules ./node_modules
COPY . .

RUN AUTH_SECRET=pic-impact export NODE_OPTIONS=--openssl-legacy-provider && corepack enable pnpm && pnpm run prisma:generate && pnpm run build

FROM base AS runner

WORKDIR /app

ENV NODE_ENV production

RUN addgroup --system --gid 1001 nodejs
RUN adduser --system --uid 1001 nextjs

COPY --from=builder /app/public ./public
COPY ./prisma ./prisma
COPY ./script.sh ./script.sh

RUN chmod +x script.sh
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

USER nextjs

ENV AUTH_TRUST_HOST true

EXPOSE 3000

ENV PORT 3000

CMD ./script.sh
4 changes: 3 additions & 1 deletion app/api/get-link/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,6 @@ import { fetchTagsShow } from '~/server/lib/query'
export async function GET() {
const data = await fetchTagsShow();
return Response.json(data)
}
}

export const dynamic = 'force-dynamic'
4 changes: 3 additions & 1 deletion app/api/v1/alist-info/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,6 @@ import { fetchAListInfo } from '~/server/lib/query'
export async function GET() {
const data = await fetchAListInfo();
return Response.json(data)
}
}

export const dynamic = 'force-dynamic'
4 changes: 3 additions & 1 deletion app/api/v1/get-images-json/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,6 @@ import { fetchAllImages } from '~/server/lib/query'
export async function GET() {
const data = await fetchAllImages();
return Response.json(data)
}
}

export const dynamic = 'force-dynamic'
4 changes: 3 additions & 1 deletion app/api/v1/get-tags/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,6 @@ import { fetchTagsList } from '~/server/lib/query'
export async function GET() {
const data = await fetchTagsList();
return Response.json(data)
}
}

export const dynamic = 'force-dynamic'
4 changes: 3 additions & 1 deletion app/api/v1/r2-info/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,6 @@ import { fetchR2Info } from '~/server/lib/query'
export async function GET() {
const data = await fetchR2Info();
return Response.json(data)
}
}

export const dynamic = 'force-dynamic'
4 changes: 3 additions & 1 deletion app/api/v1/s3-info/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,6 @@ import { fetchS3Info } from '~/server/lib/query'
export async function GET() {
const data = await fetchS3Info();
return Response.json(data)
}
}

export const dynamic = 'force-dynamic'
2 changes: 1 addition & 1 deletion instrumentation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export async function register() {
skipDuplicates: true,
})
})
console.log('数据库初始化完毕!')
console.log('初始化完毕!')
await prisma.$disconnect()
} else {
console.error('数据库初始化失败,请检查您的连接信息!')
Expand Down
1 change: 1 addition & 0 deletions next.config.mjs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/** @type {import('next').NextConfig} */
const nextConfig = {
output: "standalone",
experimental: {
serverComponentsExternalPackages: ['pg'],
instrumentationHook: true,
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
"react-dom": "^18.2.0",
"react-photo-album": "^2.3.1",
"server-only": "^0.0.1",
"sharp": "^0.33.3",
"sonner": "^1.4.41",
"swr": "^2.2.5",
"tailwind-merge": "^2.2.2",
Expand Down
Loading

0 comments on commit 2314604

Please sign in to comment.