Skip to content

Instantly share code, notes, and snippets.

@jpbarto
Last active May 15, 2020 20:03
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jpbarto/94fde57ee264c82dddec905f01818bb1 to your computer and use it in GitHub Desktop.
Save jpbarto/94fde57ee264c82dddec905f01818bb1 to your computer and use it in GitHub Desktop.
Lifecycle script for SageMaker notebook startup which installs Theia-IDE
#!/bin/bash
set -e
sudo -u ec2-user -i <<'EOP'
## INSTALL THEIA IDE FROM SOURCE
EC2_HOME=/home/ec2-user
mkdir ${EC2_HOME}/theia && cd ${EC2_HOME}/theia
### begin by installing NVM, NodeJS v10, and Yarn
curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.33.5/install.sh | bash
source ${EC2_HOME}/.nvm/nvm.sh
nvm install 10
nvm use 10
npm install -g yarn
### now compile Theia-IDE from source, retrieving the configuration package.json from GitHub
export NODE_OPTIONS=--max_old_space_size=4096
curl https://gist.githubusercontent.com/jpbarto/94fde57ee264c82dddec905f01818bb1/raw/3994ba14d994d1f887bc327920eeee2802f5891b/package.json -o ${EC2_HOME}/theia/package.json
yarn &
### Configure Theia defaults
THEIA_PATH=$PATH
mkdir ${EC2_HOME}/.theia
mkdir -p ${EC2_HOME}/SageMaker/.theia
curl https://gist.githubusercontent.com/jpbarto/94fde57ee264c82dddec905f01818bb1/raw/87e015f83070dc274fa6c890c118428ccade50f6/launch.json -o ${EC2_HOME}/SageMaker/.theia/launch.json
echo '{"workbench.iconTheme": "theia-file-icons","terminal.integrated.inheritEnv": true}' > ${EC2_HOME}/.theia/settings.json
## CONFIGURE JUPYTER PROXY TO MAP TO THE THEIA IDE
JUPYTER_ENV=/home/ec2-user/anaconda3/envs/JupyterSystemEnv
source /home/ec2-user/anaconda3/bin/activate JupyterSystemEnv
cat >>${JUPYTER_ENV}/etc/jupyter/jupyter_notebook_config.py <<EOC
c.ServerProxy.servers = {
'theia': {
'command': ['yarn', '--cwd', '/home/ec2-user/theia', 'start', '/home/ec2-user/SageMaker', '--port', '{port}'],
'environment': {'PATH': '${THEIA_PATH}'},
'absolute_url': False,
'timeout': 30
}
}
EOC
pip install jupyter-server-proxy pylint autopep8
jupyter serverextension enable --py --sys-prefix jupyter_server_proxy
source /home/ec2-user/anaconda3/bin/deactivate
EOP
## RESTART THE JUPYTER SERVER
initctl restart jupyter-server --no-wait
{
"version": "0.2.0",
"configurations": [
{
"name": "Python: Current File",
"type": "python",
"request": "launch",
"program": "${file}",
"console": "internalConsole"
}
],
"configurationAttributes": {
"launch": {
"properties": {
"module": {
"type": "string",
"description": "Name of the module to be debugged.",
"default": ""
},
"program": {
"type": "string",
"description": "Absolute path to the program.",
"default": "${file}"
},
"pythonPath": {
"type": "string",
"description": "Path (fully qualified) to python executable. Defaults to the value in settings.json",
"default": "${config:python.pythonPath}"
},
"args": {
"type": "array",
"description": "Command line arguments passed to the program",
"default": [],
"items": {
"type": "string"
}
},
"stopOnEntry": {
"type": "boolean",
"description": "Automatically stop after launch.",
"default": false
},
"showReturnValue": {
"type": "boolean",
"description": "Show return value of functions when stepping.",
"default": false
},
"console": {
"enum": [
"none",
"integratedTerminal",
"externalTerminal"
],
"description": "Where to launch the debug target: internal console, integrated terminal, or external terminal.",
"default": "integratedTerminal"
},
"cwd": {
"type": "string",
"description": "Absolute path to the working directory of the program being debugged. Default is the root directory of the file (leave empty).",
"default": "${workspaceFolder}"
},
"env": {
"type": "object",
"description": "Environment variables defined as a key value pair. Property ends up being the Environment Variable and the value of the property ends up being the value of the Env Variable.",
"default": {}
},
"envFile": {
"type": "string",
"description": "Absolute path to a file containing environment variable definitions.",
"default": "${workspaceFolder}/.env"
},
"port": {
"type": "number",
"description": "Debug port (default is 0, resulting in the use of a dynamic port).",
"default": 0
},
"host": {
"type": "string",
"description": "IP address of the of the local debug server (default is localhost).",
"default": "localhost"
},
"logToFile": {
"type": "boolean",
"description": "Enable logging of debugger events to a log file.",
"default": false
},
"redirectOutput": {
"type": "boolean",
"description": "Redirect output.",
"default": true
},
"debugStdLib": {
"type": "boolean",
"description": "Debug standard library code.",
"default": false
},
"gevent": {
"type": "boolean",
"description": "Enable debugging of gevent monkey-patched code.",
"default": false
},
"django": {
"type": "boolean",
"description": "Django debugging.",
"default": false
},
"jinja": {
"enum": [
true,
false,
null
],
"description": "Jinja template debugging (e.g. Flask).",
"default": null
},
"sudo": {
"type": "boolean",
"description": "Running debug program under elevated permissions (on Unix).",
"default": false
},
"pyramid": {
"type": "boolean",
"description": "Whether debugging Pyramid applications",
"default": false
},
"subProcess": {
"type": "boolean",
"description": "Whether to enable Sub Process debugging",
"default": false
}
}
},
"attach": {
"required": [
"port"
],
"properties": {
"port": {
"type": "number",
"description": "Debug port to attach",
"default": 0
},
"host": {
"type": "string",
"description": "IP Address of the of remote server (default is localhost or use 127.0.0.1).",
"default": "localhost"
},
"pathMappings": {
"type": "array",
"label": "Path mappings.",
"items": {
"type": "object",
"label": "Path mapping",
"required": [
"localRoot",
"remoteRoot"
],
"properties": {
"localRoot": {
"type": "string",
"label": "Local source root.",
"default": "${workspaceFolder}"
},
"remoteRoot": {
"type": "string",
"label": "Remote source root.",
"default": ""
}
}
},
"default": []
},
"logToFile": {
"type": "boolean",
"description": "Enable logging of debugger events to a log file.",
"default": false
},
"redirectOutput": {
"type": "boolean",
"description": "Redirect output.",
"default": true
},
"debugStdLib": {
"type": "boolean",
"description": "Debug standard library code.",
"default": false
},
"django": {
"type": "boolean",
"description": "Django debugging.",
"default": false
},
"jinja": {
"enum": [
true,
false,
null
],
"description": "Jinja template debugging (e.g. Flask).",
"default": null
},
"subProcess": {
"type": "boolean",
"description": "Whether to enable Sub Process debugging",
"default": false
}
}
}
}
}
{
"private": true,
"theia": {
"frontend": {
"config": {
"applicationName": "Theia IDE",
"preferences": {
"files.enableTrash": false
}
}
}
},
"dependencies": {
"@theia/callhierarchy": "1.1.0",
"@theia/debug": "1.1.0",
"@theia/editor-preview": "1.1.0",
"@theia/file-search": "1.1.0",
"@theia/getting-started": "1.1.0",
"@theia/git": "1.1.0",
"@theia/json": "1.1.0",
"@theia/markers": "1.1.0",
"@theia/messages": "1.1.0",
"@theia/mini-browser": "1.1.0",
"@theia/monaco": "1.1.0",
"@theia/navigator": "1.1.0",
"@theia/outline-view": "1.1.0",
"@theia/plugin-ext-vscode": "1.1.0",
"@theia/preferences": "1.1.0",
"@theia/preview": "1.1.0",
"@theia/search-in-workspace": "1.1.0",
"@theia/terminal": "1.1.0",
"@theia/vsx-registry": "1.1.0",
"@theia/debug": "1.1.0"
},
"resolutions": {
"vscode-json-languageserver": "1.2.2",
"vscode-languageserver-protocol": "3.15.0-next.9",
"vscode-languageserver-types": "3.15.0-next.5",
"**/vscode-json-languageserver/**/vscode-languageserver": "6.0.0-next.1",
"**/**/moment": "2.24.0"
},
"devDependencies": {
"@theia/cli": "latest"
},
"scripts": {
"prepare": "yarn run clean && yarn build && yarn run download:plugins",
"clean": "theia clean",
"build": "theia build",
"start": "theia start --plugins=local-dir:plugins",
"download:plugins": "theia download:plugins",
"postinstall": "download-debug-adapters"
},
"theiaPluginsDir": "plugins",
"theiaPlugins": {
"vscode-builtin-bat": "https://github.com/theia-ide/vscode-builtin-extensions/releases/download/v1.39.1-prel/bat-1.39.1-prel.vsix",
"vscode-builtin-clojure": "https://github.com/theia-ide/vscode-builtin-extensions/releases/download/v1.39.1-prel/clojure-1.39.1-prel.vsix",
"vscode-builtin-coffeescript": "https://github.com/theia-ide/vscode-builtin-extensions/releases/download/v1.39.1-prel/coffeescript-1.39.1-prel.vsix",
"vscode-builtin-configuration-editing": "https://github.com/theia-ide/vscode-builtin-extensions/releases/download/v1.39.1-prel/configuration-editing-1.39.1-prel.vsix",
"vscode-builtin-cpp": "https://github.com/theia-ide/vscode-builtin-extensions/releases/download/v1.39.1-prel/cpp-1.39.1-prel.vsix",
"vscode-builtin-css": "https://github.com/theia-ide/vscode-builtin-extensions/releases/download/v1.39.1-prel/css-1.39.1-prel.vsix",
"vscode-builtin-debug-auto-launch": "https://github.com/theia-ide/vscode-builtin-extensions/releases/download/v1.39.1-prel/debug-auto-launch-1.39.1-prel.vsix",
"vscode-builtin-docker": "https://github.com/theia-ide/vscode-builtin-extensions/releases/download/v1.39.1-prel/docker-1.39.1-prel.vsix",
"vscode-builtin-emmet": "https://github.com/theia-ide/vscode-builtin-extensions/releases/download/v1.39.1-prel/emmet-1.39.1-prel.vsix",
"vscode-builtin-go": "https://github.com/theia-ide/vscode-builtin-extensions/releases/download/v1.39.1-prel/go-1.39.1-prel.vsix",
"vscode-builtin-hlsl": "https://github.com/theia-ide/vscode-builtin-extensions/releases/download/v1.39.1-prel/hlsl-1.39.1-prel.vsix",
"vscode-builtin-html": "https://github.com/theia-ide/vscode-builtin-extensions/releases/download/v1.39.1-prel/html-1.39.1-prel.vsix",
"vscode-builtin-ini": "https://github.com/theia-ide/vscode-builtin-extensions/releases/download/v1.39.1-prel/ini-1.39.1-prel.vsix",
"vscode-builtin-jake": "https://github.com/theia-ide/vscode-builtin-extensions/releases/download/v1.39.1-prel/jake-1.39.1-prel.vsix",
"vscode-builtin-java": "https://github.com/theia-ide/vscode-builtin-extensions/releases/download/v1.39.1-prel/java-1.39.1-prel.vsix",
"vscode-builtin-javascript": "https://github.com/theia-ide/vscode-builtin-extensions/releases/download/v1.39.1-prel/javascript-1.39.1-prel.vsix",
"vscode-builtin-json": "https://github.com/theia-ide/vscode-builtin-extensions/releases/download/v1.39.1-prel/json-1.39.1-prel.vsix",
"vscode-builtin-less": "https://github.com/theia-ide/vscode-builtin-extensions/releases/download/v1.39.1-prel/less-1.39.1-prel.vsix",
"vscode-builtin-log": "https://github.com/theia-ide/vscode-builtin-extensions/releases/download/v1.39.1-prel/log-1.39.1-prel.vsix",
"vscode-builtin-make": "https://github.com/theia-ide/vscode-builtin-extensions/releases/download/v1.39.1-prel/make-1.39.1-prel.vsix",
"vscode-builtin-markdown": "https://github.com/theia-ide/vscode-builtin-extensions/releases/download/v1.39.1-prel/markdown-1.39.1-prel.vsix",
"vscode-builtin-merge-conflicts": "https://github.com/theia-ide/vscode-builtin-extensions/releases/download/v1.39.1-prel/merge-conflict-1.39.1-prel.vsix",
"vscode-builtin-npm": "https://github.com/theia-ide/vscode-builtin-extensions/releases/download/v1.39.1-prel/npm-1.39.1-prel.vsix",
"vscode-builtin-node-debug": "https://github.com/theia-ide/vscode-node-debug/releases/download/v1.35.3/node-debug-1.35.3.vsix",
"vscode-builtin-node-debug2": "https://github.com/theia-ide/vscode-node-debug2/releases/download/v1.33.0/node-debug2-1.33.0.vsix",
"vscode-builtin-pug": "https://github.com/theia-ide/vscode-builtin-extensions/releases/download/v1.39.1-prel/pug-1.39.1-prel.vsix",
"vscode-builtin-python": "https://github.com/theia-ide/vscode-builtin-extensions/releases/download/v1.39.1-prel/python-1.39.1-prel.vsix",
"vscode-builtin-r": "https://github.com/theia-ide/vscode-builtin-extensions/releases/download/v1.39.1-prel/r-1.39.1-prel.vsix",
"vscode-builtin-razor": "https://github.com/theia-ide/vscode-builtin-extensions/releases/download/v1.39.1-prel/razor-1.39.1-prel.vsix",
"vscode-builtin-scss": "https://github.com/theia-ide/vscode-builtin-extensions/releases/download/v1.39.1-prel/scss-1.39.1-prel.vsix",
"vscode-builtin-shaderlab": "https://github.com/theia-ide/vscode-builtin-extensions/releases/download/v1.39.1-prel/shaderlab-1.39.1-prel.vsix",
"vscode-builtin-shellscript": "https://github.com/theia-ide/vscode-builtin-extensions/releases/download/v1.39.1-prel/shellscript-1.39.1-prel.vsix",
"vscode-builtin-sql": "https://github.com/theia-ide/vscode-builtin-extensions/releases/download/v1.39.1-prel/sql-1.39.1-prel.vsix",
"vscode-builtin-theme-abyss": "https://github.com/theia-ide/vscode-builtin-extensions/releases/download/v1.39.1-prel/theme-abyss-1.39.1-prel.vsix",
"vscode-builtin-theme-defaults": "https://github.com/theia-ide/vscode-builtin-extensions/releases/download/v1.39.1-prel/theme-defaults-1.39.1-prel.vsix",
"vscode-builtin-theme-kimbie-dark": "https://github.com/theia-ide/vscode-builtin-extensions/releases/download/v1.39.1-prel/theme-kimbie-dark-1.39.1-prel.vsix",
"vscode-builtin-theme-monokai": "https://github.com/theia-ide/vscode-builtin-extensions/releases/download/v1.39.1-prel/theme-monokai-1.39.1-prel.vsix",
"vscode-builtin-theme-dimmed": "https://github.com/theia-ide/vscode-builtin-extensions/releases/download/v1.39.1-prel/theme-monokai-dimmed-1.39.1-prel.vsix",
"vscode-builtin-theme-quietlight": "https://github.com/theia-ide/vscode-builtin-extensions/releases/download/v1.39.1-prel/theme-quietlight-1.39.1-prel.vsix",
"vscode-builtin-theme-red": "https://github.com/theia-ide/vscode-builtin-extensions/releases/download/v1.39.1-prel/theme-red-1.39.1-prel.vsix",
"vscode-builtin-theme-solarized-dark": "https://github.com/theia-ide/vscode-builtin-extensions/releases/download/v1.39.1-prel/theme-solarized-dark-1.39.1-prel.vsix",
"vscode-builtin-theme-tomorrow-night-blue": "https://github.com/theia-ide/vscode-builtin-extensions/releases/download/v1.39.1-prel/theme-tomorrow-night-blue-1.39.1-prel.vsix",
"vscode-builtin-typescript": "https://github.com/theia-ide/vscode-builtin-extensions/releases/download/v1.39.1-prel/typescript-1.39.1-prel.vsix",
"vscode-builtin-typescript-language-features": "https://github.com/theia-ide/vscode-builtin-extensions/releases/download/v1.39.1-prel/typescript-language-features-1.39.1-prel.vsix",
"vscode-builtin-vb": "https://github.com/theia-ide/vscode-builtin-extensions/releases/download/v1.39.1-prel/vb-1.39.1-prel.vsix",
"vscode-builtin-icon-theme-seti": "https://github.com/theia-ide/vscode-builtin-extensions/releases/download/v1.39.1-prel/vscode-theme-seti-1.39.1-prel.vsix",
"vscode-builtin-xml": "https://github.com/theia-ide/vscode-builtin-extensions/releases/download/v1.39.1-prel/xml-1.39.1-prel.vsix",
"vscode-builtin-yaml": "https://github.com/theia-ide/vscode-builtin-extensions/releases/download/v1.39.1-prel/yaml-1.39.1-prel.vsix",
"vscode-editorconfig": "https://github.com/theia-ide/editorconfig-vscode/releases/download/v0.14.4/EditorConfig-0.14.4.vsix",
"vscode-python": "https://github.com/microsoft/vscode-python/releases/download/2020.1.58038/ms-python-release.vsix"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment