Skip to content

Commit 3fdfb21

Browse files
authored
campaigns: better handle non-root images in volume mode (#479)
Fixes #478.
1 parent 9464877 commit 3fdfb21

File tree

3 files changed

+14
-7
lines changed

3 files changed

+14
-7
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ All notable changes to `src-cli` are documented in this file.
1919

2020
### Fixed
2121

22+
- Using volume workspace mode could result in Git errors when used with Docker containers that do not run as root. These have been fixed. [#478](https://github.com/sourcegraph/src-cli/issues/478)
23+
2224
### Removed
2325

2426
## 3.25.1

docker/campaign-volume-workspace/Dockerfile

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,4 @@
44

55
FROM alpine:3.13.1@sha256:08d6ca16c60fe7490c03d10dc339d9fd8ea67c6466dea8d558526b1330a85930
66

7-
# Note that we have to configure git's user.email and user.name settings to
8-
# avoid issues when committing changes. These values are not used when creating
9-
# changesets, since we only extract the diff from the container and not a full
10-
# patch, but need to be set to avoid git erroring out.
11-
RUN apk add --update curl git unzip && \
12-
git config --global user.email campaigns@sourcegraph.com && \
13-
git config --global user.name 'Sourcegraph Campaigns'
7+
RUN apk add --update git unzip

internal/campaigns/volume_workspace.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,13 @@ set -e
7070
set -x
7171
7272
git init
73+
74+
# Note that we don't actually use these anywhere, since we're not creating the
75+
# real commits in this container, but we do need _something_ set to avoid Git
76+
# erroring out.
77+
git config user.name 'Sourcegraph Campaigns'
78+
git config user.email campaigns@sourcegraph.com
79+
7380
# --force because we want previously "gitignored" files in the repository
7481
git add --force --all
7582
git commit --quiet --all --allow-empty -m src-action-exec
@@ -282,6 +289,10 @@ func (w *dockerVolumeWorkspace) runScript(ctx context.Context, target, script st
282289
}
283290
f.Close()
284291

292+
// Sidestep any umask issues on the temporary file by always making it
293+
// executable by everyone.
294+
os.Chmod(name, 0755)
295+
285296
common, err := w.DockerRunOpts(ctx, target)
286297
if err != nil {
287298
return nil, errors.Wrap(err, "generating run options")

0 commit comments

Comments
 (0)