mirror of
https://github.com/chriswritescode-dev/opencode-manager.git
synced 2026-12-05 12:24:30 +01:00
Merge pull request #13 from theepicsaxguy/main
build(docker): Run container as non-root user - Refactored Dockerfile to run as non-root 'node' user - Updated COPY commands with --chown=node:node - Moved opencode and bun to /opt for non-root access - Added GitHub Actions workflow for multi-arch Docker builds - Fixed bun installation path for non-root user access
This commit is contained in:
commit
a0a4922520
3 files changed
+94
-8
No files matched your search
@@ -0,0 +1,77 @@
|
||||
name: Docker Build
|
||||
|
||||
on:
|
||||
pull_request:
|
||||
branches:
|
||||
- main
|
||||
paths:
|
||||
- '.github/workflows/docker-build.yml'
|
||||
- 'backend/**'
|
||||
- 'frontend/**'
|
||||
- 'shared/**'
|
||||
- 'Dockerfile'
|
||||
- 'scripts/**'
|
||||
push:
|
||||
branches:
|
||||
- main
|
||||
paths:
|
||||
- 'backend/**'
|
||||
- 'frontend/**'
|
||||
- 'shared/**'
|
||||
- 'Dockerfile'
|
||||
- 'scripts/**'
|
||||
tags:
|
||||
- 'v*'
|
||||
|
||||
concurrency:
|
||||
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
|
||||
cancel-in-progress: true
|
||||
|
||||
permissions:
|
||||
contents: read
|
||||
packages: write
|
||||
|
||||
jobs:
|
||||
build:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v4
|
||||
|
||||
- name: Docker meta
|
||||
id: meta
|
||||
uses: docker/metadata-action@v5
|
||||
with:
|
||||
images: ghcr.io/${{ github.repository }}
|
||||
tags: |
|
||||
type=ref,event=pr,prefix=pr-
|
||||
type=edge,branch=main
|
||||
type=sha,prefix=commit-,format=short,enable={{is_default_branch}}
|
||||
type=semver,pattern={{version}}
|
||||
type=semver,pattern={{major}}.{{minor}}
|
||||
type=semver,pattern={{major}}
|
||||
type=raw,value=latest,enable=${{ startsWith(github.ref, 'refs/tags/v') }}
|
||||
|
||||
- name: Set up QEMU
|
||||
uses: docker/setup-qemu-action@v3
|
||||
|
||||
- name: Set up Docker Buildx
|
||||
uses: docker/setup-buildx-action@v3
|
||||
|
||||
- name: Login to GHCR
|
||||
uses: docker/login-action@v3
|
||||
with:
|
||||
registry: ghcr.io
|
||||
username: ${{ github.actor }}
|
||||
password: ${{ secrets.GITHUB_TOKEN }}
|
||||
|
||||
- name: Build and push
|
||||
uses: docker/build-push-action@v5
|
||||
with:
|
||||
context: .
|
||||
platforms: linux/amd64,linux/arm64
|
||||
push: ${{ github.event_name != 'pull_request' }}
|
||||
tags: ${{ steps.meta.outputs.tags }}
|
||||
labels: ${{ steps.meta.outputs.labels }}
|
||||
cache-from: type=gha
|
||||
cache-to: type=gha,mode=max
|
||||
+16
-8
@@ -21,16 +21,18 @@ RUN apt-get update && apt-get install -y \
|
||||
RUN corepack enable && corepack prepare pnpm@9.15.0 --activate
|
||||
|
||||
RUN curl -fsSL https://bun.sh/install | bash && \
|
||||
ln -s $HOME/.bun/bin/bun /usr/local/bin/bun
|
||||
mv /root/.bun /opt/bun && \
|
||||
chmod -R 755 /opt/bun && \
|
||||
ln -s /opt/bun/bin/bun /usr/local/bin/bun
|
||||
|
||||
WORKDIR /app
|
||||
|
||||
FROM base AS deps
|
||||
|
||||
COPY package.json pnpm-workspace.yaml pnpm-lock.yaml ./
|
||||
COPY shared/package.json ./shared/
|
||||
COPY backend/package.json ./backend/
|
||||
COPY frontend/package.json ./frontend/
|
||||
COPY --chown=node:node package.json pnpm-workspace.yaml pnpm-lock.yaml ./
|
||||
COPY --chown=node:node shared/package.json ./shared/
|
||||
COPY --chown=node:node backend/package.json ./backend/
|
||||
COPY --chown=node:node frontend/package.json ./frontend/
|
||||
|
||||
RUN pnpm install --frozen-lockfile
|
||||
|
||||
@@ -48,7 +50,9 @@ RUN pnpm --filter frontend build
|
||||
FROM base AS runner
|
||||
|
||||
RUN curl -fsSL https://opencode.ai/install | bash && \
|
||||
ln -s $HOME/.opencode/bin/opencode /usr/local/bin/opencode
|
||||
mv /root/.opencode /opt/opencode && \
|
||||
chmod -R 755 /opt/opencode && \
|
||||
ln -s /opt/opencode/bin/opencode /usr/local/bin/opencode
|
||||
|
||||
ENV NODE_ENV=production
|
||||
ENV HOST=0.0.0.0
|
||||
@@ -57,7 +61,7 @@ ENV OPENCODE_SERVER_PORT=5551
|
||||
ENV DATABASE_PATH=/app/data/opencode.db
|
||||
ENV WORKSPACE_PATH=/workspace
|
||||
|
||||
COPY --from=deps /app/node_modules ./node_modules
|
||||
COPY --from=deps --chown=node:node /app/node_modules ./node_modules
|
||||
COPY --from=builder /app/shared ./shared
|
||||
COPY --from=builder /app/backend ./backend
|
||||
COPY --from=builder /app/frontend/dist ./frontend/dist
|
||||
@@ -69,12 +73,16 @@ RUN mkdir -p /app/backend/node_modules/@opencode-webui && \
|
||||
COPY scripts/docker-entrypoint.sh /docker-entrypoint.sh
|
||||
RUN chmod +x /docker-entrypoint.sh
|
||||
|
||||
RUN mkdir -p /workspace /app/data
|
||||
RUN mkdir -p /workspace /app/data && \
|
||||
chown -R node:node /workspace /app/data
|
||||
|
||||
EXPOSE 5003
|
||||
|
||||
HEALTHCHECK --interval=30s --timeout=3s --start-period=40s --retries=3 \
|
||||
CMD curl -f http://localhost:5003/api/health || exit 1
|
||||
|
||||
USER node
|
||||
|
||||
ENTRYPOINT ["/docker-entrypoint.sh"]
|
||||
CMD ["bun", "backend/src/index.ts"]
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
#!/bin/bash
|
||||
set -e
|
||||
|
||||
export HOME=/home/node
|
||||
export BUN_INSTALL="$HOME/.bun"
|
||||
export PATH="$BUN_INSTALL/bin:$HOME/.opencode/bin:$HOME/.local/bin:$PATH"
|
||||
|
||||
|
||||
Reference in new issue
Block a user