Skip to content

Commit 22d18ea

Browse files
committed
feat: add Docker image build and push to GHCR on release
Add Dockerfile (multi-stage build with node:22-slim) and a new docker job in the release workflow that builds and pushes to ghcr.io when release-please creates a tag.
1 parent f6a4455 commit 22d18ea

3 files changed

Lines changed: 103 additions & 0 deletions

File tree

.dockerignore

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
node_modules
2+
dist
3+
.git
4+
.gitignore
5+
.env
6+
.env.*
7+
!.env.example
8+
coverage
9+
reports
10+
vscode-extension
11+
python
12+
docs
13+
*.md
14+
!README.md
15+
.github
16+
.tsbuildinfo

.github/workflows/release.yml

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,3 +86,47 @@ jobs:
8686
echo "- npm: https://www.npmjs.com/package/@gitlawb/openclaude"
8787
echo "- GitHub: https://github.com/Gitlawb/openclaude/releases/tag/${{ needs.release-please.outputs.tag_name }}"
8888
} >> "$GITHUB_STEP_SUMMARY"
89+
90+
docker:
91+
name: Build & Push Docker Image
92+
needs: release-please
93+
if: ${{ needs.release-please.outputs.release_created == 'true' }}
94+
runs-on: ubuntu-latest
95+
permissions:
96+
contents: read
97+
packages: write
98+
steps:
99+
- name: Checkout release tag
100+
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
101+
with:
102+
ref: ${{ needs.release-please.outputs.tag_name }}
103+
104+
- name: Set up Docker Buildx
105+
uses: docker/setup-buildx-action@b5ca514318bd6ebac0fb2aedd5d36ec1b5c232a2 # v3.10.0
106+
107+
- name: Log in to GitHub Container Registry
108+
uses: docker/login-action@74a5d142397b4f367a81961eba4e8cd7edddf772 # v3.4.0
109+
with:
110+
registry: ghcr.io
111+
username: ${{ github.actor }}
112+
password: ${{ secrets.GITHUB_TOKEN }}
113+
114+
- name: Extract metadata
115+
id: meta
116+
uses: docker/metadata-action@902fa8ec7d6ecbf8d84d538b9b233a880e428804 # v5.7.0
117+
with:
118+
images: ghcr.io/${{ github.repository }}
119+
tags: |
120+
type=semver,pattern={{version}},value=${{ needs.release-please.outputs.version }}
121+
type=semver,pattern={{major}}.{{minor}},value=${{ needs.release-please.outputs.version }}
122+
type=raw,value=latest
123+
124+
- name: Build and push
125+
uses: docker/build-push-action@14487ce63c7a62a4a324b0bfb37086795e31c6c1 # v6.16.0
126+
with:
127+
context: .
128+
push: true
129+
tags: ${{ steps.meta.outputs.tags }}
130+
labels: ${{ steps.meta.outputs.labels }}
131+
cache-from: type=gha
132+
cache-to: type=gha,mode=max

Dockerfile

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
# ---- build stage ----
2+
FROM node:22-slim AS build
3+
4+
# Install Bun
5+
RUN npm install -g bun@1.3.11
6+
7+
WORKDIR /app
8+
9+
# Copy dependency manifests first for better layer caching
10+
COPY package.json bun.lock ./
11+
12+
# Install all dependencies (including devDependencies for build)
13+
RUN bun install --frozen-lockfile
14+
15+
# Copy source code
16+
COPY src/ src/
17+
COPY scripts/ scripts/
18+
COPY bin/ bin/
19+
COPY tsconfig.json ./
20+
21+
# Build the CLI bundle
22+
RUN bun run build
23+
24+
# Prune devDependencies
25+
RUN rm -rf node_modules && bun install --frozen-lockfile --production
26+
27+
# ---- runtime stage ----
28+
FROM node:22-slim
29+
30+
WORKDIR /app
31+
32+
# Copy only what's needed to run
33+
COPY --from=build /app/dist/cli.mjs dist/cli.mjs
34+
COPY --from=build /app/bin/ bin/
35+
COPY --from=build /app/node_modules/ node_modules/
36+
COPY --from=build /app/package.json package.json
37+
COPY README.md ./
38+
39+
# Install git — many CLI tool operations depend on it
40+
RUN apt-get update && apt-get install -y --no-install-recommends git \
41+
&& rm -rf /var/lib/apt/lists/*
42+
43+
ENTRYPOINT ["node", "dist/cli.mjs"]

0 commit comments

Comments
 (0)