Skip to content

Commit 6a4005c

Browse files
authored
Merge pull request QwenLM#262 from nguu0123/main
feat(sandbox): add GHA to build sandbox image
2 parents 0bc45ae + a37423b commit 6a4005c

File tree

2 files changed

+104
-16
lines changed

2 files changed

+104
-16
lines changed
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
name: Build and Publish Docker Image
2+
3+
on:
4+
push:
5+
tags:
6+
- 'v*'
7+
workflow_dispatch:
8+
inputs:
9+
publish:
10+
description: 'Publish to GHCR (only works on main branch)'
11+
type: boolean
12+
default: false
13+
14+
env:
15+
REGISTRY: ghcr.io
16+
IMAGE_NAME: ${{ github.repository }}
17+
18+
jobs:
19+
build-and-push-to-ghcr:
20+
runs-on: ubuntu-latest
21+
permissions:
22+
contents: read
23+
packages: write
24+
25+
steps:
26+
- name: Checkout repository
27+
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4
28+
29+
- name: Set up QEMU
30+
uses: docker/setup-qemu-action@v3
31+
32+
- name: Set up Docker Buildx
33+
uses: docker/setup-buildx-action@v3
34+
35+
- name: Extract metadata (tags, labels) for Docker
36+
id: meta
37+
uses: docker/metadata-action@v5
38+
with:
39+
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
40+
tags: |
41+
type=ref,event=branch
42+
type=ref,event=pr
43+
type=semver,pattern={{version}}
44+
type=semver,pattern={{major}}.{{minor}}
45+
type=sha,prefix=sha-,format=short
46+
47+
- name: Log in to the Container registry
48+
if: github.event_name != 'pull_request' && (github.ref == 'refs/heads/main' || startsWith(github.ref, 'refs/tags/v'))
49+
uses: docker/login-action@v3
50+
with:
51+
registry: ${{ env.REGISTRY }}
52+
username: ${{ github.actor }}
53+
password: ${{ secrets.GITHUB_TOKEN }}
54+
55+
- name: Build and push Docker image
56+
id: build-and-push
57+
uses: docker/build-push-action@v6
58+
with:
59+
context: .
60+
platforms: linux/amd64,linux/arm64
61+
push: ${{ github.event_name != 'pull_request' && (github.ref == 'refs/heads/main' || startsWith(github.ref, 'refs/tags/v') || github.event.inputs.publish == 'true') }}
62+
tags: ${{ steps.meta.outputs.tags }}
63+
labels: ${{ steps.meta.outputs.labels }}
64+
build-args: |
65+
CLI_VERSION_ARG=${{ github.sha }}

Dockerfile

Lines changed: 39 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,41 @@
1+
# Build stage
2+
FROM docker.io/library/node:20-slim AS builder
3+
4+
# Install build dependencies
5+
RUN apt-get update && apt-get install -y --no-install-recommends \
6+
python3 \
7+
make \
8+
g++ \
9+
git \
10+
&& apt-get clean \
11+
&& rm -rf /var/lib/apt/lists/*
12+
13+
# Set up npm global package folder
14+
RUN mkdir -p /usr/local/share/npm-global
15+
ENV NPM_CONFIG_PREFIX=/usr/local/share/npm-global
16+
ENV PATH=$PATH:/usr/local/share/npm-global/bin
17+
18+
# Copy source code
19+
COPY . /home/node/app
20+
WORKDIR /home/node/app
21+
22+
# Install dependencies and build packages
23+
RUN npm ci \
24+
&& npm run build --workspaces \
25+
&& npm pack -w @qwen-code/qwen-code --pack-destination ./packages/cli/dist \
26+
&& npm pack -w @qwen-code/qwen-code-core --pack-destination ./packages/core/dist
27+
28+
# Runtime stage
129
FROM docker.io/library/node:20-slim
230

331
ARG SANDBOX_NAME="qwen-code-sandbox"
432
ARG CLI_VERSION_ARG
533
ENV SANDBOX="$SANDBOX_NAME"
634
ENV CLI_VERSION=$CLI_VERSION_ARG
735

8-
# install minimal set of packages, then clean up
36+
# Install runtime dependencies
937
RUN apt-get update && apt-get install -y --no-install-recommends \
1038
python3 \
11-
make \
12-
g++ \
1339
man-db \
1440
curl \
1541
dnsutils \
@@ -29,22 +55,19 @@ RUN apt-get update && apt-get install -y --no-install-recommends \
2955
&& apt-get clean \
3056
&& rm -rf /var/lib/apt/lists/*
3157

32-
# set up npm global package folder under /usr/local/share
33-
# give it to non-root user node, already set up in base image
34-
RUN mkdir -p /usr/local/share/npm-global \
35-
&& chown -R node:node /usr/local/share/npm-global
58+
# Set up npm global package folder
59+
RUN mkdir -p /usr/local/share/npm-global
3660
ENV NPM_CONFIG_PREFIX=/usr/local/share/npm-global
3761
ENV PATH=$PATH:/usr/local/share/npm-global/bin
3862

39-
# switch to non-root user node
40-
USER node
63+
# Copy built packages from builder stage
64+
COPY --from=builder /home/node/app/packages/cli/dist/*.tgz /tmp/
65+
COPY --from=builder /home/node/app/packages/core/dist/*.tgz /tmp/
4166

42-
# install qwen-code and clean up
43-
COPY packages/cli/dist/qwen-code-*.tgz /usr/local/share/npm-global/qwen-code.tgz
44-
COPY packages/core/dist/qwen-code-qwen-code-core-*.tgz /usr/local/share/npm-global/qwen-code-core.tgz
45-
RUN npm install -g /usr/local/share/npm-global/qwen-code.tgz /usr/local/share/npm-global/qwen-code-core.tgz \
67+
# Install built packages globally
68+
RUN npm install -g /tmp/*.tgz \
4669
&& npm cache clean --force \
47-
&& rm -f /usr/local/share/npm-global/qwen-{code,code-core}.tgz
70+
&& rm -rf /tmp/*.tgz
4871

49-
# default entrypoint when none specified
50-
CMD ["qwen"]
72+
# Default entrypoint when none specified
73+
CMD ["qwen"]

0 commit comments

Comments
 (0)