-
Notifications
You must be signed in to change notification settings - Fork 0
/
drone-exec-linux
executable file
·55 lines (47 loc) · 1.58 KB
/
drone-exec-linux
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#!/bin/bash
if [[ "$1" == "--help" ]]; then
exec drone exec --help
fi
# Set up some variables that we'll use later on
GIT=$(which git)
PID=/tmp/git-daemon.pid
PWD=$(pwd)
DOCKER_NETWORK=drone
COUNTER=1
GIT_BRANCH=$(git -C $PWD rev-parse --abbrev-ref HEAD)
GIT_COMMIT=$(git -C $PWD rev-parse HEAD)
GIT_REPO=$(basename $PWD)
GIT_REMOTE=$(git -C $PWD config --get remote.origin.url)
function log() {
let COUNT=$((COUNTER++))
echo "[exec:${COUNT}] $1"
}
# Create a docker network for Drone if it doesn't exist
docker network inspect $DOCKER_NETWORK >/dev/null 2>&1 || docker network create $DOCKER_NETWORK >/dev/null
DOCKER_IP=$(docker network inspect $DOCKER_NETWORK -f '{{(index .IPAM.Config 0).Gateway}}')
log "Created Docker Network at ${DOCKER_IP}"
# Start git in daemon mode to serve the repo
log "Starting Git Daemon at ${PWD}"
start-stop-daemon \
--pidfile $PID \
--start \
--exec $GIT \
-- daemon \
--reuseaddr \
--listen=$DOCKER_IP \
--base-path=$PWD \
--export-all \
--verbose \
--enable=receive-pack \
--pid-file=$PID \
--detach
# Run drone
log "Running drone exec and clone from ${DOCKER_IP}"
export DRONE_REMOTE_URL=git://${DOCKER_IP}/
drone exec --network $DOCKER_NETWORK --clone --ref refs/heads/$GIT_BRANCH --branch $GIT_BRANCH --repo $GIT_REPO --sha $GIT_COMMIT --trusted --secret-file .secrets --env-file .env "$@"
# Kill git daemon
log "Stopping git-daemon"
start-stop-daemon --pidfile $PID --stop --remove-pidfile
# Remove the docker network
log "Removing Docker Network at ${DOCKER_IP}"
docker network rm $DOCKER_NETWORK >/dev/null 2>&1