From d97735c956562b16d446cc26f2b9244aabadfd42 Mon Sep 17 00:00:00 2001 From: Copilot <198982749+Copilot@users.noreply.github.com> Date: Tue, 2 Dec 2025 23:56:19 +0100 Subject: [PATCH 1/4] Feat/Run Docker container as non-root user for Kubernetes PSP/PSA compatibility (#1) * Initial plan * Add non-root user support to Dockerfile Co-authored-by: theepicsaxguy <39008574+theepicsaxguy@users.noreply.github.com> * Add SECURITY.md documentation Co-authored-by: theepicsaxguy <39008574+theepicsaxguy@users.noreply.github.com> * Add Kubernetes example manifest, verification script, and README updates Co-authored-by: theepicsaxguy <39008574+theepicsaxguy@users.noreply.github.com> * Remove documentation changes (SECURITY.md, k8s-example.yaml, verify script, README updates) Co-authored-by: theepicsaxguy <39008574+theepicsaxguy@users.noreply.github.com> --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: theepicsaxguy <39008574+theepicsaxguy@users.noreply.github.com> --- Dockerfile | 25 ++++++++++++++++++++----- scripts/docker-entrypoint.sh | 1 + 2 files changed, 21 insertions(+), 5 deletions(-) diff --git a/Dockerfile b/Dockerfile index 629cf433..a7775f3a 100644 --- a/Dockerfile +++ b/Dockerfile @@ -20,8 +20,15 @@ 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 +USER node + +RUN mkdir -p /home/node/.local/bin && \ + curl -fsSL https://bun.sh/install | bash && \ + ln -s /home/node/.bun/bin/bun /home/node/.local/bin/bun + +USER root + +ENV PATH="/home/node/.local/bin:/home/node/.bun/bin:${PATH}" WORKDIR /app @@ -47,8 +54,13 @@ 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 +USER node + +RUN mkdir -p /home/node/.local/bin && \ + curl -fsSL https://opencode.ai/install | bash && \ + ln -s /home/node/.opencode/bin/opencode /home/node/.local/bin/opencode + +USER root ENV NODE_ENV=production ENV HOST=0.0.0.0 @@ -69,7 +81,10 @@ 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 /app + +USER node EXPOSE 5003 diff --git a/scripts/docker-entrypoint.sh b/scripts/docker-entrypoint.sh index 1ca8786d..92a09220 100644 --- a/scripts/docker-entrypoint.sh +++ b/scripts/docker-entrypoint.sh @@ -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" From 3850723f499f7372ec1b17cd423370182479fde6 Mon Sep 17 00:00:00 2001 From: theepicsaxguy <39008574+theepicsaxguy@users.noreply.github.com> Date: Wed, 3 Dec 2025 15:51:45 +0100 Subject: [PATCH 2/4] Refactor Dockerfile to streamline user permissions and installation paths --- Dockerfile | 39 +++++++++++++++------------------------ 1 file changed, 15 insertions(+), 24 deletions(-) diff --git a/Dockerfile b/Dockerfile index a7775f3a..d452d453 100644 --- a/Dockerfile +++ b/Dockerfile @@ -20,24 +20,17 @@ RUN apt-get update && apt-get install -y \ RUN corepack enable && corepack prepare pnpm@9.15.0 --activate -USER node - -RUN mkdir -p /home/node/.local/bin && \ - curl -fsSL https://bun.sh/install | bash && \ - ln -s /home/node/.bun/bin/bun /home/node/.local/bin/bun - -USER root - -ENV PATH="/home/node/.local/bin:/home/node/.bun/bin:${PATH}" +RUN curl -fsSL https://bun.sh/install | bash && \ + ln -s $HOME/.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 @@ -54,13 +47,10 @@ RUN pnpm --filter frontend build FROM base AS runner -USER node - -RUN mkdir -p /home/node/.local/bin && \ - curl -fsSL https://opencode.ai/install | bash && \ - ln -s /home/node/.opencode/bin/opencode /home/node/.local/bin/opencode - -USER root +RUN curl -fsSL https://opencode.ai/install | bash && \ + 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 @@ -69,7 +59,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 @@ -82,14 +72,15 @@ COPY scripts/docker-entrypoint.sh /docker-entrypoint.sh RUN chmod +x /docker-entrypoint.sh RUN mkdir -p /workspace /app/data && \ - chown -R node:node /workspace /app/data /app - -USER node + 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"] + From d6cdf308ece51849385bdeb0fb7feb5d5fea7a77 Mon Sep 17 00:00:00 2001 From: Copilot <198982749+Copilot@users.noreply.github.com> Date: Wed, 3 Dec 2025 16:08:01 +0100 Subject: [PATCH 3/4] Add Docker build workflow with multi-arch support and caching (#3) * Initial plan * Add Docker build workflow with multi-arch support and intelligent caching Co-authored-by: theepicsaxguy <39008574+theepicsaxguy@users.noreply.github.com> * Simplify Docker workflow - remove over-engineering Co-authored-by: theepicsaxguy <39008574+theepicsaxguy@users.noreply.github.com> * Update docker-build.yml * Update docker-build.yml * Fix Dockerfile permission issues for bun and opencode installers Co-authored-by: theepicsaxguy <39008574+theepicsaxguy@users.noreply.github.com> --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: theepicsaxguy <39008574+theepicsaxguy@users.noreply.github.com> --- .github/workflows/docker-build.yml | 77 ++++++++++++++++++++++++++++++ 1 file changed, 77 insertions(+) create mode 100644 .github/workflows/docker-build.yml diff --git a/.github/workflows/docker-build.yml b/.github/workflows/docker-build.yml new file mode 100644 index 00000000..36ea07d4 --- /dev/null +++ b/.github/workflows/docker-build.yml @@ -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 From cf36167fab695577820d875b8988fffcf6256115 Mon Sep 17 00:00:00 2001 From: Chris Scott Date: Wed, 3 Dec 2025 09:43:32 -0800 Subject: [PATCH 4/4] fix(docker): Move bun to /opt for non-root user access --- Dockerfile | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index d452d453..c3a3f37b 100644 --- a/Dockerfile +++ b/Dockerfile @@ -21,7 +21,9 @@ 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