Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

3.0.0 testing #166

Open
wants to merge 16 commits into
base: 3.0.0-testing
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
16 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 10 additions & 10 deletions admin/nuvfile.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ tasks:
export USERNAME={{._username_}}
export EMAIL={{._email_}}
export PASSWORD={{._password_}}
export AUTH="$(nuv -random -u):$(nuv -random --str 64)"
export NEW_USER_AUTH="$(nuv -random -u):$(nuv -random --str 64)"

# check {{._username_}} is at least 5 chars long
if [ ${#USERNAME} -lt 5 ]
Expand Down Expand Up @@ -85,10 +85,10 @@ tasks:

export REDIS_ENABLED=false
export MONGODB_ENABLED=false
export MINIO_DATA_ENABLED=false
export MINIO_STATIC_ENABLED=false
export STORAGE_DATA_ENABLED=false
export STORAGE_STATIC_ENABLED=false
export POSTGRES_ENABLED=false
export MINIO_STORAGE_QUOTA=auto
export OBJECT_STORAGE_QUOTA=auto

if {{.__redis}} || {{.__all}}
then
Expand All @@ -110,19 +110,19 @@ tasks:
fi
fi

if {{.__minio}} || {{.__all}}
if {{.__storage}} || {{.__all}}
then
if $NUVOLARIS_MINIO
if $NUVOLARIS_MINIO || $NUVOLARIS_COSI
then
MINIO_DATA_ENABLED=true
MINIO_STATIC_ENABLED=true
STORAGE_DATA_ENABLED=true
STORAGE_STATIC_ENABLED=true
else
nuv -die "Error! Minio is not enabled in Nuvolaris"
nuv -die "Error! Onject Storage is not enabled in Nuvolaris"
fi
fi

if test -n "{{.__storagequota}}"
then MINIO_STORAGE_QUOTA={{.__storagequota}}
then OBJECT_STORAGE_QUOTA={{.__storagequota}}
fi

if {{.__postgres}} || {{.__all}}
Expand Down
4 changes: 2 additions & 2 deletions admin/nuvopts.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Subcommand: nuv admin

Usage:
admin adduser <username> <email> <password> [--all] [--redis] [--mongodb] [--minio] [--postgres] [--storagequota=<quota>|auto]
admin adduser <username> <email> <password> [--all] [--redis] [--mongodb] [--storage] [--postgres] [--storagequota=<quota>|auto]
admin deleteuser <username>

Commands:
Expand All @@ -12,6 +12,6 @@ Options:
--all enable all services
--redis enable redis
--mongodb enable mongodb
--minio enable minio
--storage enable object based storage
--postgres enable postgres
--storagequota=<quota>
8 changes: 4 additions & 4 deletions admin/user-crd.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ spec:
email: ${EMAIL}
password: ${PASSWORD}
namespace: ${USERNAME}
auth: ${AUTH}
auth: ${NEW_USER_AUTH}
redis:
enabled: ${REDIS_ENABLED}
prefix: ${USERNAME}
Expand All @@ -40,10 +40,10 @@ spec:
password: ${USER_SECRET_POSTGRES}
object-storage:
password: ${USER_SECRET_MINIO}
quota: "${MINIO_STORAGE_QUOTA:-auto}"
quota: "${OBJECT_STORAGE_QUOTA:-auto}"
data:
enabled: ${MINIO_DATA_ENABLED}
enabled: ${STORAGE_DATA_ENABLED}
bucket: ${USERNAME}-data
route:
enabled: ${MINIO_STATIC_ENABLED}
enabled: ${STORAGE_STATIC_ENABLED}
bucket: ${USERNAME}-web
59 changes: 39 additions & 20 deletions ide/deploy/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,47 +15,66 @@
# specific language governing permissions and limitations
# under the License.

from pathlib import Path
from subprocess import Popen, PIPE
import os, os.path, json
import os
import os.path
import threading
import asyncio

def get_nuvolaris_config(key, default):
try:
dir = os.environ.get("NUV_PWD", "/do_not_exists")
file = f"{dir}/package.json"
info = json.loads(Path(file).read_text())
return info.get("nuvolaris", {}).get(key, default)
except:
return default

def readlines(inp):
from typing import IO
from .config import get_nuvolaris_config


def readlines(inp: IO[str]):
"""Read line from an file descriptor

Args:
inp (IO[str]): the file descriptor
"""
for line in iter(inp.readline, ''):
print(line, end='')

# serve web area
def launch(key, default):


def launch(key: str, default: (str | list)):
"""Launch a command in a process, reading.
The command is extracted from nuvolaris config in package.json
or a default command is used

Args:
key (str): the key from which read the command
default (str | list): the default if the key is not found
"""
cmd = get_nuvolaris_config(key, default)
proc = Popen(
cmd, shell=True,
cwd=os.environ.get("NUV_PWD"), env=os.environ,
cmd, shell=True,
cwd=os.environ.get("NUV_PWD"), env=os.environ,
stdin=PIPE, stdout=PIPE, stderr=PIPE, text=True
)
threading.Thread(target=readlines, args=(proc.stdout,)).start()
threading.Thread(target=readlines, args=(proc.stderr,)).start()

def serve():

def serve():
"""Serve the web area
"""
launch("devel", "nuv ide serve")

def logs():

def logs():
"""Serve the openwhisk activation's logs
"""
launch("logs", "nuv activation poll")

# build


def build():
"""Try to build the frontend application, if the deploy command is set.

"""
deploy = get_nuvolaris_config("deploy", "true")
proc = Popen(
deploy, shell=True,
deploy, shell=True,
env=os.environ,
cwd=os.environ.get("NUV_PWD"),
stdin=PIPE, stdout=PIPE, stderr=PIPE, text=True
Expand Down
65 changes: 65 additions & 0 deletions ide/deploy/config.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.

import os
import json
from pathlib import Path

MAINS = ["__main__.py",
"index.js",
"index.php",
"main.go"]

SKIPDIR = ["virtualenv",
"node_modules",
"__pycache__"]

DEFAULT_REQ_GLOBS = ["packages/*/*/requirements.txt",
"packages/*/*/package.json",
"packages/*/*/composer.json",
"packages/*/*/go.mod"]

DEFAULT_MAIN_GLOBS = ["packages/*/*/index.js",
"packages/*/*/__main__.py",
"packages/*/*/index.php",
"packages/*/*/main.go"]

DEFAULT_SINGLES_GLOBS = ["packages/*/*.py",
"packages/*/*.js",
"packages/*/*.php",
"packages/*/*.go"]


def get_nuvolaris_config(key: str, default: list | str) -> (list | str):
"""Read package.json if exists and retrieve the required
value for passed key (if defined)

Args:
key (str): the key of the parameter to retrieve
default (list | str): the default value to return

Returns:
_type_: the list of values or the single string value.
if not defined, the default value is returned
"""
try:
dir = os.environ.get("NUV_PWD", "/do_not_exists")
file = f"{dir}/package.json"
info = json.loads(Path(file).read_text())
return info.get("nuvolaris", {}).get(key, default)
except:
return default
87 changes: 73 additions & 14 deletions ide/deploy/deploy.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,28 +15,49 @@
# specific language governing permissions and limitations
# under the License.

MAINS = ["__main__.py", "index.js", "index.php"]

import os
from os.path import exists, isdir
from os.path import exists, isdir
from subprocess import Popen
from .config import MAINS

dry_run = False

def set_dry_run(b):

def set_dry_run(b: bool):
"""Set global dry run

Args:
b (bool): true for dry run enabled
"""
global dry_run
dry_run = b

def exec(cmd):

def exec(cmd: str):
"""Exec a shell command and wait for it to complete.
If dryrun is set, the command is not executed.

Args:
cmd (str): command line to execue
"""
global dry_run
print("$", cmd)
if not dry_run:
Popen(cmd, shell=True, env=os.environ).wait()

def extract_args(files):

def extract_args(files: list) -> list:
"""Extract openwhisk args from files

Args:
files (list): the list of files to inspect

Returns:
list: a list of parameters
"""
res = []
for file in files:
#if dry_run:
# if dry_run:
# print(f": inspecting {file}")
if exists(file):
with open(file, "r") as f:
Expand All @@ -47,9 +68,16 @@ def extract_args(files):
res.append(line.strip()[2:])
return res


package_done = set()

def deploy_package(package):

def deploy_package(package: str):
"""Deploy a package on nuvolaris

Args:
package (str): the name of package
"""
global package_done
# package args
ppath = f"packages/{package}.args"
Expand All @@ -59,15 +87,38 @@ def deploy_package(package):
exec(cmd)
package_done.add(cmd)

def build_zip(package, action):

def build_zip(package: str, action: str) -> str:
"""Builds a zip for the package / action

Args:
package (str): package
action (str): action

Returns:
str: the path of the built zip file
"""
exec(f"nuv ide util zip A={package}/{action}")
return f"packages/{package}/{action}.zip"

def build_action(package, action):

def build_action(package: str, action: str) -> str:
"""Invoke the nuv ide util action command on package / action

Args:
package (_type_): _description_
action (_type_): _description_

Returns:
str: the zip with the built action
"""
exec(f"nuv ide util action A={package}/{action}")
return f"packages/{package}/{action}.zip"

def deploy_action(artifact):

def deploy_action(artifact: str):
"""Deploy an artifact calling nuv action update
"""
try:
sp = artifact.split("/")
[name, typ] = sp[-1].rsplit(".", 1)
Expand All @@ -83,18 +134,26 @@ def deploy_action(artifact):
to_inspect = [f"{base}/{x}" for x in MAINS]
else:
to_inspect = [artifact]

args = " ".join(extract_args(to_inspect))
exec(f"nuv action update {package}/{name} {artifact} {args}")


"""
file = "packages/deploy/hello.py"
file = "packages/deploy/multi.zip"
file = "packages/deploy/multi/__main__.py"
file = "packages/deploy/multi/requirements.txt"
"""
def deploy(file):
#print(f"*** {file}")


def deploy(file: str):
"""Deploy a package on nuvolaris

Args:
file (str): the file to deploy
"""
# print(f"*** {file}")
if isdir(file):
for start in MAINS:
sub = f"{file}/{start}"
Expand Down
Loading