Skip to content

Commit e5a29d7

Browse files
committed
chore: migrate from bun to pnpm and enhance docker workflow
- Replace bun with pnpm for package management to resolve build compatibility issues - Update Dockerfile to use Node.js 24 official image instead of bun - Replace bun build with rolldown for migrate script bundling - Add GitHub Actions workflow for automated Docker image building and pushing - Configure Docker Hub login, build caching, and smart tagging strategy - Support tag-based and branch-based deployment with proper cache optimization
1 parent d497ba0 commit e5a29d7

File tree

6 files changed

+15857
-3604
lines changed

6 files changed

+15857
-3604
lines changed

.github/workflows/docker-image.yml

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
name: Build and Push Docker Image
2+
3+
on:
4+
push:
5+
branches: ["main"]
6+
tags: ["v*"]
7+
pull_request:
8+
branches: ["main"]
9+
workflow_dispatch:
10+
11+
concurrency:
12+
group: ${{ github.workflow }}-${{ github.ref }}
13+
cancel-in-progress: true
14+
15+
env:
16+
IMAGE_NAME: demomacro/js.gs
17+
18+
jobs:
19+
build:
20+
runs-on: ubuntu-latest
21+
22+
permissions:
23+
contents: read
24+
packages: write
25+
26+
steps:
27+
- uses: actions/checkout@v4
28+
29+
- name: Log in to Docker Hub
30+
if: github.event_name != 'pull_request'
31+
uses: docker/login-action@v3
32+
with:
33+
username: ${{ secrets.DOCKER_USERNAME }}
34+
password: ${{ secrets.DOCKER_PASSWORD }}
35+
36+
- name: Set up Docker Buildx
37+
uses: docker/setup-buildx-action@v3
38+
39+
- name: Extract metadata for tags
40+
id: meta
41+
run: |
42+
if [[ $GITHUB_REF == refs/tags/* ]]; then
43+
VERSION=${GITHUB_REF#refs/tags/}
44+
echo "tags<<EOF" >> $GITHUB_OUTPUT
45+
echo "${{ env.IMAGE_NAME }}:${VERSION}" >> $GITHUB_OUTPUT
46+
echo "${{ env.IMAGE_NAME }}:latest" >> $GITHUB_OUTPUT
47+
echo "EOF" >> $GITHUB_OUTPUT
48+
else
49+
echo "tags<<EOF" >> $GITHUB_OUTPUT
50+
echo "${{ env.IMAGE_NAME }}:latest" >> $GITHUB_OUTPUT
51+
echo "${{ env.IMAGE_NAME }}:sha-${GITHUB_SHA::7}" >> $GITHUB_OUTPUT
52+
echo "EOF" >> $GITHUB_OUTPUT
53+
fi
54+
55+
- name: Build and push Docker images
56+
uses: docker/build-push-action@v6
57+
with:
58+
push: ${{ github.event_name != 'pull_request' }}
59+
cache-from: type=registry,ref=${{ env.IMAGE_NAME }}:cache
60+
cache-to: type=registry,ref=${{ env.IMAGE_NAME }}:cache,mode=max
61+
tags: ${{ steps.meta.outputs.tags }}
62+
file: ./Dockerfile

Dockerfile

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
1-
# use the official Bun image
2-
# see all versions at https://hub.docker.com/r/oven/bun/tags
3-
FROM oven/bun:1 AS build
1+
# use the official Node image
2+
# see all versions at https://hub.docker.com/_/node/tags
3+
FROM node:24-slim AS build
4+
RUN corepack enable
45
WORKDIR /app
56

6-
COPY package.json bun.lock* ./
7+
# Copy package.json and your lockfile, here we add pnpm-lock.yaml for illustration
8+
COPY package.json pnpm-lock.yaml .npmrc ./
79

810
# use ignore-scripts to avoid running postinstall hooks
9-
RUN bun install --frozen-lockfile --ignore-scripts
11+
RUN pnpm install --frozen-lockfile
1012

1113
# Copy the entire project
1214
COPY . .
@@ -15,13 +17,13 @@ COPY . .
1517
ENV NITRO_PRESET=node_cluster
1618
ENV NODE_ENV=production
1719
ENV SKIP_MIGRATE=true
18-
RUN bun --bun run build
20+
RUN pnpm run build
1921

20-
# Bundle migrate script into .output/scripts directory
21-
RUN bun build ./scripts/migrate.ts --outfile ./.output/scripts/migrate.mjs --target=bun --minify
22+
# Bundle migrate script into .output/scripts directory using rolldown
23+
RUN pnpx rolldown --input ./scripts/migrate.ts --format esm --file ./.output/scripts/migrate.mjs --minify --platform node --inlineDynamicImports
2224

2325
# copy production dependencies and source code into final image
24-
FROM oven/bun:1-alpine AS production
26+
FROM node:24-slim AS production
2527
WORKDIR /app
2628

2729
# Copy .output directory (which now contains migrate.mjs)
@@ -34,4 +36,4 @@ ENV PORT=3000
3436

3537
# run the app
3638
EXPOSE 3000/tcp
37-
ENTRYPOINT ["sh", "-c", "bun /app/scripts/migrate.mjs && bun --bun run /app/server/index.mjs"]
39+
ENTRYPOINT ["sh", "-c", "node /app/scripts/migrate.mjs && node /app/server/index.mjs"]

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,12 +63,12 @@ bun run preview
6363

6464
```bash
6565
# Build Docker image
66-
docker build -t JS.GS .
66+
docker build -t js.gs .
6767

6868
# Run container
6969
docker run -p 3000:3000 \
7070
--env-file .env \
71-
JS.GS
71+
js.gs
7272
```
7373

7474
## Support & Community

0 commit comments

Comments
 (0)