diff --git a/sharpdev.yml b/sharpdev.yml index 515e298..a0a654e 100644 --- a/sharpdev.yml +++ b/sharpdev.yml @@ -2,6 +2,7 @@ version: 0.1 envfile: .env values: + SECRETD: '{\"secret\":\"$PASSD\"}' SECRET: '{\"secret\":\"$PASS\"}' scripts: @@ -23,13 +24,14 @@ scripts: $(sudo docker volume rm memes) > /dev/null 2>&1 || true && $(sudo docker network rm memes) > /dev/null 2>&1 || true && sharpdev build && - ./internal/sharpcd --secret Secret123 + ./internal/sharpcd --secret $PASSD - job: curl -k -X POST -d SECRET https://localhost:5666/api/job/${SHARP_ARG_1} - logs: curl -k -X POST -d SECRET https://localhost:5666/api/logs/${SHARP_ARG_1} + job: curl -k -X POST -d SECRETD https://localhost:5666/api/job/${SHARP_ARG_1} + logs: curl -k -X POST -d SECRETD https://localhost:5666/api/logs/${SHARP_ARG_1} filter: ./internal/sharpcd addfilter https://raw.githubusercontent.com/Sharpz7/ remove: ./internal/sharpcd removefilter https://raw.githubusercontent.com/Sharpz7/ token: ./internal/sharpcd changetoken ${SHARP_ARG_1} + alljobsd: curl -k -X POST -d SECRETD https://localhost:5666/api/jobs alljobs: curl -k -X POST -d SECRET https://173.212.252.82:5666/api/jobs file: | diff --git a/src/client.go b/src/client.go index ffb38af..ecb59de 100644 --- a/src/client.go +++ b/src/client.go @@ -124,7 +124,6 @@ func postCommChecks(t task, id string) error { payload := postData{ Secret: getSec()} buildingTriggered := false - stoppingTriggered := false runningTriggered := false counter := 0 @@ -145,12 +144,6 @@ func postCommChecks(t task, id string) error { errored := job.Status == jobStatus.Errored building := job.Status == jobStatus.Building && !buildingTriggered running := job.Status == jobStatus.Running && !runningTriggered - stopping := job.Status == jobStatus.Stopping && !stoppingTriggered - - if stopping { - stoppingTriggered = true - fmt.Println("The Task already exists on server. Stopping old job...") - } if building { buildingTriggered = true diff --git a/src/jobs.go b/src/jobs.go index 2080ffd..d35ce8b 100644 --- a/src/jobs.go +++ b/src/jobs.go @@ -1,13 +1,13 @@ package main import ( + "fmt" "io/ioutil" "net/http" "os" "os/exec" "regexp" "strings" - "time" ) // Pointer to variable storing all jobs @@ -46,9 +46,6 @@ func createJob(payload postData) { // Assign its ID to the old job ID newJob.ID = job.ID - // Stop the old job - job.Stop() - // Replace and run the new job *job = newJob job.Run() @@ -89,38 +86,6 @@ func (job *taskJob) Run() { } } -// Stop a job Task -func (job *taskJob) Stop() { - - var cmd *exec.Cmd - - // Mark Job as stopping, Clear error Message - job.Status = jobStatus.Stopping - - // Makes sure to run the correct stop sequence - switch job.Type { - case "docker": - cmd = job.DockerStop() - } - - err := cmd.Run() - handleAPI(err, job, "Failed to Stop Job") - - // Sleeps to API can pick it up - time.Sleep(2 * time.Second) -} - -// Stop sequence for a docker job -func (job *taskJob) DockerStop() *exec.Cmd { - composeLoc := folder.Docker + job.ID + "/docker-compose.yml" - - // Stopping the container - cmd := exec.Command("docker-compose", "-f", composeLoc, "down") - cmd.Env = job.insertEnviroment() - - return cmd -} - // Get cmd for a Docker Job func (job *taskJob) DockerCmd() *exec.Cmd { @@ -175,11 +140,15 @@ func (job *taskJob) DockerCmd() *exec.Cmd { if err != nil { return nil } - // Remove any previous containers job.buildCommand("-f", composeLoc, "down") + // Run Code job.buildCommand("-f", composeLoc, "up", "-d") + + if job.Registry != "" { + job.dockerLogout() + } } // Get logging Running @@ -204,7 +173,15 @@ func (job *taskJob) insertEnviroment() []string { } func (job *taskJob) dockerLogin() { - cmd := exec.Command("docker", "login", job.Registry, "-u", job.Enviroment["DOCKER_USER"], "-p", job.Enviroment["DOCKER_PASS"]) + cmd := exec.Command("docker", "login", "-u", job.Enviroment["DOCKER_USER"], "-p", job.Enviroment["DOCKER_PASS"], job.Registry) + out, err := cmd.CombinedOutput() + errMsg := string(out) + fmt.Println(errMsg) + handleAPI(err, job, errMsg) +} + +func (job *taskJob) dockerLogout() { + cmd := exec.Command("docker", "logout", job.Registry) out, err := cmd.CombinedOutput() errMsg := string(out) handleAPI(err, job, errMsg) @@ -215,6 +192,7 @@ func (job *taskJob) buildCommand(args ...string) error { cmd := exec.Command("docker-compose", args...) cmd.Env = job.insertEnviroment() out, err := cmd.CombinedOutput() + fmt.Println(string(out)) // Add conditions for volumes and networks if strings.Contains(string(out), "404") {