Skip to content
Snippets Groups Projects
Commit 7b03b930 authored by istmxrein's avatar istmxrein
Browse files

add feature to use floating ipv4 address for ssh connection (default)

parent 14d8e314
No related branches found
No related tags found
No related merge requests found
...@@ -11,18 +11,23 @@ LABEL maintainer="Max Reinheimer <max@reinheimer.dev>" \ ...@@ -11,18 +11,23 @@ LABEL maintainer="Max Reinheimer <max@reinheimer.dev>" \
description="A GitLab runner image with openstack custom executor." \ description="A GitLab runner image with openstack custom executor." \
io.k8s.description="A GitLab runner image with openstack custom executor." io.k8s.description="A GitLab runner image with openstack custom executor."
COPY cleanup.py env.py config.sh prepare.py run.py requirements.txt /data/ COPY requirements.txt /data/
COPY entrypoint.sh /usr/bin/entrypoint
WORKDIR /data
RUN apt-get update && apt-get -y install curl dumb-init gcc libffi-dev && \ RUN apt-get update && apt-get -y install curl dumb-init gcc libffi-dev && \
curl -L --output /usr/bin/gitlab-runner "${GITLAB_RUNNER_URL}" && \ curl -L --output /usr/bin/gitlab-runner "${GITLAB_RUNNER_URL}" && \
pip3 install -r /data/requirements.txt && \ pip3 install -r /data/requirements.txt && \
chmod +x /data/* /usr/bin/entrypoint /usr/bin/gitlab-runner && \ chmod +x /usr/bin/gitlab-runner && \
useradd --comment 'GitLab Runner' --create-home gitlab-runner --shell /bin/bash && \ useradd --comment 'GitLab Runner' --create-home gitlab-runner --shell /bin/bash && \
apt-get remove -y gcc curl && apt autoremove -y && apt-get clean apt-get remove -y gcc curl && apt autoremove -y && apt-get clean
COPY cleanup.py env.py config.sh prepare.py run.py /data/
COPY entrypoint.sh /usr/bin/entrypoint
RUN chmod +x /data/* /usr/bin/entrypoint
USER gitlab-runner USER gitlab-runner
WORKDIR /data
ENTRYPOINT ["dumb-init", "--"] ENTRYPOINT ["dumb-init", "--"]
CMD ["entrypoint"] CMD ["entrypoint"]
#!/bin/bash #!/bin/bash
trap cleanup SIGTERM trap cleanup SIGTERM SIGINT
cleanup() { cleanup() {
gitlab-runner unregister --all-runners gitlab-runner unregister --all-runners
......
...@@ -9,7 +9,8 @@ KEY_PAIR_NAME = os.getenv("CUSTOM_ENV_KEY_PAIR_NAME") or os.getenv("KEY_PAIR_NAM ...@@ -9,7 +9,8 @@ KEY_PAIR_NAME = os.getenv("CUSTOM_ENV_KEY_PAIR_NAME") or os.getenv("KEY_PAIR_NAM
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"
SSH_TIMEOUT = os.getenv("CUSTOM_ENV_SSH_TIMEOUT") or os.getenv("SSH_TIMEOUT") or "30" SSH_TIMEOUT = os.getenv("CUSTOM_ENV_SSH_TIMEOUT") or os.getenv("SSH_TIMEOUT") or "20"
FLOATING_IP_NETWORK = os.getenv("FLOATING_IP_NETWORK") or "public"
SSH_IP_VERSION = os.getenv("SSH_IP_VERSION") or "4"
BUILD_FAILURE_EXIT_CODE = os.getenv("BUILD_FAILURE_EXIT_CODE") BUILD_FAILURE_EXIT_CODE = os.getenv("BUILD_FAILURE_EXIT_CODE")
SYSTEM_FAILURE_EXIT_CODE = os.getenv("SYSTEM_FAILURE_EXIT_CODE") SYSTEM_FAILURE_EXIT_CODE = os.getenv("SYSTEM_FAILURE_EXIT_CODE")
...@@ -26,13 +26,22 @@ def provision_server( ...@@ -26,13 +26,22 @@ def provision_server(
security_groups=[{"name": group} for group in env.SECURITY_GROUPS.split()], security_groups=[{"name": group} for group in env.SECURITY_GROUPS.split()],
networks=[{"uuid": network.id}], networks=[{"uuid": network.id}],
) )
return conn.compute.wait_for_server(server, wait=600) server = conn.compute.wait_for_server(server, wait=600)
if env.SSH_IP_VERSION == "4":
ips = conn.available_floating_ip(network=env.FLOATING_IP_NETWORK, server=server)
conn.compute.add_floating_ip_to_server(server, ips.floating_ip_address, fixed_address=None)
return server
def get_server_ip( def get_server_ip(
conn: openstack.connection.Connection, server: openstack.compute.v2.server.Server conn: openstack.connection.Connection, server: openstack.compute.v2.server.Server
) -> str: ) -> str:
return list(conn.compute.server_ips(server))[0].address if env.SSH_IP_VERSION == "4":
return list(conn.compute.server_ips(server))[2].address
else:
return list(conn.compute.server_ips(server))[0].address
def check_ssh(ip: str) -> None: def check_ssh(ip: str) -> None:
......
...@@ -9,7 +9,10 @@ import env ...@@ -9,7 +9,10 @@ import env
def get_server_ip(conn: openstack.connection.Connection) -> str: def get_server_ip(conn: openstack.connection.Connection) -> str:
server = list(conn.compute.servers(name=env.VM_NAME, status="ACTIVE"))[0] server = list(conn.compute.servers(name=env.VM_NAME, status="ACTIVE"))[0]
return list(conn.compute.server_ips(server))[0].address if env.SSH_IP_VERSION == "4":
return list(conn.compute.server_ips(server))[2].address
else:
return list(conn.compute.server_ips(server))[0].address
def execute_script_on_server(ssh: paramiko.client.SSHClient, script_path: str) -> int: def execute_script_on_server(ssh: paramiko.client.SSHClient, script_path: str) -> int:
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment