Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use Mutagen pause/resume on stopped environments #141

Merged
merged 1 commit into from
Apr 15, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@
## UNRELEASED [x.y.z](https://github.com/davidalger/warden/tree/x.y.z) (yyyy-mm-dd)
[All Commits](https://github.com/davidalger/warden/compare/0.4.0..develop)

**Enhancements:**

* Added pause, resume and monitor to `warden sync` command
* Changed Mutagen sync to pause on `warden env stop` and resume on `warden env up -d`

## Version [0.4.1](https://github.com/davidalger/warden/tree/0.4.1) (2020-04-11)
[All Commits](https://github.com/davidalger/warden/compare/0.4.0..0.4.1)

Expand Down
20 changes: 19 additions & 1 deletion commands/env.cmd
Original file line number Diff line number Diff line change
Expand Up @@ -83,11 +83,29 @@ export TRAEFIK_ADDRESS="$(docker container inspect traefik \
' 2>/dev/null || true
)"

## pause mutagen sync if needed
if [[ "${WARDEN_PARAMS[0]}" == "stop" ]] \
&& [[ $OSTYPE =~ ^darwin ]] && [[ -f "${WARDEN_DIR}/environments/${WARDEN_ENV_TYPE}/${WARDEN_ENV_TYPE}.mutagen.yml" ]]
then
warden sync pause
fi

## anything not caught above is simply passed through to docker-compose to orchestrate
docker-compose \
--project-directory "${WARDEN_ENV_PATH}" -p "${WARDEN_ENV_NAME}" \
"${DOCKER_COMPOSE_ARGS[@]}" "${WARDEN_PARAMS[@]}" "$@"

## resume mutagen sync if available and php-fpm container id hasn't changed
if ([[ "${WARDEN_PARAMS[0]}" == "up" ]] || [[ "${WARDEN_PARAMS[0]}" == "start" ]]) \
&& [[ $OSTYPE =~ ^darwin ]] && [[ -f "${WARDEN_DIR}/environments/${WARDEN_ENV_TYPE}/${WARDEN_ENV_TYPE}.mutagen.yml" ]] \
&& [[ $(warden sync list | grep -i 'Status: \[Paused\]' | wc -l | awk '{print $1}') == "1" ]] \
&& [[ $(warden env ps -q php-fpm) ]] \
&& [[ $(docker container inspect $(warden env ps -q php-fpm) --format '{{ .State.Status }}') = "running" ]] \
&& [[ $(warden env ps -q php-fpm) = $(warden sync list | grep -i 'URL: docker' | awk -F'/' '{print $3}') ]]
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One thing I am unsure about is if we need to use = or ==. The existing implementation seems to use both and my bash knowledge is limited as to what to prefer here.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The short version is = is the original equality operator, and at some point bash (and other shells) added == as an alias. They are both lexical string comparison operators when enclosed in [ ] but this changes when you enclose them in (( )) (arithmetic operator) where the two are no longer synonymous.

then
warden sync resume
fi

## start mutagen sync if needed
if ([[ "${WARDEN_PARAMS[0]}" == "up" ]] || [[ "${WARDEN_PARAMS[0]}" == "start" ]]) \
&& [[ $OSTYPE =~ ^darwin ]] && [[ -f "${WARDEN_DIR}/environments/${WARDEN_ENV_TYPE}/${WARDEN_ENV_TYPE}.mutagen.yml" ]] \
Expand All @@ -99,7 +117,7 @@ then
fi

## stop mutagen sync if needed
if ([[ "${WARDEN_PARAMS[0]}" == "down" ]] || [[ "${WARDEN_PARAMS[0]}" == "stop" ]]) \
if [[ "${WARDEN_PARAMS[0]}" == "down" ]] \
&& [[ $OSTYPE =~ ^darwin ]] && [[ -f "${WARDEN_DIR}/environments/${WARDEN_ENV_TYPE}/${WARDEN_ENV_TYPE}.mutagen.yml" ]]
then
warden sync stop
Expand Down
12 changes: 12 additions & 0 deletions commands/sync.cmd
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,18 @@ case "${WARDEN_PARAMS[0]}" in
fi
printf .; sleep 1; done; echo
;;
monitor)
## monitor only sessions labeled with this env name
mutagen sync monitor --label-selector "warden-sync=${WARDEN_ENV_NAME}"
;;
pause)
## pause only sessions labeled with this env name
mutagen sync pause --label-selector "warden-sync=${WARDEN_ENV_NAME}"
;;
resume)
## resume only sessions labeled with this env name
mutagen sync resume --label-selector "warden-sync=${WARDEN_ENV_NAME}"
;;
stop)
## terminate only sessions labeled with this env name
mutagen sync terminate --label-selector "warden-sync=${WARDEN_ENV_NAME}"
Expand Down
3 changes: 3 additions & 0 deletions commands/sync.help
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,8 @@ WARDEN_USAGE=$(cat <<EOF
stop Stops the mutagen sync for the current project environment
list Lists mutagen session status for current project environment
and optionally (with -v) the full configuration
pause Pauses the mutagen sync for the current project environment
resume Resumes the mutagen sync for the current project environment
monitor Continously lists mutagen session status for current project environment
EOF
)