Merge pull request #8965 from zmstone/0914-allow-ssh-agent-in-buildx
build: allow passing ssh agent to docker run in buildx.sh
This commit is contained in:
commit
e3d7ad0fec
|
@ -262,7 +262,6 @@ jobs:
|
||||||
--profile "${PROFILE}" \
|
--profile "${PROFILE}" \
|
||||||
--pkgtype "${PACKAGE}" \
|
--pkgtype "${PACKAGE}" \
|
||||||
--arch "${ARCH}" \
|
--arch "${ARCH}" \
|
||||||
--system "${SYSTEM}" \
|
|
||||||
--builder "ghcr.io/emqx/emqx-builder/4.4-19:${OTP}-${SYSTEM}"
|
--builder "ghcr.io/emqx/emqx-builder/4.4-19:${OTP}-${SYSTEM}"
|
||||||
- uses: actions/upload-artifact@v1
|
- uses: actions/upload-artifact@v1
|
||||||
with:
|
with:
|
||||||
|
|
|
@ -60,3 +60,4 @@ erlang_ls.config
|
||||||
# For direnv
|
# For direnv
|
||||||
.envrc
|
.envrc
|
||||||
mix.lock
|
mix.lock
|
||||||
|
.gitconfig.tmp
|
||||||
|
|
|
@ -20,10 +20,12 @@ help() {
|
||||||
echo "--arch amd64|arm64: Target arch to build the EMQ X package for"
|
echo "--arch amd64|arm64: Target arch to build the EMQ X package for"
|
||||||
echo "--src_dir <SRC_DIR>: EMQ X source ode in this dir, default to PWD"
|
echo "--src_dir <SRC_DIR>: EMQ X source ode in this dir, default to PWD"
|
||||||
echo "--builder <BUILDER>: Builder image to pull"
|
echo "--builder <BUILDER>: Builder image to pull"
|
||||||
echo "--system <SYSTEM>: The target OS system the package is being built for, ex: debian11"
|
echo " E.g. ghcr.io/emqx/emqx-builder/4.4-19:24.1.5-3-debian11"
|
||||||
echo " E.g. ghcr.io/emqx/emqx-builder/4.4-19:24.1.5-3-debian10"
|
echo "--ssh: Pass ssh agent to the builder."
|
||||||
|
echo " Also configures git in container to use ssh instead of https to clone deps"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
USE_SSH='no'
|
||||||
while [ "$#" -gt 0 ]; do
|
while [ "$#" -gt 0 ]; do
|
||||||
case $1 in
|
case $1 in
|
||||||
-h|--help)
|
-h|--help)
|
||||||
|
@ -50,9 +52,9 @@ while [ "$#" -gt 0 ]; do
|
||||||
ARCH="$2"
|
ARCH="$2"
|
||||||
shift 2
|
shift 2
|
||||||
;;
|
;;
|
||||||
--system)
|
--ssh)
|
||||||
SYSTEM="$2"
|
USE_SSH='yes'
|
||||||
shift 2
|
shift
|
||||||
;;
|
;;
|
||||||
*)
|
*)
|
||||||
echo "WARN: Unknown arg (ignored): $1"
|
echo "WARN: Unknown arg (ignored): $1"
|
||||||
|
@ -72,18 +74,42 @@ if [ "$PKGTYPE" != 'zip' ] && [ "$PKGTYPE" != 'pkg' ]; then
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
## Although we have 'deterministic' set in 'erl_opts', and foced overriding at project level,
|
||||||
|
## still, some of the beams might be compiled (e.g. by erlang.mk) without this flag
|
||||||
|
## longer file path means larger beam files
|
||||||
|
## i.e. Keep the path to work dir short!
|
||||||
|
DOCKER_WORKDIR='/emqx'
|
||||||
|
|
||||||
cd "${SRC_DIR:-.}"
|
cd "${SRC_DIR:-.}"
|
||||||
|
|
||||||
set -x
|
cat <<EOF >.gitconfig.tmp
|
||||||
# $SYSTEM below is used by the `relup-base-vsns.escript` to correctly
|
[core]
|
||||||
# output the list of relup base versions.
|
sshCommand = ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no
|
||||||
|
[safe]
|
||||||
|
directory = $DOCKER_WORKDIR
|
||||||
|
EOF
|
||||||
|
|
||||||
|
if [ "$USE_SSH" = 'yes' ]; then
|
||||||
|
cat <<EOF >>.gitconfig.tmp
|
||||||
|
[url "ssh://git@github.com/"]
|
||||||
|
insteadOf = https://github.com/
|
||||||
|
EOF
|
||||||
|
# when passing ssh agent, we assume this command is executed locally not in ci, so add '-t' option
|
||||||
|
SSH_AGENT_OPTION="-t -e SSH_AUTH_SOCK=/ssh-agent -v ${SSH_AUTH_SOCK}:/ssh-agent"
|
||||||
|
else
|
||||||
|
SSH_AGENT_OPTION=''
|
||||||
|
fi
|
||||||
|
|
||||||
docker info
|
docker info
|
||||||
docker run --rm --privileged tonistiigi/binfmt:latest --install "${ARCH}"
|
docker run --rm --privileged tonistiigi/binfmt:latest --install "${ARCH}"
|
||||||
|
|
||||||
|
# shellcheck disable=SC2086
|
||||||
docker run -i --rm \
|
docker run -i --rm \
|
||||||
-v "$(pwd)":/emqx \
|
-v "$(pwd)":$DOCKER_WORKDIR \
|
||||||
--workdir /emqx \
|
-v "$(pwd)/.gitconfig.tmp":/root/.gitconfig \
|
||||||
|
--workdir $DOCKER_WORKDIR \
|
||||||
--platform="linux/$ARCH" \
|
--platform="linux/$ARCH" \
|
||||||
--user root \
|
--user root \
|
||||||
-e SYSTEM="$SYSTEM" \
|
$SSH_AGENT_OPTION \
|
||||||
"$BUILDER" \
|
"$BUILDER" \
|
||||||
bash -euc "git config --global --add safe.directory /emqx && chown -R root:root _build && make ${PROFILE}-${PKGTYPE} && .ci/build_packages/tests.sh $PROFILE $PKGTYPE"
|
bash -euc "mkdir -p _build && chown -R root:root _build && make ${PROFILE}-${PKGTYPE} && .ci/build_packages/tests.sh $PROFILE $PKGTYPE"
|
||||||
|
|
|
@ -160,7 +160,7 @@ fetch_version(Vsn, VsnMap) ->
|
||||||
|
|
||||||
filter_froms(Froms0, AvailableVersionsIndex) ->
|
filter_froms(Froms0, AvailableVersionsIndex) ->
|
||||||
Froms1 =
|
Froms1 =
|
||||||
case os:getenv("SYSTEM") of
|
case get_system() of
|
||||||
%% we do not support relup for windows
|
%% we do not support relup for windows
|
||||||
"windows" ->
|
"windows" ->
|
||||||
[];
|
[];
|
||||||
|
@ -178,6 +178,14 @@ filter_froms(Froms0, AvailableVersionsIndex) ->
|
||||||
fun(V) -> maps:get(V, AvailableVersionsIndex, false) end,
|
fun(V) -> maps:get(V, AvailableVersionsIndex, false) end,
|
||||||
Froms1).
|
Froms1).
|
||||||
|
|
||||||
|
get_system() ->
|
||||||
|
case os:getenv("SYSTEM") of
|
||||||
|
false ->
|
||||||
|
string:trim(os:cmd("./scripts/get-distro.sh"));
|
||||||
|
System ->
|
||||||
|
System
|
||||||
|
end.
|
||||||
|
|
||||||
%% assumes that's X.Y.Z, without pre-releases
|
%% assumes that's X.Y.Z, without pre-releases
|
||||||
parse_vsn(VsnBin) ->
|
parse_vsn(VsnBin) ->
|
||||||
{match, [Major0, Minor0, Patch0]} = re:run(VsnBin, "([0-9]+)\\.([0-9]+)\\.([0-9]+)",
|
{match, [Major0, Minor0, Patch0]} = re:run(VsnBin, "([0-9]+)\\.([0-9]+)\\.([0-9]+)",
|
||||||
|
|
Loading…
Reference in New Issue