-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #13 from jmetz/uploader-object
Status on EBI, files on Hypha (for now)
- Loading branch information
Showing
68 changed files
with
1,340 additions
and
11,143 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
import os | ||
import io | ||
import argparse | ||
from typing import Optional | ||
import json | ||
from minio import Minio | ||
# from minio.error import S3Error | ||
|
||
def create_parser() -> argparse.ArgumentParser: | ||
parser = argparse.ArgumentParser() | ||
parser.add_argument("model_name", help="Model name") | ||
parser.add_argument("status", help="Status") | ||
parser.add_argument("step", help="Step", nargs="?", default=0, type=int) | ||
parser.add_argument("num_steps", help="Status", nargs="?", default=0, type=int) | ||
return parser | ||
|
||
|
||
def get_args(argv: Optional[list] = None): | ||
""" | ||
Get command-line arguments | ||
""" | ||
parser = create_parser() | ||
return parser.parse_args(argv) | ||
|
||
|
||
def main(): | ||
args = get_args() | ||
model_name = args.model_name | ||
step = args.step | ||
num_steps = args.num_steps | ||
filename = "status.json" | ||
status = args.status | ||
s3_host = os.getenv("S3_HOST") | ||
s3_bucket = os.getenv("S3_BUCKET") | ||
s3_root_folder = os.getenv("S3_ROOT_FOLDER") | ||
s3_access_key_id = os.getenv("S3_ACCESS_KEY_ID") | ||
s3_secret_access_key = os.getenv("S3_SECRET_ACCESS_KEY") | ||
|
||
client = Minio( | ||
s3_host, | ||
access_key=s3_access_key_id, | ||
secret_key=s3_secret_access_key, | ||
) | ||
found = client.bucket_exists(s3_bucket) | ||
if not found: | ||
raise Exception("target bucket does not exist: {s3_bucket}") | ||
|
||
status_message = json.dumps({"status": status, step=step, num_steps=num_steps}).encode() | ||
|
||
status_file_object = io.BytesIO(status_message) | ||
s3_path = f"{s3_root_folder}/{model_name}/{filename}" | ||
|
||
client.put_object( | ||
s3_bucket, | ||
s3_path, | ||
status_file_object, | ||
length=len(status_message), | ||
content_type="application/json", | ||
) | ||
|
||
|
||
if __name__ == "__main__": | ||
main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,55 @@ | ||
#!/bin/sh | ||
curl -X PUT -H 'Content-Type: application/json' -d '{"status": "'"$2"'"}' "$1" | ||
# Updated to use S3 creds: | ||
# S3_HOST | ||
# S3_BUCKET | ||
# S3_ROOT_FOLDER | ||
# S3_ACCESS_KEY_ID | ||
# S3_SECRET_ACCESS_KEY | ||
# First arg is now model_nickname | ||
|
||
FILENAME=status.json | ||
|
||
MODEL_NAME=$1 | ||
STATUS=$2 | ||
|
||
if [ -z "$MODEL_NAME" ]; then | ||
printf '%s\n' "MODEL_NAME is unset or empty" >&2; | ||
exit 1 | ||
fi | ||
if [ -z "$S3_HOST" ]; then | ||
printf '%s\n' "S3_HOST is unset or empty" >&2; | ||
exit 1 | ||
fi | ||
if [ -z "$S3_BUCKET" ]; then | ||
printf '%s\n' "S3_BUCKET is unset or empty" >&2; | ||
exit 1 | ||
fi | ||
if [ -z "$S3_ROOT_FOLDER" ]; then | ||
printf '%s\n' "S3_ROOT_FOLDER is unset or empty" >&2; | ||
exit 1 | ||
fi | ||
if [ -z "$S3_ACCESS_KEY_ID" ]; then | ||
printf '%s\n' "S3_ACCESS_KEY_ID is unset or empty" >&2; | ||
exit 1 | ||
fi | ||
if [ -z "$S3_SECRET_ACCESS_KEY" ]; then | ||
printf '%s\n' "S3_SECRET_ACCESS_KEY is unset or empty" >&2; | ||
exit 1 | ||
fi | ||
|
||
|
||
#curl -X PUT -H 'Content-Type: application/json' -d '{"status": "'"$2"'"}' "$1" | ||
|
||
RESOURCE="/${S3_BUCKET}/${S3_ROOT_FOLDER}/${MODEL_NAME}/${FILENAME}" | ||
CONTENT_TYPE="application/json" | ||
DATE=`date -R` | ||
_SIGNATURE="PUT\n\n${CONTENT_TYPE}\n${DATE}\n${RESOURCE}" | ||
SIGNATURE=`echo -en ${_SIGNATURE} | openssl sha1 -hmac ${S3_SECRET_ACCESS_KEY} -binary | base64` | ||
|
||
curl -X PUT -d '{"status": "'"$STATUS"'"}' \ | ||
-H "Host: ${S3_HOST}" \ | ||
-H "Date: ${DATE}" \ | ||
-H "Content-Type: ${CONTENT_TYPE}" \ | ||
-H "Authorization: AWS ${S3_ACCESS_KEY_ID}:${SIGNATURE}" \ | ||
https://${S3_HOST}${RESOURCE} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,3 +12,4 @@ bun.lockb | |
|
||
# Local Netlify folder | ||
.netlify | ||
dist/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,38 +1,71 @@ | ||
# create-svelte | ||
# Uploader Overview | ||
|
||
Everything you need to build a Svelte project, powered by [`create-svelte`](https://github.com/sveltejs/kit/tree/master/packages/create-svelte). | ||
```mermaid | ||
stateDiagram-v2 | ||
User --> Client | ||
Upload --> CI | ||
Upload --> ZipFile | ||
ZipFile --> PresignedURL | ||
CreateStatus --> status.json | ||
status.json --> Status | ||
Unzip --> FileSet | ||
CreateTritonModel --> TritonModel | ||
TestTritonModel --> BioEngineRunner | ||
TritonModel --> BioEngineRunner | ||
Publish --> PublishedFileSet | ||
## Creating a project | ||
state Client { | ||
Add --> Edit | ||
Edit --> Verify | ||
Verify --> Upload | ||
Upload --> PresignedURL | ||
PresignedURL --> Status | ||
} | ||
If you're seeing this, you've probably already done this step. Congrats! | ||
state CI{ | ||
CreateStatus --> Unzip | ||
Unzip --> TestModel | ||
TestModel --> CreateTritonModel | ||
CreateTritonModel --> TestTritonModel | ||
TestTritonModel --> Publish | ||
} | ||
```bash | ||
# create a new project in the current directory | ||
npm create svelte@latest | ||
state HyphaAppEngine { | ||
HyphaS3 | ||
BioEngineRunner | ||
state HyphaS3{ | ||
ZipFile | ||
} | ||
} | ||
state EBI_S3 { | ||
status.json | ||
FileSet | ||
TritonModel | ||
} | ||
# create a new project in my-app | ||
npm create svelte@latest my-app | ||
state Zenodo { | ||
PublishedFileSet | ||
} | ||
``` | ||
|
||
|
||
## Developing | ||
|
||
Once you've created a project and installed dependencies with `npm install` (or `pnpm install` or `yarn`), start a development server: | ||
Start a development server: | ||
|
||
```bash | ||
npm run dev | ||
ntl dev | ||
|
||
# or start the server and open the app in a new browser tab | ||
npm run dev -- --open | ||
# or run without netlify functions: | ||
npm run dev | ||
``` | ||
|
||
## Building | ||
|
||
To create a production version of your app: | ||
To create a production version of the app: | ||
|
||
```bash | ||
npm run build | ||
``` | ||
|
||
You can preview the production build with `npm run preview`. | ||
|
||
> To deploy your app, you may need to install an [adapter](https://kit.svelte.dev/docs/adapters) for your target environment. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
export default async (event) => { | ||
const data = await event.json(); | ||
const url = data.url; | ||
let obj = {}; | ||
try{ | ||
obj = await (await fetch(url)).json(); | ||
}catch(err){ | ||
obj = {status: "CI not started yet"}; | ||
} | ||
console.log("Got status for"); | ||
console.log(url); | ||
console.log("Answer:"); | ||
console.log(obj); | ||
const res = Response.json(obj); | ||
res.headers.set("Access-Control-Allow-Origin", "*"); | ||
res.headers.append("Access-Control-Allow-Headers", "*"); | ||
res.headers.append("Access-Control-Allow-Methods", "*"); | ||
return res; | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.