Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
C
cx-custom-gitlab-runner
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Lukas Werner
cx-custom-gitlab-runner
Commits
aa9bfe2c
Commit
aa9bfe2c
authored
3 years ago
by
Lukas Werner
Browse files
Options
Downloads
Patches
Plain Diff
Prepare run script for testcluster
parent
d79e49b1
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
runner_scripts/root/run.sh
+17
-14
17 additions, 14 deletions
runner_scripts/root/run.sh
with
17 additions
and
14 deletions
runner_scripts/root/run.sh
100755 → 100644
+
17
−
14
View file @
aa9bfe2c
#!/bin/bash
-l
#!/bin/bash
set
-euf
-o
pipefail
set
-euf
-o
pipefail
shopt
-s
inherit_errexit
shopt
-s
inherit_errexit
module load slurm
hash awk
hash awk
hash chown
hash chown
hash
diff
hash
diff
...
@@ -15,14 +13,13 @@ hash sed
...
@@ -15,14 +13,13 @@ hash sed
hash
srun
hash
srun
hash
ssh-keygen
hash
ssh-keygen
function
error
{
function
error
{
:
"
${
RV
:
=
${
2
:-
$BUILD_FAILURE_EXIT_CODE
}}
"
:
"
${
RV
:
=
${
2
:-
$BUILD_FAILURE_EXIT_CODE
}}
"
echo
"
$1
"
>
&2
echo
"
$1
"
>
&2
return
"
$RV
"
return
"
$RV
"
}
}
## User authenti
fi
cation
## User authentication
:
"
${
CUSTOM_ENV_AUTH_USER
:?
"AUTH_USER CI/CD variable has not been set."
}
"
:
"
${
CUSTOM_ENV_AUTH_USER
:?
"AUTH_USER CI/CD variable has not been set."
}
"
:
"
${
CUSTOM_ENV_AUTH_KEY
:?
"AUTH_KEY CI/CD variable has not been set."
}
"
:
"
${
CUSTOM_ENV_AUTH_KEY
:?
"AUTH_KEY CI/CD variable has not been set."
}
"
...
@@ -30,7 +27,7 @@ function error {
...
@@ -30,7 +27,7 @@ function error {
AUTH_USER
=
$CUSTOM_ENV_AUTH_USER
AUTH_USER
=
$CUSTOM_ENV_AUTH_USER
AUTH_USER_HOME
=
$(
getent passwd
"
$AUTH_USER
"
|
awk
-F
":"
'{print $6}'
)
AUTH_USER_HOME
=
$(
getent passwd
"
$AUTH_USER
"
|
awk
-F
":"
'{print $6}'
)
AUTH_USER_SHELL
=
$(
getent passwd
"
$AUTH_USER
"
|
awk
-F
":"
'{print $7}'
)
AUTH_USER_SHELL
=
$(
getent passwd
"
$AUTH_USER
"
|
awk
-F
":"
'{print $7}'
)
AUTH_USER_WORK
=
$(
runuser
"
$AUTH_USER
"
--command
"echo
\$
WORK"
)
AUTH_USER_WORK
=
$(
runuser
"
$AUTH_USER
"
--login
--command
"echo
\$
WORK"
)
## Check if the user exists and the validity of its ID
## Check if the user exists and the validity of its ID
id
-u
"
$AUTH_USER
"
>
/dev/null 2>&1
||
error
"User
$AUTH_USER
does not exist"
id
-u
"
$AUTH_USER
"
>
/dev/null 2>&1
||
error
"User
$AUTH_USER
does not exist"
...
@@ -43,22 +40,21 @@ AUTH_PUB=/etc/gitlab-runner/authorized_keys
...
@@ -43,22 +40,21 @@ AUTH_PUB=/etc/gitlab-runner/authorized_keys
(
(
while
read
-r
PUB
while
read
-r
PUB
do
do
diff <
(
ssh-keygen
-y
-e
-f
/dev/stdin
<<<
"
$AUTH_KEY
"
)
<
(
ssh-keygen
-y
-e
-f
/dev/stdin
<<<
"
$PUB
"
)
&&
exit
0
diff
--color
=
never
<
(
ssh-keygen
-y
-e
-f
/dev/stdin
<<<
"
$AUTH_KEY
"
)
<
(
ssh-keygen
-y
-e
-f
/dev/stdin
<<<
"
$PUB
"
)
>
/dev/null
&&
exit
0
done
<
"
$AUTH_PUB
"
done
<
"
$AUTH_PUB
"
exit
1
exit
1
)
||
error
"Authentication failed."
)
||
error
"Authentication failed."
### Env setup
### Env setup
chown
-R
"
$AUTH_USER
"
"
$TMPDIR
"
chown
-R
"
$AUTH_USER
"
"
$TMPDIR
"
BASE_DIR
=
$AUTH_USER_WORK
/gitlab-runner/builds/
${
CUSTOM_ENV_CI_CONCURRENT_PROJECT_ID
:?
}
/
${
CUSTOM_ENV_CI_PROJECT_NAMESPACE
:?
}
/
${
CUSTOM_ENV_CI_PROJECT_NAME
:?
}
BASE_DIR
=
$AUTH_USER_WORK
/gitlab-runner/builds/
${
CUSTOM_ENV_CI_CONCURRENT_PROJECT_ID
:?
}
/
${
CUSTOM_ENV_CI_PROJECT_NAMESPACE
:?
}
/
${
CUSTOM_ENV_CI_PROJECT_NAME
:?
}
runuser
"
$AUTH_USER
"
--command
"mkdir -p
$BASE_DIR
"
runuser
"
$AUTH_USER
"
--login
--command
"mkdir -p
$BASE_DIR
"
if
[[
(
"
$2
"
==
"step_script"
||
"
$2
"
==
"build_script"
)
&&
${
CUSTOM_ENV_SUBMIT_TO_SLURM
:-}
]]
if
[[
(
"
$2
"
==
"step_script"
||
"
$2
"
==
"build_script"
)
&&
${
CUSTOM_ENV_SUBMIT_TO_SLURM
:-}
]]
then
then
## The script is the one specified in the gitlab-ci.yml script directive and the SUBMIT_TO_SLURM variable is set
,
## The script is the one specified in the gitlab-ci.yml script directive and the SUBMIT_TO_SLURM variable is set
for
E
in
$(
env
|
grep
-E
"^CUSTOM_ENV_SLURM_"
)
for
E
in
$(
env
|
grep
-E
"^CUSTOM_ENV_SLURM_"
)
do
do
...
@@ -79,12 +75,19 @@ then
...
@@ -79,12 +75,19 @@ then
do
do
SALLOC_OPTIONS+
=(
"
$(
echo
"
${
E
#SLURM_
}
"
|
awk
-F
"="
'{gsub("_", "-", $1); print "--"tolower($1)"="$2}'
)
"
)
SALLOC_OPTIONS+
=(
"
$(
echo
"
${
E
#SLURM_
}
"
|
awk
-F
"="
'{gsub("_", "-", $1); print "--"tolower($1)"="$2}'
)
"
)
done
done
runuser
--login
"
$AUTH_USER
"
--command
"cp
$1
$BASE_DIR
.tmp/
$CUSTOM_ENV_CI_JOB_ID
.sh"
runuser
--login
"
$AUTH_USER
"
--command
"cp
$1
$BASE_DIR
.tmp/
$CUSTOM_ENV_CI_JOB_ID
.sh"
exec
salloc
--quiet
--uid
"
$AUTH_USER
"
--gid
"
$(
id
-g
-n
"
$AUTH_USER
"
)
"
--chdir
"
$BASE_DIR
"
"
${
SALLOC_OPTIONS
[@]
}
"
\
echo
"#!/bin/bash"
>
"
$TMPDIR
"
/salloc.sh
srun
--cpu-bind
none
--export
=
HOME
=
"
$AUTH_USER_HOME
"
,SHELL
=
"
$AUTH_USER_SHELL
"
--wait
0
--kill-on-bad-exit
=
1
\
echo
"salloc --quiet --chdir
\"
$BASE_DIR
\"
${
SALLOC_OPTIONS
[@]
}
\
"
$AUTH_USER_SHELL
"
--login
"
$BASE_DIR
.tmp/
$CUSTOM_ENV_CI_JOB_ID
.sh"
srun --cpu-bind none --wait 0 --kill-on-bad-exit=1
\
\"
$AUTH_USER_SHELL
\"
--login
\"
$BASE_DIR
.tmp/
$CUSTOM_ENV_CI_JOB_ID
.sh
\"
"
>>
"
$TMPDIR
"
/salloc.sh
chmod
+x
"
$TMPDIR
"
/salloc.sh
exec
runuser
--login
"
$AUTH_USER
"
--command
"
$TMPDIR
"
/salloc.sh
#exec runuser --login "$AUTH_USER" --command "salloc --quiet --chdir \"$BASE_DIR\" ${SALLOC_OPTIONS[@]} \
# srun --cpu-bind none --wait 0 --kill-on-bad-exit=1 \
# \"$AUTH_USER_SHELL\" --login \"$BASE_DIR.tmp/$CUSTOM_ENV_CI_JOB_ID.sh\""
else
else
runuser
--login
"
$AUTH_USER
"
--command
"cd
\"
$BASE_DIR
\"
;
$1
"
runuser
--login
"
$AUTH_USER
"
--command
"cd
\"
$BASE_DIR
\"
;
$1
"
fi
fi
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment