From 706795c45a3c3dde692abbc2841a1d9bfa56060f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Franti=C5=A1ek=20=C5=98ezn=C3=AD=C4=8Dek?= <246254@mail.muni.cz> Date: Mon, 29 Apr 2024 19:16:44 +0200 Subject: [PATCH] feat: add ssh keypair mounting / generation --- .gitlab-ci.yml | 2 +- CHANGELOG.md | 6 ++++++ ci/toolset-container/entrypoint.sh | 1 + ci/toolset-container/lib.sh.inc | 8 ++++++++ infra-action.sh | 9 ++++++++- .../2tier_public_bastion_private_vm_farm/variables.tf | 2 +- 6 files changed, 25 insertions(+), 3 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index cfcd43e..22c77e8 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -16,7 +16,7 @@ before_script: after_script: &container-images-list - echo "Pushed container images are:" -- awk '{print " " $0}' container-release.uri +- awk '{print " " $0}' ci/toolset-container/container-release.uri # build and release container image # --------------------------------------------------------------------------- diff --git a/CHANGELOG.md b/CHANGELOG.md index b68d109..12115c6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] + +## [1.5.0] - 2024-04-29 +### Fixed +- CI container listing +- add SSh key pair generation if needed + ## [1.4.0] - 2024-04-29 ### Fixed - container entrypoint diff --git a/ci/toolset-container/entrypoint.sh b/ci/toolset-container/entrypoint.sh index 83e9554..bb9e115 100755 --- a/ci/toolset-container/entrypoint.sh +++ b/ci/toolset-container/entrypoint.sh @@ -23,6 +23,7 @@ elif [ "${OPERATION}" == "cloud-connect" ]; then ostack_cloud_connect elif [ "${OPERATION}" == "infra-deploy" -o "${OPERATION}" == "infra-destroy" ]; then + generate_ssh_keypair_if_missing id_rsa source_if_exists ${OPENSTACK_RC_FILES} ostack_cloud_connect project_type=group diff --git a/ci/toolset-container/lib.sh.inc b/ci/toolset-container/lib.sh.inc index 8f26c71..50b7780 100644 --- a/ci/toolset-container/lib.sh.inc +++ b/ci/toolset-container/lib.sh.inc @@ -68,3 +68,11 @@ function is_personal_project() { fi } +function generate_ssh_keypair_if_missing() { + local ssh_private_key_file="$1" + + if [ ! -s "${ssh_private_key_file}.pub" ]; then + ssh-keygen -t rsa -b 4096 -f "${ssh_private_key_file}" + fi +} + diff --git a/infra-action.sh b/infra-action.sh index 06d272a..46b0f1b 100755 --- a/infra-action.sh +++ b/infra-action.sh @@ -17,8 +17,15 @@ CONTAINER_RUNTIME_EXE=$(get_container_engine) CONTAINER_IMAGE="${CONTAINER_IMAGE:-"registry.gitlab.ics.muni.cz:443/cloud/terraform/modules/dask-distributed-2t-infra:1"}" REPO_NAME=dask-distributed-2t-infra +ADDITIONAL_ARGS="" +if [ "${HOME}/.ssh/id_rsa.pub" ]; then + ADDITIONAL_ARGS="-v ${HOME}/.ssh/id_rsa.pub:${WORKDIR}/${REPO_NAME}/example/id_rsa.pub:ro" +fi + if [[ "${OPERATION}" =~ ^(shell|cloud-connect|infra-deploy|infra-destroy)$ ]]; then - ${CONTAINER_RUNTIME_EXE} run -it -v "$PWD:${WORKDIR}/${REPO_NAME}" "${CONTAINER_IMAGE}" "${OPERATION}" + ${CONTAINER_RUNTIME_EXE} run -it -v "$PWD:${WORKDIR}/${REPO_NAME}" ${ADDITIONAL_ARGS} "${CONTAINER_IMAGE}" "${OPERATION}" +elif [ "${OPERATION}" == "-h" -o "${OPERATION}" == "--help" ]; then + awk 'NR>1{if ($1=="#"){$1=" ";print $0}else{exit(0)}}' $0 else logerr "ERROR: Invalid operation (${OPERATION})" exit 2 diff --git a/modules/2tier_public_bastion_private_vm_farm/variables.tf b/modules/2tier_public_bastion_private_vm_farm/variables.tf index 24c96e9..a6b5a82 100644 --- a/modules/2tier_public_bastion_private_vm_farm/variables.tf +++ b/modules/2tier_public_bastion_private_vm_farm/variables.tf @@ -7,7 +7,7 @@ variable "infra_name" { } variable "ssh_public_key" { - default = "~/.ssh/id_rsa.pub" + default = "id_rsa.pub" } variable "internal_network_cidr" { -- GitLab