Skip to content

Commit

Permalink
Merge pull request #12 from Sharpz7/dev
Browse files Browse the repository at this point in the history
Updated to V3
  • Loading branch information
Sharpz7 authored Nov 3, 2021
2 parents f2b5a73 + a3680bd commit 3ae1b2f
Show file tree
Hide file tree
Showing 12 changed files with 221 additions and 137 deletions.
2 changes: 1 addition & 1 deletion .version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
VERSION=0.2.0
VERSION=3
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ tasks:
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
╰─➤ sudo curl -s -L https://github.com/Sharpz7/sharpcd/releases/download/3/install.sh | sudo bash
```

## Command Options
Expand Down
25 changes: 17 additions & 8 deletions installs/install.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,18 @@
#/bin/bash

if [[ $1 == "client" ]];
then
# Download and unpack
wget https://github.com/Sharpz7/sharpcd/releases/download/XXXXX/linux.tar.gz
sudo mkdir -p /tmp/sharpcd
sudo tar -C /tmp/sharpcd -zxvf linux.tar.gz
sudo cp /tmp/sharpcd/sharpcd /usr/local/bin/sharpcd
rm -r linux.tar.gz

sharpcd --help
exit 0
fi

echo "Installing required modules"
sudo apt-get install -y lsof

Expand All @@ -10,14 +23,11 @@ sudo kill $(sudo lsof -t -i:5666) > /dev/null 2>&1 || true
ver=$(echo $(sharpcd version) | sed "s/^.*Version: \([0-9.]*\).*/\1/")
vernum=$(echo "$ver" | sed -r 's/[.0]+//g')

if [[ $vernum =~ ^[0-9]+$ ]];
then
if [[ $vernum < 0 ]];
then
if [[ $vernum =~ ^[0-9]+$ ]]; then
if [[ $vernum < 0 ]]; then
echo "Breaking changes: Removing old sharpcd-data"
read -r -p "Are you sure? [y/N] " response
if [[ "$response" =~ ^([yY][eE][sS]|[yY])$ ]]
then
if [[ "$response" =~ ^([yY][eE][sS]|[yY])$ ]]; then
echo "Deleting old Data..."
sudo rm -r /usr/local/bin/sharpcd-data
else
Expand Down Expand Up @@ -58,7 +68,6 @@ sudo chmod +x /usr/local/bin/sharpcd
sudo chmod 755 /usr/local/bin/sharpcd
sudo chown -R sharpcd:sharpcd /usr/local/bin/sharpcd-data


# Create system service
test=$(cat <<-END
[Unit]
Expand Down Expand Up @@ -98,4 +107,4 @@ echo "Use the follow IP table commands to block port 5666 from outside localhost
echo "sudo iptables -D INPUT -p tcp --dport 5666 -s localhost -j ACCEPT"
echo "sudo iptables -D INPUT -p tcp --dport 5666 -j DROP"
echo "sudo iptables -A INPUT -p tcp --dport 5666 -s localhost -j ACCEPT"
echo "sudo iptables -A INPUT -p tcp --dport 5666 -j DROP"
echo "sudo iptables -A INPUT -p tcp --dport 5666 -j DROP"
35 changes: 24 additions & 11 deletions sharpdev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,27 +9,46 @@ scripts:
build: |
go build -o ./internal/sharpcd ./src
sharpcd1: |
sharpcd: |
sharpdev build
./internal/sharpcd $_ARG1
./internal/sharpcd $_ARG1 $_ARG2 $_ARG3 $_ARG4 $_ARG5
server: |
sharedserver: |
sudo apt-get install -y lsof
sudo kill $(sudo lsof -t -i:5666) > /dev/null 2>&1 || true
sharpdev build
$(sudo ./internal/sharpcd server &) &
server: |
sharpdev sharedserver
$(sudo ./internal/sharpcd server) &
serveropen: |
sharpdev sharedserver
sudo ./internal/sharpcd server
test: |
sharpdev server
sharpdev clientr
sharpdev kill
kill: |
sudo apt-get install -y lsof
sudo kill $(sudo lsof -t -i:5666) > /dev/null 2>&1 || true
client: |
shared: |
sudo docker-compose -f "./internal/sharpcd-data/docker/external_task/docker-compose.yml" down
$(sudo docker volume rm memes) > /dev/null 2>&1 || true
$(sudo docker network rm memes) > /dev/null 2>&1 || true
sharpdev build
client: |
sharpdev shared
./internal/sharpcd --secret $PASSD
clientr: |
sharpdev shared
sharpdev sharpcd --secret $PASSD --remotefile https://raw.githubusercontent.com/Sharpz7/sharpcd/master/sharpcd.yml
trak: |
sharpdev build
./internal/sharpcd --secret $PASSD trak $_ARG1 $_ARG2 $_ARG3
Expand All @@ -43,16 +62,10 @@ scripts:
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

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
Expand Down
19 changes: 14 additions & 5 deletions src/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"net/http"
"os"
"os/exec"
"sort"
"strings"
)

Expand All @@ -17,7 +18,13 @@ func getAPIData(r *http.Request, resp *response) error {
path := strings.Split(r.URL.Path[5:], "/")
switch path[0] {
case "jobs":
resp.Jobs = allJobs.List
for _, job := range allJobs {
resp.Jobs = append(resp.Jobs, job)
}

sort.Slice(resp.Jobs, func(i, j int) bool {
return resp.Jobs[i].ID < resp.Jobs[j].ID
})
return nil
case "job":
resp.Job, err = getJobs(path[1])
Expand Down Expand Up @@ -65,8 +72,8 @@ func getLogsFeed(path string) (string, error) {
func getJobs(path string) (*taskJob, error) {
var emptyJob *taskJob

for _, job := range allJobs.List {
if job.ID == path {
for id, job := range allJobs {
if id == path {
err := checkJobStatus(job)
return job, err
}
Expand All @@ -77,8 +84,10 @@ func getJobs(path string) (*taskJob, error) {

func checkJobStatus(job *taskJob) error {
logs, err := getLogs(job.ID)
if strings.Contains(logs, "exited with code") {
job.Status = jobStatus.Stopped

exited := strings.Contains(logs, "exited with code")
if exited && (job.Status != jobStatus.Building) {
job.Status = jobStatus.Errored
job.ErrMsg = "A Container has maybe exited unexpectedly"
}

Expand Down
27 changes: 21 additions & 6 deletions src/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,27 @@ import (
func client() {

var globalErr bool

// Get config, get data from it
f, err := ioutil.ReadFile("./sharpcd.yml")
var con config
err = yaml.Unmarshal(f, &con)
handle(err, "Failed to read and extract sharpcd.yml")
var err error
var file []byte

if len(secretFlag) == 0 {
resp, err := http.Get(secretFlag)
handle(err, "Failed to download remote sharpcd.yml")
defer resp.Body.Close()

if resp.StatusCode == http.StatusOK {
file, err = ioutil.ReadAll(resp.Body)
handle(err, "Failed to read remote sharpcd.yml")
}
} else {
// Get config, get data from it
file, err = ioutil.ReadFile("./sharpcd.yml")
handle(err, "Failed to read and extract sharpcd.yml")
}

err = yaml.Unmarshal(file, &con)
handle(err, "Failed to read yaml from sharpcd.yml")

// POST to sharpcd server for each task
for id, task := range con.Tasks {
Expand Down Expand Up @@ -183,7 +198,7 @@ func postCommChecks(t task, id string) error {
}

if lastIssue != job.Issue {
fmt.Println("No fatal Issue found: " + job.Issue)
fmt.Println("Non fatal Issue found: " + job.Issue)
lastIssue = job.Issue
}

Expand Down
Loading

0 comments on commit 3ae1b2f

Please sign in to comment.