Skip to content

Commit 3a9ee7d

Browse files
authoredMar 28, 2025··
feat: Add Dockerfile that installs cody from source (#7513)
[Slack context](https://sourcegraph.slack.com/archives/C04MSD3DP5L/p1742314663276049) [Linear ticket](https://linear.app/sourcegraph/issue/REL-806/release-cody-cli-as-docker-image-for-version-5517) ~~This is just so that we have a reference here for now. We're unblocking a customer while we integrate a CI pipeline that will publish this whenever an agent release goes out. That means coping the _built_ files into this container, rather than using npm. We'll also need to give the GHA the creds to publish this to Dockerhub.~~ This handles creation of a docker container, pushed to docker hub, which comes pre-installed with the cody npm package, built from source. Previously a single image was published for a customer under the `ccsourcegraph` account, but this PR makes the process production ready, and hooks into existing CI actions, under the `sourcegraph` dockerhub account. ~~I have chosen not to publish this image given it doesn't currently exist in the Sourcegraph Dockerhub registry. If the customer demands it, I could.~~ Once approved and merged, I'll publish the specific image for `5.5.17` to dockerhub since that CI run has already passed. Running `docker build . -t sourcegraph/cody-cli:5.5.17` from the `cody/cli` directory will give you a container that has `cody` installed. ## Test plan ``` > docker run --rm sourcegraph/cody-cli cody --help Usage: cody [options] [command] The Cody cli supports running Cody in headless mode and interacting with it via JSON-RPC. Run `cody chat -m "Hello" to get started. Options: -v, --version output the version number -h, --help display help for command Commands: auth Authenticate Cody with Sourcegraph chat [options] Chat with codebase context. Examples: cody chat -m 'Tell me about React hooks' cody chat --context-file README.md --message 'Summarize this readme' git diff | cody chat --stdin -m 'Explain this diff' Enterprise Only: cody chat --context-repo github.com/sourcegraph/cody --message 'What is the agent?' models Manage models api internal help [command] display help for command ``` <!-- Required. See https://docs-legacy.sourcegraph.com/dev/background-information/testing_principles. -->

File tree

3 files changed

+74
-0
lines changed

3 files changed

+74
-0
lines changed
 

‎.dockerignore

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# Dependencies - will be installed during build
2+
**/node_modules/
3+
node_modules/
4+
5+
# Git directories
6+
.git/
7+
**/.git/

‎.github/workflows/agent-release.yml

+22
Original file line numberDiff line numberDiff line change
@@ -51,3 +51,25 @@ jobs:
5151
env:
5252
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
5353
- run: pnpm publish --no-git-checks agent
54+
55+
# Build and push Docker image
56+
- name: Set up Docker Buildx
57+
uses: docker/setup-buildx-action@v3
58+
59+
# Login to Docker Hub
60+
- name: Login to Docker Hub
61+
uses: docker/login-action@v3
62+
with:
63+
username: ${{ secrets.DOCKER_USERNAME }}
64+
password: ${{ secrets.DOCKER_TOKEN }}
65+
66+
# Build and push
67+
- name: Build and push Docker image
68+
uses: docker/build-push-action@v5
69+
with:
70+
context: .
71+
file: ./Dockerfile
72+
push: true
73+
tags: |
74+
sourcegraph/cody-cli:latest
75+
sourcegraph/cody-cli:${{ env.EXT_VERSION }}

‎Dockerfile

+45
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
# Cody Agent Docker Image
2+
#
3+
# This Dockerfile builds the Cody Agent CLI tool in a multi-stage process:
4+
# 1. First stage: Build the agent from source using the pnpm workspace
5+
# 2. Second stage: Create a minimal runtime image with just the agent installed
6+
#
7+
# Usage:
8+
# docker build -t cody-agent .
9+
# docker run -it --rm cody-agent cody --version
10+
# docker run -it --rm cody-agent
11+
12+
# ===== Build Stage =====
13+
FROM node:23 AS builder
14+
15+
# Install pnpm with specific version from package.json
16+
RUN npm install -g pnpm
17+
18+
# Copy the entire repository to build with workspace dependencies
19+
WORKDIR /cody
20+
COPY . .
21+
RUN pnpm install
22+
RUN pnpm build
23+
24+
FROM alpine:3.21
25+
26+
# Install Node.js and dependencies
27+
RUN apk update
28+
RUN apk add --no-cache nodejs npm libsecret gnome-keyring
29+
30+
# Copy the built agent package from the builder stage
31+
WORKDIR /app
32+
COPY --from=builder /cody/agent/dist /app/dist
33+
COPY --from=builder /cody/agent/package.json /app/
34+
35+
# Create an executable wrapper script for cody
36+
RUN echo '#!/bin/sh' > /usr/local/bin/cody && \
37+
echo 'node /app/dist/index.js "$@"' >> /usr/local/bin/cody && \
38+
chmod +x /usr/local/bin/cody
39+
40+
# Test that the agent is installed correctly
41+
RUN which cody || echo "Cody not found in PATH"
42+
RUN cody --version || echo "Cody installation failed"
43+
44+
# Set cody as the default command
45+
CMD ["cody"]

0 commit comments

Comments
 (0)
Please sign in to comment.