From a7531ddbf18911932f58779ed753a2e9868c964f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?L=C3=86S?= Date: Sun, 27 Oct 2024 06:17:55 +0530 Subject: [PATCH 01/29] chore: add .choreo/component.yaml for deployment --- .choreo/component.yaml | 102 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 102 insertions(+) create mode 100644 .choreo/component.yaml diff --git a/.choreo/component.yaml b/.choreo/component.yaml new file mode 100644 index 0000000..d37c99c --- /dev/null +++ b/.choreo/component.yaml @@ -0,0 +1,102 @@ +name: CodeX API +version: 1.0.0 +displayName: CodeX API Service +description: Execute code in various programming languages and retrieve supported languages with additional information. +type: REST +categories: + - Code Execution + - Programming Languages + - Development Tools + +configuration: + auth: + type: NONE + description: No authentication required for local setup. + + inputs: + properties: + - name: language + displayName: Programming Language + description: The programming language for code execution. + type: string + required: true + - name: code + displayName: Code + description: The code to execute. + type: string + required: true + - name: input + displayName: Input + description: Input data for the code execution, if applicable. + type: string + required: false + - name: timeout + displayName: Timeout + description: Maximum execution time in seconds for code execution. + type: integer + default: 30 + + outputs: + properties: + - name: output + displayName: Execution Output + description: Output of the executed code, if successful. + type: string + - name: error + displayName: Execution Error + description: Error details if the code execution fails. + type: string + - name: supported_languages + displayName: Supported Languages + description: List of supported languages with additional information. + type: array + items: + type: object + properties: + - name: language + displayName: Language + description: Name of the programming language. + type: string + - name: info + displayName: Information + description: Version and additional information for the language. + type: string + +execution: + steps: + - name: executeCode + description: "Executes provided code in the specified language." + action: + type: HTTP + url: http://localhost:3000/ + method: POST + headers: + Content-Type: application/json + requestBody: + language: ${configuration.inputs.language} + code: ${configuration.inputs.code} + input: ${configuration.inputs.input} + response: + - when: "200" + set: + outputs.output: "$.output" + outputs.error: "$.error" + - when: "default" + error: + message: "Failed to execute code" + details: "$.error" + + - name: getSupportedLanguages + description: "Retrieves the list of supported programming languages with additional information." + action: + type: HTTP + url: http://localhost:3000/list + method: GET + response: + - when: "200" + set: + outputs.supported_languages: "$.supportedLanguages" + - when: "default" + error: + message: "Failed to retrieve supported languages" + details: "$.error" From de85da67c34de168a0b2ccb55d7786666dddc5b1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?L=C3=86S?= Date: Sun, 27 Oct 2024 06:20:40 +0530 Subject: [PATCH 02/29] fix: add schemaVersion --- .choreo/component.yaml | 1 + 1 file changed, 1 insertion(+) diff --git a/.choreo/component.yaml b/.choreo/component.yaml index d37c99c..2cb8bb2 100644 --- a/.choreo/component.yaml +++ b/.choreo/component.yaml @@ -1,3 +1,4 @@ +schemaVersion: 1.0 name: CodeX API version: 1.0.0 displayName: CodeX API Service From 6176dc5bfa86e6cfefdae644db03d67f036fdbf5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?L=C3=86S?= Date: Sun, 27 Oct 2024 06:24:23 +0530 Subject: [PATCH 03/29] chore: setup dockerfile for choreo --- Dockerfile | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/Dockerfile b/Dockerfile index f96e77a..6ebd506 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,17 +1,20 @@ FROM ubuntu:18.04 +# Ensure proper dpkg configuration RUN dpkg --configure -a +# Set environment variables ENV PYTHON_VERSION 3.7.7 ENV PYTHON_PIP_VERSION 20.1 ENV DEBIAN_FRONTEND noninteractive -RUN apt-get update -RUN apt-get -y install gcc mono-mcs golang-go \ +# Install dependencies +RUN apt-get update && apt-get -y install gcc mono-mcs golang-go \ default-jre default-jdk nodejs npm \ python3-pip python3 curl && \ rm -rf /var/lib/apt/lists/* +# Install Node.js using NVM ENV NODE_VERSION=16.13.2 RUN curl https://raw.githubusercontent.com/nvm-sh/nvm/v0.38.0/install.sh | bash ENV NVM_DIR=/root/.nvm @@ -19,11 +22,18 @@ RUN . "$NVM_DIR/nvm.sh" && nvm install ${NODE_VERSION} RUN . "$NVM_DIR/nvm.sh" && nvm use v${NODE_VERSION} RUN . "$NVM_DIR/nvm.sh" && nvm alias default v${NODE_VERSION} ENV PATH="/root/.nvm/versions/node/v${NODE_VERSION}/bin/:${PATH}" -# RUN nvm install 16.13.2 -COPY . /app +# Create a non-root user and switch to it +RUN useradd -m appuser +USER appuser + +# Copy application code and set up the working directory +COPY --chown=appuser:appuser . /app WORKDIR /app RUN npm install +# Expose the application port EXPOSE 3000 + +# Start the application CMD ["npm", "start"] From e84a82c19cd1479f5c0a7fae6310a78ac9b768ae Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?L=C3=86S?= Date: Sun, 27 Oct 2024 06:27:18 +0530 Subject: [PATCH 04/29] fix: set user to 10001 --- Dockerfile | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Dockerfile b/Dockerfile index 6ebd506..7ffdf5d 100644 --- a/Dockerfile +++ b/Dockerfile @@ -23,9 +23,9 @@ RUN . "$NVM_DIR/nvm.sh" && nvm use v${NODE_VERSION} RUN . "$NVM_DIR/nvm.sh" && nvm alias default v${NODE_VERSION} ENV PATH="/root/.nvm/versions/node/v${NODE_VERSION}/bin/:${PATH}" -# Create a non-root user and switch to it -RUN useradd -m appuser -USER appuser +# Create a non-root user with a UID between 10000 and 20000 +RUN useradd -m -u 10001 appuser +USER 10001 # Copy application code and set up the working directory COPY --chown=appuser:appuser . /app From 27e0ca4ac94ddd0444ff79e65a13a6919d0721d0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?L=C3=86S?= Date: Sun, 27 Oct 2024 06:50:34 +0530 Subject: [PATCH 05/29] fix: set path for nvm node version --- Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index 7ffdf5d..56b3d39 100644 --- a/Dockerfile +++ b/Dockerfile @@ -21,7 +21,7 @@ ENV NVM_DIR=/root/.nvm RUN . "$NVM_DIR/nvm.sh" && nvm install ${NODE_VERSION} RUN . "$NVM_DIR/nvm.sh" && nvm use v${NODE_VERSION} RUN . "$NVM_DIR/nvm.sh" && nvm alias default v${NODE_VERSION} -ENV PATH="/root/.nvm/versions/node/v${NODE_VERSION}/bin/:${PATH}" +ENV PATH $NVM_DIR/versions/node/v$NODE_VERSION/bin:$PATH # Create a non-root user with a UID between 10000 and 20000 RUN useradd -m -u 10001 appuser From a73ca8939a93a003d470adf5035351ada7ed1e89 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?L=C3=86S?= Date: Sun, 27 Oct 2024 07:08:57 +0530 Subject: [PATCH 06/29] fix: directly install node 16 instead of using nvm --- Dockerfile | 21 +++++++-------------- 1 file changed, 7 insertions(+), 14 deletions(-) diff --git a/Dockerfile b/Dockerfile index 56b3d39..53c1906 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,27 +1,20 @@ FROM ubuntu:18.04 -# Ensure proper dpkg configuration -RUN dpkg --configure -a - # Set environment variables ENV PYTHON_VERSION 3.7.7 ENV PYTHON_PIP_VERSION 20.1 ENV DEBIAN_FRONTEND noninteractive +ENV NODE_VERSION 16 -# Install dependencies +# Update and install dependencies, including Node 16 directly RUN apt-get update && apt-get -y install gcc mono-mcs golang-go \ - default-jre default-jdk nodejs npm \ - python3-pip python3 curl && \ + default-jre default-jdk python3-pip python3 curl && \ + curl -fsSL https://deb.nodesource.com/setup_16.x | bash - && \ + apt-get install -y nodejs && \ rm -rf /var/lib/apt/lists/* -# Install Node.js using NVM -ENV NODE_VERSION=16.13.2 -RUN curl https://raw.githubusercontent.com/nvm-sh/nvm/v0.38.0/install.sh | bash -ENV NVM_DIR=/root/.nvm -RUN . "$NVM_DIR/nvm.sh" && nvm install ${NODE_VERSION} -RUN . "$NVM_DIR/nvm.sh" && nvm use v${NODE_VERSION} -RUN . "$NVM_DIR/nvm.sh" && nvm alias default v${NODE_VERSION} -ENV PATH $NVM_DIR/versions/node/v$NODE_VERSION/bin:$PATH +# Verify that Node 16 is installed +RUN node -v && npm -v # Create a non-root user with a UID between 10000 and 20000 RUN useradd -m -u 10001 appuser From f1bd9a64b79b7c4639a7288abdbf8c7c6f4edf0d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?L=C3=86S?= Date: Sun, 27 Oct 2024 07:18:09 +0530 Subject: [PATCH 07/29] fix: use tmp folder for compilation --- src/file-system/createCodeFile.js | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/src/file-system/createCodeFile.js b/src/file-system/createCodeFile.js index c924a3c..1825773 100644 --- a/src/file-system/createCodeFile.js +++ b/src/file-system/createCodeFile.js @@ -1,24 +1,24 @@ -const {v4: getUUID} = require("uuid"); -const {existsSync, mkdirSync, writeFileSync} = require("fs") -const {join} = require("path"); +const { v4: getUUID } = require("uuid"); +const { existsSync, mkdirSync, writeFileSync } = require("fs"); +const { join } = require("path"); -if (!existsSync(join(process.cwd(), "codes"))) - mkdirSync(join(process.cwd(), "codes")); +const CODES_DIR = process.env.CODES_DIR || "/tmp/codes"; +const OUTPUTS_DIR = process.env.OUTPUTS_DIR || "/tmp/outputs"; -if (!existsSync(join(process.cwd(), "outputs"))) - mkdirSync(join(process.cwd(), "outputs")); +if (!existsSync(CODES_DIR)) mkdirSync(CODES_DIR, { recursive: true }); +if (!existsSync(OUTPUTS_DIR)) mkdirSync(OUTPUTS_DIR, { recursive: true }); const createCodeFile = async (language, code) => { const jobID = getUUID(); const fileName = `${jobID}.${language}`; - const filePath = join(process.cwd(), `codes/${fileName}`) + const filePath = join(CODES_DIR, fileName); - await writeFileSync(filePath, code?.toString()) + await writeFileSync(filePath, code?.toString()); return { fileName, filePath, - jobID + jobID, }; }; From 102b9790575f10f4476145315180eded8e157f4e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?L=C3=86S?= Date: Sun, 27 Oct 2024 07:19:07 +0530 Subject: [PATCH 08/29] fix: use tmp folder when removing code files --- src/file-system/removeCodeFile.js | 26 +++++++++++++++++++------- 1 file changed, 19 insertions(+), 7 deletions(-) diff --git a/src/file-system/removeCodeFile.js b/src/file-system/removeCodeFile.js index d130af1..02b1b52 100644 --- a/src/file-system/removeCodeFile.js +++ b/src/file-system/removeCodeFile.js @@ -1,14 +1,26 @@ -const {unlinkSync} = require("fs"), - {join} = require("path"); +const { unlinkSync } = require("fs"); +const { join } = require("path"); + +const CODES_DIR = process.env.CODES_DIR || "/tmp/codes"; +const OUTPUTS_DIR = process.env.OUTPUTS_DIR || "/tmp/outputs"; const removeCodeFile = async (uuid, lang, outputExt) => { - const codeFile = join(process.cwd(), `codes/${uuid}.${lang}`), - outputFile = join(process.cwd(), `outputs/${uuid}.${outputExt}`); + const codeFile = join(CODES_DIR, `${uuid}.${lang}`); + const outputFile = join(OUTPUTS_DIR, `${uuid}.${outputExt}`); - await unlinkSync(codeFile); + try { + unlinkSync(codeFile); + } catch (err) { + console.error(`Failed to delete code file: ${codeFile}`, err); + } - if (outputExt) - await unlinkSync(outputFile); + if (outputExt) { + try { + unlinkSync(outputFile); + } catch (err) { + console.error(`Failed to delete output file: ${outputFile}`, err); + } + } }; module.exports = { From 4c49096d5978756796a2b5ad37b391915b535ae9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?L=C3=86S?= Date: Sun, 27 Oct 2024 07:48:40 +0530 Subject: [PATCH 09/29] fix: add endpoints --- .choreo/component.yaml | 55 +++++++++++------------------------------- 1 file changed, 14 insertions(+), 41 deletions(-) diff --git a/.choreo/component.yaml b/.choreo/component.yaml index 2cb8bb2..6190e1d 100644 --- a/.choreo/component.yaml +++ b/.choreo/component.yaml @@ -2,93 +2,70 @@ schemaVersion: 1.0 name: CodeX API version: 1.0.0 displayName: CodeX API Service -description: Execute code in various programming languages and retrieve supported languages with additional information. +description: Execute code in various programming languages and retrieve supported languages information. type: REST -categories: - - Code Execution - - Programming Languages - - Development Tools + +endpoints: + - name: executeCode + type: http + port: 3000 + basePath: / + visibility: PUBLIC + + - name: getSupportedLanguages + type: http + port: 3000 + basePath: /list + visibility: PUBLIC configuration: auth: type: NONE - description: No authentication required for local setup. inputs: properties: - name: language - displayName: Programming Language - description: The programming language for code execution. type: string required: true - name: code - displayName: Code - description: The code to execute. type: string required: true - name: input - displayName: Input - description: Input data for the code execution, if applicable. type: string required: false - name: timeout - displayName: Timeout - description: Maximum execution time in seconds for code execution. type: integer default: 30 outputs: properties: - name: output - displayName: Execution Output - description: Output of the executed code, if successful. type: string - name: error - displayName: Execution Error - description: Error details if the code execution fails. type: string - name: supported_languages - displayName: Supported Languages - description: List of supported languages with additional information. type: array items: type: object properties: - name: language - displayName: Language - description: Name of the programming language. type: string - name: info - displayName: Information - description: Version and additional information for the language. type: string execution: steps: - name: executeCode - description: "Executes provided code in the specified language." action: type: HTTP url: http://localhost:3000/ method: POST - headers: - Content-Type: application/json - requestBody: - language: ${configuration.inputs.language} - code: ${configuration.inputs.code} - input: ${configuration.inputs.input} response: - when: "200" set: outputs.output: "$.output" outputs.error: "$.error" - - when: "default" - error: - message: "Failed to execute code" - details: "$.error" - - name: getSupportedLanguages - description: "Retrieves the list of supported programming languages with additional information." action: type: HTTP url: http://localhost:3000/list @@ -97,7 +74,3 @@ execution: - when: "200" set: outputs.supported_languages: "$.supportedLanguages" - - when: "default" - error: - message: "Failed to retrieve supported languages" - details: "$.error" From 4573659d850cf271f76f63848b7fd7792815f7e7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?L=C3=86S?= Date: Sun, 27 Oct 2024 07:51:44 +0530 Subject: [PATCH 10/29] fix: endpoints in choreo --- .choreo/component.yaml | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/.choreo/component.yaml b/.choreo/component.yaml index 6190e1d..78ca6d0 100644 --- a/.choreo/component.yaml +++ b/.choreo/component.yaml @@ -1,20 +1,22 @@ schemaVersion: 1.0 -name: CodeX API +name: codex-api version: 1.0.0 displayName: CodeX API Service description: Execute code in various programming languages and retrieve supported languages information. type: REST endpoints: - - name: executeCode - type: http - port: 3000 + - name: execute_code + type: REST + service: + port: 3000 basePath: / visibility: PUBLIC - - name: getSupportedLanguages - type: http - port: 3000 + - name: get_supported_languages + type: REST + service: + port: 3000 basePath: /list visibility: PUBLIC @@ -55,7 +57,7 @@ configuration: execution: steps: - - name: executeCode + - name: execute_code action: type: HTTP url: http://localhost:3000/ @@ -65,7 +67,7 @@ execution: set: outputs.output: "$.output" outputs.error: "$.error" - - name: getSupportedLanguages + - name: get_supported_languages action: type: HTTP url: http://localhost:3000/list From fc64462b3c7ddde7845cc71ab6a3b148d4eb7bb7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?L=C3=86S?= Date: Sun, 27 Oct 2024 07:53:01 +0530 Subject: [PATCH 11/29] fix: add base path --- .choreo/component.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.choreo/component.yaml b/.choreo/component.yaml index 78ca6d0..27564aa 100644 --- a/.choreo/component.yaml +++ b/.choreo/component.yaml @@ -2,7 +2,7 @@ schemaVersion: 1.0 name: codex-api version: 1.0.0 displayName: CodeX API Service -description: Execute code in various programming languages and retrieve supported languages information. +description: Execute code and retrieve supported languages information. type: REST endpoints: From 9b24bfff877f4ba4162b7ffa6a516c0b6dedec56 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?L=C3=86S?= Date: Sun, 27 Oct 2024 07:56:27 +0530 Subject: [PATCH 12/29] fix: remove inputs and outputs from component.yaml --- .choreo/component.yaml | 54 +++++++----------------------------------- 1 file changed, 8 insertions(+), 46 deletions(-) diff --git a/.choreo/component.yaml b/.choreo/component.yaml index 27564aa..f11bb10 100644 --- a/.choreo/component.yaml +++ b/.choreo/component.yaml @@ -1,60 +1,31 @@ schemaVersion: 1.0 name: codex-api version: 1.0.0 -displayName: CodeX API Service -description: Execute code and retrieve supported languages information. +displayName: CodeX API +description: Service for executing code snippets and listing supported languages. type: REST endpoints: - name: execute_code type: REST + basePath: / service: port: 3000 - basePath: / - visibility: PUBLIC + networkVisibilities: + - Public - name: get_supported_languages type: REST + basePath: /list service: port: 3000 - basePath: /list - visibility: PUBLIC + networkVisibilities: + - Public configuration: auth: type: NONE - inputs: - properties: - - name: language - type: string - required: true - - name: code - type: string - required: true - - name: input - type: string - required: false - - name: timeout - type: integer - default: 30 - - outputs: - properties: - - name: output - type: string - - name: error - type: string - - name: supported_languages - type: array - items: - type: object - properties: - - name: language - type: string - - name: info - type: string - execution: steps: - name: execute_code @@ -62,17 +33,8 @@ execution: type: HTTP url: http://localhost:3000/ method: POST - response: - - when: "200" - set: - outputs.output: "$.output" - outputs.error: "$.error" - name: get_supported_languages action: type: HTTP url: http://localhost:3000/list method: GET - response: - - when: "200" - set: - outputs.supported_languages: "$.supportedLanguages" From 0fac1fe1281f2031efe4b5ea62c97c5b99b9b538 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?L=C3=86S?= Date: Sun, 27 Oct 2024 08:00:13 +0530 Subject: [PATCH 13/29] fix: only add endpoints --- .choreo/component.yaml | 27 +++++---------------------- 1 file changed, 5 insertions(+), 22 deletions(-) diff --git a/.choreo/component.yaml b/.choreo/component.yaml index f11bb10..527a4a4 100644 --- a/.choreo/component.yaml +++ b/.choreo/component.yaml @@ -2,39 +2,22 @@ schemaVersion: 1.0 name: codex-api version: 1.0.0 displayName: CodeX API -description: Service for executing code snippets and listing supported languages. +description: Service for code execution and supported language retrieval. type: REST endpoints: - name: execute_code type: REST - basePath: / service: + basePath: / port: 3000 - networkVisibilities: + networkVisibilities: - Public - name: get_supported_languages type: REST - basePath: /list service: + basePath: /list port: 3000 - networkVisibilities: + networkVisibilities: - Public - -configuration: - auth: - type: NONE - -execution: - steps: - - name: execute_code - action: - type: HTTP - url: http://localhost:3000/ - method: POST - - name: get_supported_languages - action: - type: HTTP - url: http://localhost:3000/list - method: GET From 68ed84d9718ea14f248282ca9468d2e449f580cb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?L=C3=86S?= Date: Sun, 27 Oct 2024 08:14:02 +0530 Subject: [PATCH 14/29] fix: update tmp file path when running code --- src/run-code/instructions.js | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/src/run-code/instructions.js b/src/run-code/instructions.js index 8a99b24..8d1cd4d 100644 --- a/src/run-code/instructions.js +++ b/src/run-code/instructions.js @@ -1,12 +1,15 @@ const {join} = require('path') +const CODES_DIR = process.env.CODES_DIR || "/tmp/codes"; +const OUTPUTS_DIR = process.env.OUTPUTS_DIR || "/tmp/outputs"; + const commandMap = (jobID, language) => { switch (language) { case 'java': return { executeCodeCommand: 'java', executionArgs: [ - join(process.cwd(), `codes/${jobID}.java`) + join(process.cwd(), `${CODES_DIR}/${jobID}.java`) ], compilerInfoCommand: 'java --version' }; @@ -14,9 +17,9 @@ const commandMap = (jobID, language) => { return { compileCodeCommand: 'g++', compilationArgs: [ - join(process.cwd(), `codes/${jobID}.cpp`), + join(process.cwd(), `${CODES_DIR}/${jobID}.cpp`), '-o', - join(process.cwd(), `outputs/${jobID}.out`) + join(process.cwd(), `${OUTPUTS_DIR}/${jobID}.out`) ], executeCodeCommand: join(process.cwd(), `outputs/${jobID}.out`), outputExt: 'out', @@ -26,7 +29,7 @@ const commandMap = (jobID, language) => { return { executeCodeCommand: 'python3', executionArgs: [ - join(process.cwd(), `codes/${jobID}.py`) + join(process.cwd(), `${CODES_DIR}/${jobID}.py`) ], compilerInfoCommand: 'python3 --version' } @@ -34,9 +37,9 @@ const commandMap = (jobID, language) => { return { compileCodeCommand: 'gcc', compilationArgs: [ - join(process.cwd(), `codes/${jobID}.c`), + join(process.cwd(), `${CODES_DIR}/${jobID}.c`), '-o', - join(process.cwd(), `outputs/${jobID}.out`) + join(process.cwd(), `${OUTPUTS_DIR}/${jobID}.out`) ], executeCodeCommand: join(process.cwd(), `outputs/${jobID}.out`), outputExt: 'out', @@ -46,7 +49,7 @@ const commandMap = (jobID, language) => { return { executeCodeCommand: 'node', executionArgs: [ - join(process.cwd(), `codes/${jobID}.js`) + join(process.cwd(), `${CODES_DIR}/${jobID}.js`) ], compilerInfoCommand: 'node --version' } @@ -55,7 +58,7 @@ const commandMap = (jobID, language) => { executeCodeCommand: 'go', executionArgs: [ 'run', - join(process.cwd(), `codes/${jobID}.go`) + join(process.cwd(), `${CODES_DIR}/${jobID}.go`) ], compilerInfoCommand: 'go version' } @@ -67,11 +70,11 @@ const commandMap = (jobID, language) => { process.cwd(), `outputs/${jobID}` )}.exe`, - `${join(process.cwd(), `codes/${jobID}.cs`)}`, + `${join(process.cwd(), `${CODES_DIR}/${jobID}.cs`)}`, ], executeCodeCommand: 'mono', executionArgs: [ - `${join(process.cwd(), `outputs/${jobID}`)}.exe` + `${join(process.cwd(), `${OUTPUTS_DIR}/${jobID}`)}.exe` ], outputExt: 'exe', compilerInfoCommand: 'mcs --version' @@ -81,4 +84,4 @@ const commandMap = (jobID, language) => { const supportedLanguages = ['java', 'cpp', 'py', 'c', 'js', 'go', 'cs']; -module.exports = {commandMap, supportedLanguages} \ No newline at end of file +module.exports = {commandMap, supportedLanguages} From 20cdb2f3c1cb48ea2b172301244acc70d3983aeb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?L=C3=86S?= Date: Sun, 27 Oct 2024 08:19:13 +0530 Subject: [PATCH 15/29] chore: add auth type NONE --- .choreo/component.yaml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.choreo/component.yaml b/.choreo/component.yaml index 527a4a4..f126678 100644 --- a/.choreo/component.yaml +++ b/.choreo/component.yaml @@ -21,3 +21,7 @@ endpoints: port: 3000 networkVisibilities: - Public + +configuration: + auth: + type: NONE From aa1f0e26202d81561cde8a0f97a15b9bd02f4e7e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?L=C3=86S?= Date: Sun, 27 Oct 2024 08:22:03 +0530 Subject: [PATCH 16/29] chore: use the right endpoint names --- .choreo/component.yaml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.choreo/component.yaml b/.choreo/component.yaml index f126678..8835e9c 100644 --- a/.choreo/component.yaml +++ b/.choreo/component.yaml @@ -6,7 +6,7 @@ description: Service for code execution and supported language retrieval. type: REST endpoints: - - name: execute_code + - name: root type: REST service: basePath: / @@ -14,7 +14,7 @@ endpoints: networkVisibilities: - Public - - name: get_supported_languages + - name: list type: REST service: basePath: /list From d1d62a539faeb89830890b51c9e829b81d54db84 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?L=C3=86S?= Date: Sun, 27 Oct 2024 12:54:49 +0530 Subject: [PATCH 17/29] fix: use older version of choreo manifest --- .choreo/component.yaml | 29 +++++++---------------------- 1 file changed, 7 insertions(+), 22 deletions(-) diff --git a/.choreo/component.yaml b/.choreo/component.yaml index 8835e9c..5c3b471 100644 --- a/.choreo/component.yaml +++ b/.choreo/component.yaml @@ -1,27 +1,12 @@ -schemaVersion: 1.0 -name: codex-api -version: 1.0.0 -displayName: CodeX API -description: Service for code execution and supported language retrieval. -type: REST - +version: 0.1 endpoints: - name: root + port: 3000 type: REST - service: - basePath: / - port: 3000 - networkVisibilities: - - Public - + networkVisibility: Public + context: / - name: list + port: 3000 type: REST - service: - basePath: /list - port: 3000 - networkVisibilities: - - Public - -configuration: - auth: - type: NONE + networkVisibility: Public + context: /list From 36333dba61f34c7a15887955a0049ac4cc9cfbd1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?L=C3=86S?= Date: Sun, 27 Oct 2024 12:57:06 +0530 Subject: [PATCH 18/29] chore: rename component.yaml to endpoints.yaml --- .choreo/{component.yaml => endpoints.yaml} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename .choreo/{component.yaml => endpoints.yaml} (100%) diff --git a/.choreo/component.yaml b/.choreo/endpoints.yaml similarity index 100% rename from .choreo/component.yaml rename to .choreo/endpoints.yaml From ebc326548608f2afe9164563e91f69d8d84f3214 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?L=C3=86S?= Date: Sun, 27 Oct 2024 13:14:30 +0530 Subject: [PATCH 19/29] fix: fix broken instructions --- src/run-code/instructions.js | 29 +++++++++++++---------------- 1 file changed, 13 insertions(+), 16 deletions(-) diff --git a/src/run-code/instructions.js b/src/run-code/instructions.js index 8d1cd4d..27e104b 100644 --- a/src/run-code/instructions.js +++ b/src/run-code/instructions.js @@ -9,7 +9,7 @@ const commandMap = (jobID, language) => { return { executeCodeCommand: 'java', executionArgs: [ - join(process.cwd(), `${CODES_DIR}/${jobID}.java`) + `${CODES_DIR}/${jobID}.java` ], compilerInfoCommand: 'java --version' }; @@ -17,11 +17,11 @@ const commandMap = (jobID, language) => { return { compileCodeCommand: 'g++', compilationArgs: [ - join(process.cwd(), `${CODES_DIR}/${jobID}.cpp`), + `${CODES_DIR}/${jobID}.cpp`, '-o', - join(process.cwd(), `${OUTPUTS_DIR}/${jobID}.out`) + `${OUTPUTS_DIR}/${jobID}.out` ], - executeCodeCommand: join(process.cwd(), `outputs/${jobID}.out`), + executeCodeCommand: `${OUTPUTS_DIR}/${jobID}.out`, outputExt: 'out', compilerInfoCommand: 'g++ --version' }; @@ -29,7 +29,7 @@ const commandMap = (jobID, language) => { return { executeCodeCommand: 'python3', executionArgs: [ - join(process.cwd(), `${CODES_DIR}/${jobID}.py`) + `${CODES_DIR}/${jobID}.py` ], compilerInfoCommand: 'python3 --version' } @@ -37,11 +37,11 @@ const commandMap = (jobID, language) => { return { compileCodeCommand: 'gcc', compilationArgs: [ - join(process.cwd(), `${CODES_DIR}/${jobID}.c`), + `${CODES_DIR}/${jobID}.c`, '-o', - join(process.cwd(), `${OUTPUTS_DIR}/${jobID}.out`) + `${OUTPUTS_DIR}/${jobID}.out` ], - executeCodeCommand: join(process.cwd(), `outputs/${jobID}.out`), + executeCodeCommand: `${OUTPUTS_DIR}/${jobID}.out`, outputExt: 'out', compilerInfoCommand: 'gcc --version' } @@ -49,7 +49,7 @@ const commandMap = (jobID, language) => { return { executeCodeCommand: 'node', executionArgs: [ - join(process.cwd(), `${CODES_DIR}/${jobID}.js`) + `${CODES_DIR}/${jobID}.js` ], compilerInfoCommand: 'node --version' } @@ -58,7 +58,7 @@ const commandMap = (jobID, language) => { executeCodeCommand: 'go', executionArgs: [ 'run', - join(process.cwd(), `${CODES_DIR}/${jobID}.go`) + `${CODES_DIR}/${jobID}.go` ], compilerInfoCommand: 'go version' } @@ -66,15 +66,12 @@ const commandMap = (jobID, language) => { return { compileCodeCommand: 'mcs', compilationArgs: [ - `-out:${join( - process.cwd(), - `outputs/${jobID}` - )}.exe`, - `${join(process.cwd(), `${CODES_DIR}/${jobID}.cs`)}`, + `-out:`${OUTPUTS_DIR}/${jobID}`.exe`, + `${CODES_DIR}/${jobID}.cs`, ], executeCodeCommand: 'mono', executionArgs: [ - `${join(process.cwd(), `${OUTPUTS_DIR}/${jobID}`)}.exe` + `${OUTPUTS_DIR}/${jobID}.exe` ], outputExt: 'exe', compilerInfoCommand: 'mcs --version' From a46a587b22103cde70acfe323555cc8d8294f6df Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?L=C3=86S?= Date: Sun, 27 Oct 2024 13:15:13 +0530 Subject: [PATCH 20/29] fix: remove extra back ticks --- src/run-code/instructions.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/run-code/instructions.js b/src/run-code/instructions.js index 27e104b..d20a45c 100644 --- a/src/run-code/instructions.js +++ b/src/run-code/instructions.js @@ -66,7 +66,7 @@ const commandMap = (jobID, language) => { return { compileCodeCommand: 'mcs', compilationArgs: [ - `-out:`${OUTPUTS_DIR}/${jobID}`.exe`, + `-out:${OUTPUTS_DIR}/${jobID}.exe`, `${CODES_DIR}/${jobID}.cs`, ], executeCodeCommand: 'mono', From 0e3a11671e07cec23c45bd859134215de64da532 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?L=C3=86S?= Date: Sun, 27 Oct 2024 14:42:28 +0530 Subject: [PATCH 21/29] fix: remove extra endpoint --- .choreo/endpoints.yaml | 5 ----- 1 file changed, 5 deletions(-) diff --git a/.choreo/endpoints.yaml b/.choreo/endpoints.yaml index 5c3b471..2b4b727 100644 --- a/.choreo/endpoints.yaml +++ b/.choreo/endpoints.yaml @@ -5,8 +5,3 @@ endpoints: type: REST networkVisibility: Public context: / - - name: list - port: 3000 - type: REST - networkVisibility: Public - context: /list From 2502d7258433f224df8ac6302a71c99ec9d2c8dd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?L=C3=86S?= Date: Sun, 27 Oct 2024 17:11:58 +0530 Subject: [PATCH 22/29] feat: add uptime status badge to readme --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index eb6e86f..28fef36 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,7 @@ # CodeX API +![CodeX](https://cronitor.io/badges/H2ppWF/production/F7bEkD7FFEXp0uypGbzlGEUtkzk.svg) + > This API is still in very early stages of development. So consider not using the API in production since things might change in the future. ### Introducing the new CodeX API From a39035665b4c91f88533afd2c42f2644de9633ae Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?L=C3=86S?= Date: Sun, 27 Oct 2024 18:03:25 +0530 Subject: [PATCH 23/29] chore: add choreo credit to readme --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 28fef36..e5590a8 100644 --- a/README.md +++ b/README.md @@ -123,6 +123,6 @@ This endpoint allows you to list all languages supported and their versions. } ``` -> This API is deployed on a free instance on [render](https://render.com/) so shoutout to render for providing a platform that helped bringing back the CodeX API after a long down time. Since I am using a free tier, the API might be slow sometimes, so please be patient while I try to fund this project. +> This API is deployed on a free instance on [choreo](https://choreo.dev/) so shoutout to @wso2 for providing a platform that helped bringing back the CodeX API after a long down time. Since I am using a free tier, the API might be slow sometimes, so please be patient while I try to fund this project. Happy hacking! From 6225682a8f8ccbc16127f0f506660d0cb67cb3ed Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?L=C3=86S?= Date: Sun, 27 Oct 2024 21:14:55 +0530 Subject: [PATCH 24/29] fix: expose port 8080 instead of 3000 for autoscale --- Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index 53c1906..49770e8 100644 --- a/Dockerfile +++ b/Dockerfile @@ -26,7 +26,7 @@ WORKDIR /app RUN npm install # Expose the application port -EXPOSE 3000 +EXPOSE 8080 # Start the application CMD ["npm", "start"] From ad75d6ae7fa9289b474a4414be32ea9ab80442ca Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?L=C3=86S?= Date: Sun, 27 Oct 2024 21:15:31 +0530 Subject: [PATCH 25/29] fix: set default port as 8080 instead of 3000 ...for autoscaling --- src/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/index.js b/src/index.js index 1dd18d7..6ddc5f7 100644 --- a/src/index.js +++ b/src/index.js @@ -4,7 +4,7 @@ const {supportedLanguages} = require("./run-code/instructions"); const express = require("express"); const bodyParser = require("body-parser"); const app = express(); -const port = process.env.PORT || 3000; +const port = process.env.PORT || 8080; const cors = require("cors"); const {info} = require("./run-code/info"); From ebbb0077efd666d748009a568b263dfd0f0f824e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?L=C3=86S?= Date: Sun, 27 Oct 2024 21:16:08 +0530 Subject: [PATCH 26/29] fix: set choreo endpoint port to 8080 instead of 3000 ...for autoscaling instance --- .choreo/endpoints.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.choreo/endpoints.yaml b/.choreo/endpoints.yaml index 2b4b727..4874171 100644 --- a/.choreo/endpoints.yaml +++ b/.choreo/endpoints.yaml @@ -1,7 +1,7 @@ version: 0.1 endpoints: - name: root - port: 3000 + port: 8080 type: REST networkVisibility: Public context: / From 5077aa4ae9eef61753deb24e63685dacf0b81824 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?L=C3=86S?= Date: Sun, 29 Dec 2024 00:09:23 +0530 Subject: [PATCH 27/29] add: trivyignore to fix build failures --- .trivyignore | 1 + 1 file changed, 1 insertion(+) create mode 100644 .trivyignore diff --git a/.trivyignore b/.trivyignore new file mode 100644 index 0000000..72e8ffc --- /dev/null +++ b/.trivyignore @@ -0,0 +1 @@ +* From 3ba178113b8ea64602bd16a68bba93b805fa9871 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?L=C3=86S?= Date: Sat, 1 Feb 2025 22:59:13 +0530 Subject: [PATCH 28/29] fix: docker read-only issue on choreo --- Dockerfile | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/Dockerfile b/Dockerfile index 49770e8..d6690d6 100644 --- a/Dockerfile +++ b/Dockerfile @@ -6,24 +6,31 @@ ENV PYTHON_PIP_VERSION 20.1 ENV DEBIAN_FRONTEND noninteractive ENV NODE_VERSION 16 -# Update and install dependencies, including Node 16 directly +# Update and install dependencies RUN apt-get update && apt-get -y install gcc mono-mcs golang-go \ default-jre default-jdk python3-pip python3 curl && \ curl -fsSL https://deb.nodesource.com/setup_16.x | bash - && \ + apt-get update && \ apt-get install -y nodejs && \ rm -rf /var/lib/apt/lists/* -# Verify that Node 16 is installed +# Verify that Node.js is installed RUN node -v && npm -v # Create a non-root user with a UID between 10000 and 20000 RUN useradd -m -u 10001 appuser -USER 10001 -# Copy application code and set up the working directory -COPY --chown=appuser:appuser . /app +# Set up the working directory with correct permissions WORKDIR /app -RUN npm install +COPY . /app +RUN chown -R appuser:appuser /app + +# Temporarily switch to root to run npm install +USER root +RUN npm install --unsafe-perm + +# Switch back to non-root user +USER appuser # Expose the application port EXPOSE 8080 From e32c7a33c7c165263ea1302006d0fd83f5082334 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?L=C3=86S?= Date: Sun, 2 Feb 2025 01:23:36 +0530 Subject: [PATCH 29/29] fix: build failure --- Dockerfile | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Dockerfile b/Dockerfile index d6690d6..67c2ec3 100644 --- a/Dockerfile +++ b/Dockerfile @@ -20,6 +20,9 @@ RUN node -v && npm -v # Create a non-root user with a UID between 10000 and 20000 RUN useradd -m -u 10001 appuser +# Verify that the user is set correctly +RUN id -u appuser + # Set up the working directory with correct permissions WORKDIR /app COPY . /app