ci: ensure docker-compose up erlang container with root when test Kafka
This commit is contained in:
parent
e5ced07665
commit
95f3df9a10
|
@ -15,7 +15,7 @@ on:
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
prepare:
|
prepare:
|
||||||
runs-on: ubuntu-20.04
|
runs-on: aws-amd64
|
||||||
# prepare source with any OTP version, no need for a matrix
|
# prepare source with any OTP version, no need for a matrix
|
||||||
container: "ghcr.io/emqx/emqx-builder/5.0-18:1.13.4-24.3.4.2-1-ubuntu20.04"
|
container: "ghcr.io/emqx/emqx-builder/5.0-18:1.13.4-24.3.4.2-1-ubuntu20.04"
|
||||||
outputs:
|
outputs:
|
||||||
|
|
|
@ -115,6 +115,9 @@ for dep in ${CT_DEPS}; do
|
||||||
'.ci/docker-compose-file/docker-compose-pgsql-tls.yaml' )
|
'.ci/docker-compose-file/docker-compose-pgsql-tls.yaml' )
|
||||||
;;
|
;;
|
||||||
kafka)
|
kafka)
|
||||||
|
# Kafka container generates root owned ssl files
|
||||||
|
# the files are shared with EMQX (with a docker volume)
|
||||||
|
NEED_ROOT=yes
|
||||||
FILES+=( '.ci/docker-compose-file/docker-compose-kafka.yaml' )
|
FILES+=( '.ci/docker-compose-file/docker-compose-kafka.yaml' )
|
||||||
;;
|
;;
|
||||||
*)
|
*)
|
||||||
|
@ -130,13 +133,19 @@ for file in "${FILES[@]}"; do
|
||||||
F_OPTIONS="$F_OPTIONS -f $file"
|
F_OPTIONS="$F_OPTIONS -f $file"
|
||||||
done
|
done
|
||||||
|
|
||||||
# Passing $UID to docker-compose to be used in erlang container
|
if [[ "${NEED_ROOT:-}" == 'yes' ]]; then
|
||||||
# as owner of the main process to avoid git repo permissions issue.
|
export UID_GID='root:root'
|
||||||
# Permissions issue happens because we are mounting local filesystem
|
else
|
||||||
# where files are owned by $UID to docker container where it's using
|
# Passing $UID to docker-compose to be used in erlang container
|
||||||
# root (UID=0) by default, and git is not happy about it.
|
# as owner of the main process to avoid git repo permissions issue.
|
||||||
|
# Permissions issue happens because we are mounting local filesystem
|
||||||
|
# where files are owned by $UID to docker container where it's using
|
||||||
|
# root (UID=0) by default, and git is not happy about it.
|
||||||
|
export UID_GID="$UID:$UID"
|
||||||
|
fi
|
||||||
|
|
||||||
# shellcheck disable=2086 # no quotes for F_OPTIONS
|
# shellcheck disable=2086 # no quotes for F_OPTIONS
|
||||||
UID_GID="$UID:$UID" docker-compose $F_OPTIONS up -d --build
|
docker-compose $F_OPTIONS up -d --build
|
||||||
|
|
||||||
# /emqx is where the source dir is mounted to the Erlang container
|
# /emqx is where the source dir is mounted to the Erlang container
|
||||||
# in .ci/docker-compose-file/docker-compose.yaml
|
# in .ci/docker-compose-file/docker-compose.yaml
|
||||||
|
@ -145,10 +154,11 @@ if [[ -t 1 ]]; then
|
||||||
TTY='-t'
|
TTY='-t'
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
echo "Fixing file owners and permissions for $UID_GID"
|
||||||
# rebar and hex cache directory need to be writable by $UID
|
# rebar and hex cache directory need to be writable by $UID
|
||||||
docker exec -i $TTY -u root:root "$ERLANG_CONTAINER" bash -c "mkdir /.cache && chown $UID:$UID /.cache"
|
docker exec -i $TTY -u root:root "$ERLANG_CONTAINER" bash -c "mkdir -p /.cache && chown $UID_GID /.cache && chown -R $UID_GID /emqx"
|
||||||
# need to initialize .erlang.cookie manually here because / is not writable by $UID
|
# need to initialize .erlang.cookie manually here because / is not writable by $UID
|
||||||
docker exec -i $TTY -u root:root "$ERLANG_CONTAINER" bash -c "openssl rand -base64 16 > /.erlang.cookie && chown $UID:$UID /.erlang.cookie && chmod 0400 /.erlang.cookie"
|
docker exec -i $TTY -u root:root "$ERLANG_CONTAINER" bash -c "openssl rand -base64 16 > /.erlang.cookie && chown $UID_GID /.erlang.cookie && chmod 0400 /.erlang.cookie"
|
||||||
|
|
||||||
if [ "$ONLY_UP" = 'yes' ]; then
|
if [ "$ONLY_UP" = 'yes' ]; then
|
||||||
exit 0
|
exit 0
|
||||||
|
@ -166,7 +176,7 @@ else
|
||||||
exit $RESULT
|
exit $RESULT
|
||||||
else
|
else
|
||||||
# shellcheck disable=2086 # no quotes for F_OPTIONS
|
# shellcheck disable=2086 # no quotes for F_OPTIONS
|
||||||
UID_GID="$UID:$UID" docker-compose $F_OPTIONS down
|
docker-compose $F_OPTIONS down
|
||||||
exit $RESULT
|
exit $RESULT
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
Loading…
Reference in New Issue