Skip to content

Commit

Permalink
Merge pull request #146 from rosineygp/feat/include-cached
Browse files Browse the repository at this point in the history
feat: use cache for remote include
  • Loading branch information
rosineygp authored Mar 8, 2021
2 parents d799cf4 + 33c676f commit 4c8b18a
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 27 deletions.
45 changes: 29 additions & 16 deletions .mkdkr
Original file line number Diff line number Diff line change
Expand Up @@ -87,23 +87,32 @@ _remote_git_clone() {
local -r checkout="${1}"; shift
local -r file="${1}"; shift
local -r include_path="${1}"; shift
local -r link_path="${1}"; shift

_pretty "light_cyan" "alias: ${alias}, repos: ${repos}, checkout: ${checkout}, file: ${file}\n"
if [[ ! -e "${link_path}" ]] || [[ "${MKDKR_FORCE_DOWNLOAD_INCLUDE}" == "true" ]]; then
_pretty "light_cyan" "alias: ${alias}, repos: ${repos}, checkout: ${checkout}, file: ${file}\n"

git clone "${repos}" \
--quiet \
--config advice.detachedHead=false \
--branch "${checkout}" \
--depth "${MKDKR_INCLUDE_CLONE_DEPTH:-1}" \
"${include_path}" >&2
git clone "${repos}" \
--quiet \
--config advice.detachedHead=false \
--branch "${checkout}" \
--depth "${MKDKR_INCLUDE_CLONE_DEPTH:-1}" \
"${include_path}" >&2

local -r exit_code="$?"
if [ "$exit_code" != "0" ]; then
exit "$exit_code"
local -r exit_code="$?"
if [ "$exit_code" != "0" ]; then
exit "$exit_code"
fi

ln -sf "${include_path}" "${link_path}"

rm -rf "${include_path}/.git"
chmod -R o+w "${include_path}"
else
_pretty "light_blue" "[cached] alias: ${alias}, repos: ${repos}, checkout: ${checkout}, file: ${file}\n"
fi

rm -rf "${include_path}/.git"
chmod -R o+w "${include_path}"

}

_remote_include() {
Expand All @@ -125,18 +134,22 @@ _remote_include() {
local checkout="${params[2]:-master}"
local mk="${params[3]:-main.mk}"
local tag="latest"

if [[ "$checkout" != "master" ]]; then
tag="$checkout"
fi

mkdir -p "${_MKDKR_TMP_DIR}/includes"
include_path="${_MKDKR_TMP_DIR}/includes/${alias}_$(uuid)"

# shellcheck disable=SC2086
slug_checkout="$(_branch_or_tag_name_slug $checkout)"
link_path="${_MKDKR_TMP_DIR}/includes/${alias}_${slug_checkout}"

_remote_git_clone "${alias}" "${repos}" "${checkout}" "${mk}" "${include_path}"
_remote_force_tag "${tag}" "${include_path}/${mk}"
_remote_git_clone "${alias}" "${repos}" "${checkout}" "${mk}" "${include_path}" "${link_path}"
_remote_force_tag "${tag}" "${link_path}/${mk}"

include_list+=("${include_path}/${mk}")
include_list+=("${link_path}/${mk}")
done < <(grep -v '^ *#' <mkdkr.csv)

echo "${include_list[*]}"
Expand Down
23 changes: 12 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -675,17 +675,18 @@ pipeline:

# Environment Variables

| Name | Default | Description |
|---------------------------|-------------------------------------|-------------------------------------------------------------------|
| MKDKR_TTL | 3600 | The time limit to a job or service run |
| MKDKR_SHELL | sh | Change to another shell eg. bash, csh |
| MKDKR_JOB_STDOUT | last stdout | Path of file, generated with last stdout output |
| MKDKR_JOB_NAME* | (job\|service)\_target-name\_(uuid) | Unique job name, used as container name suffix |
| MKDKR_INCLUDE_CLONE_DEPTH | 1 | In the most of case you no need change history for includes |
| MKDKR_BRANCH_NAME | | Return current git branch, if it exist |
| MKDKR_BRANCH_NAME_SLUG | | Return current git branch, if it exist, with safe values |
| MKDKR_NETWORK_ARGS | | Arguments of docker create networks |
| MKDKR_DOCKER_IMAGE_PULL | missing | Set "always" to force pull images before docker instance creation |
| Name | Default | Description |
|------------------------------|-------------------------------------|-------------------------------------------------------------------------|
| MKDKR_TTL | 3600 | The time limit to a job or service run |
| MKDKR_SHELL | sh | Change to another shell eg. bash, csh |
| MKDKR_JOB_STDOUT | last stdout | Path of file, generated with last stdout output |
| MKDKR_JOB_NAME* | (job\|service)\_target-name\_(uuid) | Unique job name, used as container name suffix |
| MKDKR_INCLUDE_CLONE_DEPTH | 1 | In the most of case you no need change history for includes |
| MKDKR_BRANCH_NAME | | Return current git branch, if it exist |
| MKDKR_BRANCH_NAME_SLUG | | Return current git branch, if it exist, with safe values |
| MKDKR_NETWORK_ARGS | | Arguments of docker create networks |
| MKDKR_DOCKER_IMAGE_PULL | missing | Set "always" to force pull images before docker instance creation |
| MKDKR_FORCE_DOWNLOAD_INCLUDE | | "true" for download include files even it already dowloaded [no cached] |

> - to overwrite the values use: `export <var>=<value>`
> - \* auto generated
Expand Down

0 comments on commit 4c8b18a

Please sign in to comment.