Skip to content

Commit

Permalink
add CD undo.
Browse files Browse the repository at this point in the history
  • Loading branch information
hughjfchen committed May 14, 2022
1 parent 25a7a68 commit 6cd333b
Show file tree
Hide file tree
Showing 6 changed files with 86 additions and 59 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,15 @@ fi

init_with_root_or_sudo "$0"

begin_banner "Top level" "project deploy - packing"
begin_banner "Top level" "project deploy - fixup - undo"

set +u
[[ -e $HOME/.nix-profile/etc/profile.d/nix.sh ]] && . $HOME/.nix-profile/etc/profile.d/nix.sh
[[ -e $HOME/.nix-profile/etc/profile.d/nix.sh ]] && . "$HOME"/.nix-profile/etc/profile.d/nix.sh
set -u

done_banner "Top level" "project deploy - packing"
if [ -n "$RELEASE_HAS_SYSTEMD_SERVICE" ]; then
THE_SERVICE_NAME=$(awk -F'"' '/unitsToStart\+\=/ {print $2}' "$NIX_STORE_PATH"/bin/setup-systemd-units)
[ -n "$THE_SERVICE_NAME" ] && sudo systemctl stop "$THE_SERVICE_NAME"
fi

done_banner "Top level" "project deploy - fixup - undo"
Original file line number Diff line number Diff line change
Expand Up @@ -30,49 +30,51 @@ if [ "X${myGroup2}" != "X" ]; then
fi
set -e

if type docker >/dev/null 2>&1; then
info "docker found, trying to uninstall it"
case ${THE_DISTRIBUTION_ID} in
rhel) info "This script not know how to install docker-ce on RHEL, so that docker cna't be installed by this script. Ignore."
;;
debian|ubuntu) my_arch=$(uname -m)
if [ "${my_arch}" = "aarch64" ]; then
docker_arm="arm64"
else
docker_arm="amd64"
fi
sudo apt-get purge -y docker-ce docker-ce-cli containerd.io
;;
centos) sudo yum erase -y docker-ce docker-ce-cli containerd.io
;;
Darwin) if type brew > /dev/null 2>&1; then
brew cask uninstall docker
brew cask unlink docker
else
info "Don't know how to uninstall the docker desktop for macOS package."
info "please refer to the installation web page for uninstallation instructions."
fi
;;
*) warn "Not supported distribution OS."
;;
esac
fi
if [ -n "$RELEASE_DOCKER_ON_TARGET" ]; then
if type docker >/dev/null 2>&1; then
info "docker found, trying to uninstall it"
case ${THE_DISTRIBUTION_ID} in
rhel) info "This script not know how to install docker-ce on RHEL, so that docker cna't be installed by this script. Ignore."
;;
debian|ubuntu) my_arch=$(uname -m)
if [ "${my_arch}" = "aarch64" ]; then
docker_arm="arm64"
else
docker_arm="amd64"
fi
sudo apt-get purge -y docker-ce docker-ce-cli containerd.io
;;
centos) sudo yum erase -y docker-ce docker-ce-cli containerd.io
;;
Darwin) if type brew > /dev/null 2>&1; then
brew cask uninstall docker
brew cask unlink docker
else
info "Don't know how to uninstall the docker desktop for macOS package."
info "please refer to the installation web page for uninstallation instructions."
fi
;;
*) warn "Not supported distribution OS."
;;
esac
fi

if type docker-compose >/dev/null 2>&1; then
info "docker-compose found, trying to uninstall it"
case ${THE_DISTRIBUTION_ID} in
rhel) info "This script not know how to install docker-compose on RHEL, so that docker-compose cna't be installed by this script. Ignore."
;;
debian|ubuntu) sudo apt-get purge -y docker-compose
;;
centos) [[ -e /usr/local/bin/docker-compose ]] && sudo rm /usr/local/bin/docker-compose
[[ -L /usr/bin/docker-compose ]] && sudo rm /usr/bin/docker-compose
;;
Darwin) info "docker-compose will be uninstalled with docker for desktop package. skip."
;;
*) warn "Not supported distribution OS"
;;
esac
if type docker-compose >/dev/null 2>&1; then
info "docker-compose found, trying to uninstall it"
case ${THE_DISTRIBUTION_ID} in
rhel) info "This script not know how to install docker-compose on RHEL, so that docker-compose cna't be installed by this script. Ignore."
;;
debian|ubuntu) sudo apt-get purge -y docker-compose
;;
centos) [[ -e /usr/local/bin/docker-compose ]] && sudo rm /usr/local/bin/docker-compose
[[ -L /usr/bin/docker-compose ]] && sudo rm /usr/bin/docker-compose
;;
Darwin) info "docker-compose will be uninstalled with docker for desktop package. skip."
;;
*) warn "Not supported distribution OS"
;;
esac
fi
fi

done_banner "Top level" "deploy env unprepare"
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,12 @@ fi

init_with_root_or_sudo "$0"

begin_banner "Top level" "project deploy - packing"
begin_banner "Top level" "project deploy - unpacking - undo"

set +u
[[ -e $HOME/.nix-profile/etc/profile.d/nix.sh ]] && . $HOME/.nix-profile/etc/profile.d/nix.sh
set -u

done_banner "Top level" "project deploy - packing"
# do we need to remove the nix stoer path? but there're unique, leave it for now.a

done_banner "Top level" "project deploy - unpacking - undo"
14 changes: 10 additions & 4 deletions project-scaffold-template/nixos2111-ghc8107-haskell.nix/deploy
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,16 @@ if [ -f "$SCRIPT_ABS_PATH"/.I.am.here.to.indicate.this.is.the.building.machine ]
"$SCRIPT_ABS_PATH"/ci/fix-up/do.sh "$6" "$(basename "$0")"

else
#RELEASE_DOCKER_ON_TARGET="true" RELEASE_USER_NAME="$3" "$SCRIPT_ABS_PATH"/cd/prepare-env/do.sh
BUILT_ATTRIBUTE_NAME=$(cat "$SCRIPT_ABS_PATH"/.built.attribute.name) RELEASE_DOCKER_ON_TARGET="$(cat "$SCRIPT_ABS_PATH"/.release.docker.on.target)" RELEASE_USER_NAME="$(cat "$SCRIPT_ABS_PATH"/.release.user.name)" "$SCRIPT_ABS_PATH"/cd/prepare-env/do.sh
BUILT_ATTRIBUTE_NAME=$(cat "$SCRIPT_ABS_PATH"/.built.attribute.name) RELEASE_USER_NAME="$(cat "$SCRIPT_ABS_PATH"/.release.user.name)" RELEASE_TARBALL_NAME="$(cat "$SCRIPT_ABS_PATH"/.release.tarball.name)" "$SCRIPT_ABS_PATH"/cd/unpack-tarball/do.sh
BUILT_ATTRIBUTE_NAME=$(cat "$SCRIPT_ABS_PATH"/.built.attribute.name) RELEASE_HAS_SYSTEMD_SERVICE="$(cat "$SCRIPT_ABS_PATH"/.release.has.systemd.service)" NIX_STORE_PATH="$(cat "$SCRIPT_ABS_PATH"/.build.output.nix.store.path)" "$SCRIPT_ABS_PATH"/cd/fix-up/do.sh
if [ -n "$DEPLOY_UNDO" ]; then
BUILT_ATTRIBUTE_NAME=$(cat "$SCRIPT_ABS_PATH"/.built.attribute.name) RELEASE_HAS_SYSTEMD_SERVICE="$(cat "$SCRIPT_ABS_PATH"/.release.has.systemd.service)" NIX_STORE_PATH="$(cat "$SCRIPT_ABS_PATH"/.build.output.nix.store.path)" "$SCRIPT_ABS_PATH"/cd/fix-up/undo.sh
BUILT_ATTRIBUTE_NAME=$(cat "$SCRIPT_ABS_PATH"/.built.attribute.name) RELEASE_USER_NAME="$(cat "$SCRIPT_ABS_PATH"/.release.user.name)" RELEASE_TARBALL_NAME="$(cat "$SCRIPT_ABS_PATH"/.release.tarball.name)" "$SCRIPT_ABS_PATH"/cd/unpack-tarball/undo.sh
BUILT_ATTRIBUTE_NAME=$(cat "$SCRIPT_ABS_PATH"/.built.attribute.name) RELEASE_DOCKER_ON_TARGET="" RELEASE_USER_NAME="$(cat "$SCRIPT_ABS_PATH"/.release.user.name)" "$SCRIPT_ABS_PATH"/cd/prepare-env/do.sh
else
#RELEASE_DOCKER_ON_TARGET="true" RELEASE_USER_NAME="$3" "$SCRIPT_ABS_PATH"/cd/prepare-env/do.sh
BUILT_ATTRIBUTE_NAME=$(cat "$SCRIPT_ABS_PATH"/.built.attribute.name) RELEASE_DOCKER_ON_TARGET="" RELEASE_USER_NAME="$(cat "$SCRIPT_ABS_PATH"/.release.user.name)" "$SCRIPT_ABS_PATH"/cd/prepare-env/do.sh
BUILT_ATTRIBUTE_NAME=$(cat "$SCRIPT_ABS_PATH"/.built.attribute.name) RELEASE_USER_NAME="$(cat "$SCRIPT_ABS_PATH"/.release.user.name)" RELEASE_TARBALL_NAME="$(cat "$SCRIPT_ABS_PATH"/.release.tarball.name)" "$SCRIPT_ABS_PATH"/cd/unpack-tarball/do.sh
BUILT_ATTRIBUTE_NAME=$(cat "$SCRIPT_ABS_PATH"/.built.attribute.name) RELEASE_HAS_SYSTEMD_SERVICE="$(cat "$SCRIPT_ABS_PATH"/.release.has.systemd.service)" NIX_STORE_PATH="$(cat "$SCRIPT_ABS_PATH"/.build.output.nix.store.path)" "$SCRIPT_ABS_PATH"/cd/fix-up/do.sh
fi
fi

done_banner "Top level" "project deploy - generic"
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,16 @@ if [ -f "$SCRIPT_ABS_PATH"/.I.am.here.to.indicate.this.is.the.building.machine ]
"$SCRIPT_ABS_PATH"/ci/fix-up/do.sh "$4" "$(basename "$0")"

else
#RELEASE_DOCKER_ON_TARGET="true" RELEASE_USER_NAME="$3" "$SCRIPT_ABS_PATH"/cd/prepare-env/do.sh
BUILT_ATTRIBUTE_NAME=$(cat "$SCRIPT_ABS_PATH"/.built.attribute.name) RELEASE_DOCKER_ON_TARGET="" RELEASE_USER_NAME="$(cat "$SCRIPT_ABS_PATH"/.release.user.name)" "$SCRIPT_ABS_PATH"/cd/prepare-env/do.sh
BUILT_ATTRIBUTE_NAME=$(cat "$SCRIPT_ABS_PATH"/.built.attribute.name) RELEASE_USER_NAME="$(cat "$SCRIPT_ABS_PATH"/.release.user.name)" RELEASE_TARBALL_NAME="$(cat "$SCRIPT_ABS_PATH"/.release.tarball.name)" "$SCRIPT_ABS_PATH"/cd/unpack-tarball/do.sh
BUILT_ATTRIBUTE_NAME=$(cat "$SCRIPT_ABS_PATH"/.built.attribute.name) RELEASE_HAS_SYSTEMD_SERVICE="$(cat "$SCRIPT_ABS_PATH"/.release.has.systemd.service)" NIX_STORE_PATH="$(cat "$SCRIPT_ABS_PATH"/.build.output.nix.store.path)" "$SCRIPT_ABS_PATH"/cd/fix-up/do.sh
if [ -n "$DEPLOY_UNDO" ]; then
BUILT_ATTRIBUTE_NAME=$(cat "$SCRIPT_ABS_PATH"/.built.attribute.name) RELEASE_HAS_SYSTEMD_SERVICE="$(cat "$SCRIPT_ABS_PATH"/.release.has.systemd.service)" NIX_STORE_PATH="$(cat "$SCRIPT_ABS_PATH"/.build.output.nix.store.path)" "$SCRIPT_ABS_PATH"/cd/fix-up/undo.sh
BUILT_ATTRIBUTE_NAME=$(cat "$SCRIPT_ABS_PATH"/.built.attribute.name) RELEASE_USER_NAME="$(cat "$SCRIPT_ABS_PATH"/.release.user.name)" RELEASE_TARBALL_NAME="$(cat "$SCRIPT_ABS_PATH"/.release.tarball.name)" "$SCRIPT_ABS_PATH"/cd/unpack-tarball/undo.sh
BUILT_ATTRIBUTE_NAME=$(cat "$SCRIPT_ABS_PATH"/.built.attribute.name) RELEASE_DOCKER_ON_TARGET="" RELEASE_USER_NAME="$(cat "$SCRIPT_ABS_PATH"/.release.user.name)" "$SCRIPT_ABS_PATH"/cd/prepare-env/do.sh
else
#RELEASE_DOCKER_ON_TARGET="true" RELEASE_USER_NAME="$3" "$SCRIPT_ABS_PATH"/cd/prepare-env/do.sh
BUILT_ATTRIBUTE_NAME=$(cat "$SCRIPT_ABS_PATH"/.built.attribute.name) RELEASE_DOCKER_ON_TARGET="" RELEASE_USER_NAME="$(cat "$SCRIPT_ABS_PATH"/.release.user.name)" "$SCRIPT_ABS_PATH"/cd/prepare-env/do.sh
BUILT_ATTRIBUTE_NAME=$(cat "$SCRIPT_ABS_PATH"/.built.attribute.name) RELEASE_USER_NAME="$(cat "$SCRIPT_ABS_PATH"/.release.user.name)" RELEASE_TARBALL_NAME="$(cat "$SCRIPT_ABS_PATH"/.release.tarball.name)" "$SCRIPT_ABS_PATH"/cd/unpack-tarball/do.sh
BUILT_ATTRIBUTE_NAME=$(cat "$SCRIPT_ABS_PATH"/.built.attribute.name) RELEASE_HAS_SYSTEMD_SERVICE="$(cat "$SCRIPT_ABS_PATH"/.release.has.systemd.service)" NIX_STORE_PATH="$(cat "$SCRIPT_ABS_PATH"/.build.output.nix.store.path)" "$SCRIPT_ABS_PATH"/cd/fix-up/do.sh
fi
fi

done_banner "Top level" "project deploy - production-vm"
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,16 @@ if [ -f "$SCRIPT_ABS_PATH"/.I.am.here.to.indicate.this.is.the.building.machine ]
"$SCRIPT_ABS_PATH"/ci/fix-up/do.sh "$4" "$(basename "$0")"

else
#RELEASE_DOCKER_ON_TARGET="true" RELEASE_USER_NAME="$3" "$SCRIPT_ABS_PATH"/cd/prepare-env/do.sh
BUILT_ATTRIBUTE_NAME=$(cat "$SCRIPT_ABS_PATH"/.built.attribute.name) RELEASE_DOCKER_ON_TARGET="" RELEASE_USER_NAME="$(cat "$SCRIPT_ABS_PATH"/.release.user.name)" "$SCRIPT_ABS_PATH"/cd/prepare-env/do.sh
BUILT_ATTRIBUTE_NAME=$(cat "$SCRIPT_ABS_PATH"/.built.attribute.name) RELEASE_USER_NAME="$(cat "$SCRIPT_ABS_PATH"/.release.user.name)" RELEASE_TARBALL_NAME="$(cat "$SCRIPT_ABS_PATH"/.release.tarball.name)" "$SCRIPT_ABS_PATH"/cd/unpack-tarball/do.sh
BUILT_ATTRIBUTE_NAME=$(cat "$SCRIPT_ABS_PATH"/.built.attribute.name) RELEASE_HAS_SYSTEMD_SERVICE="$(cat "$SCRIPT_ABS_PATH"/.release.has.systemd.service)" NIX_STORE_PATH="$(cat "$SCRIPT_ABS_PATH"/.build.output.nix.store.path)" "$SCRIPT_ABS_PATH"/cd/fix-up/do.sh
if [ -n "$DEPLOY_UNDO" ]; then
BUILT_ATTRIBUTE_NAME=$(cat "$SCRIPT_ABS_PATH"/.built.attribute.name) RELEASE_HAS_SYSTEMD_SERVICE="$(cat "$SCRIPT_ABS_PATH"/.release.has.systemd.service)" NIX_STORE_PATH="$(cat "$SCRIPT_ABS_PATH"/.build.output.nix.store.path)" "$SCRIPT_ABS_PATH"/cd/fix-up/undo.sh
BUILT_ATTRIBUTE_NAME=$(cat "$SCRIPT_ABS_PATH"/.built.attribute.name) RELEASE_USER_NAME="$(cat "$SCRIPT_ABS_PATH"/.release.user.name)" RELEASE_TARBALL_NAME="$(cat "$SCRIPT_ABS_PATH"/.release.tarball.name)" "$SCRIPT_ABS_PATH"/cd/unpack-tarball/undo.sh
BUILT_ATTRIBUTE_NAME=$(cat "$SCRIPT_ABS_PATH"/.built.attribute.name) RELEASE_DOCKER_ON_TARGET="" RELEASE_USER_NAME="$(cat "$SCRIPT_ABS_PATH"/.release.user.name)" "$SCRIPT_ABS_PATH"/cd/prepare-env/do.sh
else
#RELEASE_DOCKER_ON_TARGET="true" RELEASE_USER_NAME="$3" "$SCRIPT_ABS_PATH"/cd/prepare-env/do.sh
BUILT_ATTRIBUTE_NAME=$(cat "$SCRIPT_ABS_PATH"/.built.attribute.name) RELEASE_DOCKER_ON_TARGET="" RELEASE_USER_NAME="$(cat "$SCRIPT_ABS_PATH"/.release.user.name)" "$SCRIPT_ABS_PATH"/cd/prepare-env/do.sh
BUILT_ATTRIBUTE_NAME=$(cat "$SCRIPT_ABS_PATH"/.built.attribute.name) RELEASE_USER_NAME="$(cat "$SCRIPT_ABS_PATH"/.release.user.name)" RELEASE_TARBALL_NAME="$(cat "$SCRIPT_ABS_PATH"/.release.tarball.name)" "$SCRIPT_ABS_PATH"/cd/unpack-tarball/do.sh
BUILT_ATTRIBUTE_NAME=$(cat "$SCRIPT_ABS_PATH"/.built.attribute.name) RELEASE_HAS_SYSTEMD_SERVICE="$(cat "$SCRIPT_ABS_PATH"/.release.has.systemd.service)" NIX_STORE_PATH="$(cat "$SCRIPT_ABS_PATH"/.build.output.nix.store.path)" "$SCRIPT_ABS_PATH"/cd/fix-up/do.sh
fi
fi

done_banner "Top level" "project deploy - test-vm"

0 comments on commit 6cd333b

Please sign in to comment.