Skip to content

Commit 3dacdcc

Browse files
author
Gabriel Monroy
committed
Merge pull request #2227 from gabrtv/pre-receive
ref(builder): switch to pre-receive hook
2 parents 464f102 + a27a0b3 commit 3dacdcc

2 files changed

Lines changed: 7 additions & 29 deletions

File tree

builder/templates/builder

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,6 @@ get_app_name() {
1111
echo $1 | awk -F"." '{print $1}'
1212
}
1313

14-
get_git_sha() {
15-
repo=$1
16-
branch=$2
17-
branch_file="${repo}/${branch}"
18-
cat $branch_file
19-
}
20-
2114
indent() {
2215
echo " $@"
2316
}
@@ -35,7 +28,7 @@ puts-warn() {
3528
}
3629

3730
usage() {
38-
echo "Usage: $0 <user> <repo> <branch>"
31+
echo "Usage: $0 <user> <repo> <sha>"
3932
}
4033

4134
if [ $# -ne $ARGS ]; then
@@ -45,7 +38,8 @@ fi
4538

4639
USER=$1
4740
REPO=$2
48-
BRANCH=$3
41+
GIT_SHA=$3
42+
SHORT_SHA=${GIT_SHA:0:8}
4943
APP_NAME=$(get_app_name $REPO)
5044

5145
cd $(dirname $0) # ensure we are in the root dir
@@ -56,10 +50,6 @@ REPO_DIR="${ROOT_DIR}/${REPO}"
5650
BUILD_DIR="${REPO_DIR}/build"
5751
CACHE_DIR="${REPO_DIR}/cache"
5852

59-
# get git sha of branch
60-
GIT_SHA=$(get_git_sha $REPO_DIR $BRANCH)
61-
SHORT_SHA=${GIT_SHA:0:8}
62-
6353
# define image names
6454
IMAGE_NAME="$APP_NAME:git-$SHORT_SHA"
6555
TMP_IMAGE="{{ .deis_registry_host }}:{{ .deis_registry_port }}/$IMAGE_NAME"
@@ -70,8 +60,7 @@ mkdir -p $BUILD_DIR $CACHE_DIR
7060
TMP_DIR=$(mktemp -d --tmpdir=$BUILD_DIR)
7161

7262
cd $REPO_DIR
73-
# extract git branch
74-
git archive $BRANCH | tar -xmC $TMP_DIR
63+
git archive $GIT_SHA | tar -xmC $TMP_DIR
7564

7665
# switch to app context
7766
cd $TMP_DIR

builder/templates/gitreceive

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -35,37 +35,26 @@ case "$1" in
3535
cat | $SELF pre-receive
3636
EOF
3737
chmod +x $PRERECEIVE_HOOK
38-
POSTRECEIVE_HOOK="$REPO_PATH/hooks/post-receive"
39-
# inject a post-receive hook
40-
cat > $POSTRECEIVE_HOOK <<EOF
41-
#!/bin/bash
42-
cat | $SELF post-receive
43-
EOF
44-
chmod +x $POSTRECEIVE_HOOK
38+
# call the original git-shell
4539
git-shell -c "$SSH_ORIGINAL_COMMAND"
4640
;;
4741

4842
pre-receive)
4943
while read oldrev newrev refname
5044
do
45+
# check for authorization on this repo
5146
$GITHOME/receiver "$RECEIVE_REPO" "$newrev" "$RECEIVE_USER" "$RECEIVE_FINGERPRINT"
5247
rc=$?
5348
if [[ $rc != 0 ]] ; then
5449
echo " ERROR: failed on rev $newrev - push denied"
5550
exit $rc
5651
fi
57-
done
58-
;;
59-
60-
post-receive)
61-
while read oldrev newrev refname
62-
do
6352
# builder assumes that we are running this script from $GITHOME
6453
cd $GITHOME
6554
# if we're processing a receive-pack on an existing repo, run a build
6655
if [[ $SSH_ORIGINAL_COMMAND == git-receive-pack* ]]; then
6756
# SECURITY: git user runs the builder as root (for docker access)
68-
sudo $GITHOME/builder $RECEIVE_USER $RECEIVE_REPO $refname 2>&1 | strip_remote_prefix
57+
sudo $GITHOME/builder $RECEIVE_USER $RECEIVE_REPO $newrev 2>&1 | strip_remote_prefix
6958
fi
7059
done
7160
;;

0 commit comments

Comments
 (0)