Skip to content

Commit 508b6e1

Browse files
committed
Better permissions on the build-in-docker scripts
1 parent 36a9d5b commit 508b6e1

File tree

3 files changed

+13
-2
lines changed

3 files changed

+13
-2
lines changed

Dockerfile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,9 @@ COPY buildInDocker.sh $GOPATH
6666
RUN chmod 777 $GOPATH/buildInDocker.sh
6767

6868
# Copy the rest of the source tree from this directory into the container
69+
# And make sure it's readable by the id that will run the compiles (not just root)
6970
COPY . $GOPATH/src/$ORG/$REPO
71+
RUN chmod -R a+rx $GOPATH/src
7072

7173
# Set the entrypoint to the script that will do the compilation
7274
ENTRYPOINT $GOPATH/buildInDocker.sh

buildInDocker.sh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@
2020
export PATH="${PATH}:/usr/lib/go-${GOVERSION}/bin:/go/bin"
2121
export CGO_CFLAGS="-I/opt/mqm/inc/"
2222
export CGO_LDFLAGS_ALLOW="-Wl,-rpath.*"
23+
export GOCACHE=/tmp/.gocache
24+
25+
echo "Running as " `id`
2326

2427
# Build the libraries so they can be used by other programs
2528
cd $GOPATH/src

buildSamples.sh

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,11 +42,17 @@ then
4242
rm -rf $OUTBINDIR $OUTPKGDIR >/dev/null 2>&1
4343
mkdir -p $OUTBINDIR $OUTPKGDIR
4444

45+
# The container will be run as the current user to ensure files
46+
# written back to the host image are owned by that person instead of root.
47+
uid=`id -u`
48+
gid=`id -g`
49+
4550
# Mount an output directory
4651
# Delete the container once it's done its job
4752
docker run --rm \
48-
-v $OUTBINDIR:$GOPATH/bin:z \
49-
-v $OUTPKGDIR:$GOPATH/pkg:z \
53+
--user $uid:$gid \
54+
-v $OUTBINDIR:$GOPATH/bin \
55+
-v $OUTPKGDIR:$GOPATH/pkg \
5056
$TAG:$VER
5157
echo "Compiled samples should now be in $OUTBINDIR"
5258
fi

0 commit comments

Comments
 (0)