[Dev] Add repo hash or tag in pipeline sock directory

This commit is contained in:
samuel 2023-05-02 11:46:23 +02:00
parent 13085feb9c
commit 0f28de2bee
1 changed files with 11 additions and 11 deletions

View File

@ -215,24 +215,23 @@ main() (
"${err_pipeline_sock_dir_not_writable}"
fi
# Generate pipeline tmp sock.
tsp="$(date +%s)"
random="$(echo "${RANDOM}" | md5sum | head --bytes 32)"
rd_pipeline_sock_dir="${pipeline_sock_dir}/${pipeline}-${tsp}-${random}"
rd_pipeline_sock="${rd_pipeline_sock_dir}/pipeline.sock"
# Generate random string.
random="$(echo "${RANDOM}" | md5sum | head --bytes 8)"
# Build runner request.
case "${pipeline}" in
newcommit)
rd_pipeline_sock_dir="${pipeline_sock_dir}/${pipeline}-${repo_hash}-${random}"
runner_request="$(jq --null-input --compact-output \
--arg s "${rd_pipeline_sock}" \
--arg s "${rd_pipeline_sock_dir}/pipeline.sock" \
--arg n "${repo_name}" \
--arg h "${repo_hash}" \
'{"response_sock":$s,"repo_name":$n,"repo_hash":$h}')"
;;
newtag)
rd_pipeline_sock_dir="${pipeline_sock_dir}/${pipeline}-${repo_tag}-${random}"
runner_request="$(jq --null-input --compact-output \
--arg s "${rd_pipeline_sock}" \
--arg s "${rd_pipeline_sock_dir}/pipeline.sock" \
--arg n "${repo_name}" \
--arg h "${repo_hash}" \
--arg t "${repo_tag}" \
@ -254,17 +253,18 @@ main() (
(
inotifywait --timeout 1 --quiet --quiet \
--event create "${rd_pipeline_sock_dir}" || true
chmod 775 "${rd_pipeline_sock}"
chgrp "${git_runner_groupname}" "${rd_pipeline_sock}"
chmod 775 "${rd_pipeline_sock_dir}/pipeline.sock"
chgrp "${git_runner_groupname}" "${rd_pipeline_sock_dir}/pipeline.sock"
echo "${runner_request}" | ncat --unixsock "${runner_sock}"
) &
# Wait for runner response.
cd "${rd_pipeline_sock_dir}"
if [ "${runner_timeout}" -gt 0 ]; then
response="$(timeout "${runner_timeout}" ncat --listen \
--unixsock "${rd_pipeline_sock}")"
--unixsock pipeline.sock)"
else
response="$(ncat --listen --unixsock "${rd_pipeline_sock}")"
response="$(ncat --listen --unixsock pipeline.sock)"
fi
# Remove random directory.