Skip to content

Commit

Permalink
feat: set workdir to another path
Browse files Browse the repository at this point in the history
  • Loading branch information
rosineygp committed May 31, 2020
1 parent 81debe9 commit b67af0e
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 5 deletions.
26 changes: 21 additions & 5 deletions .mkdkr
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
#!/usr/bin/env bash

_MKDKR_TMP_DIR="${PWD}/.tmp"
_MKDKR_WORKDIR="${PWD}"

#output fn
# output fn
declare -A colors
_pretty() {
colors+=(
Expand All @@ -27,7 +28,7 @@ _pretty() {
echo -e "${colors[${key}]}${*:2}\e[0m" >&2
}

#requirements fn
# requirements fn
_command_exist() {
local -r cmd="${1}"
if ! [[ -x $(command -v "${cmd}") ]]; then
Expand Down Expand Up @@ -77,7 +78,7 @@ _local_requirements() {
_verify_git_version "$(git --version | awk '{ print $3 }')"
}

#git fn
# git fn
_remote_git_clone() {
local -r alias="${1}"; shift
local -r repos="${1}"; shift
Expand Down Expand Up @@ -205,6 +206,11 @@ _network_create() {
fi
}

_update_workdir() {
local -r container_name="${1}"
_MKDKR_WORKDIR=$(docker inspect --format='{{.Config.WorkingDir}}' "${container_name}")
}

# header fn
_header_render() {
cat <<EOF
Expand Down Expand Up @@ -430,6 +436,8 @@ instance:() {
"${image}" sleep "${MKDKR_TTL:-3600}" >&2

_exit_handler "$?"

_update_workdir "job_${MKDKR_JOB_NAME}"
IFS=$oldIFS
}

Expand Down Expand Up @@ -492,6 +500,8 @@ dind:() {
"${image}" sleep "${MKDKR_TTL:-3600}" >&2

_exit_handler "$?"

_update_workdir "job_${MKDKR_JOB_NAME}"
IFS=$oldIFS
}

Expand All @@ -506,7 +516,7 @@ run:() {
local -r step=$(_step_id)
_step_header "$step"

docker exec -i "${container_name}" "${MKDKR_SHELL:-sh}" -c "$*" | tee -a "${_MKDKR_TMP_DIR}/${MKDKR_TARGET_NAME}.log"
docker exec -i -w "${_MKDKR_WORKDIR}" "${container_name}" "${MKDKR_SHELL:-sh}" -c "$*" | tee -a "${_MKDKR_TMP_DIR}/${MKDKR_TARGET_NAME}.log"
local -r exit_code="${PIPESTATUS[0]}"

_step_footer "$step"
Expand All @@ -533,7 +543,7 @@ retry:() {
local step
step=$(_step_id)
_step_header "$step"
docker exec -i "${container_name}" "${MKDKR_SHELL:-sh}" -c "$cmd" | tee -a "${_MKDKR_TMP_DIR}/${MKDKR_TARGET_NAME}.log"
docker exec -i -w "${_MKDKR_WORKDIR}" "${container_name}" "${MKDKR_SHELL:-sh}" -c "$cmd" | tee -a "${_MKDKR_TMP_DIR}/${MKDKR_TARGET_NAME}.log"
exit_code="${PIPESTATUS[0]}"
_step_footer "$step"

Expand Down Expand Up @@ -589,6 +599,12 @@ pull:() {
_exit_handler "${exit_code}"
}

cd:() {
local -r workdir="${1}"
_pretty "green" "\ncd: ${workdir}"
_MKDKR_WORKDIR="${workdir}"
}

if [[ "$1" == "init" ]]; then

_local_requirements
Expand Down
20 changes: 20 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ Table of contents
* [log:](#log)
* [push:](#push)
* [pull:](#pull)
* [cd:](#cd)
* [Includes](#includes)
* [Explicit](#explicit)
* [Implicit](#implicit)
Expand Down Expand Up @@ -370,6 +371,25 @@ pull:

[Example](examples/pull.mk)

## cd:

Move folder context.

**Parameters:**
- String, workdir: Set workdir.

**Return**
- None.

```Makefile
change-folder:
@$(dkr)
instance: debian
cd: /tmp
run: pwd
# /tmp
```

# Includes

Is possible create jobs or fragments of jobs and reuse it in another projects, like a code package library.
Expand Down

0 comments on commit b67af0e

Please sign in to comment.