Last active
May 21, 2019 23:51
-
-
Save tribela/da0ecfc198d18a0ff11017d10d521043 to your computer and use it in GitHub Desktop.
Git push to deploy
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Remove
.git
directory by separate data directory.