Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
O
Openstack Gitlab Executor
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Pi-Lab
Infrastructure
Openstack Gitlab Executor
Commits
314ce699
Commit
314ce699
authored
2 years ago
by
istmxrein
Browse files
Options
Downloads
Patches
Plain Diff
generate ssh keypair for each connection
parent
7b03b930
No related branches found
No related tags found
No related merge requests found
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
Containerfile
+0
-55
0 additions, 55 deletions
Containerfile
cleanup.py
+1
-1
1 addition, 1 deletion
cleanup.py
entrypoint.sh
+0
-2
0 additions, 2 deletions
entrypoint.sh
env.py
+1
-1
1 addition, 1 deletion
env.py
prepare.py
+29
-3
29 additions, 3 deletions
prepare.py
with
31 additions
and
62 deletions
Containerfile
deleted
100644 → 0
+
0
−
55
View file @
7b03b930
ARG
GITLAB_RUNNER_VERSION=v13.12.0
FROM
registry.access.redhat.com/ubi8:8.5
AS
builder
ARG
GITLAB_RUNNER_VERSION
ENV
GITLAB_REPO=https://gitlab.com/gitlab-org/gitlab-runner.git \
PATH=$PATH:/root/go/bin/
RUN
dnf
install
-y
git-core make go ncurses
&&
\
git clone
--depth
=
1
--branch
=
${
GITLAB_RUNNER_VERSION
}
${
GITLAB_REPO
}
&&
\
cd
gitlab-runner
&&
\
make runner-bin-host
&&
\
chmod
a+x out/binaries/gitlab-runner
&&
\
out/binaries/gitlab-runner
--version
FROM
registry.access.redhat.com/ubi8:8.5
ARG
GITLAB_RUNNER_VERSION
COPY
--from=builder /gitlab-runner/out/binaries/gitlab-runner /usr/bin
ENV
HOME=/home/gitlab-runner \
VENV=/openstack_driver_venv
ENV
PATH="$VENV/bin:$PATH"
LABEL
maintainer="Dmitry Misharov <misharov@redhat.com>" \
io.openshift.tags="gitlab,ci,runner" \
name="openstack-gitlab-runner" \
io.k8s.display-name="GitLab runner" \
summary="GitLab runner" \
description="A GitLab runner image with openstack custom executor." \
io.k8s.description="A GitLab runner image with openstack custom executor."
WORKDIR
$HOME
COPY
cleanup.py env.py config.sh prepare.py run.py requirements.txt start.sh ./
RUN
dnf
install
-y
--nodocs
python38-pip git-core
&&
\
pip3
install
dumb-init
&&
\
python3.8
-m
venv
$VENV
&&
\
pip
install
wheel
&&
\
pip
install
-r
requirements.txt
&&
\
dnf remove
-y
git-core
&&
\
dnf clean all
-y
RUN
chgrp
-R
0
$HOME
&&
\
chmod
+x cleanup.py config.sh prepare.py run.py start.sh
&&
\
chmod
-R
g
=
u
$HOME
USER
1001
ENTRYPOINT
["dumb-init", "--"]
CMD
["./start.sh"]
This diff is collapsed.
Click to expand it.
cleanup.py
+
1
−
1
View file @
314ce699
...
@@ -8,7 +8,7 @@ def main() -> None:
...
@@ -8,7 +8,7 @@ def main() -> None:
conn
=
openstack
.
connect
()
conn
=
openstack
.
connect
()
for
server
in
conn
.
compute
.
servers
(
name
=
env
.
VM_NAME
):
for
server
in
conn
.
compute
.
servers
(
name
=
env
.
VM_NAME
):
conn
.
compute
.
delete_server
(
server
)
conn
.
compute
.
delete_server
(
server
)
conn
.
delete_keypair
(
env
.
KEY_PAIR_NAME
)
if
__name__
==
"
__main__
"
:
if
__name__
==
"
__main__
"
:
main
()
main
()
This diff is collapsed.
Click to expand it.
entrypoint.sh
+
0
−
2
View file @
314ce699
...
@@ -12,8 +12,6 @@ if [[ "$TLS_CA_CERT" ]]; then
...
@@ -12,8 +12,6 @@ if [[ "$TLS_CA_CERT" ]]; then
echo
"
$TLS_CA_CERT
"
>
"
$HOME
"
/.gitlab-runner/certs/
$(
echo
"
$CI_SERVER_URL
"
|
cut
-d
'/'
-f3
|
cut
-d
':'
-f1
)
.crt
echo
"
$TLS_CA_CERT
"
>
"
$HOME
"
/.gitlab-runner/certs/
$(
echo
"
$CI_SERVER_URL
"
|
cut
-d
'/'
-f3
|
cut
-d
':'
-f1
)
.crt
fi
fi
echo
"
$PRIVATE_KEY
"
>
"
$HOME
"
/priv_key
gitlab-runner register
--non-interactive
\
gitlab-runner register
--non-interactive
\
--executor
=
custom
\
--executor
=
custom
\
--custom-config-exec
=
/data/config.sh
\
--custom-config-exec
=
/data/config.sh
\
...
...
This diff is collapsed.
Click to expand it.
env.py
+
1
−
1
View file @
314ce699
...
@@ -5,7 +5,7 @@ VM_NAME = f"gitlab-builder-{os.getenv('CUSTOM_ENV_CI_RUNNER_ID')}-project-{os.ge
...
@@ -5,7 +5,7 @@ VM_NAME = f"gitlab-builder-{os.getenv('CUSTOM_ENV_CI_RUNNER_ID')}-project-{os.ge
FLAVOR
=
os
.
getenv
(
"
CUSTOM_ENV_FLAVOR
"
)
or
os
.
getenv
(
"
FLAVOR
"
)
FLAVOR
=
os
.
getenv
(
"
CUSTOM_ENV_FLAVOR
"
)
or
os
.
getenv
(
"
FLAVOR
"
)
BUILDER_IMAGE
=
os
.
getenv
(
"
CUSTOM_ENV_BUILDER_IMAGE
"
)
or
os
.
getenv
(
"
BUILDER_IMAGE
"
)
BUILDER_IMAGE
=
os
.
getenv
(
"
CUSTOM_ENV_BUILDER_IMAGE
"
)
or
os
.
getenv
(
"
BUILDER_IMAGE
"
)
NETWORK
=
os
.
getenv
(
"
CUSTOM_ENV_NETWORK
"
)
or
os
.
getenv
(
"
NETWORK
"
)
NETWORK
=
os
.
getenv
(
"
CUSTOM_ENV_NETWORK
"
)
or
os
.
getenv
(
"
NETWORK
"
)
KEY_PAIR_NAME
=
os
.
getenv
(
"
CUSTOM_ENV_KEY_PAIR_NAME
"
)
or
os
.
getenv
(
"
KEY_PAIR
_NAME
"
)
KEY_PAIR_NAME
=
f
'
key-
{
VM
_NAME
}
'
SECURITY_GROUPS
=
os
.
getenv
(
"
CUSTOM_ENV_SECURITY_GROUPS
"
)
or
os
.
getenv
(
"
SECURITY_GROUPS
"
)
SECURITY_GROUPS
=
os
.
getenv
(
"
CUSTOM_ENV_SECURITY_GROUPS
"
)
or
os
.
getenv
(
"
SECURITY_GROUPS
"
)
USERNAME
=
os
.
getenv
(
"
CUSTOM_ENV_USERNAME
"
)
or
os
.
getenv
(
"
USERNAME
"
)
USERNAME
=
os
.
getenv
(
"
CUSTOM_ENV_USERNAME
"
)
or
os
.
getenv
(
"
USERNAME
"
)
PRIVATE_KEY_PATH
=
f
"
{
os
.
getenv
(
'
HOME
'
)
}
/priv_key
"
PRIVATE_KEY_PATH
=
f
"
{
os
.
getenv
(
'
HOME
'
)
}
/priv_key
"
...
...
This diff is collapsed.
Click to expand it.
prepare.py
+
29
−
3
View file @
314ce699
#!/usr/bin/env python
#!/usr/bin/env python
import
sys
import
sys
import
traceback
import
traceback
import
os
import
openstack
import
openstack
import
paramiko
import
paramiko
from
tenacity
import
retry
from
tenacity
import
retry
from
tenacity
import
RetryCallState
from
tenacity
import
RetryCallState
from
tenacity
import
stop_after_attempt
from
tenacity
import
stop_after_attempt
from
tenacity
import
wait_fixed
from
tenacity
import
wait_fixed
from
cryptography.hazmat.primitives
import
serialization
from
cryptography.hazmat.primitives.asymmetric
import
rsa
from
cryptography.hazmat.backends
import
default_backend
import
env
import
env
def
provision_server
(
def
provision_server
(
conn
:
openstack
.
connection
.
Connection
,
conn
:
openstack
.
connection
.
Connection
,
public_key
:
str
)
->
openstack
.
compute
.
v2
.
server
.
Server
:
)
->
openstack
.
compute
.
v2
.
server
.
Server
:
conn
.
create_keypair
(
env
.
KEY_PAIR_NAME
,
public_key
=
public_key
)
image
=
conn
.
compute
.
find_image
(
env
.
BUILDER_IMAGE
)
image
=
conn
.
compute
.
find_image
(
env
.
BUILDER_IMAGE
)
flavor
=
conn
.
compute
.
find_flavor
(
env
.
FLAVOR
)
flavor
=
conn
.
compute
.
find_flavor
(
env
.
FLAVOR
)
network
=
conn
.
network
.
find_network
(
env
.
NETWORK
)
network
=
conn
.
network
.
find_network
(
env
.
NETWORK
)
...
@@ -75,6 +79,27 @@ def check_ssh(ip: str) -> None:
...
@@ -75,6 +79,27 @@ def check_ssh(ip: str) -> None:
ssh_client
.
close
()
ssh_client
.
close
()
def
generate_rsa_keypair
():
# generate private/public key pair
key
=
rsa
.
generate_private_key
(
backend
=
default_backend
(),
public_exponent
=
65537
,
\
key_size
=
2048
)
# get public key in OpenSSH format
public_key
=
key
.
public_key
().
public_bytes
(
serialization
.
Encoding
.
OpenSSH
,
\
serialization
.
PublicFormat
.
OpenSSH
)
# get private key in PEM container format
pem
=
key
.
private_bytes
(
encoding
=
serialization
.
Encoding
.
PEM
,
format
=
serialization
.
PrivateFormat
.
TraditionalOpenSSL
,
encryption_algorithm
=
serialization
.
NoEncryption
())
with
open
(
env
.
PRIVATE_KEY_PATH
,
'
wb
'
)
as
content_file
:
content_file
.
write
(
pem
.
decode
(
'
utf-8
'
))
public_key_str
=
public_key
.
decode
(
'
utf-8
'
)
print
(
f
'
Public Key:
{
public_key_str
}
'
)
return
public_key_str
def
main
()
->
None
:
def
main
()
->
None
:
print
(
print
(
"
Source code of this driver https://github.com/RedHatQE/openstack-gitlab-executor
"
,
"
Source code of this driver https://github.com/RedHatQE/openstack-gitlab-executor
"
,
...
@@ -84,7 +109,8 @@ def main() -> None:
...
@@ -84,7 +109,8 @@ def main() -> None:
try
:
try
:
conn
=
openstack
.
connect
()
conn
=
openstack
.
connect
()
print
(
f
"
Provisioning an instance
{
env
.
VM_NAME
}
"
,
flush
=
True
)
print
(
f
"
Provisioning an instance
{
env
.
VM_NAME
}
"
,
flush
=
True
)
server
=
provision_server
(
conn
)
public_key
=
generate_rsa_keypair
()
server
=
provision_server
(
conn
,
public_key
)
ip
=
get_server_ip
(
conn
,
server
)
ip
=
get_server_ip
(
conn
,
server
)
print
(
f
"
Instance
{
env
.
VM_NAME
}
is running on address
{
ip
}
"
,
flush
=
True
)
print
(
f
"
Instance
{
env
.
VM_NAME
}
is running on address
{
ip
}
"
,
flush
=
True
)
conn
.
close
()
conn
.
close
()
...
...
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