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