Skip to content
Snippets Groups Projects
Commit 486bda7a authored by František Řezníček's avatar František Řezníček
Browse files

feat: add container automation

parent 367ea964
No related branches found
No related tags found
No related merge requests found
Pipeline #435602 passed
......@@ -6,8 +6,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
## [Unreleased]
## [1.2.0] - 2024-04-29
### Changed
- container automation added (entrypoint)
- repo automation added (infra-action.sh)
## [1.+.0] - 2024-04-2ý
## [1.1.0] - 2024-04-27
### Changed
- Automation improved ()
### Fixed
......
......@@ -3,7 +3,7 @@ FROM ubuntu:jammy
ENV TZ=Europe/Prague
ENV DEBIAN_FRONTEND=noninteractive
COPY *.sh /usr/local/bin/
COPY *.sh* /usr/local/bin/
COPY requirements.* /tmp/
RUN /usr/local/bin/install-apt-repo.sh https://apt.releases.hashicorp.com https://apt.releases.hashicorp.com/gpg /etc/apt/trusted.gpg.d/hashicorp.gpg && \
......@@ -14,6 +14,7 @@ RUN /usr/local/bin/install-apt-repo.sh https://apt.releases.hashicorp.com https:
WORKDIR /workdir
# Terraform autocomplete
RUN touch ~/.bashrc && terraform -install-autocomplete
ENTRYPOINT ["/usr/local/bin/entrypoint.sh"]
#!/usr/bin/env bash
#
# entrypoint.sh <OPERATION>
#
# container entrypoint performs operation <OPERATION>
# * shell interactive shell
# * cloud-connect connect to the cloud
# * infra-deploy deploy the infrastructure
# * infra-destroy destroy the infrastructure
OPERATION="${1:-"shell"}"
SCRIPT_DIR=$(dirname $(readlink -f $0))
source "${SCRIPT_DIR}/lib.sh.inc"
if [ "${OPERATION}" == "shell" ]; then
bash
elif [ "${OPERATION}" == "cloud-connect" ]; then
source_if_exists ${OPENSTACK_RC_FILES}
ostack_cloud_connect
elif [ "${OPERATION}" == "infra-deploy" -o "${OPERATION}" == "infra-destroy" ]; then
pushd "${WORKDIR}/dask-distributed-2t-infra/example"
source_if_exists ${OPENSTACK_RC_FILES}
ostack_cloud_connect
project_type=group
tf_variable_file=g1-prod-brno-group-projects.tfvars
if project_name=$(is_personal_project); then
project_type=personal
tf_variable_file=g1-prod-brno-personal-projects.tfvars
fi
terraform init
terraform validate
if [ "${OPERATION}" == "infra-destroy" ]; then
terraform destroy -var-file ${tf_variable_file}
else
terraform plan -var-file ${tf_variable_file} --out plan
terraform apply plan
fi
else
logerr "ERROR: Invalid operation (${OPERATION})"
exit 2
fi
#############################################################################
# variables
#############################################################################
OPENSTACK_BIN="${OPENSTACK_BIN:-openstack}"
OPENSTACK_RC_FILES="${OPENSTACK_RC_FILES=:-"./project-openrc.sh ../project-openrc.sh"}"
WORKDIR="/workdir"
#############################################################################
# functions
#############################################################################
function log() {
echo -e "$@"
}
function logerr() {
echo -e "$@" >&2
}
function get_container_engine() {
local container_engine_clients="podman docker nerdctl"
for i_container_engine_client in $container_engine_clients; do
if $i_container_engine_client info &>/dev/null; then
echo "$i_container_engine_client"
return 0
fi
done
return 1
}
function source_if_exists() {
for i_file in "$@"; do
[ -f "${i_file}" -a -r "${i_file}" ] && \
source "${i_file}"
done
}
function ostack_cloud_connect() {
if reply=$(${OPENSTACK_BIN} version show -fcsv); then
echo "${reply}" | grep identity
else
return 1
fi
}
function is_personal_project() {
if [ -n "${OS_APPLICATION_CREDENTIAL_ID}" ]; then
local project_id="$(${OPENSTACK_BIN} application credential show ${OS_APPLICATION_CREDENTIAL_ID} -f value -c project_id)"
local user_id="$(${OPENSTACK_BIN} application credential show ${OS_APPLICATION_CREDENTIAL_ID} -f value -c user_id)"
local project_name="$(${OPENSTACK_BIN} project show "${project_id}" -fvalue -c name)"
local user_name="$(${OPENSTACK_BIN} user show "${user_id}" -fvalue -c name)"
echo "${project_name}"
[[ "${project_name}" == "${user_name}" && "${user_name}" =~ [a-fA-F0-9]+@[a-z.]+ ]]
elif [ -n "${OS_USERNAME}" -a -n "${OS_PROJECT_NAME}" ]; then
echo "${OS_PROJECT_NAME}"
[[ "${OS_PROJECT_NAME}" == "${OS_USERNAME}" && "${OS_USERNAME}" =~ [a-fA-F0-9]+@[a-z.]+ ]]
else
return 2
fi
}
infra-init/bastion-cloudinit.txt
\ No newline at end of file
infra-init/nodes-cloudinit.txt.tmpl
\ No newline at end of file
#!/usr/bin/env bash
#
# infra-action.sh <OPERATION>
#
# perform infra action <OPERATION>
# * shell interactive shell
# * cloud-connect connect to the cloud
# * infra-deploy deploy the infrastructure
# * infra-destroy destroy the infrastructure
OPERATION="${1:-"shell"}"
SCRIPT_DIR=$(dirname $(readlink -f $0))
source "${SCRIPT_DIR}/ci/toolset-container/lib.sh.inc"
CONTAINER_RUNTIME_EXE=$(get_container_engine)
CONTAINER_IMAGE="${CONTAINER_IMAGE:-"registry.gitlab.ics.muni.cz:443/cloud/terraform/modules/dask-distributed-2t-infra:v1"}"
REPO_NAME=dask-distributed-2t-infra
if [[ "${OPERATION}" =~ ^(shell|cloud-connect|infra-deploy|infra-destroy)$ ]]; then
${CONTAINER_RUNTIME_EXE} run -it -v "$PWD:${WORKDIR}/${REPO_NAME}" "${CONTAINER_IMAGE}" "${OPERATION}"
else
logerr "ERROR: Invalid operation (${OPERATION})"
exit 2
fi
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment