entrypoint in docker container not acting like expected
Summary
I expect the container used to run a job to have git repository available in the entrypoint.sh. But looks like it's not the case. Also the WORKDIR changes to /builds/group/project <- which is bad because it changes between projects.
I expect the container to perform tasks on the git repository in it's entrypoint.sh - which can change over time - it should not require any updates to the .gitlab-ci.yml file.
Steps to reproduce
Using docker image with entrypoint.sh to run a job:
#!/bin/bash
set -euox pipefail
# simulate performing some action on git files
pwd
ls -al $(pwd)
"$@"
FROM alpine
RUN apk add bash
COPY entrypoint.sh /entrypoint.sh
RUN chmod +x /entrypoint.sh
WORKDIR /app
ENTRYPOINT ["/entrypoint.sh"]
test:
stage: test
image: dockerfile-from-above
# do nothing - entrypoint.sh is the script
# but to show that git files are loaded after entrypoint
# just do the same thing that entrypoint.sh does:
script:
- pwd
- ls -al
Executing "step_script" stage of the job script
00:00
+ pwd
++ pwd
+ ls -al /app
/app <-- WORKDIR from Dockerfile.
total 16 <-- GIT files not mounted.
drwxr-xr-x 2 root root 4096 Oct 7 12:51 .
drwxr-xr-x 1 root root 4096 Oct 7 12:52 ..
+ sh -c 'if [ -x /usr/local/bin/bash ]; then
exec /usr/local/bin/bash
elif [ -x /usr/bin/bash ]; then
exec /usr/bin/bash
elif [ -x /bin/bash ]; then
exec /bin/bash
elif [ -x /usr/local/bin/sh ]; then
exec /usr/local/bin/sh
elif [ -x /usr/bin/sh ]; then
exec /usr/bin/sh
elif [ -x /bin/sh ]; then
exec /bin/sh
elif [ -x /busybox/sh ]; then
exec /busybox/sh
else
echo shell not found
exit 1
fi
'
$ pwd
/builds/bukowa/go-ci-build <-- WORKDIR has changed - i expect it does not.
$ ls -al
total 60 <-- GIT files are mounted but in the WORKDIR above.
drwxrwxrwx 3 root root 4096 Oct 7 12:52 .
drwxrwxrwx 4 root root 4096 Oct 7 12:52 ..
drwxrwxrwx 6 root root 4096 Oct 7 12:52 .git
-rw-rw-rw- 1 root root 530 Oct 7 12:52 .gitlab-ci.yml
-rw-rw-rw- 1 root root 133 Oct 7 12:52 Dockerfile
-rw-rw-rw- 1 root root 0 Oct 7 12:52 empty.php
-rw-rw-rw- 1 root root 100 Oct 7 12:52 entrypoint.sh
-rw-rw-rw- 1 root root 71 Oct 7 12:52 main.go
Cleaning up file based variables
00:01
Job succeeded
Full example is here: https://gitlab.com/bukowa/go-ci-build
Expected behaviour
Executing "step_script" stage of the job script
00:00
+ pwd
++ pwd
+ ls -al /app
/app <-- WORKDIR from Dockerfile.
total 60 <-- GIT files are mounted.
drwxrwxrwx 3 root root 4096 Oct 7 12:52 .
drwxrwxrwx 4 root root 4096 Oct 7 12:52 ..
drwxrwxrwx 6 root root 4096 Oct 7 12:52 .git
-rw-rw-rw- 1 root root 530 Oct 7 12:52 .gitlab-ci.yml
-rw-rw-rw- 1 root root 133 Oct 7 12:52 Dockerfile
-rw-rw-rw- 1 root root 0 Oct 7 12:52 empty.php
-rw-rw-rw- 1 root root 100 Oct 7 12:52 entrypoint.sh
-rw-rw-rw- 1 root root 71 Oct 7 12:52 main.go
+ sh -c 'if [ -x /usr/local/bin/bash ]; then
exec /usr/local/bin/bash
elif [ -x /usr/bin/bash ]; then
exec /usr/bin/bash
elif [ -x /bin/bash ]; then
exec /bin/bash
elif [ -x /usr/local/bin/sh ]; then
exec /usr/local/bin/sh
elif [ -x /usr/bin/sh ]; then
exec /usr/bin/sh
elif [ -x /bin/sh ]; then
exec /bin/sh
elif [ -x /busybox/sh ]; then
exec /busybox/sh
else
echo shell not found
exit 1
fi
'
$ pwd
/app <-- WORKDIR is the same as in Dockerfile.
$ ls -al
total 60 <-- GIT files are mounted in the WORKDIR.
drwxrwxrwx 3 root root 4096 Oct 7 12:52 .
drwxrwxrwx 4 root root 4096 Oct 7 12:52 ..
drwxrwxrwx 6 root root 4096 Oct 7 12:52 .git
-rw-rw-rw- 1 root root 530 Oct 7 12:52 .gitlab-ci.yml
-rw-rw-rw- 1 root root 133 Oct 7 12:52 Dockerfile
-rw-rw-rw- 1 root root 0 Oct 7 12:52 empty.php
-rw-rw-rw- 1 root root 100 Oct 7 12:52 entrypoint.sh
-rw-rw-rw- 1 root root 71 Oct 7 12:52 main.go
Cleaning up file based variables
00:01
Job succeeded
See full example at: https://gitlab.com/bukowa/go-ci-build
Edited by Buk Bukowski