Skip to content

Commit 7c07d4a

Browse files
committed
fix problems with file mounts in Docker containers
1 parent fda9f1a commit 7c07d4a

File tree

2 files changed

+43
-4
lines changed

2 files changed

+43
-4
lines changed

deploy.sh

+3-4
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,9 @@ ALLOW_STOP=0 # Use Web UI or allow "docker stop <container>"
3030
HTTP_PORT=\${HTTP_PORT:-8010}
3131
SLAVE_PORT=\${SLAVE_PORT:-9989}
3232
33-
OPTS="\$DOCKER_OPTS --name \${CONTAINER}"
34-
35-
[[ -z \$CONTAINER_HOSTNAME ]] || OPTS="\$OPTS --hostname \$CONTAINER_HOSTNAME"
33+
. docker_utils.sh # updates OPTS variable
34+
docker_mount_add credentials/htpasswd /etc/buildbot/htpasswd ro
35+
docker_mount_finalize || exit 1
3636
3737
create_container() {
3838
docker create -it \\
@@ -41,7 +41,6 @@ create_container() {
4141
-p \${SLAVE_PORT}:9989 \\
4242
-v \${P}:/app \\
4343
-v \${P}_data/master:/data \\
44-
-v \${P}/credentials/htpasswd:/etc/buildbot/htpasswd:ro \\
4544
\${IMAGE}
4645
}
4746
EOF

docker_utils.sh

+40
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
# Don't use this as a standalone script
2+
3+
OPTS="$DOCKER_OPTS --name ${CONTAINER}"
4+
[[ -z $CONTAINER_HOSTNAME ]] || OPTS="$OPTS --hostname $CONTAINER_HOSTNAME"
5+
6+
# Reset file
7+
echo "#!/bin/bash" > ".update_docker_mount.sh"
8+
chmod +x ".update_docker_mount.sh"
9+
10+
# There are several issues with mounting of configuration files into container.
11+
# One of them is related to files "update" problem with live container (without container re-creation).
12+
# Tools (ansible, vim) usually creates new file and then rename it "atomically" (this assigns new "inode" to file).
13+
# Docker binds "inode", not a file name, so that changes are not updated in the container.
14+
# Workaround is mounting file "clones" instead of original files.
15+
docker_mount_add()
16+
{
17+
SRC="${P}/$1"
18+
DST=$2
19+
if [[ "x$DST" == "x" ]]; then
20+
DST="/opt/pullrequest/$1"
21+
fi
22+
MODE=${3}
23+
if [[ "x$MODE" != "x" ]]; then
24+
MODE=":${MODE}"
25+
fi
26+
27+
if [[ -f "$SRC" ]]; then
28+
DOCKER_SRC="${P}/.docker/$1"
29+
DIR=$(dirname "${DOCKER_SRC}")
30+
echo "mkdir -p $DIR" >> ".update_docker_mount.sh"
31+
echo "cp -p \"$SRC\" \"${DOCKER_SRC}\"" >> ".update_docker_mount.sh"
32+
SRC="${DOCKER_SRC}"
33+
fi
34+
OPTS="$OPTS -v ${SRC}:${DST}${MODE}"
35+
}
36+
37+
docker_mount_finalize()
38+
{
39+
. .update_docker_mount.sh || exit 1
40+
}

0 commit comments

Comments
 (0)