bugfix double kill process, update scripts

This commit is contained in:
AJ ONeal 2020-10-09 08:34:46 +00:00
parent fd361fd43a
commit f78fafd3c4
2 changed files with 26 additions and 12 deletions

View File

@ -1,18 +1,22 @@
#!/bin/bash #!/bin/bash
for x in $@; do # These environment variables are set by the caller
echo "$x"
done
my_envs='GIT_REF_NAME my_envs='GIT_REF_NAME
GIT_REF_TYPE GIT_REF_TYPE
GIT_REPO_ID
GIT_REPO_OWNER GIT_REPO_OWNER
GIT_REPO_NAME GIT_REPO_NAME
GIT_CLONE_URL' GIT_CLONE_URL'
echo 'Doing "work" ...' base_dir="$(dirname "$(readlink -f "$0")")"
sleep 5 if [[ -f "scripts/${GIT_REPO_ID}/deploy.sh" ]]
then
for x in $my_envs; do echo "Running deplay script for ${GIT_REPO_ID}"
echo "$x=${!x}" bash "scripts/${GIT_REPO_ID}/deploy.sh"
done else
echo "Nothing to do for ${GIT_REPO_ID}"
for x in $my_envs; do
echo "$x=${!x}"
done
sleep 1
fi

14
main.go
View File

@ -10,6 +10,7 @@ import (
"net/http" "net/http"
"os" "os"
"os/exec" "os/exec"
"strings"
"time" "time"
"git.ryanburnette.com/ryanburnette/git-deploy/assets" "git.ryanburnette.com/ryanburnette/git-deploy/assets"
@ -316,11 +317,18 @@ func runHook(hook webhooks.Ref) {
} }
cmd := exec.Command("bash", args...) cmd := exec.Command("bash", args...)
// https://git.example.com/example/project.git
// => git.example.com/example/project
repoID := strings.TrimPrefix(hook.HTTPSURL, "https://")
repoID = strings.TrimPrefix(repoID, "https://")
repoID = strings.TrimSuffix(repoID, ".git")
env := os.Environ() env := os.Environ()
envs := []string{ envs := []string{
"GIT_DEPLOY_JOB_ID=" + jobID, "GIT_DEPLOY_JOB_ID=" + jobID,
"GIT_REF_NAME=" + hook.RefName, "GIT_REF_NAME=" + hook.RefName,
"GIT_REF_TYPE=" + hook.RefType, "GIT_REF_TYPE=" + hook.RefType,
"GIT_REPO_ID=" + repoID,
"GIT_REPO_OWNER=" + hook.Owner, "GIT_REPO_OWNER=" + hook.Owner,
"GIT_REPO_NAME=" + hook.Repo, "GIT_REPO_NAME=" + hook.Repo,
"GIT_CLONE_URL=" + hook.HTTPSURL, "GIT_CLONE_URL=" + hook.HTTPSURL,
@ -349,8 +357,10 @@ func runHook(hook webhooks.Ref) {
go func() { go func() {
log.Printf("git-deploy job for %s#%s started\n", hook.HTTPSURL, hook.RefName) log.Printf("git-deploy job for %s#%s started\n", hook.HTTPSURL, hook.RefName)
_ = cmd.Wait() if err := cmd.Wait(); nil != err {
killers <- jobID log.Printf("git-deploy job for %s#%s exited with error: %v", hook.HTTPSURL, hook.RefName, err)
return
}
log.Printf("git-deploy job for %s#%s finished\n", hook.HTTPSURL, hook.RefName) log.Printf("git-deploy job for %s#%s finished\n", hook.HTTPSURL, hook.RefName)
// TODO check for backlog // TODO check for backlog
}() }()