Skip to content

Commit

Permalink
Merge pull request #11 from Sharpz7/dev
Browse files Browse the repository at this point in the history
Move to 0.2.0
  • Loading branch information
Sharpz7 authored Oct 29, 2021
2 parents 5b9ed51 + efb8c36 commit f2b5a73
Show file tree
Hide file tree
Showing 19 changed files with 602 additions and 60 deletions.
2 changes: 1 addition & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ version: 2.1

orbs:
release: sharptools/release@0.0.3
go: sharptools/go@0.0.5
go: sharptools/go@0.0.7


workflows:
Expand Down
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
.env
.vscode
__debug_bin
__debug_bin
docker
2 changes: 1 addition & 1 deletion .version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
VERSION=0.1.10
VERSION=0.2.0
79 changes: 71 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,16 +1,79 @@
[![CircleCI](https://circleci.com/gh/Sharpz7/sharpcd.svg?style=svg)](https://circleci.com/gh/Sharpz7/sharpcd)

SharpCD || Continuous Development for your server
===========
# SharpCD || Continuous Development for your server

![](https://files.mcaq.me/zbnf.png)

# Example Config
```yml
version: 1

trak:
local: https://localhost:5666
remote: https://mcaq.me:5666

tasks:
basic_task:
name: Basic
type: docker
sharpurl: https://localhost:5666
giturl: https://raw.githubusercontent.com/Sharpz7/
compose: /sharpcd/dev/testing/basic.yml

registry_task:
name: Registry
type: docker
registry: docker.mcaq.me
envfile: .env
sharpurl: https://localhost:5666
giturl: https://raw.githubusercontent.com/Sharpz7/
compose: /sharpcd/dev/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
```
# Installation
On linux, just run:
```console
╭─adam@box ~/
╰─➤ sudo curl -s -L https://github.com/Sharpz7/sharpcd/releases/download/0.2.0/install.sh | sudo bash
```

## Command Options

Installation
===========
On linux, just run:
```console
adam@console~$ sudo curl -s -L https://github.com/Sharpz7/sharpcd/releases/download/0.1.10/install.sh | sudo bash
╭─adam@box ~/
╰─➤ sharpcd help

Args of SharpCD:

- server: Run the sharpcd server
- setsecret: Set the secret for API and Task Calls
- addfilter: Add a url for a compose file
- changetoken: Add a token for private github repos
- removefilter: Remove a url for a compose file
- version: Returns the Current Version
- trak: Run the Trak program

Sub Command Trak:

- alljobs {type}: Get info on all jobs
- job {type} {id}: Get info on job with logging
- list {type}: Get all jobs running on sharpcd server

Flags:

-secret string
Put secret as a arg for automation tasks
```

Maintainers and Developers
==========
## Maintainers

- Sharp / [@Sharpz7](https://github.com/Sharpz7)
- [Adam McArthur](https://adam.mcaq.me)
5 changes: 5 additions & 0 deletions gopack.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,10 @@ packages:
- github.com/joho/godotenv
- golang.org/x/term
- github.com/hashicorp/go-version
- github.com/gosuri/uilive
- github.com/gizak/termui
- github.com/common-nighthawk/go-figure
- github.com/gorilla/websocket

devpackages:
- golang.org/x/sys/unix
2 changes: 0 additions & 2 deletions internal/sharpcd-data/logs/.gitignore

This file was deleted.

16 changes: 10 additions & 6 deletions sharpcd.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
version: 1

trak:
local: https://localhost:5666
remote: https://mcaq.me:5666

tasks:
basic_task:
name: Basic
Expand Down Expand Up @@ -47,16 +51,16 @@ tasks:
giturl: https://raw.githubusercontent.com/Sharpz7/
compose: /sharpcd/dev/testing/basic

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

Restart_task:
name: Test Log exit
trak_task:
name: Trak Log Test
type: docker
sharpurl: https://localhost:5666
giturl: https://raw.githubusercontent.com/Sharpz7/
compose: /sharpcd/dev/testing/restart.yml
compose: /sharpcd/dev/testing/trak.yml
48 changes: 32 additions & 16 deletions sharpdev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,19 @@ scripts:
build: |
go build -o ./internal/sharpcd ./src
revert: git revert $_ARG1..HEAD
list: git branch
archive: |
git tag archive/$_ARG1 $_ARG1
git branch -d $_ARG1
sharpcd1: |
sharpdev build
./internal/sharpcd $_ARG1
server: |
sudo apt-get install -y lsof
sudo kill $(sudo lsof -t -i:5666) > /dev/null 2>&1 || true
sharpdev build
sudo ./internal/sharpcd server
$(sudo ./internal/sharpcd server &) &
kill: |
sudo apt-get install -y lsof
sudo kill $(sudo lsof -t -i:5666) > /dev/null 2>&1 || true
client: |
sudo docker-compose -f "./internal/sharpcd-data/docker/external_task/docker-compose.yml" down
Expand All @@ -28,23 +30,37 @@ scripts:
sharpdev build
./internal/sharpcd --secret $PASSD
job: curl -k -X POST -d SECRETD https://localhost:5666/api/job/$_ARG1
logs: curl -k -X POST -d SECRETD https://localhost:5666/api/logs/$_ARG1
trak: |
sharpdev build
./internal/sharpcd --secret $PASSD trak $_ARG1 $_ARG2 $_ARG3
trakone: |
sharpdev trak job local $_ARG1
trakall: |
sharpdev trak alljobs local
traklist: |
sharpdev trak list local
filter: ./internal/sharpcd addfilter https://raw.githubusercontent.com/Sharpz7/
remove: ./internal/sharpcd removefilter https://raw.githubusercontent.com/Sharpz7/
token: ./internal/sharpcd changetoken $_ARG1
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: |
curl -H 'Authorization: token $_ARG1' \
-H 'Accept: application/vnd.github.v3.raw' \
-O \
-L https://raw.githubusercontent.com/Sharpz7/stuandbob/main/docker-compose.yml

test: |
git checkout dev
git push origin dev
sharpdev client
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
logsfeed: curl -k -X POST -d SECRETD https://localhost:5666/api/logsfeed/$_ARG1
job: curl -k -X POST -d SECRETD https://localhost:5666/api/job/$_ARG1
logs: curl -k -X POST -d SECRETD https://localhost:5666/api/logs/$_ARG1
logsremote: curl -k -X POST -d SECRET https://mcaq.me:5666/api/logs/$_ARG1

keygen: |
sudo openssl req -x509 -nodes -days 730 -newkey rsa:2048 -keyout /home/coder/code-server/go/src/sharpCD/internal/sharpcd-data/private/server.key -out /home/coder/code-server/go/src/sharpCD/internal/sharpcd-data/private/server.crt -config /home/coder/code-server/go/src/sharpCD/testing/openssl.conf -extensions 'v3_req'
21 changes: 19 additions & 2 deletions src/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"io/ioutil"
"net/http"
"os"
"os/exec"
"strings"
)

Expand All @@ -24,14 +25,17 @@ func getAPIData(r *http.Request, resp *response) error {
case "logs":
resp.Message, err = getLogs(path[1])
return err
case "logsfeed":
resp.Message, err = getLogsFeed(path[1])
return err
}

return nil
}

// Gets the logs from the task ID's file
func getLogs(path string) (string, error) {
logs := folder.Logs + path + "/info.log"
logs := folder.Docker + path + "/info.log"
file, err := os.Open(logs)
if err != nil {
return "", err
Expand All @@ -45,6 +49,19 @@ func getLogs(path string) (string, error) {
return string(bytes), nil
}

func getLogsFeed(path string) (string, error) {
logs := folder.Docker + path + "/info.log"

cmd := exec.Command("tail", "-11", logs)
out, err := cmd.CombinedOutput()
msg := string(out)
if err != nil {
return msg, errors.New("Failed to run Docker Compose")
}

return msg, nil
}

func getJobs(path string) (*taskJob, error) {
var emptyJob *taskJob

Expand All @@ -62,7 +79,7 @@ func checkJobStatus(job *taskJob) error {
logs, err := getLogs(job.ID)
if strings.Contains(logs, "exited with code") {
job.Status = jobStatus.Stopped
job.ErrMsg = "A Container exited unexpectedly"
job.ErrMsg = "A Container has maybe exited unexpectedly"
}

return err
Expand Down
5 changes: 5 additions & 0 deletions src/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,8 @@ func postCommChecks(t task, id string) error {
counter := 0

fmt.Println("Waiting on server response...")

// Ensure task hasn't stopped unexpectantly early
for {
resp, code := post(payload, jobURL)
if code != statCode.Accepted {
Expand All @@ -148,6 +150,7 @@ func postCommChecks(t task, id string) error {
building := job.Status == jobStatus.Building && !buildingTriggered
running := job.Status == jobStatus.Running && !runningTriggered

// Marks that a new build has started
if building {
buildingTriggered = true
fmt.Println("The Task is now building a job")
Expand All @@ -159,6 +162,7 @@ func postCommChecks(t task, id string) error {
fmt.Println("Making sure it does not stop unexpectedly...")
}

// Marks some sort of error
if errored || stopped {
fmt.Println("Task stopped running!")
fmt.Println("Error Message: " + job.ErrMsg)
Expand All @@ -183,6 +187,7 @@ func postCommChecks(t task, id string) error {
lastIssue = job.Issue
}

// If 7 seconds has elapsed, comsider it started properly
if counter > 7 {
fmt.Println("Task has started Properly!")
return nil
Expand Down
19 changes: 12 additions & 7 deletions src/handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,7 @@ func httpHandleAPI(w http.ResponseWriter, r *http.Request) {
if status == statCode.Accepted {

} else {
resp = response{}
resp.Message = getFailMessage(status)
resp.Message = getFailMessage(status) + " Message: " + resp.Message
}

json.NewEncoder(w).Encode(resp)
Expand Down Expand Up @@ -138,15 +137,21 @@ func checkMethod(method string) error {
return nil
}

// Check that client versions match
func checkVersion(clientVersion string) error {
v1, err := version.NewVersion(clientVersion)
v2, err := version.NewVersion(sharpCDVersion)
if clientVersion != "" {
v1, err := version.NewVersion(clientVersion)
v2, err := version.NewVersion(sharpCDVersion)

if v1.LessThan(v2) {
err = errors.New("Wrong Client Version")
}

if v1.LessThan(v2) {
err = errors.New("Wrong Client Version")
return err
}

return err
// Means its a non-sharpcd task
return nil
}

// Checks if URLs are okay
Expand Down
Loading

0 comments on commit f2b5a73

Please sign in to comment.