merged with main
This commit is contained in:
commit
8b8e2e7343
14 changed files with 88874 additions and 81 deletions
|
|
@ -10,13 +10,20 @@ primary_region = 'sea'
|
|||
|
||||
[env]
|
||||
PORT = '8080'
|
||||
FLY_ORG="personal"
|
||||
COMMON_BUCKET="snakeapi-deployment-test-bucket"
|
||||
AWS_ACCESS_KEY_ID="tid__NSmOVaGknqitaCySppZjqVTgJSdDFnFbWcQllkC_juHwkbQZO"
|
||||
AWS_SECRET_ACCESS_KEY="tsec_6Bz1aMbfYQftuq5WfIVEDZkHwskU4MMjVywdtxSP6uxetEBvkSC2VHI9HfTeDgHr4D6kiz"
|
||||
AWS_ENDPOINT_URL_S3="https://fly.storage.tigris.dev"
|
||||
AWS_REGION="auto"
|
||||
FLY_API_BASE_URL = "https://api.machines.dev/v1"
|
||||
|
||||
[http_service]
|
||||
internal_port = 8080
|
||||
force_https = true
|
||||
auto_stop_machines = 'stop'
|
||||
auto_start_machines = true
|
||||
min_machines_running = 0
|
||||
min_machines_running = 1
|
||||
processes = ['app']
|
||||
|
||||
[[services]]
|
||||
|
|
|
|||
379
assignment-service/package-lock.json
generated
379
assignment-service/package-lock.json
generated
|
|
@ -9,7 +9,8 @@
|
|||
"version": "1.0.0",
|
||||
"license": "ISC",
|
||||
"dependencies": {
|
||||
"axios": "^1.8.4",
|
||||
"aws-sdk": "^2.1692.0",
|
||||
"axios": "^1.9.0",
|
||||
"bcrypt": "^5.1.1",
|
||||
"cors": "^2.8.5",
|
||||
"dotenv": "^16.5.0",
|
||||
|
|
@ -91,15 +92,6 @@
|
|||
}
|
||||
}
|
||||
},
|
||||
"node_modules/ansi-regex": {
|
||||
"version": "5.0.1",
|
||||
"resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-5.0.1.tgz",
|
||||
"integrity": "sha512-quJQXlTSUGL2LH9SUXo8VwsY4soanhgo6LNSm84E1LBcE8s3O0wpdiRzyR9z/ZZJMlMWv37qOOb9pdJlMUEKFQ==",
|
||||
"license": "MIT",
|
||||
"engines": {
|
||||
"node": ">=8"
|
||||
}
|
||||
},
|
||||
"node_modules/anymatch": {
|
||||
"version": "3.1.3",
|
||||
"resolved": "https://registry.npmjs.org/anymatch/-/anymatch-3.1.3.tgz",
|
||||
|
|
@ -139,16 +131,52 @@
|
|||
"node": ">=10"
|
||||
}
|
||||
},
|
||||
"node_modules/are-we-there-yet/node_modules/readable-stream": {
|
||||
"version": "3.6.2",
|
||||
"resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-3.6.2.tgz",
|
||||
"integrity": "sha512-9u/sniCrY3D5WdsERHzHE4G2YCXqoG5FTHUiCC4SIbr6XcLZBY05ya9EKjYek9O5xOAwjGq+1JdGBAS7Q9ScoA==",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"inherits": "^2.0.3",
|
||||
"string_decoder": "^1.1.1",
|
||||
"util-deprecate": "^1.0.1"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">= 6"
|
||||
}
|
||||
},
|
||||
"node_modules/asynckit": {
|
||||
"version": "0.4.0",
|
||||
"resolved": "https://registry.npmjs.org/asynckit/-/asynckit-0.4.0.tgz",
|
||||
"integrity": "sha512-Oei9OH4tRh0YqU3GxhX79dM/mwVgvbZJaSNaRk+bshkj0S5cfHcgYakreBjrHwatXKbz+IoIdYLxrKim2MjW0Q==",
|
||||
"license": "MIT"
|
||||
},
|
||||
"node_modules/aws-sdk": {
|
||||
"version": "2.1692.0",
|
||||
"resolved": "https://registry.npmjs.org/aws-sdk/-/aws-sdk-2.1692.0.tgz",
|
||||
"integrity": "sha512-x511uiJ/57FIsbgUe5csJ13k3uzu25uWQE+XqfBis/sB0SFoiElJWXRkgEAUh0U6n40eT3ay5Ue4oPkRMu1LYw==",
|
||||
"hasInstallScript": true,
|
||||
"license": "Apache-2.0",
|
||||
"dependencies": {
|
||||
"buffer": "4.9.2",
|
||||
"events": "1.1.1",
|
||||
"ieee754": "1.1.13",
|
||||
"jmespath": "0.16.0",
|
||||
"querystring": "0.2.0",
|
||||
"sax": "1.2.1",
|
||||
"url": "0.10.3",
|
||||
"util": "^0.12.4",
|
||||
"uuid": "8.0.0",
|
||||
"xml2js": "0.6.2"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">= 10.0.0"
|
||||
}
|
||||
},
|
||||
"node_modules/axios": {
|
||||
"version": "1.8.4",
|
||||
"resolved": "https://registry.npmjs.org/axios/-/axios-1.8.4.tgz",
|
||||
"integrity": "sha512-eBSYY4Y68NNlHbHBMdeDmKNtDgXWhQsJcGqzO3iLUM0GraQFSS9cVgPX5I9b3lbdFKyYoAEGAZF1DwhTaljNAw==",
|
||||
"version": "1.9.0",
|
||||
"resolved": "https://registry.npmjs.org/axios/-/axios-1.9.0.tgz",
|
||||
"integrity": "sha512-re4CqKTJaURpzbLHtIi6XpDv20/CnpXOtjRY5/CU32L8gU8ek9UIivcfvSWvmKEngmVbrUtPpdDwWDWL7DNHvg==",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"follow-redirects": "^1.15.6",
|
||||
|
|
@ -162,6 +190,26 @@
|
|||
"integrity": "sha512-3oSeUO0TMV67hN1AmbXsK4yaqU7tjiHlbxRDZOpH0KW9+CeX4bRAaX0Anxt0tx2MrpRpWwQaPwIlISEJhYU5Pw==",
|
||||
"license": "MIT"
|
||||
},
|
||||
"node_modules/base64-js": {
|
||||
"version": "1.5.1",
|
||||
"resolved": "https://registry.npmjs.org/base64-js/-/base64-js-1.5.1.tgz",
|
||||
"integrity": "sha512-AKpaYlHn8t4SVbOHCy+b5+KKgvR4vrsD8vbvrbiQJps7fKDTkjkDry6ji0rUJjC0kzbNePLwzxq8iypo41qeWA==",
|
||||
"funding": [
|
||||
{
|
||||
"type": "github",
|
||||
"url": "https://github.com/sponsors/feross"
|
||||
},
|
||||
{
|
||||
"type": "patreon",
|
||||
"url": "https://www.patreon.com/feross"
|
||||
},
|
||||
{
|
||||
"type": "consulting",
|
||||
"url": "https://feross.org/support"
|
||||
}
|
||||
],
|
||||
"license": "MIT"
|
||||
},
|
||||
"node_modules/bcrypt": {
|
||||
"version": "5.1.1",
|
||||
"resolved": "https://registry.npmjs.org/bcrypt/-/bcrypt-5.1.1.tgz",
|
||||
|
|
@ -247,6 +295,17 @@
|
|||
"node": ">=8"
|
||||
}
|
||||
},
|
||||
"node_modules/buffer": {
|
||||
"version": "4.9.2",
|
||||
"resolved": "https://registry.npmjs.org/buffer/-/buffer-4.9.2.tgz",
|
||||
"integrity": "sha512-xq+q3SRMOxGivLhBNaUdC64hDTQwejJ+H0T/NB1XMtTVEwNTrfFF3gAxiyW0Bu/xWEGhjVKgUcMhCrUy2+uCWg==",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"base64-js": "^1.0.2",
|
||||
"ieee754": "^1.1.4",
|
||||
"isarray": "^1.0.0"
|
||||
}
|
||||
},
|
||||
"node_modules/buffer-from": {
|
||||
"version": "1.1.2",
|
||||
"resolved": "https://registry.npmjs.org/buffer-from/-/buffer-from-1.1.2.tgz",
|
||||
|
|
@ -377,36 +436,6 @@
|
|||
"typedarray": "^0.0.6"
|
||||
}
|
||||
},
|
||||
"node_modules/concat-stream/node_modules/readable-stream": {
|
||||
"version": "2.3.8",
|
||||
"resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-2.3.8.tgz",
|
||||
"integrity": "sha512-8p0AUk4XODgIewSi0l8Epjs+EVnWiK7NoDIEGU0HhE7+ZyY8D1IMY7odu5lRrFXGg71L15KG8QrPmum45RTtdA==",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"core-util-is": "~1.0.0",
|
||||
"inherits": "~2.0.3",
|
||||
"isarray": "~1.0.0",
|
||||
"process-nextick-args": "~2.0.0",
|
||||
"safe-buffer": "~5.1.1",
|
||||
"string_decoder": "~1.1.1",
|
||||
"util-deprecate": "~1.0.1"
|
||||
}
|
||||
},
|
||||
"node_modules/concat-stream/node_modules/safe-buffer": {
|
||||
"version": "5.1.2",
|
||||
"resolved": "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.1.2.tgz",
|
||||
"integrity": "sha512-Gd2UZBJDkXlY7GbJxfsE8/nvKkUEU1G38c1siN6QP6a9PT9MmHB8GnpscSmMJSoF8LOIrt8ud/wPtojys4G6+g==",
|
||||
"license": "MIT"
|
||||
},
|
||||
"node_modules/concat-stream/node_modules/string_decoder": {
|
||||
"version": "1.1.1",
|
||||
"resolved": "https://registry.npmjs.org/string_decoder/-/string_decoder-1.1.1.tgz",
|
||||
"integrity": "sha512-n/ShnvDi6FHbbVfviro+WojiFzv+s8MPMHBczVePfUpDJLwoLT0ht1l4YwBCbi8pJAveEEdnkHyPyTP/mzRfwg==",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"safe-buffer": "~5.1.0"
|
||||
}
|
||||
},
|
||||
"node_modules/console-control-strings": {
|
||||
"version": "1.1.0",
|
||||
"resolved": "https://registry.npmjs.org/console-control-strings/-/console-control-strings-1.1.0.tgz",
|
||||
|
|
@ -592,12 +621,6 @@
|
|||
"integrity": "sha512-WMwm9LhRUo+WUaRN+vRuETqG89IgZphVSNkdFgeb6sS/E4OrDIN7t48CAewSHXc6C8lefD8KKfr5vY61brQlow==",
|
||||
"license": "MIT"
|
||||
},
|
||||
"node_modules/emoji-regex": {
|
||||
"version": "8.0.0",
|
||||
"resolved": "https://registry.npmjs.org/emoji-regex/-/emoji-regex-8.0.0.tgz",
|
||||
"integrity": "sha512-MSjYzcWNOA0ewAHpz0MxpYFvwg6yjy1NG3xteoqz644VCo/RPgnr1/GGt+ic3iJTzQ8Eu3TdM14SawnVUmGE6A==",
|
||||
"license": "MIT"
|
||||
},
|
||||
"node_modules/encodeurl": {
|
||||
"version": "2.0.0",
|
||||
"resolved": "https://registry.npmjs.org/encodeurl/-/encodeurl-2.0.0.tgz",
|
||||
|
|
@ -667,6 +690,15 @@
|
|||
"node": ">= 0.6"
|
||||
}
|
||||
},
|
||||
"node_modules/events": {
|
||||
"version": "1.1.1",
|
||||
"resolved": "https://registry.npmjs.org/events/-/events-1.1.1.tgz",
|
||||
"integrity": "sha512-kEcvvCBByWXGnZy6JUlgAp2gBIUjfCAV6P6TgT1/aaQKcmuAEC4OZTV1I4EWQLz2gxZw76atuVyvHhTxvi0Flw==",
|
||||
"license": "MIT",
|
||||
"engines": {
|
||||
"node": ">=0.4.x"
|
||||
}
|
||||
},
|
||||
"node_modules/express": {
|
||||
"version": "5.1.0",
|
||||
"resolved": "https://registry.npmjs.org/express/-/express-5.1.0.tgz",
|
||||
|
|
@ -901,6 +933,20 @@
|
|||
"integrity": "sha512-OO0pH2lK6a0hZnAdau5ItzHPI6pUlvI7jMVnxUQRtw4owF2wk8lOSabtGDCTP4Ggrg2MbGnWO9X8K1t4+fGMDw==",
|
||||
"license": "ISC"
|
||||
},
|
||||
"node_modules/fsevents": {
|
||||
"version": "2.3.3",
|
||||
"resolved": "https://registry.npmjs.org/fsevents/-/fsevents-2.3.3.tgz",
|
||||
"integrity": "sha512-5xoDfX+fL7faATnagmWPpbFtwh/R77WmMMqqHGS65C3vvB0YHrgF+B1YmZ3441tMj5n63k0212XNoJwzlhffQw==",
|
||||
"hasInstallScript": true,
|
||||
"license": "MIT",
|
||||
"optional": true,
|
||||
"os": [
|
||||
"darwin"
|
||||
],
|
||||
"engines": {
|
||||
"node": "^8.16.0 || ^10.6.0 || >=11.0.0"
|
||||
}
|
||||
},
|
||||
"node_modules/function-bind": {
|
||||
"version": "1.1.2",
|
||||
"resolved": "https://registry.npmjs.org/function-bind/-/function-bind-1.1.2.tgz",
|
||||
|
|
@ -1125,6 +1171,12 @@
|
|||
"node": ">=0.10.0"
|
||||
}
|
||||
},
|
||||
"node_modules/ieee754": {
|
||||
"version": "1.1.13",
|
||||
"resolved": "https://registry.npmjs.org/ieee754/-/ieee754-1.1.13.tgz",
|
||||
"integrity": "sha512-4vf7I2LYV/HaWerSo3XmlMkp5eZ83i+/CDluXi/IGTs/O1sejBNhTtnxzmRZfvOUqj7lZjqHkeTvpgSFDlWZTg==",
|
||||
"license": "BSD-3-Clause"
|
||||
},
|
||||
"node_modules/ignore-by-default": {
|
||||
"version": "1.0.1",
|
||||
"resolved": "https://registry.npmjs.org/ignore-by-default/-/ignore-by-default-1.0.1.tgz",
|
||||
|
|
@ -1157,6 +1209,22 @@
|
|||
"node": ">= 0.10"
|
||||
}
|
||||
},
|
||||
"node_modules/is-arguments": {
|
||||
"version": "1.2.0",
|
||||
"resolved": "https://registry.npmjs.org/is-arguments/-/is-arguments-1.2.0.tgz",
|
||||
"integrity": "sha512-7bVbi0huj/wrIAOzb8U1aszg9kdi3KN/CyU19CTI7tAoZYEZoL9yCDXpbXN+uPsuWnP02cyug1gleqq+TU+YCA==",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"call-bound": "^1.0.2",
|
||||
"has-tostringtag": "^1.0.2"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">= 0.4"
|
||||
},
|
||||
"funding": {
|
||||
"url": "https://github.com/sponsors/ljharb"
|
||||
}
|
||||
},
|
||||
"node_modules/is-binary-path": {
|
||||
"version": "2.1.0",
|
||||
"resolved": "https://registry.npmjs.org/is-binary-path/-/is-binary-path-2.1.0.tgz",
|
||||
|
|
@ -1178,13 +1246,22 @@
|
|||
"node": ">=0.10.0"
|
||||
}
|
||||
},
|
||||
"node_modules/is-fullwidth-code-point": {
|
||||
"version": "3.0.0",
|
||||
"resolved": "https://registry.npmjs.org/is-fullwidth-code-point/-/is-fullwidth-code-point-3.0.0.tgz",
|
||||
"integrity": "sha512-zymm5+u+sCsSWyD9qNaejV3DFvhCKclKdizYaJUuHA83RLjb7nSuGnddCHGv0hk+KY7BMAlsWeK4Ueg6EV6XQg==",
|
||||
"node_modules/is-generator-function": {
|
||||
"version": "1.1.0",
|
||||
"resolved": "https://registry.npmjs.org/is-generator-function/-/is-generator-function-1.1.0.tgz",
|
||||
"integrity": "sha512-nPUB5km40q9e8UfN/Zc24eLlzdSf9OfKByBw9CIdw4H1giPMeA0OIJvbchsCu4npfI2QcMVBsGEBHKZ7wLTWmQ==",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"call-bound": "^1.0.3",
|
||||
"get-proto": "^1.0.0",
|
||||
"has-tostringtag": "^1.0.2",
|
||||
"safe-regex-test": "^1.1.0"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=8"
|
||||
"node": ">= 0.4"
|
||||
},
|
||||
"funding": {
|
||||
"url": "https://github.com/sponsors/ljharb"
|
||||
}
|
||||
},
|
||||
"node_modules/is-glob": {
|
||||
|
|
@ -1214,6 +1291,39 @@
|
|||
"integrity": "sha512-hvpoI6korhJMnej285dSg6nu1+e6uxs7zG3BYAm5byqDsgJNWwxzM6z6iZiAgQR4TJ30JmBTOwqZUw3WlyH3AQ==",
|
||||
"license": "MIT"
|
||||
},
|
||||
"node_modules/is-regex": {
|
||||
"version": "1.2.1",
|
||||
"resolved": "https://registry.npmjs.org/is-regex/-/is-regex-1.2.1.tgz",
|
||||
"integrity": "sha512-MjYsKHO5O7mCsmRGxWcLWheFqN9DJ/2TmngvjKXihe6efViPqc274+Fx/4fYj/r03+ESvBdTXK0V6tA3rgez1g==",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"call-bound": "^1.0.2",
|
||||
"gopd": "^1.2.0",
|
||||
"has-tostringtag": "^1.0.2",
|
||||
"hasown": "^2.0.2"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">= 0.4"
|
||||
},
|
||||
"funding": {
|
||||
"url": "https://github.com/sponsors/ljharb"
|
||||
}
|
||||
},
|
||||
"node_modules/is-typed-array": {
|
||||
"version": "1.1.15",
|
||||
"resolved": "https://registry.npmjs.org/is-typed-array/-/is-typed-array-1.1.15.tgz",
|
||||
"integrity": "sha512-p3EcsicXjit7SaskXHs1hA91QxgTw46Fv6EFKKGS5DRFLD8yKnohjF3hxoju94b/OcMZoQukzpPpBE9uLVKzgQ==",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"which-typed-array": "^1.1.16"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">= 0.4"
|
||||
},
|
||||
"funding": {
|
||||
"url": "https://github.com/sponsors/ljharb"
|
||||
}
|
||||
},
|
||||
"node_modules/isarray": {
|
||||
"version": "1.0.0",
|
||||
"resolved": "https://registry.npmjs.org/isarray/-/isarray-1.0.0.tgz",
|
||||
|
|
@ -1227,28 +1337,31 @@
|
|||
"dev": true,
|
||||
"license": "ISC"
|
||||
},
|
||||
"node_modules/jmespath": {
|
||||
"version": "0.16.0",
|
||||
"resolved": "https://registry.npmjs.org/jmespath/-/jmespath-0.16.0.tgz",
|
||||
"integrity": "sha512-9FzQjJ7MATs1tSpnco1K6ayiYE3figslrXA72G2HQ/n76RzvYlofyi5QM+iX4YRs/pu3yzxlVQSST23+dMDknw==",
|
||||
"license": "Apache-2.0",
|
||||
"engines": {
|
||||
"node": ">= 0.6.0"
|
||||
}
|
||||
},
|
||||
"node_modules/make-dir": {
|
||||
"version": "3.1.0",
|
||||
"resolved": "https://registry.npmjs.org/make-dir/-/make-dir-3.1.0.tgz",
|
||||
"integrity": "sha512-g3FeP20LNwhALb/6Cz6Dd4F2ngze0jz7tbzrD2wAV+o9FeNHe4rL+yK2md0J/fiSf1sa1ADhXqi5+oVwOM/eGw==",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"semver": "^6.0.0"
|
||||
"call-bound": "^1.0.2",
|
||||
"gopd": "^1.2.0",
|
||||
"has-tostringtag": "^1.0.2",
|
||||
"hasown": "^2.0.2"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=8"
|
||||
"node": ">= 0.4"
|
||||
},
|
||||
"funding": {
|
||||
"url": "https://github.com/sponsors/sindresorhus"
|
||||
}
|
||||
},
|
||||
"node_modules/make-dir/node_modules/semver": {
|
||||
"version": "6.3.1",
|
||||
"resolved": "https://registry.npmjs.org/semver/-/semver-6.3.1.tgz",
|
||||
"integrity": "sha512-BR7VvDCVHO+q2xBEWskxS6DJE1qRnb7DxzUrogb71CWoSficBxYsiAGd+Kl0mmq/MprG9yArRkyrQxTO6XjMzA==",
|
||||
"license": "ISC",
|
||||
"bin": {
|
||||
"semver": "bin/semver.js"
|
||||
"url": "https://github.com/sponsors/ljharb"
|
||||
}
|
||||
},
|
||||
"node_modules/math-intrinsics": {
|
||||
|
|
@ -1727,6 +1840,12 @@
|
|||
"integrity": "sha512-77DZwxQmxKnu3aR542U+X8FypNzbfJ+C5XQDk3uWjWxn6151aIMGthWYRXTqT1E5oJvg+ljaa2OJi+VfvCOQ8w==",
|
||||
"license": "MIT"
|
||||
},
|
||||
"node_modules/punycode": {
|
||||
"version": "1.3.2",
|
||||
"resolved": "https://registry.npmjs.org/punycode/-/punycode-1.3.2.tgz",
|
||||
"integrity": "sha512-RofWgt/7fL5wP1Y7fxE7/EmTLzQVnB0ycyibJ0OOHIlJqTNzglYFxVwETOcIoJqJmpDXJ9xImDv+Fq34F/d4Dw==",
|
||||
"license": "MIT"
|
||||
},
|
||||
"node_modules/qs": {
|
||||
"version": "6.14.0",
|
||||
"resolved": "https://registry.npmjs.org/qs/-/qs-6.14.0.tgz",
|
||||
|
|
@ -1742,6 +1861,15 @@
|
|||
"url": "https://github.com/sponsors/ljharb"
|
||||
}
|
||||
},
|
||||
"node_modules/querystring": {
|
||||
"version": "0.2.0",
|
||||
"resolved": "https://registry.npmjs.org/querystring/-/querystring-0.2.0.tgz",
|
||||
"integrity": "sha512-X/xY82scca2tau62i9mDyU9K+I+djTMUsvwf7xnUX5GLvVzgJybOJf4Y6o9Zx3oJK/LSXg5tTZBjwzqVPaPO2g==",
|
||||
"deprecated": "The querystring API is considered Legacy. new code should use the URLSearchParams API instead.",
|
||||
"engines": {
|
||||
"node": ">=0.4.x"
|
||||
}
|
||||
},
|
||||
"node_modules/random-bytes": {
|
||||
"version": "1.0.0",
|
||||
"resolved": "https://registry.npmjs.org/random-bytes/-/random-bytes-1.0.0.tgz",
|
||||
|
|
@ -1776,17 +1904,33 @@
|
|||
}
|
||||
},
|
||||
"node_modules/readable-stream": {
|
||||
"version": "3.6.2",
|
||||
"resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-3.6.2.tgz",
|
||||
"integrity": "sha512-9u/sniCrY3D5WdsERHzHE4G2YCXqoG5FTHUiCC4SIbr6XcLZBY05ya9EKjYek9O5xOAwjGq+1JdGBAS7Q9ScoA==",
|
||||
"version": "2.3.8",
|
||||
"resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-2.3.8.tgz",
|
||||
"integrity": "sha512-8p0AUk4XODgIewSi0l8Epjs+EVnWiK7NoDIEGU0HhE7+ZyY8D1IMY7odu5lRrFXGg71L15KG8QrPmum45RTtdA==",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"inherits": "^2.0.3",
|
||||
"string_decoder": "^1.1.1",
|
||||
"util-deprecate": "^1.0.1"
|
||||
"core-util-is": "~1.0.0",
|
||||
"inherits": "~2.0.3",
|
||||
"isarray": "~1.0.0",
|
||||
"process-nextick-args": "~2.0.0",
|
||||
"safe-buffer": "~5.1.1",
|
||||
"string_decoder": "~1.1.1",
|
||||
"util-deprecate": "~1.0.1"
|
||||
}
|
||||
},
|
||||
"engines": {
|
||||
"node": ">= 6"
|
||||
"node_modules/readable-stream/node_modules/safe-buffer": {
|
||||
"version": "5.1.2",
|
||||
"resolved": "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.1.2.tgz",
|
||||
"integrity": "sha512-Gd2UZBJDkXlY7GbJxfsE8/nvKkUEU1G38c1siN6QP6a9PT9MmHB8GnpscSmMJSoF8LOIrt8ud/wPtojys4G6+g==",
|
||||
"license": "MIT"
|
||||
},
|
||||
"node_modules/readable-stream/node_modules/string_decoder": {
|
||||
"version": "1.1.1",
|
||||
"resolved": "https://registry.npmjs.org/string_decoder/-/string_decoder-1.1.1.tgz",
|
||||
"integrity": "sha512-n/ShnvDi6FHbbVfviro+WojiFzv+s8MPMHBczVePfUpDJLwoLT0ht1l4YwBCbi8pJAveEEdnkHyPyTP/mzRfwg==",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"safe-buffer": "~5.1.0"
|
||||
}
|
||||
},
|
||||
"node_modules/readdirp": {
|
||||
|
|
@ -1870,12 +2014,35 @@
|
|||
],
|
||||
"license": "MIT"
|
||||
},
|
||||
"node_modules/safe-regex-test": {
|
||||
"version": "1.1.0",
|
||||
"resolved": "https://registry.npmjs.org/safe-regex-test/-/safe-regex-test-1.1.0.tgz",
|
||||
"integrity": "sha512-x/+Cz4YrimQxQccJf5mKEbIa1NzeCRNI5Ecl/ekmlYaampdNLPalVyIcCZNNH3MvmqBugV5TMYZXv0ljslUlaw==",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"call-bound": "^1.0.2",
|
||||
"es-errors": "^1.3.0",
|
||||
"is-regex": "^1.2.1"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">= 0.4"
|
||||
},
|
||||
"funding": {
|
||||
"url": "https://github.com/sponsors/ljharb"
|
||||
}
|
||||
},
|
||||
"node_modules/safer-buffer": {
|
||||
"version": "2.1.2",
|
||||
"resolved": "https://registry.npmjs.org/safer-buffer/-/safer-buffer-2.1.2.tgz",
|
||||
"integrity": "sha512-YZo3K82SD7Riyi0E1EQPojLz7kpepnSQI9IyPbHHg1XXXevb5dJI7tpyN2ADxGcQbHG7vcyRHk0cbwqcQriUtg==",
|
||||
"license": "MIT"
|
||||
},
|
||||
"node_modules/sax": {
|
||||
"version": "1.2.1",
|
||||
"resolved": "https://registry.npmjs.org/sax/-/sax-1.2.1.tgz",
|
||||
"integrity": "sha512-8I2a3LovHTOpm7NV5yOyO8IHqgVsfK4+UuySrXU8YXkSRX7k6hCV9b3HrkKCr3nMpgj+0bmocaJJWpvp1oc7ZA==",
|
||||
"license": "ISC"
|
||||
},
|
||||
"node_modules/semver": {
|
||||
"version": "7.7.1",
|
||||
"resolved": "https://registry.npmjs.org/semver/-/semver-7.7.1.tgz",
|
||||
|
|
@ -2231,6 +2398,29 @@
|
|||
"node": ">= 0.8"
|
||||
}
|
||||
},
|
||||
"node_modules/url": {
|
||||
"version": "0.10.3",
|
||||
"resolved": "https://registry.npmjs.org/url/-/url-0.10.3.tgz",
|
||||
"integrity": "sha512-hzSUW2q06EqL1gKM/a+obYHLIO6ct2hwPuviqTTOcfFVc61UbfJ2Q32+uGL/HCPxKqrdGB5QUwIe7UqlDgwsOQ==",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"punycode": "1.3.2",
|
||||
"querystring": "0.2.0"
|
||||
}
|
||||
},
|
||||
"node_modules/util": {
|
||||
"version": "0.12.5",
|
||||
"resolved": "https://registry.npmjs.org/util/-/util-0.12.5.tgz",
|
||||
"integrity": "sha512-kZf/K6hEIrWHI6XqOFUiiMa+79wE/D8Q+NCNAWclkyg3b4d2k7s0QGepNjiABc+aR3N1PAyHL7p6UcLY6LmrnA==",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"inherits": "^2.0.3",
|
||||
"is-arguments": "^1.0.4",
|
||||
"is-generator-function": "^1.0.7",
|
||||
"is-typed-array": "^1.1.3",
|
||||
"which-typed-array": "^1.1.2"
|
||||
}
|
||||
},
|
||||
"node_modules/util-deprecate": {
|
||||
"version": "1.0.2",
|
||||
"resolved": "https://registry.npmjs.org/util-deprecate/-/util-deprecate-1.0.2.tgz",
|
||||
|
|
@ -2246,6 +2436,15 @@
|
|||
"node": ">= 0.4.0"
|
||||
}
|
||||
},
|
||||
"node_modules/uuid": {
|
||||
"version": "8.0.0",
|
||||
"resolved": "https://registry.npmjs.org/uuid/-/uuid-8.0.0.tgz",
|
||||
"integrity": "sha512-jOXGuXZAWdsTH7eZLtyXMqUb9EcWMGZNbL9YcGBJl4MH4nrxHmZJhEHvyLFrkxo+28uLb/NYRcStH48fnD0Vzw==",
|
||||
"license": "MIT",
|
||||
"bin": {
|
||||
"uuid": "dist/bin/uuid"
|
||||
}
|
||||
},
|
||||
"node_modules/vary": {
|
||||
"version": "1.1.2",
|
||||
"resolved": "https://registry.npmjs.org/vary/-/vary-1.1.2.tgz",
|
||||
|
|
@ -2287,6 +2486,16 @@
|
|||
"node": ">= 8"
|
||||
}
|
||||
},
|
||||
"node_modules/which-typed-array": {
|
||||
"version": "1.1.19",
|
||||
"resolved": "https://registry.npmjs.org/which-typed-array/-/which-typed-array-1.1.19.tgz",
|
||||
"integrity": "sha512-rEvr90Bck4WZt9HHFC4DJMsjvu7x+r6bImz0/BrbWb7A2djJ8hnZMrWnHo9F8ssv0OMErasDhftrfROTyqSDrw==",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"tr46": "~0.0.3",
|
||||
"webidl-conversions": "^3.0.0"
|
||||
}
|
||||
},
|
||||
"node_modules/wide-align": {
|
||||
"version": "1.1.5",
|
||||
"resolved": "https://registry.npmjs.org/wide-align/-/wide-align-1.1.5.tgz",
|
||||
|
|
@ -2302,6 +2511,28 @@
|
|||
"integrity": "sha512-l4Sp/DRseor9wL6EvV2+TuQn63dMkPjZ/sp9XkghTEbV9KlPS1xUsZ3u7/IQO4wxtcFB4bgpQPRcR3QCvezPcQ==",
|
||||
"license": "ISC"
|
||||
},
|
||||
"node_modules/xml2js": {
|
||||
"version": "0.6.2",
|
||||
"resolved": "https://registry.npmjs.org/xml2js/-/xml2js-0.6.2.tgz",
|
||||
"integrity": "sha512-T4rieHaC1EXcES0Kxxj4JWgaUQHDk+qwHcYOCFHfiwKz7tOVPLq7Hjq9dM1WCMhylqMEfP7hMcOIChvotiZegA==",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"sax": ">=0.6.0",
|
||||
"xmlbuilder": "~11.0.0"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=4.0.0"
|
||||
}
|
||||
},
|
||||
"node_modules/xmlbuilder": {
|
||||
"version": "11.0.1",
|
||||
"resolved": "https://registry.npmjs.org/xmlbuilder/-/xmlbuilder-11.0.1.tgz",
|
||||
"integrity": "sha512-fDlsI/kFEx7gLvbecc0/ohLG50fugQp8ryHzMTuW9vSa1GJ0XYWKnhsUx7oie3G98+r56aTQIUB4kht42R3JvA==",
|
||||
"license": "MIT",
|
||||
"engines": {
|
||||
"node": ">=4.0"
|
||||
}
|
||||
},
|
||||
"node_modules/xtend": {
|
||||
"version": "4.0.2",
|
||||
"resolved": "https://registry.npmjs.org/xtend/-/xtend-4.0.2.tgz",
|
||||
|
|
|
|||
|
|
@ -10,7 +10,8 @@
|
|||
"license": "ISC",
|
||||
"description": "",
|
||||
"dependencies": {
|
||||
"axios": "^1.8.4",
|
||||
"aws-sdk": "^2.1692.0",
|
||||
"axios": "^1.9.0",
|
||||
"bcrypt": "^5.1.1",
|
||||
"cors": "^2.8.5",
|
||||
"dotenv": "^16.5.0",
|
||||
|
|
|
|||
|
|
@ -4,14 +4,22 @@ const passport = require("passport");
|
|||
const session = require("express-session");
|
||||
|
||||
const express = require("express");
|
||||
const AWS = require("aws-sdk");
|
||||
const instructorRouter = require("./routes/InstructorRouter");
|
||||
const studentRouter = require("./routes/StudentRouter");
|
||||
|
||||
const s3 = new AWS.S3({
|
||||
endpoint: process.env.AWS_ENDPOINT_URL_S3,
|
||||
accessKeyId: process.env.AWS_ACCESS_KEY_ID,
|
||||
secretAccessKey: process.env.AWS_SECRET_ACCESS_KEY,
|
||||
region: process.env.AWS_REGION,
|
||||
s3ForcePathStyle: true
|
||||
});
|
||||
const BUCKET = process.env.COMMON_BUCKET;
|
||||
|
||||
const app = express();
|
||||
app.use(express.json());
|
||||
app.use(express.urlencoded({ extended: true }));
|
||||
|
||||
// Allow all origins (not recommended for production)
|
||||
app.use(cors());
|
||||
|
||||
// app.use(
|
||||
|
|
@ -34,10 +42,33 @@ app.use(cors());
|
|||
// methods: ["GET", "POST"],
|
||||
// credentials: true,
|
||||
// })
|
||||
// )
|
||||
// );
|
||||
|
||||
app.use("/instructor", instructorRouter);
|
||||
app.use("/student", studentRouter);
|
||||
|
||||
app.get("/", (req, res) => {
|
||||
res.send("OK");
|
||||
});
|
||||
|
||||
app.get("/notebook/:appName", async (req, res) => {
|
||||
try {
|
||||
const { appName } = req.params;
|
||||
const prefix = `${appName}/notebooks/`;
|
||||
const list = await s3.listObjectsV2({ Bucket: BUCKET, Prefix: prefix }).promise();
|
||||
if (!list.Contents || list.Contents.length === 0) {
|
||||
return res.status(404).json({ error: "Notebook not found" });
|
||||
}
|
||||
const latest = list.Contents.reduce((prev, curr) =>
|
||||
prev.LastModified > curr.LastModified ? prev : curr
|
||||
);
|
||||
const data = await s3.getObject({ Bucket: BUCKET, Key: latest.Key }).promise();
|
||||
res.send(data.Body.toString("utf-8"));
|
||||
} catch (error) {
|
||||
console.error("Failed to load notebook:", error);
|
||||
res.status(500).json({ error: "Failed to load notebook" });
|
||||
}
|
||||
});
|
||||
|
||||
const port = process.env.NODE_PORT || 8080;
|
||||
app.listen(port, () => console.log(`Listening on port ${port}...`));
|
||||
app.listen(port, "0.0.0.0", () => console.log(`Listening on 0.0.0.0:${port}...`));
|
||||
|
|
|
|||
13
deployment-service/Dockerfile
Normal file
13
deployment-service/Dockerfile
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
FROM node:18-alpine
|
||||
WORKDIR /app
|
||||
|
||||
COPY package.json package-lock.json ./
|
||||
RUN npm ci --only=production
|
||||
|
||||
COPY src ./src
|
||||
COPY snakeapi_service ./snakeapi_service
|
||||
|
||||
ENV FLY_ACCESS_TOKEN="FlyV1 fm2_lJPECAAAAAAACJJHxBByW6wRXXxQ17OD8xlRRR5cwrVodHRwczovL2FwaS5mbHkuaW8vdjGUAJLOAA//nh8Lk7lodHRwczovL2FwaS5mbHkuaW8vYWFhL3YxxDwQBQg0Vif1OLMYOJOtNVokX+9SIVL2E8QoNub0JDBE4wNh97aUAPiiNvpAAMhM/eO7SWUVAx5rcDTBjf7ETtdnvXtcHaqOnK2HmNSV9K9UVy5Or3Sd+0+kxqDoWRXGE0y5pdb8+HNqwMcryszYvAv8HVcoKFgF4qd7GmzniNvZETOkrbsjMsU1+mVXTMQgh7H9z6IcGVjJozV92cDsSn91USqxOmBdwFQAkFGwPV0=,fm2_lJPETtdnvXtcHaqOnK2HmNSV9K9UVy5Or3Sd+0+kxqDoWRXGE0y5pdb8+HNqwMcryszYvAv8HVcoKFgF4qd7GmzniNvZETOkrbsjMsU1+mVXTMQQqnJP464DwxC6D4e3p9THZMO5aHR0cHM6Ly9hcGkuZmx5LmlvL2FhYS92MZgEks5oESI9zwAAAAEkCUBbF84AD2FZCpHOAA9hWQzEEL6gO8olFxMOq1uFxP1yJavEIBDKb7RuqVr/sFQniKl0S2HMM6+AQJH3940ly0mufbYx"
|
||||
|
||||
EXPOSE 3006
|
||||
CMD ["node", "src/index.js"]
|
||||
19
deployment-service/fly.toml
Normal file
19
deployment-service/fly.toml
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
app = 'deployment-service-test'
|
||||
primary_region = 'sea'
|
||||
|
||||
[build]
|
||||
dockerfile = "Dockerfile"
|
||||
|
||||
[env]
|
||||
FLY_ORG="personal"
|
||||
COMMON_BUCKET="snakeapi-deployment-test-bucket"
|
||||
AWS_ACCESS_KEY_ID="tid__NSmOVaGknqitaCySppZjqVTgJSdDFnFbWcQllkC_juHwkbQZO"
|
||||
AWS_SECRET_ACCESS_KEY="tsec_6Bz1aMbfYQftuq5WfIVEDZkHwskU4MMjVywdtxSP6uxetEBvkSC2VHI9HfTeDgHr4D6kiz"
|
||||
AWS_ENDPOINT_URL_S3="https://fly.storage.tigris.dev"
|
||||
AWS_REGION="auto"
|
||||
IMAGE_REF="registry.fly.io/snake-api-template:latest"
|
||||
FLY_API_BASE_URL = "https://api.machines.dev/v1"
|
||||
|
||||
[http_service]
|
||||
internal_port = 3006
|
||||
force_https = true
|
||||
1793
deployment-service/package-lock.json
generated
Normal file
1793
deployment-service/package-lock.json
generated
Normal file
File diff suppressed because it is too large
Load diff
20
deployment-service/package.json
Normal file
20
deployment-service/package.json
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
{
|
||||
"name": "deployment-service",
|
||||
"version": "1.0.0",
|
||||
"description": "Manage Fly.io Notebook API servers with Tigris storage",
|
||||
"main": "src/index.js",
|
||||
"scripts": {
|
||||
"start": "node src/index.js",
|
||||
"dev": "nodemon src/index.js"
|
||||
},
|
||||
"dependencies": {
|
||||
"aws-sdk": "^2.1420.0",
|
||||
"axios": "^1.4.0",
|
||||
"dotenv": "^16.0.3",
|
||||
"express": "^4.18.2",
|
||||
"tar": "^7.4.3"
|
||||
},
|
||||
"devDependencies": {
|
||||
"nodemon": "^2.0.22"
|
||||
}
|
||||
}
|
||||
28
deployment-service/snakeapi_service/Dockerfile
Normal file
28
deployment-service/snakeapi_service/Dockerfile
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
FROM python:3.11-slim
|
||||
WORKDIR /app
|
||||
|
||||
# disable Python output buffering
|
||||
ENV PYTHONUNBUFFERED=1
|
||||
# wrapper server port
|
||||
ENV PORT=8000
|
||||
# notebook server port
|
||||
ENV NOTEBOOK_PORT=3006
|
||||
|
||||
RUN pip install --no-cache-dir \
|
||||
flask \
|
||||
flask-cors \
|
||||
awscli \
|
||||
jupyter \
|
||||
nbconvert \
|
||||
nbformat \
|
||||
requests
|
||||
|
||||
COPY entrypoint.sh .
|
||||
COPY snakeapi_server.py .
|
||||
COPY notebooks ./notebooks
|
||||
|
||||
RUN chmod +x entrypoint.sh
|
||||
|
||||
EXPOSE ${PORT} ${NOTEBOOK_PORT}
|
||||
|
||||
CMD ["./entrypoint.sh"]
|
||||
29
deployment-service/snakeapi_service/entrypoint.sh
Normal file
29
deployment-service/snakeapi_service/entrypoint.sh
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
#!/usr/bin/env bash
|
||||
set -eux
|
||||
|
||||
NOTEBOOK_DIR="notebooks"
|
||||
mkdir -p "${NOTEBOOK_DIR}"
|
||||
|
||||
# sync notebooks from S3
|
||||
aws --endpoint-url "$AWS_ENDPOINT_URL_S3" --region "$AWS_REGION" \
|
||||
s3 sync "s3://$COMMON_BUCKET/$INSTANCE_PREFIX/notebooks/" "${NOTEBOOK_DIR}/"
|
||||
|
||||
# pick latest notebook
|
||||
latest_ipynb=$(ls -t "${NOTEBOOK_DIR}"/*.ipynb | head -n1)
|
||||
cp "$latest_ipynb" "${NOTEBOOK_DIR}/notebook.ipynb"
|
||||
|
||||
# convert notebook to script
|
||||
jupyter nbconvert --to script "${NOTEBOOK_DIR}/notebook.ipynb" \
|
||||
--output notebook --output-dir "${NOTEBOOK_DIR}"
|
||||
|
||||
# remove IPython magics only
|
||||
sed -i '/get_ipython()/d' "${NOTEBOOK_DIR}/notebook.py"
|
||||
sed -i '/^!/d' "${NOTEBOOK_DIR}/notebook.py"
|
||||
sed -i '/^%/d' "${NOTEBOOK_DIR}/notebook.py"
|
||||
|
||||
# remove standalone Flask run calls
|
||||
sed -i '/app\.run(/d' "${NOTEBOOK_DIR}/notebook.py"
|
||||
|
||||
# export path and launch server
|
||||
export NOTEBOOK_PATH="$(pwd)/${NOTEBOOK_DIR}/notebook.py"
|
||||
exec python snakeapi_server.py
|
||||
86329
deployment-service/snakeapi_service/notebooks/notebook.ipynb
Normal file
86329
deployment-service/snakeapi_service/notebooks/notebook.ipynb
Normal file
File diff suppressed because it is too large
Load diff
55
deployment-service/snakeapi_service/snakeapi_server.py
Normal file
55
deployment-service/snakeapi_service/snakeapi_server.py
Normal file
|
|
@ -0,0 +1,55 @@
|
|||
import os
|
||||
import logging
|
||||
import importlib.util
|
||||
from flask import Flask, request, jsonify, Response
|
||||
from flask_cors import CORS
|
||||
|
||||
logging.basicConfig(level=logging.INFO)
|
||||
|
||||
NOTEBOOK_PATH = os.environ.get("NOTEBOOK_PATH")
|
||||
if not NOTEBOOK_PATH or not os.path.isfile(NOTEBOOK_PATH):
|
||||
raise RuntimeError(f"NOTEBOOK_PATH not set or file not found: {NOTEBOOK_PATH}")
|
||||
|
||||
# Determine .ipynb path
|
||||
notebook_ipynb_path = NOTEBOOK_PATH[:-3] + ".ipynb"
|
||||
|
||||
spec = importlib.util.spec_from_file_location("notebook_module", NOTEBOOK_PATH)
|
||||
notebook_module = importlib.util.module_from_spec(spec)
|
||||
spec.loader.exec_module(notebook_module)
|
||||
|
||||
app = Flask(__name__)
|
||||
CORS(app)
|
||||
|
||||
@app.route("/health", methods=["GET"])
|
||||
def health():
|
||||
return jsonify({"status": "ok"}), 200
|
||||
|
||||
@app.route("/", methods=["GET"])
|
||||
def info():
|
||||
return jsonify(notebook_module.info())
|
||||
|
||||
@app.route("/start", methods=["POST"])
|
||||
def start():
|
||||
data = request.get_json()
|
||||
return jsonify(notebook_module.start(data))
|
||||
|
||||
@app.route("/move", methods=["POST"])
|
||||
def move():
|
||||
data = request.get_json()
|
||||
return jsonify(notebook_module.move(data))
|
||||
|
||||
@app.route("/end", methods=["POST"])
|
||||
def end():
|
||||
data = request.get_json()
|
||||
return jsonify(notebook_module.end(data))
|
||||
|
||||
@app.route("/notebook", methods=["GET"])
|
||||
def get_notebook():
|
||||
if os.path.isfile(notebook_ipynb_path):
|
||||
with open(notebook_ipynb_path, "r", encoding="utf-8") as f:
|
||||
return Response(f.read(), mimetype="application/json")
|
||||
return jsonify({"error": "notebook not found"}), 404
|
||||
|
||||
if __name__ == "__main__":
|
||||
port = int(os.environ.get("PORT", 8000))
|
||||
app.run(host="0.0.0.0", port=port)
|
||||
231
deployment-service/src/index.js
Normal file
231
deployment-service/src/index.js
Normal file
|
|
@ -0,0 +1,231 @@
|
|||
const express = require('express');
|
||||
const fs = require('fs');
|
||||
const path = require('path');
|
||||
const AWS = require('aws-sdk');
|
||||
const axios = require('axios');
|
||||
|
||||
const {
|
||||
FLY_ORG,
|
||||
COMMON_BUCKET,
|
||||
AWS_ACCESS_KEY_ID,
|
||||
AWS_SECRET_ACCESS_KEY,
|
||||
AWS_ENDPOINT_URL_S3,
|
||||
AWS_REGION,
|
||||
FLY_ACCESS_TOKEN,
|
||||
IMAGE_REF
|
||||
} = process.env;
|
||||
|
||||
// Log environment variables for debugging
|
||||
console.log('--- ENV START ---');
|
||||
console.log('FLY_ORG: ', FLY_ORG);
|
||||
console.log('COMMON_BUCKET: ', COMMON_BUCKET);
|
||||
console.log('AWS_ACCESS_KEY_ID: ', AWS_ACCESS_KEY_ID ? '(found)' : '(NOT SET)');
|
||||
console.log('AWS_SECRET_ACCESS_KEY:', AWS_SECRET_ACCESS_KEY ? '(found)' : '(NOT SET)');
|
||||
console.log('AWS_ENDPOINT_URL_S3: ', AWS_ENDPOINT_URL_S3);
|
||||
console.log('AWS_REGION: ', AWS_REGION);
|
||||
console.log('FLY_ACCESS_TOKEN: ', FLY_ACCESS_TOKEN ? '(found)' : '(NOT SET)');
|
||||
console.log('IMAGE_REF: ', IMAGE_REF);
|
||||
console.log('--- ENV END ---');
|
||||
|
||||
// Initialize S3 client
|
||||
const s3 = new AWS.S3({
|
||||
endpoint: AWS_ENDPOINT_URL_S3,
|
||||
region: AWS_REGION,
|
||||
credentials: new AWS.Credentials(AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY),
|
||||
s3ForcePathStyle: true
|
||||
});
|
||||
|
||||
// Create Fly Machines API client
|
||||
function createFlyClient() {
|
||||
return axios.create({
|
||||
baseURL: 'https://api.machines.dev/v1',
|
||||
headers: {
|
||||
Authorization: `Bearer ${FLY_ACCESS_TOKEN}`,
|
||||
'Content-Type': 'application/json'
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// Create Fly GraphQL client (for IP allocation)
|
||||
const gqlClient = axios.create({
|
||||
baseURL: 'https://api.fly.io/graphql',
|
||||
headers: {
|
||||
Authorization: `Bearer ${FLY_ACCESS_TOKEN}`,
|
||||
'Content-Type': 'application/json'
|
||||
}
|
||||
});
|
||||
|
||||
// Define GraphQL mutation for IP allocation
|
||||
const ALLOCATE_IP_MUTATION = `
|
||||
mutation AllocateIp($input: AllocateIPAddressInput!) {
|
||||
allocateIpAddress(input: $input) {
|
||||
ipAddress {
|
||||
address
|
||||
type
|
||||
}
|
||||
}
|
||||
}
|
||||
`;
|
||||
|
||||
const app = express();
|
||||
app.use(express.json({ limit: '10mb' }));
|
||||
|
||||
app.post('/deploy', async (req, res) => {
|
||||
console.log('Received /deploy:', req.body);
|
||||
const { appName, region, notebookName } = req.body;
|
||||
if (!appName || !notebookName) {
|
||||
return res.status(400).json({ error: 'appName and notebookName required' });
|
||||
}
|
||||
|
||||
const notebookPath = path.join(__dirname, '../snakeapi_service/notebooks', notebookName);
|
||||
console.log('Resolved notebookPath:', notebookPath);
|
||||
if (!fs.existsSync(notebookPath)) {
|
||||
console.error('Notebook not found at:', notebookPath);
|
||||
return res.status(500).json({ error: `Notebook not found: ${notebookPath}` });
|
||||
}
|
||||
|
||||
try {
|
||||
const fly = createFlyClient();
|
||||
|
||||
console.log('Creating Fly app:', appName);
|
||||
await fly.post('/apps', {
|
||||
app_name: appName,
|
||||
org_slug: FLY_ORG,
|
||||
primary_region: region
|
||||
});
|
||||
|
||||
console.log('Uploading notebook to S3');
|
||||
const data = fs.readFileSync(notebookPath);
|
||||
const key = `${appName}/notebooks/${Date.now()}-notebook.ipynb`;
|
||||
console.log('S3 key:', key);
|
||||
await s3.putObject({
|
||||
Bucket: COMMON_BUCKET,
|
||||
Key: key,
|
||||
Body: data,
|
||||
ContentType: 'application/json'
|
||||
}).promise();
|
||||
|
||||
console.log('Creating machine');
|
||||
const machineConfig = {
|
||||
name: `${appName}-machine`,
|
||||
region: 'sea',
|
||||
count: 1,
|
||||
vm_size: 'shared-cpu-1x',
|
||||
autostart: true,
|
||||
config: {
|
||||
image: IMAGE_REF,
|
||||
env: {
|
||||
INSTANCE_PREFIX: appName,
|
||||
NOTEBOOK_KEY: key,
|
||||
COMMON_BUCKET: COMMON_BUCKET,
|
||||
AWS_ACCESS_KEY_ID,
|
||||
AWS_SECRET_ACCESS_KEY,
|
||||
AWS_ENDPOINT_URL_S3,
|
||||
AWS_REGION
|
||||
},
|
||||
http_service: {
|
||||
internal_port: 8000,
|
||||
force_https: true,
|
||||
auto_stop_machines: 'stop',
|
||||
auto_start_machines: true,
|
||||
min_machines_running: 0,
|
||||
processes: ['app']
|
||||
},
|
||||
services: [
|
||||
{
|
||||
protocol: 'tcp',
|
||||
internal_port: 8000,
|
||||
ports: [
|
||||
{ port: 443, handlers: ['tls', 'http'] },
|
||||
{ port: 80, handlers: ['http'] }
|
||||
]
|
||||
}
|
||||
],
|
||||
guest: {
|
||||
memory_mb: 512,
|
||||
cpu_kind: 'shared',
|
||||
cpus: 1
|
||||
}
|
||||
}
|
||||
};
|
||||
console.log('Machine config:', JSON.stringify(machineConfig, null, 2));
|
||||
await fly.post(`/apps/${appName}/machines`, machineConfig);
|
||||
|
||||
console.log('Allocating IPv4 via GraphQL API');
|
||||
const v4resp = await gqlClient.post('', {
|
||||
query: ALLOCATE_IP_MUTATION,
|
||||
variables: { input: { appId: appName, type: 'v4' } }
|
||||
});
|
||||
const ipv4 = v4resp.data.data.allocateIpAddress.ipAddress.address;
|
||||
console.log('Allocated IPv4:', ipv4);
|
||||
|
||||
console.log('Allocating IPv6 via GraphQL API');
|
||||
const v6resp = await gqlClient.post('', {
|
||||
query: ALLOCATE_IP_MUTATION,
|
||||
variables: { input: { appId: appName, type: 'v6' } }
|
||||
});
|
||||
const ipv6 = v6resp.data.data.allocateIpAddress.ipAddress.address;
|
||||
console.log('Allocated IPv6:', ipv6);
|
||||
|
||||
return res.json({
|
||||
status: 'created',
|
||||
app: appName,
|
||||
ipv4,
|
||||
ipv6,
|
||||
url_v4: `http://${ipv4}`,
|
||||
url_v6: `http://[${ipv6}]`
|
||||
});
|
||||
} catch (err) {
|
||||
console.error('Deployment error:', err.response?.data || err.stack || err.message);
|
||||
return res.status(500).json({ error: err.response?.data || err.message });
|
||||
}
|
||||
});
|
||||
|
||||
// Upload notebook to S3 for an existing app
|
||||
app.post('/:appName/upload', async (req, res) => {
|
||||
const { appName } = req.params;
|
||||
const { notebookName, fileContentBase64 } = req.body;
|
||||
|
||||
if (!notebookName || !fileContentBase64) {
|
||||
return res.status(400).json({ error: 'notebookName and fileContentBase64 are required' });
|
||||
}
|
||||
|
||||
try {
|
||||
const buffer = Buffer.from(fileContentBase64, 'base64');
|
||||
const key = `${appName}/notebooks/${notebookName}`;
|
||||
|
||||
console.log(`Uploading notebook to: s3://${COMMON_BUCKET}/${key}`);
|
||||
await s3.putObject({
|
||||
Bucket: COMMON_BUCKET,
|
||||
Key: key,
|
||||
Body: buffer,
|
||||
ContentType: 'application/json'
|
||||
}).promise();
|
||||
|
||||
return res.json({ status: 'uploaded', app: appName, key });
|
||||
} catch (err) {
|
||||
console.error('Notebook upload error:', err);
|
||||
return res.status(500).json({ error: err.message });
|
||||
}
|
||||
});
|
||||
|
||||
// Delete a Fly app
|
||||
app.post('/:appName/delete', async (req, res) => {
|
||||
const { appName } = req.params;
|
||||
|
||||
try {
|
||||
const fly = createFlyClient();
|
||||
console.log('Destroying Fly app:', appName);
|
||||
await fly.delete(`/apps/${appName}`);
|
||||
|
||||
return res.json({ status: 'deleted', app: appName });
|
||||
} catch (err) {
|
||||
console.error('App deletion error:', err.response?.data || err.message);
|
||||
return res.status(500).json({ error: err.response?.data || err.message });
|
||||
}
|
||||
});
|
||||
|
||||
const LISTEN_PORT = process.env.PORT || 3006;
|
||||
app.listen(LISTEN_PORT, '0.0.0.0', () => {
|
||||
console.log(`Deployment service listening on port ${LISTEN_PORT}`);
|
||||
});
|
||||
6
package-lock.json
generated
Normal file
6
package-lock.json
generated
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
{
|
||||
"name": "bytecamp-services",
|
||||
"lockfileVersion": 3,
|
||||
"requires": true,
|
||||
"packages": {}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue