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
38 changes: 19 additions & 19 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"publisher": "OceanProtocol",
"displayName": "Ocean Nodes VS Code Extension",
"description": "Easily publish assets and test your algorithms with the official Ocean Protocol vscode extension.",
"version": "0.1.4",
"version": "0.1.5",
"engines": {
"vscode": "^1.96.0"
},
Expand Down Expand Up @@ -99,7 +99,7 @@
"@libp2p/tcp": "^10.0.7",
"@libp2p/websockets": "^9.0.6",
"@multiformats/multiaddr": "^12.3.1",
"@oceanprotocol/lib": "^5.0.3",
"@oceanprotocol/lib": "^5.0.4",
"chai": "^4.3.10",
"cross-fetch": "^4.0.0",
"crypto": "^1.0.1",
Expand Down
27 changes: 26 additions & 1 deletion src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,20 @@ export async function activate(context: vscode.ExtensionContext) {
}
})

const envContent = await checkAndReadFile(algorithmDir, '.env')
const envVars: Record<string, string> = {}
if (envContent) {
envContent.split('\n').forEach(line => {
const trimmed = line.trim()
if (trimmed && !trimmed.startsWith('#')) {
const idx = trimmed.indexOf('=')
if (idx > 0) {
envVars[trimmed.substring(0, idx).trim()] = trimmed.substring(idx + 1).trim()
}
}
})
}

const computeResponse = await computeStart(
config,
algorithmContent,
Expand All @@ -228,7 +242,8 @@ export async function activate(context: vscode.ExtensionContext) {
dockerImage,
dockerTag,
dockerfile,
additionalDockerFiles
additionalDockerFiles,
envVars
)
console.log('Compute result received:', computeResponse)
const jobId = computeResponse.jobId
Expand Down Expand Up @@ -271,6 +286,16 @@ export async function activate(context: vscode.ExtensionContext) {
)
}

if (status?.terminationDetails?.OOMKilled === true) {
const errorMessage = `Job failed: Out of memory. Exit code: ${status?.terminationDetails?.exitCode}`
vscode.window.showErrorMessage(errorMessage)
computeLogsChannel.appendLine(errorMessage)
savedJobId = null
provider.sendMessage({ type: 'jobStopped' })

return;
}

if (
status.statusText.toLowerCase().includes('error') ||
status.statusText.toLowerCase().includes('failed')
Expand Down
14 changes: 9 additions & 5 deletions src/helpers/compute.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,11 @@
}
}

if (dockerImage && dockerTag) {
if (dockerImage) {
return {
image: dockerImage,
tag: dockerTag,
entrypoint: fileExtension === 'py' ? 'python $ALGO' : 'node $ALGO',
tag: dockerTag || 'latest',
entrypoint: fileExtension === 'py' ? 'python $ALGO' : fileExtension === 'js' ? 'node $ALGO' : '',
dockerfile,
additionalDockerFiles,
checksum: '',
Expand All @@ -65,7 +65,7 @@
checksum: ''
}
default:
throw new Error('File extension not supported')
throw new Error('Cannot start job. Do you have a .py/.js file or a docker image in Setup section?')
}
}

Expand Down Expand Up @@ -129,6 +129,9 @@
dockerfile?: string,
additionalDockerFiles?: {
[key: string]: string
},
envVars?: {
[key: string]: string
}
): Promise<ComputeJob> {
try {
Expand All @@ -138,7 +141,8 @@
meta: {
rawcode: algorithmContent,
container
}
},
envs: envVars
}

if (!config.environmentId) {
Expand Down Expand Up @@ -399,5 +403,5 @@
}
}

throw lastError!

Check warning on line 406 in src/helpers/compute.ts

View workflow job for this annotation

GitHub Actions / test

Expected an error object to be thrown
}
36 changes: 35 additions & 1 deletion src/helpers/project-data.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,16 @@
import * as fs from 'fs'
import * as path from 'path'

export const projectFileNames = [
'.env',
'algo.py',
'algo.js',
'Dockerfile',
'requirements.txt',
'package.json',
'algo.placeholder',
]

export const dockerfilePy = `
FROM ubuntu:24.04

Expand Down Expand Up @@ -96,9 +106,25 @@ export const packageJsonJs = `
}
`

export const algoPlaceholder = `
# This is a placeholder algorithm file. No changes are needed here.
# You need to setup the 'Docker image' and 'Docker tag' in the Setup section.
# Example:
# Docker image: oceanprotocol/c2d_examples
# Docker tag: py-general
`

export const envTemplate = `# Environment variables for compute job
# Add your environment variables here (one per line)
# Example:
# API_KEY=your_api_key_here
# DEBUG=true
`

export enum Language {
PYTHON = 'Python',
JAVASCRIPT = 'JavaScript'
JAVASCRIPT = 'JavaScript',
DOCKER_IMAGE = 'Docker Image'
}

export function getAvailableLanguages(): string[] {
Expand All @@ -123,6 +149,14 @@ export function getLanguageTemplates(language: Language) {
algorithmFileName: 'algo.js',
dependenciesFileName: 'package.json'
}
case Language.DOCKER_IMAGE:
return {
dockerfile: null,
algorithm: algoPlaceholder,
dependencies: null,
algorithmFileName: 'algo.placeholder',
dependenciesFileName: null
}
default:
throw new Error(`Unsupported language: ${language}`)
}
Expand Down
25 changes: 12 additions & 13 deletions src/viewProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import * as vscode from 'vscode'
import * as fs from 'fs'
import * as path from 'path'
import { SelectedConfig } from './types'
import { Language, getAvailableLanguages, getLanguageTemplates, detectProjectType } from './helpers/project-data'
import { Language, getAvailableLanguages, getLanguageTemplates, detectProjectType, envTemplate, projectFileNames } from './helpers/project-data'

export class OceanProtocolViewProvider implements vscode.WebviewViewProvider {
public static readonly viewType = 'oceanProtocolExplorer'
Expand Down Expand Up @@ -35,7 +35,7 @@ export class OceanProtocolViewProvider implements vscode.WebviewViewProvider {
private async closeOldProjectTabs() {
try {
const openEditors = vscode.window.tabGroups.all.flatMap(group => group.tabs)
const projectFileNames = ['algo.py', 'algo.js', 'Dockerfile', 'requirements.txt', 'package.json']


for (const tab of openEditors) {
if (tab.input instanceof vscode.TabInputText) {
Expand All @@ -53,15 +53,8 @@ export class OceanProtocolViewProvider implements vscode.WebviewViewProvider {

private async openProjectFiles(projectPath: string) {
try {
const projectFiles = [
'Dockerfile',
'algo.py',
'requirements.txt',
'algo.js',
'package.json'
]

const fileChecks = projectFiles.map(async (fileName) => {

const fileChecks = projectFileNames.map(async (fileName) => {
const filePath = path.join(projectPath, fileName)
const exists = await fs.promises.access(filePath).then(() => true).catch(() => false)
return { fileName, filePath, exists }
Expand Down Expand Up @@ -188,10 +181,16 @@ export class OceanProtocolViewProvider implements vscode.WebviewViewProvider {

const templates = getLanguageTemplates(language as Language)

await fs.promises.writeFile(path.join(projectPath, 'Dockerfile'), templates.dockerfile)
await fs.promises.writeFile(path.join(projectPath, templates.dependenciesFileName), templates.dependencies)
if (templates.dockerfile) {
await fs.promises.writeFile(path.join(projectPath, 'Dockerfile'), templates.dockerfile)
}
if (templates.dependencies && templates.dependenciesFileName) {
await fs.promises.writeFile(path.join(projectPath, templates.dependenciesFileName), templates.dependencies)
}
await fs.promises.writeFile(path.join(projectPath, templates.algorithmFileName), templates.algorithm)

await fs.promises.writeFile(path.join(projectPath, '.env'), envTemplate)

const resultsPath = path.join(projectPath, 'results')
await fs.promises.mkdir(resultsPath, { recursive: true })

Expand Down