forked from github/plane
dev: auto instance registration script
This commit is contained in:
parent
efbf834e77
commit
32a8133a9f
@ -43,7 +43,7 @@ USER captain
|
||||
COPY manage.py manage.py
|
||||
COPY plane plane/
|
||||
COPY templates templates/
|
||||
|
||||
COPY package.json package.json
|
||||
COPY gunicorn.config.py ./
|
||||
USER root
|
||||
RUN apk --no-cache add "bash~=5.2"
|
||||
|
@ -3,12 +3,10 @@ import os, sys
|
||||
import json
|
||||
import uuid
|
||||
import requests
|
||||
|
||||
# Django imports
|
||||
from django.utils import timezone
|
||||
|
||||
# Module imports
|
||||
from plane.db.models import User
|
||||
from plane.license.models import Instance
|
||||
|
||||
sys.path.append("/code")
|
||||
|
||||
@ -20,12 +18,17 @@ django.setup()
|
||||
|
||||
|
||||
def instance_registration():
|
||||
try:
|
||||
# Module imports
|
||||
from plane.db.models import User
|
||||
from plane.license.models import Instance
|
||||
|
||||
# Check if the instance is registered
|
||||
instance = Instance.objects.first()
|
||||
|
||||
# If instance is None then register this instance
|
||||
if instance is None:
|
||||
with open("package.json", "r") as file:
|
||||
with open("/code/package.json", "r") as file:
|
||||
# Load JSON content from the file
|
||||
data = json.load(file)
|
||||
|
||||
@ -68,13 +71,23 @@ def instance_registration():
|
||||
instance_id=data.get("id"),
|
||||
license_key=data.get("license_key"),
|
||||
api_key=data.get("api_key"),
|
||||
version=data.get("version"),
|
||||
version=0.1,
|
||||
email=data.get("email"),
|
||||
owner=user,
|
||||
last_checked_at=timezone.now(),
|
||||
)
|
||||
print("Instance succesfully registered")
|
||||
|
||||
print(f"Instance succesfully registered with owner: {instance.owner.email}")
|
||||
return
|
||||
print("Instance could not be registered")
|
||||
return
|
||||
else:
|
||||
print(f"Instance already registered with instance owner: {instance.owner.email}")
|
||||
print(
|
||||
f"Instance already registered with instance owner: {instance.owner.email}"
|
||||
)
|
||||
return
|
||||
except ImportError:
|
||||
raise ImportError
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
instance_registration()
|
||||
|
Loading…
Reference in New Issue
Block a user