Skip to content

Commit

Permalink
add option for mount folder (#41)
Browse files Browse the repository at this point in the history
  • Loading branch information
syan-tibco authored Dec 21, 2024
1 parent d05d2aa commit 859fa9c
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 13 deletions.
28 changes: 21 additions & 7 deletions dev/platform-provisioner-test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
# ACCOUNT: the account you want to assume to
# REGION: the region
# AWS_PROFILE: the aws profile; we normally needs to do AWS sso login to update this profile
# GITHUB_TOKEN: the github token
# GITHUB_TOKEN: the GitHub token
# PIPELINE_PATH: the pipeline path
# PIPELINE_NAME: We currently support 2 pipelines: generic-runner and helm-install
# PIPELINE_TRIGGER_RUN_SH: true or other string if true, will run task directly. if other string, will just go to bash
Expand All @@ -37,6 +37,7 @@
# It will also run the command defined in all pipeline task.
# It will also run the task if PIPELINE_TRIGGER_RUN_SH is set to true.
# Samples:
# export PIPELINE_INPUT_RECIPE=""
# ./platform-provisioner-test.sh
#######################################

Expand Down Expand Up @@ -88,9 +89,26 @@ else
export _DOCKER_FOR_MAC_ADD_HOST="--add-host=kubernetes.docker.internal:127.0.0.1"
fi

# optional env for docker engin
# optional env for docker engine
_OPTIONAL_ENV=""

# mount folders if exist
if [[ -d "${HOME}/.aws" ]]; then
export _OPTIONAL_ENV="${_OPTIONAL_ENV} --mount type=bind,source="${HOME}/.aws",target=/root/.aws"
fi

if [[ -d "${HOME}/.azure" ]]; then
export _OPTIONAL_ENV="${_OPTIONAL_ENV} --mount type=bind,source="${HOME}/.azure",target=/root/.azure"
fi

if [[ -d "${HOME}/.config/gcloud" ]]; then
export _OPTIONAL_ENV="${_OPTIONAL_ENV} --mount type=bind,source="${HOME}/.config/gcloud",target=/root/.config/gcloud"
fi

if [[ -d "${HOME}/.kube" ]]; then
export _OPTIONAL_ENV="${_OPTIONAL_ENV} --mount type=bind,source="${HOME}/.kube/config",target=/root/.kube/config-on-prem"
fi

# this case is used for on prem cluster; user can specify kubeconfig file name
if [[ -n "${PIPELINE_ON_PREM_KUBECONFIG_FILE_NAME}" ]]; then
export _OPTIONAL_ENV="${_OPTIONAL_ENV} --mount type=bind,source=${HOME}/.kube/${PIPELINE_ON_PREM_KUBECONFIG_FILE_NAME},target=/root/.kube/${PIPELINE_ON_PREM_KUBECONFIG_FILE_NAME}"
Expand Down Expand Up @@ -134,12 +152,8 @@ docker run -it --rm \
-e PIPELINE_CMD_NAME_YQ \
-e PIPELINE_CHART_REPO \
-e PIPELINE_NAME \
"${_DOCKER_FOR_MAC_ADD_HOST}" ${_OPTIONAL_ENV} \
-v `pwd`:/tmp/dev \
--mount type=bind,source="${HOME}/.aws",target=/root/.aws \
--mount type=bind,source="${HOME}/.azure",target=/root/.azure \
--mount type=bind,source="${HOME}/.config/gcloud",target=/root/.config/gcloud \
--mount type=bind,source="${HOME}/.kube/config",target=/root/.kube/config-on-prem\
"${_DOCKER_FOR_MAC_ADD_HOST}" ${_OPTIONAL_ENV}\
-v "${PIPELINE_PATH}"/charts:/tmp/charts \
"${PIPELINE_DOCKER_IMAGE}" bash -c 'export REGION=${REGION:-"us-west-2"} \
&& declare -xr WORKING_PATH=/workspace \
Expand Down
26 changes: 20 additions & 6 deletions dev/platform-provisioner.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
# ACCOUNT: the account you want to assume to
# REGION: the region
# AWS_PROFILE: the aws profile; we normally needs to do AWS sso login to update this profile
# GITHUB_TOKEN: the github token
# GITHUB_TOKEN: the GitHub token
# PIPELINE_NAME: We currently support 2 pipelines: generic-runner and helm-install
# PIPELINE_TRIGGER_RUN_SH: true or other string if true, will run task directly. if other string, will just go to bash
# PIPELINE_INPUT_RECIPE: the input file name; default is recipe.yaml
Expand All @@ -35,6 +35,7 @@
# It will also run the command defined in all pipeline task.
# It will also run the task if PIPELINE_TRIGGER_RUN_SH is set to true.
# Samples:
# export PIPELINE_INPUT_RECIPE=""
# ./platform-provisioner.sh
#######################################

Expand Down Expand Up @@ -83,6 +84,23 @@ fi
# optional env for docker engine
_OPTIONAL_ENV=""

# mount folders if exist
if [[ -d "${HOME}/.aws" ]]; then
export _OPTIONAL_ENV="${_OPTIONAL_ENV} --mount type=bind,source="${HOME}/.aws",target=/root/.aws"
fi

if [[ -d "${HOME}/.azure" ]]; then
export _OPTIONAL_ENV="${_OPTIONAL_ENV} --mount type=bind,source="${HOME}/.azure",target=/root/.azure"
fi

if [[ -d "${HOME}/.config/gcloud" ]]; then
export _OPTIONAL_ENV="${_OPTIONAL_ENV} --mount type=bind,source="${HOME}/.config/gcloud",target=/root/.config/gcloud"
fi

if [[ -d "${HOME}/.kube" ]]; then
export _OPTIONAL_ENV="${_OPTIONAL_ENV} --mount type=bind,source="${HOME}/.kube/config",target=/root/.kube/config-on-prem"
fi

# this case is used for on prem cluster; user can specify kubeconfig file name
if [[ -n "${PIPELINE_ON_PREM_KUBECONFIG_FILE_NAME}" ]]; then
export _OPTIONAL_ENV="${_OPTIONAL_ENV} --mount type=bind,source=${HOME}/.kube/${PIPELINE_ON_PREM_KUBECONFIG_FILE_NAME},target=/root/.kube/${PIPELINE_ON_PREM_KUBECONFIG_FILE_NAME}"
Expand Down Expand Up @@ -126,11 +144,7 @@ docker run -it --rm \
-e PIPELINE_CMD_NAME_YQ \
-e PIPELINE_CHART_REPO \
-e PIPELINE_NAME \
--mount type=bind,source="${HOME}/.aws",target=/root/.aws \
--mount type=bind,source="${HOME}/.azure",target=/root/.azure \
--mount type=bind,source="${HOME}/.config/gcloud",target=/root/.config/gcloud \
--mount type=bind,source="${HOME}/.kube/config",target=/root/.kube/config-on-prem\
"${_DOCKER_FOR_MAC_ADD_HOST}" ${_OPTIONAL_ENV}\
"${_DOCKER_FOR_MAC_ADD_HOST}" ${_OPTIONAL_ENV} \
"${PIPELINE_DOCKER_IMAGE}" bash -c 'export REGION=${REGION:-"us-west-2"} \
&& declare -xr WORKING_PATH=/workspace \
&& declare -xr SCRIPTS=${WORKING_PATH}/task-scripts \
Expand Down

0 comments on commit 859fa9c

Please sign in to comment.