Skip to content

Commit

Permalink
Merge pull request #4 from Sharpz7/developer
Browse files Browse the repository at this point in the history
Updated to 0.1.5 with Bug Fixes
  • Loading branch information
Sharpz7 authored Jan 21, 2021
2 parents 2cf800e + b9a2a4d commit b3bd092
Show file tree
Hide file tree
Showing 3 changed files with 72 additions and 65 deletions.
16 changes: 8 additions & 8 deletions sharpcd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ tasks:
type: docker
sharpurl: https://localhost:5666
giturl: https://raw.githubusercontent.com/Sharpz7/
compose: /sharpcd/dev/testing/basic.yml
compose: /sharpcd/developer/testing/basic.yml

registry_task:
name: Registry
Expand All @@ -15,48 +15,48 @@ tasks:
envfile: .env
sharpurl: https://localhost:5666
giturl: https://raw.githubusercontent.com/Sharpz7/
compose: /sharpcd/dev/testing/registry.yml
compose: /sharpcd/developer/testing/registry.yml

env_task:
name: Enviroment Test Fail
type: docker
envfile: .env
sharpurl: https://localhost:5666
giturl: https://raw.githubusercontent.com/Sharpz7/
compose: /sharpcd/dev/testing/env.yml
compose: /sharpcd/developer/testing/env.yml

external_task:
name: External Docker Parts
type: docker
sharpurl: https://localhost:5666
giturl: https://raw.githubusercontent.com/Sharpz7/
compose: /sharpcd/dev/testing/external.yml
compose: /sharpcd/developer/testing/external.yml

env_task2:
name: Enviroment Test Pass
type: docker
envfile: ./testing/.env
sharpurl: https://localhost:5666
giturl: https://raw.githubusercontent.com/Sharpz7/
compose: /sharpcd/dev/testing/env.yml
compose: /sharpcd/developer/testing/env.yml

file_task:
name: No Compose File
type: docker
sharpurl: https://localhost:5666
giturl: https://raw.githubusercontent.com/Sharpz7/
compose: /sharpcd/dev/testing/basic
compose: /sharpcd/developer/testing/basic

Delayed_task:
name: Delayed stop
type: docker
sharpurl: https://localhost:5666
giturl: https://raw.githubusercontent.com/Sharpz7/
compose: /sharpcd/dev/testing/delayed.yml
compose: /sharpcd/developer/testing/delayed.yml

Restart_task:
name: Test Log exit
type: docker
sharpurl: https://localhost:5666
giturl: https://raw.githubusercontent.com/Sharpz7/
compose: /sharpcd/dev/testing/restart.yml
compose: /sharpcd/developer/testing/restart.yml
86 changes: 46 additions & 40 deletions src/jobs.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,50 +130,56 @@ func (job *taskJob) DockerCmd() *exec.Cmd {
logsLoc := folder.Logs + id
composeLoc := folder.Docker + id + "/docker-compose.yml"

// Get github token
f, err := readFilter()
if err != nil {
handleAPI(err, job, "Failed to get Token")
}
if job.Reconnect == false {
// Get github token
f, err := readFilter()
if err != nil {
handleAPI(err, job, "Failed to get Token")
}

// Make url, read the compose file
req, err := http.NewRequest("GET", url, nil)
if err != nil {
handleAPI(err, job, "Failed to build request")
}
req.Header.Set("Authorization", "token "+f.Token)
req.Header.Set("Accept", "application/vnd.github.v3.raw")
// Make url, read the compose file
req, err := http.NewRequest("GET", url, nil)
if err != nil {
handleAPI(err, job, "Failed to build request")
}

resp, err := http.DefaultClient.Do(req)
if err != nil {
handleAPI(err, job, "Failed to get compose URL")
}
defer resp.Body.Close()
file, err := ioutil.ReadAll(resp.Body)
handleAPI(err, job, "Failed to read compose file")

// Make directory for docker and logs and save file
os.Mkdir(folder.Docker+id, 0777)
os.Mkdir(logsLoc, 0777)
err = ioutil.WriteFile(composeLoc, file, 0777)
handleAPI(err, job, "Failed to write to file")

if job.Registry != "" {
job.dockerLogin()
}
if f.Token != "" {
req.Header.Set("Authorization", "token "+f.Token)
}

// Make sure config is valid
err = job.buildCommand("-f", composeLoc, "up", "--no-start")
if err != nil {
return nil
}
req.Header.Set("Accept", "application/vnd.github.v3.raw")

resp, err := http.DefaultClient.Do(req)
if err != nil {
handleAPI(err, job, "Failed to get compose URL")
}
defer resp.Body.Close()
file, err := ioutil.ReadAll(resp.Body)
handleAPI(err, job, "Failed to read compose file")

// Make directory for docker and logs and save file
os.Mkdir(folder.Docker+id, 0777)
os.Mkdir(logsLoc, 0777)
err = ioutil.WriteFile(composeLoc, file, 0777)
handleAPI(err, job, "Failed to write to file")

if job.Registry != "" {
job.dockerLogin()
}

// Remove any previous containers
job.buildCommand("-f", composeLoc, "down")
// Pull new images
job.buildCommand("-f", composeLoc, "pull")
// Run Code
job.buildCommand("-f", composeLoc, "up", "-d")
// Make sure config is valid
err = job.buildCommand("-f", composeLoc, "up", "--no-start")
if err != nil {
return nil
}

// Remove any previous containers
job.buildCommand("-f", composeLoc, "down")
// Pull new images
job.buildCommand("-f", composeLoc, "pull")
// Run Code
job.buildCommand("-f", composeLoc, "up", "-d")
}

// Get logging Running
cmd := exec.Command("docker-compose", "-f", composeLoc, "logs", "-f", "--no-color")
Expand Down
35 changes: 18 additions & 17 deletions src/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package main
import (
"crypto/tls"
"fmt"
"io/ioutil"
"log"
"net/http"
"os"
Expand Down Expand Up @@ -50,20 +51,20 @@ func server() {
}

// Try and reconnect to previous containers
//func reconnect() {
//
// items, _ := ioutil.ReadDir(folder.Docker)
// for _, item := range items {
// if item.IsDir() {
// newJob := taskJob{
// Name: "Restarted Task",
// Type: "docker",
// Reconnect: true}
//
// newJob.ID = item.Name()
// allJobs.List = append(allJobs.List, &newJob)
// comm := &newJob
// go comm.Run()
// }
// }
//}
func reconnect() {

items, _ := ioutil.ReadDir(folder.Docker)
for _, item := range items {
if item.IsDir() {
newJob := taskJob{
Name: "Restarted Task",
Type: "docker",
Reconnect: true}

newJob.ID = item.Name()
allJobs.List = append(allJobs.List, &newJob)
comm := &newJob
go comm.Run()
}
}
}

0 comments on commit b3bd092

Please sign in to comment.