Skip to content

Commit 289e14c

Browse files
authored
Dockerfile: split release and dev recipes (#457)
Combined with the new documentation, this should make it easier to test Renovate PRs like #455 in the future without changing any actual behaviour.
1 parent 846b38d commit 289e14c

File tree

5 files changed

+63
-1
lines changed

5 files changed

+63
-1
lines changed

.dockerignore

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# Anything Git or VSCode related is definitely irrelevant for a build.
2+
.git*
3+
.vscode
4+
5+
# The docker directory contains other Docker images.
6+
docker
7+
8+
# The release directory is created by goreleaser and isn't required here.
9+
release
10+
11+
# Documentation and examples aren't needed.
12+
*.md
13+
*.{yaml,yml}

.goreleaser.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ brews:
3838
# Default is the root folder.
3939
folder: Formula
4040
dockers:
41+
- dockerfile: Dockerfile.release
4142
- image_templates:
4243
- "sourcegraph/src-cli:{{ .Tag }}"
4344
- "sourcegraph/src-cli:{{ .Major }}"

DEVELOPMENT.md

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,30 @@ If a new feature is added to a new `3.91.6` release of src-cli and this change r
3939

4040
Note that if instead the recommended src-cli version for Sourcegraph `3.99` was `3.90.4` in the example above, there is no additional step required, and the new patch version of src-cli will be available to both Sourcegraph versions.
4141

42+
## `src-cli` Docker image
43+
44+
Each release of `src` results in a new tag of the [`sourcegraph/src-cli` Docker image](https://hub.docker.com/r/sourcegraph/src-cli) being pushed to Docker Hub. This is handled by [goreleaser's Docker support](https://goreleaser.com/customization/docker/).
45+
46+
The main gotcha here is that the way goreleaser builds the Docker image is fairly difficult to replicate from the desktop: it builds a `src` binary without any runtime libc dependencies that can be installed in a `scratch` image, but unless you work on Alpine, your desktop is _not_ configured to build Go binaries like that.
47+
48+
As a result, there are two Dockerfiles in this project. goreleaser uses `Dockerfile.release`, which is replicated in a multi-stage `Dockerfile` that builds `src` in a builder container to ensure it's built in a way that can be tested.
49+
50+
### Testing
51+
52+
If you need to test a change to the Dockerfile (for example, due to a Renovate PR bumping the base image), you should pull that change, then build a local image with something like:
53+
54+
```bash
55+
docker build -t local-src-cli .
56+
```
57+
58+
After which you should be able to run:
59+
60+
```bash
61+
docker run --rm local-src-cli
62+
```
63+
64+
and get the normal help output from `src`.
65+
4266
## Dependent Docker images
4367

4468
`src campaign apply` and `src campaign preview` use a Docker image published as `sourcegraph/src-campaign-volume-workspace` for utility purposes when the volume workspace is selected, which is the default on macOS. This [Docker image](./docker/campaign-volume-workspace/Dockerfile) is built by [a Python script](./docker/campaign-volume-workspace/push.py) invoked by the GitHub Action workflow described in [`docker.yml`](.github/workflows/docker.yml).

Dockerfile

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,20 @@
1+
# Since we're going to provide images based on Alpine, we also want to build on
2+
# Alpine, rather than relying on the ./src in the surrounding environment to be
3+
# sane.
4+
#
5+
# Nothing fancy here: we copy in the source code and build on the Alpine Go
6+
# image. Refer to .dockerignore to get a sense of what we're not going to copy.
7+
FROM golang:1.15-alpine as builder
8+
9+
COPY . /src
10+
WORKDIR /src
11+
RUN go build ./cmd/src
12+
13+
# This stage should be kept in sync with Dockerfile.release.
114
FROM sourcegraph/alpine:3.12@sha256:133a0a767b836cf86a011101995641cf1b5cbefb3dd212d78d7be145adde636d
215

316
# needed for `src lsif upload` and `src actions exec`
417
RUN apk add --no-cache git
518

6-
COPY src /usr/bin/
19+
COPY --from=builder /src/src /usr/bin/
720
ENTRYPOINT ["/usr/bin/src"]

Dockerfile.release

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# This Dockerfile is used by goreleaser when publishing a release, and is not
2+
# suitable for testing, since it depends on a src binary being at the project
3+
# root _and_ that src binary being runnable on Alpine. To test this, refer to
4+
# the main Dockerfile, which should have an identical second stage.
5+
FROM sourcegraph/alpine:3.12@sha256:133a0a767b836cf86a011101995641cf1b5cbefb3dd212d78d7be145adde636d
6+
7+
# needed for `src lsif upload` and `src actions exec`
8+
RUN apk add --no-cache git
9+
10+
COPY src /usr/bin/
11+
ENTRYPOINT ["/usr/bin/src"]

0 commit comments

Comments
 (0)