Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
G
GitLab runner SSH executor
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
JetBrains YouTrack
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
KSZK
Open Source
GitLab runner SSH executor
Commits
a917f84d
Commit
a917f84d
authored
Jul 9, 2020
by
Robotka István Adrián
Browse files
Options
Downloads
Patches
Plain Diff
implementation of the executor
parent
834e3109
No related branches found
No related tags found
No related merge requests found
Changes
5
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
README.md
+31
-1
31 additions, 1 deletion
README.md
install_executor.sh
+7
-0
7 additions, 0 deletions
install_executor.sh
prepare.sh
+22
-0
22 additions, 0 deletions
prepare.sh
run.sh
+31
-6
31 additions, 6 deletions
run.sh
ssh_config
+13
-0
13 additions, 0 deletions
ssh_config
with
104 additions
and
7 deletions
README.md
+
31
−
1
View file @
a917f84d
...
...
@@ -3,6 +3,36 @@
The original SSH executor can only be used for a single/static host described
in the runner config. This is not as flexible as our use-case's needs.
# Sources
# Install
```
sh
cd
/opt
git clone git@git.sch.bme.hu:kszk/opensource/ssh-executor.git ssh-executor
cd
ssh-executor
./install/executor.sh
```
Generate an SSH key for the root user. This will be used for the authentication of the ssh executor.
Setup a runner in the
`/etc/gitlab-runner/config.toml`
file like the following:
```
yaml
[[
runners
]]
name = "kszk-deploy"
url = "https://git.sch.bme.hu/"
token = "**********"
executor = "custom"
builds_dir = "/tmp/kszk-deploy/builds"
# remote deploy/repo dir (ssh)
cache_dir = "/tmp/kszk-deploy/cache"
# remote cache dir (ssh)
[
runners.custom_build_dir
]
[
runners.cache
]
[
runners.cache.s3
]
[
runners.cache.gcs
]
[
runners.custom
]
prepare_exec = "/opt/ssh-executor/prepare.sh"
# suctom executor script
run_exec = "/opt/ssh-executor/run.sh"
# suctom executor script
```
Profit.
# Sources/credits
-
<https://docs.gitlab.com/runner/executors/ssh.html>
-
<https://docs.gitlab.com/runner/executors/custom_examples/lxd.html>
This diff is collapsed.
Click to expand it.
install_executor.sh
0 → 100755
+
7
−
0
View file @
a917f84d
#!/usr/bin/env bash
#!/usr/bin/env bash
cp
ssh_config /root/.ssh/config
chown
-R
root:root
.
chmod
664 /root/.ssh/config
This diff is collapsed.
Click to expand it.
prepare.sh
0 → 100755
+
22
−
0
View file @
a917f84d
#!/usr/bin/env bash
# this will make your script exit if any command in a pipeline errors.
set
-eo
pipefail
# trap any error, and mark it as a system failure.
trap
"exit
$SYSTEM_FAILURE_EXIT_CODE
"
ERR
if
[
-z
"
$CUSTOM_ENV_SSH_HOST
"
]
;
then
echo
"SSH_HOST variable is NOT present. Please provide it in the .gitlab-ci.yml file in the variables directive."
exit
1
fi
SSH_HOST
=
$CUSTOM_ENV_SSH_HOST
SSH_USER
=
${
CUSTOM_ENV_SSH_USER
:
=kszk-gitlab-deployer
}
SSH_PORT
=
${
CUSTOM_ENV_SSH_PORT
:
=22
}
# This will run the script generated by GitLab Runner
SSH_CMD
=
"ssh
$SSH_USER
@
$SSH_HOST
-p
$SSH_PORT
-T"
echo
"Prepare SSH command:
$SSH_CMD
"
echo
"
$SSH_CMD
"
>
ssh_command
This diff is collapsed.
Click to expand it.
run.sh
+
31
−
6
View file @
a917f84d
#!/usr/bin/env bash
JOB_ID
=
"runner-
$CUSTOM_ENV_CI_RUNNER_ID
-project-
$CUSTOM_ENV_CI_PROJECT_ID
-concurrent-
$CUSTOM_ENV_CI_CONCURRENT_PROJECT_ID
-
$CUSTOM_ENV_CI_JOB_ID
"
# This script will be executed MULTIPLE times
# see: https://docs.gitlab.com/runner/executors/custom.html#run
# Two arguments:
# $1: The path to the script that GitLab Runner creates for the Custom executor to run.
# $2: Name of the stage.
SCRIPT_PATH
=
"
$1
"
STAGE
=
"
$2
"
# Sub stages (in sequential order):
# - prepare_script
# - get_sources
# - restore_cache
# - download_artifacts
# - step_*
# - build_script
# - step_*
# - after_script
# - archive_cache
# - upload_artifacts_on_success OR upload_artifacts_on_failure
# this will make your script exit if any command in a pipeline errors.
set
-eo
pipefail
# trap any error, and mark it as a system failure.
trap
"exit
$SYSTEM_FAILURE_EXIT_CODE
"
ERR
trap
"echo FAIL_HERE; exit
$SYSTEM_FAILURE_EXIT_CODE
"
ERR
# debug sub-stages:
#echo "Running run.sh with args: $*"
echo
"Running in
$JOB_ID
"
# see: prepare.sh
SSH_CMD
=
$(
cat
ssh_command
)
# This will run the script generated by GitLab Runner by sending the
# content of the script to the container via STDIN.
# This will run the script generated by GitLab Runner on the remote host
# leave exit 0 at the end, it causes exit 1 with the ssh command
head
-n
-1
"
${
1
}
"
|
$SSH_CMD
cat
<
"
${
1
}
"
if
[
$?
-ne
0
]
;
then
# Exit using the variable, to make the build as failure in GitLab CI.
exit
$BUILD_FAILURE_EXIT_CODE
fi
exit
This diff is collapsed.
Click to expand it.
ssh_config
0 → 100644
+
13
−
0
View file @
a917f84d
### DO NOT EDIT, it will be overwriten
### DO NOT EDIT, it will be overwriten
### DO NOT EDIT, it will be overwriten
# Edit only in repo: https://git.sch.bme.hu/kszk/opensource/ssh-executor
Host
*
KexAlgorithms
curve25519-sha256@libssh.org,diffie-hellman-group-exchange-sha256
MACs
hmac-sha2-512-etm@openssh.com,hmac-sha2-256-etm@openssh.com,umac-128-etm@openssh.com,hmac-sha2-512,hmac-sha2-256,umac-128@openssh.com
Ciphers
chacha20-poly1305@openssh.com,aes256-gcm@openssh.com,aes128-gcm@openssh.com,aes256-ctr,aes192-ctr,aes128-ctr
ServerAliveInterval
10
ControlMaster
auto
ControlPersist
yes
ControlPath
~/.ssh/socket-%r@%h:%p
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