Skip to content

Instantly share code, notes, and snippets.

@tribela
Last active May 21, 2019 23:51
Show Gist options
  • Save tribela/da0ecfc198d18a0ff11017d10d521043 to your computer and use it in GitHub Desktop.
Save tribela/da0ecfc198d18a0ff11017d10d521043 to your computer and use it in GitHub Desktop.
Git push to deploy
#!/bin/bash
set -eo pipefail
TARGET_BRANCH=master
GIT_DIR="$(git worktree list | head -n1 | cut -d' ' -f1)"
APPNAME="${GIT_DIR##*/}"
build_app() {
local rev=$1
echo "$rev"
working_path=$(mktemp -d "/tmp/${APPNAME}-XXX")
env -u GIT_QUARANTINE_PATH git worktree add "$working_path" "$rev" > /dev/null
echo "Using $working_path as build dir"
trap 'rm -rf "$working_path"; git worktree prune' RETURN INT TERM EXIT
find "$working_path" -name .git -exec rm -rf {} \;
container_id=$(docker run -d --env=USER=herokuishuser -v "$GIT_DIR/cache:/tmp/cache" -v "$working_path:/tmp/app" gliderlabs/herokuish /build)
docker attach "$container_id"
docker wait "$container_id"
docker commit "$container_id" "build/$APPNAME"
docker rm "$container_id"
# TODO: run
}
while read -r oldrev newrev refname; do
branch=${refname##refs/heads/}
if [[ "$branch" = "$TARGET_BRANCH" ]]; then
echo "Build $branch"
build_app $newrev
fi
done
@tribela
Copy link
Author

tribela commented Mar 1, 2018

Remove .git directory by separate data directory.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment