Skip to content

Commit

Permalink
Merge pull request #45 from Native-Planet/standalone
Browse files Browse the repository at this point in the history
Beta-3.3.0
  • Loading branch information
nallux-dozryl authored Nov 29, 2022
2 parents 9d4ea4d + 3c876a3 commit 1ec504f
Show file tree
Hide file tree
Showing 32 changed files with 453 additions and 445 deletions.
10 changes: 10 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,16 @@ __pycache__/
# C extensions
*.so

# Nuitka
*.bin
groundseg.dist/
groundseg.build/
groundseg.onefile-build/

# GroundSeg
settings/
uploaded/

# Distribution / packaging
.Python
build/
Expand Down
61 changes: 2 additions & 59 deletions Jenkinsfile
Original file line number Diff line number Diff line change
@@ -1,67 +1,10 @@
pipeline {
agent any
environment {
reg_pw = credentials('Dockerhub PW')
environ = sh (
script: '''
echo $BRANCH_NAME|sed 's@origin/@@g'
''',
returnStdout: true
).trim()
}
stages {
stage('Build') {
environment {
environ = sh (
script: '''
echo $BRANCH_NAME|sed 's@origin/@@g'
''',
returnStdout: true
).trim()
tag = sh (
script: '''
if [ "${environ}" = "dev" ]; then
echo "staging"
elif [ "${environ}" = "master" ]; then
echo "latest"
else
echo "nobuild"
fi
''',
returnStdout: true
).trim()
}
steps {
script {
if( "${tag}" == "nobuild" ) {
currentBuild.getRawBuild().getExecutor().interrupt(Result.ABORTED)
print("Ignoring branch ${tag}")
sleep(1)
}
}
git url: 'https://github.com/Native-Planet/anchor-source.git',
credentialsId: 'Github token',
branch: "${environ}"
sh "docker login -u nativeplanet -p $reg_pw docker.io"
dir("${env.WORKSPACE}/"){
sh (
script: '''
docker buildx build --platform linux/amd64 --no-cache ./api/ -t groundseg-api:${tag}
docker tag groundseg-api:${tag} nativeplanet/groundseg-api:${tag}
docker buildx build --platform linux/amd64 --no-cache ./ui/ -t anchor-webui:${tag}
docker tag groundseg-webui:${tag} nativeplanet/groundseg-webui:${tag}
docker push nativeplanet/groundseg-api:${tag}
docker push nativeplanet/groundseg-webui:${tag}
''',
returnStdout: true
)
}
sh 'mv ./release/version.csv /opt/groundseg/version/version.csv'
}
}
}
post {
always {
cleanWs deleteDirs: true, notFailBuild: true
}
}
}
}
66 changes: 60 additions & 6 deletions api/app.py → api/groundseg.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,13 @@
import threading, time, os, copy, shutil, psutil, sys, requests
import threading
import time
import os
import copy
import shutil
import psutil
import sys
import requests
import urllib.request

from datetime import datetime
from flask import Flask, jsonify, request, make_response
from flask_cors import CORS
Expand All @@ -7,13 +16,55 @@
from updater_docker import WatchtowerDocker

# Load GroundSeg
orchestrator = Orchestrator("/settings/system.json")
orchestrator = Orchestrator("/opt/nativeplanet/groundseg/settings/system.json")

app = Flask(__name__)
app.config['TEMP_FOLDER'] = '/tmp/'

CORS(app, supports_credentials=True)

# Binary Updater
def check_bin_updates():
print("Binary updater thread started", file=sys.stderr)

cur_hash = orchestrator.config['binHash']

while True:

try:
new_name, new_hash, dl_url = requests.get(orchestrator.config['updateUrl']).text.split('\n')[0].split(',')[0:3]

if orchestrator.config['updateMode'] == 'auto' and cur_hash != new_hash:
print(f"Latest version: {new_name}", file=sys.stderr)
print("Downloading new groundseg binary", file=sys.stderr)
urllib.request.urlretrieve(dl_url, f"{orchestrator.config['CFG_DIR']}/groundseg_new")

print("Removing old groundseg binary", file=sys.stderr)
os.remove(f"{orchestrator.config['CFG_DIR']}/groundseg")

time.sleep(3)

print("Renaming new groundseg binary", file=sys.stderr)
os.rename(f"{orchestrator.config['CFG_DIR']}/groundseg_new",
f"{orchestrator.config['CFG_DIR']}/groundseg")

time.sleep(2)
print("Setting launch permissions for new binary", file=sys.stderr)
os.system(f"chmod +x {orchestrator.config['CFG_DIR']}/groundseg")

time.sleep(1)

print("Restarting groundseg...", file=sys.stderr)
if sys.platform == "darwin":
os.system("launchctl load /Library/LaunchDaemons/io.nativeplanet.groundseg.plist")
else:
os.system("systemctl restart groundseg")

except Exception as e:
print(e, file=sys.stderr)

time.sleep(90)


# Get updated Anchor information every 12 hours
def anchor_information():
print("Anchor information thread started", file=sys.stderr)
Expand Down Expand Up @@ -66,6 +117,9 @@ def meld_loop():

time.sleep(30)

# Start binary updater thread
threading.Thread(target=check_bin_updates).start()

# Start system monitoring on a new thread
threading.Thread(target=sys_monitor).start()

Expand Down Expand Up @@ -198,10 +252,10 @@ def pier_upload():
patp = filename.split('.')[0]

# Create subfolder
file_subfolder = f"{app.config['TEMP_FOLDER']}{patp}"
os.system(f"mkdir -p {file_subfolder}")
file_subfolder = f"{orchestrator.config['CFG_DIR']}/uploaded/{patp}"
os.makedirs(file_subfolder, exist_ok=True)

fn = save_path = f"{app.config['TEMP_FOLDER']}{patp}/{filename}"
fn = save_path = f"{file_subfolder}/{filename}"
current_chunk = int(request.form['dzchunkindex'])

if current_chunk == 0:
Expand Down
2 changes: 1 addition & 1 deletion api/minio_docker.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ def run(self):

self.container.exec_run('mkdir /data/bucket')

shutil.copy('/app/mc', f'/var/lib/docker/volumes/{self.minio_name}/_data/mc')
shutil.copy('/opt/nativeplanet/groundseg/mc', f'/var/lib/docker/volumes/{self.minio_name}/_data/mc')

self.container.exec_run("chmod +x /data/mc")
self.container.exec_run(f"/data/mc alias set myminio http://localhost:{s3_port} {self.config['pier_name']} {self.config['minio_password']}")
Expand Down
Loading

0 comments on commit 1ec504f

Please sign in to comment.