Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
7 changes: 6 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,12 @@ SecretNote SF 现在隐语实训平台提供云端版本,开箱即用,无需

使用上述配置的节点地址为 `127.0.0.1:8090` 和 `127.0.0.1:8092`。在代码中,节点间可通过 service 名相互访问;镜像使用 8888 作为 Notebook 服务端口,6379 作为 Ray 端口,8000 作为 SecretFlow 集群网络端口,8001 作为 SPU 端口

- 如有需要,请查看更完整的具体[示例](docs/SECRETFLOW-INTRO.md)
- 典型的本地运行的两计算节点(2PC)架构示意图如下所示。如有需要,请查看更完整的具体[示例](docs/SECRETFLOW-INTRO.md)

<p align="center">
<img src="docs/images/sf-2pc-arch.jpg" alt="sf-2pc-arch" style="width: 600px;" />
</p>


### 本地启动 SecretNote SCQL

Expand Down
2 changes: 1 addition & 1 deletion docker/secretflow-secretnote/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# This Dockerfile will build the secretflow/secretnote image for depolying a node
# for SecretNote.

ARG SECRETFLOW_VERSION="1.10.0b0"
ARG SECRETFLOW_VERSION="1.11.0b1"

# Get the repository and remove unncessary files
FROM alpine:3.14 AS source-tree
Expand Down
5 changes: 4 additions & 1 deletion docker/secretflow-secretnote/root/scripts/start.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,7 @@ if [ -z "${PORT}" ]; then
PORT=8888
fi

secretnote sf --config=/home/secretnote/.jupyter/jupyter_server_config.py --allow-root --no-browser --port $PORT
# `--_as-compute-node` is a private flag only used for SecretNote SF Docker image build
secretnote sf --_as-compute-node \
--config=/home/secretnote/.jupyter/jupyter_server_config.py \
--allow-root --no-browser --port $PORT
4 changes: 2 additions & 2 deletions docker/secretnote-sf-sim/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
services:
alice:
image: secretflow/secretnote:1.10.0b0
image: secretflow/secretnote:1.11.0b1
pull_policy: if_not_present
platform: linux/amd64
environment:
Expand All @@ -11,7 +11,7 @@ services:
- ./alice:/home/secretnote/workspace

bob:
image: secretflow/secretnote:1.10.0b0
image: secretflow/secretnote:1.11.0b1
pull_policy: if_not_present
platform: linux/amd64
environment:
Expand Down
Binary file added docs/images/sf-2pc-arch.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"ci:check:javascript": "nx run-many -t format:prettier -t lint:eslint -t typecheck:tsc",
"ci:check:python": "nx run-many -t format:black -t test:pytest -t typecheck:pyright",
"ci:build": "nx run-many -t build:component -t build:site && nx run-many -t build:py:ci",
"docker:build": "docker buildx build --build-arg SECRETFLOW_VERSION=1.10.0b0 --platform linux/arm64 -t secretflow/secretnote:1.10.0b0 -f ./docker/secretflow-secretnote/Dockerfile .",
"docker:build": "docker buildx build --build-arg SECRETFLOW_VERSION=1.11.0b1 --platform linux/arm64 -t secretflow/secretnote:1.11.0b1 -f ./docker/secretflow-secretnote/Dockerfile .",
"docker:up": "docker-compose -f ./docker/secretnote-sf-sim/docker-compose.yml up"
},
"devDependencies": {
Expand Down
2 changes: 1 addition & 1 deletion packages/secretnote-sf/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@alipay/secretnote-sf",
"version": "0.0.51",
"version": "0.0.52",
"license": "Apache-2.0",
"author": "[email protected]",
"repository": "https://github.com/secretflow/secretnote/tree/main/packages/secretnote",
Expand Down
10 changes: 9 additions & 1 deletion packages/secretnote-sf/src/modules/preview/index.less
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
.secretnote-split-panel-right {
.secretnote-preview-split-panel-right {
.libro-view-content-left {
padding-right: 0 !important;
}

> .mana-view-container {
> .libro-view {
> .libro-view-top {
display: none;
}
}
}
}
4 changes: 2 additions & 2 deletions packages/secretnote-sf/src/modules/preview/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ const PreviewSecreteNoteLayout: React.FC = () => {
<SplitPanel id="split-panel" direction="left-to-right">
<SplitPanel.Pane
id="split-panel-left"
className="secretnote-split-panel-left"
className="secretnote-preview-split-panel-left"
// hide the left sidebar when preview
defaultSize={0}
minSize={0}
Expand All @@ -36,7 +36,7 @@ const PreviewSecreteNoteLayout: React.FC = () => {
minSize={400}
flex={1}
flexGrow={1}
className="secretnote-split-panel-right"
className="secretnote-preview-split-panel-right"
>
<Slot name={LayoutArea.main} />
</SplitPanel.Pane>
Expand Down
9 changes: 0 additions & 9 deletions packages/secretnote-sf/src/pages/sf-preview/index.less

This file was deleted.

1 change: 0 additions & 1 deletion packages/secretnote-sf/src/pages/sf-preview/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import { useRunOnce } from '@/utils/hook';

import '@/lang';
import '../../override.less';
import './index.less';

export interface ISecretNotePreviewProps {
fileURL?: string; // file URL of the notebook to preview
Expand Down
2 changes: 1 addition & 1 deletion pyprojects/secretnote/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "secretnote",
"private": true,
"version": "0.0.51",
"version": "0.0.52",
"type": "module",
"scripts": {
"dev:sf": "cd .. && NODE_ENV=development python -m secretnote sf --config=./secretnote/secretnote/sf/.jupyter/config_dev.py --no-browser",
Expand Down
2 changes: 1 addition & 1 deletion pyprojects/secretnote/secretnote/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "0.0.51"
__version__ = "0.0.52"
8 changes: 6 additions & 2 deletions pyprojects/secretnote/secretnote/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ def main():
parser.add_argument(
"_positionals",
nargs=argparse.ZERO_OR_MORE,
help=f"<mode>? <work_dir>?. <mode> in {MODE_CHOICES} (default: sf). <work_dir> (default: .).",
help=f"<mode>? <work_dir>? [<mode> in {MODE_CHOICES} (default: sf); <work_dir> (default: .)]",
)
# [DEPRECATED] legacy --mode support
_deprecationWarning = "[DEPRECATED] `--mode`. Use positional `mode` instead."
Expand All @@ -17,6 +17,8 @@ def main():
required=False,
help=_deprecationWarning,
)
# [PRIVATE] whether it's running as a compute node inside the Docker image
parser.add_argument("--_as-compute-node", action=argparse.BooleanOptionalAction)
args, rest_args = parser.parse_known_args()

# normalize positional arguments
Expand All @@ -38,7 +40,9 @@ def main():

SecretNoteApp().launch([work_dir, *rest_args])
else:
from .sf.server.app import SecretNoteApp
from .sf.server.app import SecretNoteApp, set_as_compute_node

set_as_compute_node(args._as_compute_node)

SecretNoteApp().launch([work_dir, *rest_args])

Expand Down
11 changes: 9 additions & 2 deletions pyprojects/secretnote/secretnote/sf/server/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,19 @@
import os
from jupyter_server.extension.application import ExtensionApp, ExtensionAppJinjaMixin
from .services.nodes_handlers import nodes_handlers
from .services.pages_handlers import pages_handlers
from .services.pages_handlers import pages_handlers, compute_node_pages_handlers
from .services.misc_handlers import misc_handlers
from .services.contents_handlers import contents_handlers

__dirname__ = os.path.dirname(__file__)

_AS_COMPUTE_NODE = False


def set_as_compute_node(value: bool):
global _AS_COMPUTE_NODE
_AS_COMPUTE_NODE = value


class SecretNoteApp(ExtensionAppJinjaMixin, ExtensionApp):
"""The SecretNote application acted as an ExtensionApp of Jupyter Server."""
Expand Down Expand Up @@ -39,7 +46,7 @@ def initialize_handlers(self):
*misc_handlers,
*contents_handlers,
*nodes_handlers,
*pages_handlers,
*(compute_node_pages_handlers if _AS_COMPUTE_NODE else pages_handlers),
]
self.handlers.extend(handlers)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,33 @@ async def get(self, path: str = "/"):
self.write(self.render_template("index.html"))


class ThisIsComputeNodeHintPageHandler(
ExtensionHandlerMixin,
ExtensionHandlerJinjaMixin,
FileFindHandler,
):
@web.authenticated
async def get(self, *_):
"""This handler is only activated when `--_as-compute-node` flag is set,
so as to hint the user is visiting the wrong SecretNote page holding
by the compute node instead of the SecretNote installed locally.
"""
self.clear()
self.write(self.render_template("this-is-compute-node.html"))


pages_handlers: List[Tuple[str, Type[JupyterHandler], Dict]] = [
(
"/secretnote/(.*)",
SinglePageApplicationHandler,
{"path": single_page_static_path},
),
]

compute_node_pages_handlers: List[Tuple[str, Type[JupyterHandler], Dict]] = [
(
"/secretnote/(.*)",
ThisIsComputeNodeHintPageHandler,
{},
),
]
5 changes: 5 additions & 0 deletions scripts/clean.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,11 @@ const candidates = [
// Python projects
'./pyprojects/secretnote/.ipynb_checkpoints',
...distAndDep('./pyprojects/secretnote'),
'./pyprojects/secretnote/secretnote/__pycache__',
'./pyprojects/secretnote/secretnote/sf/www',
'./pyprojects/secretnote/secretnote/scql/www',
'./pyprojects/secretnote/secretnote/sf/__pycache__',
'./pyprojects/secretnote/secretnote/scql/__pycache__',
].map((v) => path.join(workDir, v));

candidates.forEach((dir) => {
Expand Down
8 changes: 8 additions & 0 deletions scripts/post-build-site.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,11 @@ fs.rmSync(dst, {
fs.cpSync(src, dst, {
recursive: true,
});
// copy the hint page for --_as-compute-node
if (siteName === 'sf') {
const filename = 'this-is-compute-node.html';
fs.copyFileSync(
path.join(__dirname, `./${filename}`),
path.join(dst, `./${filename}`),
);
}
53 changes: 53 additions & 0 deletions scripts/this-is-compute-node.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>这是 SecretNote SF 的计算节点</title>
<style>
body {
font-family: Arial, sans-serif;
display: flex;
justify-content: center;
align-items: center;
height: 100vh;
margin: 0;
background-color: #f0f0f0;
color: #333;
}
div {
background-color: #fff;
margin: -20px 20px 0 20px;
padding: 20px;
border-radius: 10px;
box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
}
a {
color: #0079d3;
text-decoration: none;
}
</style>
</head>
<body>
<div>
<h1>👉 这是 SecretNote SF 的计算节点</h1>
<p>
您正在直接访问计算节点上的 Jupyter
Server,这不符合预期。计算节点只用来承载计算任务,不用来编写程序。
</p>
<p>
请使用本地的 SecretNote SF(通常在
<a href="http://localhost:8888" target="_blank" rel="noreferrer noopener"
>http://localhost:8888</a
>
)在右上角添加计算节点(见
<a
href="https://github.com/secretflow/secretnote?tab=readme-ov-file#%E6%9C%AC%E5%9C%B0%E5%90%AF%E5%8A%A8-secretnote-sf"
target="_blank"
rel="noreferrer noopener"
>文档</a
>),随后即可正常使用相关功能。
</p>
</div>
</body>
</html>