-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #23 from lispking/feat/issue-22
issue(#22): After optimizing NextJS, Dockerfile and ci process
- Loading branch information
Showing
15 changed files
with
2,729 additions
and
45 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
Dockerfile | ||
.dockerignore | ||
node_modules | ||
npm-debug.log | ||
README.md | ||
.next | ||
.git |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"extends": "next/core-web-vitals" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,118 @@ | ||
name: Build & Publish Images | ||
|
||
on: | ||
push: | ||
tags: | ||
- v[0-9]+.* | ||
|
||
permissions: | ||
contents: read | ||
packages: write | ||
|
||
jobs: | ||
build: | ||
name: Build Image | ||
runs-on: ubuntu-latest | ||
strategy: | ||
fail-fast: false | ||
matrix: | ||
platform: [linux/amd64, linux/arm64] | ||
bin: [playground] | ||
include: | ||
- bin: playground | ||
dockerfile: ./Dockerfile | ||
|
||
steps: | ||
- name: Set environment variable | ||
run: echo "IMAGE_NAME=ghcr.io/${{ github.repository_owner }}/${{ matrix.bin }}" >> $GITHUB_ENV | ||
|
||
- name: Checkout repository | ||
uses: actions/checkout@v4 | ||
|
||
- name: Set up Docker Buildx | ||
uses: docker/setup-buildx-action@v3 | ||
|
||
- name: Login to GitHub Container Registry | ||
uses: docker/login-action@v3 | ||
with: | ||
registry: ghcr.io | ||
username: ${{ github.actor }} | ||
password: ${{ secrets.GITHUB_TOKEN }} | ||
|
||
- name: Extract metadata (tags, labels) for Docker | ||
id: meta | ||
uses: docker/metadata-action@v5 | ||
with: | ||
images: ${{ env.IMAGE_NAME }} | ||
|
||
- name: Build and push image by digest | ||
id: build | ||
uses: docker/build-push-action@v5 | ||
with: | ||
context: . | ||
file: ${{ matrix.dockerfile }} | ||
platforms: ${{ matrix.platform }} | ||
labels: ${{ steps.meta.outputs.labels }} | ||
outputs: type=image,name=${{ env.IMAGE_NAME }},push-by-digest=true,name-canonical=true,push=true | ||
provenance: false | ||
cache-from: type=gha | ||
cache-to: type=gha | ||
|
||
- name: Export digest | ||
run: | | ||
mkdir -p "/tmp/digests/${{ matrix.bin }}" | ||
digest="${{ steps.build.outputs.digest }}" | ||
touch "/tmp/digests/${{ matrix.bin }}/${digest#sha256:}" | ||
- name: Upload digests | ||
uses: actions/upload-artifact@v4 | ||
with: | ||
name: ${{ matrix.bin }}-digests | ||
path: /tmp/digests/${{ matrix.bin }}/* | ||
if-no-files-found: error | ||
retention-days: 1 | ||
|
||
merge: | ||
name: Merge digests | ||
runs-on: ubuntu-latest | ||
needs: build | ||
strategy: | ||
fail-fast: false | ||
matrix: | ||
bin: [playground] | ||
|
||
steps: | ||
- name: Set environment variable | ||
run: echo "IMAGE_NAME=ghcr.io/${{ github.repository_owner }}/${{ matrix.bin }}" >> $GITHUB_ENV | ||
|
||
- name: Download digests | ||
uses: actions/download-artifact@v4 | ||
with: | ||
name: ${{ matrix.bin }}-digests | ||
path: /tmp/digests/${{ matrix.bin }} | ||
|
||
- name: Set up Docker Buildx | ||
uses: docker/setup-buildx-action@v3 | ||
|
||
- name: Extract metadata (tags, labels) for Docker | ||
id: meta | ||
uses: docker/metadata-action@v5 | ||
with: | ||
images: ${{ env.IMAGE_NAME }} | ||
|
||
- name: Login to GitHub Container Registry | ||
uses: docker/login-action@v3 | ||
with: | ||
registry: ghcr.io | ||
username: ${{ github.actor }} | ||
password: ${{ secrets.GITHUB_TOKEN }} | ||
|
||
- name: Create manifest list and push | ||
working-directory: /tmp/digests/${{ matrix.bin }} | ||
run: | | ||
docker buildx imagetools create $(jq -cr '.tags | map("-t " + .) | join(" ")' <<< "$DOCKER_METADATA_OUTPUT_JSON") \ | ||
$(printf '${{ env.IMAGE_NAME }}@sha256:%s ' *) | ||
- name: Inspect image | ||
run: | | ||
docker buildx imagetools inspect ${{ env.IMAGE_NAME }}:${{ steps.meta.outputs.version }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -57,4 +57,3 @@ dist-ssr | |
*.sw? | ||
|
||
package-lock.json | ||
yarn.lock |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,46 @@ | ||
# docker build -t amphitheatre-playground:v0.0.1 . | ||
FROM node:18-buster-slim AS build | ||
# | ||
# docker build -t ghcr.io/amphitheatre-app/playground:v0.0.1 . | ||
# | ||
FROM node:21-slim AS base | ||
|
||
WORKDIR /app/playground | ||
COPY package*.json ./ | ||
RUN npm i | ||
# Install dependencies only when needed | ||
FROM base AS deps | ||
WORKDIR /app | ||
COPY package.json ./ | ||
RUN yarn config set registry https://registry.npmmirror.com | ||
RUN yarn --frozen-lockfile | ||
|
||
# Rebuild the source code only when needed | ||
FROM base AS builder | ||
WORKDIR /app | ||
COPY --from=deps /app/node_modules ./node_modules | ||
COPY . . | ||
RUN yarn build | ||
|
||
RUN npm run build | ||
# Production image, copy all the files and run next | ||
FROM base AS runner | ||
WORKDIR /app | ||
|
||
FROM node:18-buster-slim AS prod | ||
ENV NODE_ENV production | ||
|
||
WORKDIR /home/app | ||
RUN npm uninstall -g yarn | ||
|
||
COPY --from=build /app/playground/dist /home/app/dist | ||
COPY --from=build /app/playground/node_modules /home/app/node_modules | ||
RUN addgroup --system --gid 1001 nodejs | ||
RUN adduser --system --uid 1001 nextjs | ||
|
||
ENV NODE_ENV production | ||
# Automatically leverage output traces to reduce image size | ||
# https://nextjs.org/docs/advanced-features/output-file-tracing | ||
COPY --from=builder --chown=nextjs:nodejs /app/build/standalone ./ | ||
COPY --from=builder --chown=nextjs:nodejs /app/build/static ./build/static | ||
COPY --from=builder --chown=nextjs:nodejs /app/public ./public | ||
COPY --from=builder --chown=nextjs:nodejs /app/node_modules ./node_modules | ||
COPY --from=builder --chown=nextjs:nodejs /app/package.json ./package.json | ||
|
||
USER nextjs | ||
|
||
# set hostname to localhost | ||
ENV HOSTNAME "0.0.0.0" | ||
ENV PORT 3000 | ||
EXPOSE $PORT | ||
|
||
CMD [ "./node_modules/vite/bin/vite.js", "./dist" ] | ||
CMD ["node", "server.js"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
/** @type {import('next').NextConfig} */ | ||
const nextConfig = { | ||
distDir: 'build', | ||
output: 'standalone', | ||
experimental: { | ||
turbotrace: { | ||
logAll: true, | ||
}, | ||
}, | ||
} | ||
export default nextConfig |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.