diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 99734f7d80f21d38734268ec55c1f0fe705d0582..34d91e32768af1ce2f76d7851e66a3d6d693c00b 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -17,8 +17,6 @@ build: services: - docker:18.09.6-dind script: - # setup config for extension - - cp -rf ./deadlock-plugins/deadlock-extension/src/core/config.prod.ts ./deadlock-plugins/deadlock-extension/src/core/config.ts - ./build.sh - docker login -u gitlab-ci-token -p $CI_JOB_TOKEN registry.e-biz.fr - docker build . -t $CI_REGISTRY_IMAGE diff --git a/Dockerfile b/Dockerfile index f0f98e21c77e48a85c8f47dcad441efd178f295e..29b766a6c02467c88711bc7a18282c7150eab1a6 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,4 @@ -FROM registry.e-biz.fr/deadlock-public/theia:1.20 +FROM registry.e-biz.fr/deadlock-public/theia:1.201 USER root diff --git a/build-plugins.sh b/build-plugins.sh index cd04431c78d85f34d799d70216b1a54330e42f00..d3f7861fbd6ee93c4508398e831fab7660f06dd6 100755 --- a/build-plugins.sh +++ b/build-plugins.sh @@ -5,7 +5,11 @@ set -e CI_COMMIT_SHORT_SHA=${CI_COMMIT_SHORT_SHA:-local} for dir in deadlock-plugins/*/; do + echo + echo "===============================================" echo "Building $dir" + echo "===============================================" + echo cd $dir CURRENT_PLUGIN_DIR=$(basename "$PWD") ./install.sh diff --git a/deadlock-plugins/deadlock-extension/src/core/config.ts b/deadlock-plugins/deadlock-extension/src/core/config.ts index ba0d19723574f6949a39947d5b72f391b2e524df..c99f4e45c5393af1b13793dd5182caa51f138b13 100644 --- a/deadlock-plugins/deadlock-extension/src/core/config.ts +++ b/deadlock-plugins/deadlock-extension/src/core/config.ts @@ -1,19 +1,32 @@ import * as path from 'path'; +import * as os from 'os'; -// DEV CONFIG +const homeDir = os.homedir(); +// if we are on container, means the directory will depend differently +const onContainer = homeDir.includes('theia') || homeDir.includes('root'); -if (!process.env['HOME']) { - console.error('Could not get home user.'); -} +const deadlockExtensionPath = path.join(homeDir, 'deadlock-extension'); -const home = process.env['HOME'] ?? ''; +export const PROJECT_SRC_PATH = onContainer + ? '/project' + : path.join(homeDir, 'deadlock-extension', '/project'); -export const DEADLOCK_EXTENSION_PATH = path.join(home, 'deadlock-extension'); -export const DOCS_PATH = path.join(DEADLOCK_EXTENSION_PATH, 'docs'); -export const CONFIG_PATH = path.join(DEADLOCK_EXTENSION_PATH, 'config'); -export const USER_CHALLENGE_PATH = path.join(CONFIG_PATH, 'user-challenge.json'); -export const PROJECT_SRC_PATH = path.join(DEADLOCK_EXTENSION_PATH, 'project'); -export const PROJECT_THEIA_PATH = path.join(DEADLOCK_EXTENSION_PATH, 'project-theia'); +export const PROJECT_THEIA_PATH = onContainer + ? path.join('/home/project') + : path.join(deadlockExtensionPath, 'project-theia'); +export const DOCS_PATH = path.join( + path.join(onContainer ? '/home/theia' : deadlockExtensionPath), + 'docs' +); -export const BRIEFING_FILE_NAME = 'briefing.md'; \ No newline at end of file +export const CONFIG_PATH = onContainer + ? '/home/config/' + : path.join(deadlockExtensionPath, 'config'); + +export const USER_CHALLENGE_PATH = path.join( + CONFIG_PATH, + 'user-challenge.json' +); + +export const BRIEFING_FILE_NAME = 'briefing.md'; diff --git a/deadlock-plugins/deadlock-extension/src/core/userConfig.ts b/deadlock-plugins/deadlock-extension/src/core/userConfig.ts index bf4ab4f4ce9969424394018d36e4d4eca7d2d492..34fa4c07bc1786738bb9e045a658e2f9a8987e81 100644 --- a/deadlock-plugins/deadlock-extension/src/core/userConfig.ts +++ b/deadlock-plugins/deadlock-extension/src/core/userConfig.ts @@ -16,6 +16,8 @@ * } */ +import { error } from '../recorder/utils'; + export interface UserDetails { firstName: string; lastName: string; @@ -74,7 +76,7 @@ export default abstract class UserConfig { return this.userConfigJson?.remoteUserDetails; } - abstract async loadText(): Promise<string>; + abstract loadText(): Promise<string>; public async init() { try { @@ -83,8 +85,8 @@ export default abstract class UserConfig { this.userConfigJson = JSON.parse(userConfig); return Promise.resolve(); } catch (e) { - console.error('Cannot load userConfig'); - console.error(e); + error('Cannot load userConfig'); + error(e); return Promise.reject(); } } diff --git a/deadlock-plugins/deadlock-extension/src/extension.ts b/deadlock-plugins/deadlock-extension/src/extension.ts index 0e984fe8eedf83e783d686821761fb2b7ca0bf4e..1840979df272bee60ea44bb886bb783f5eabcbee 100644 --- a/deadlock-plugins/deadlock-extension/src/extension.ts +++ b/deadlock-plugins/deadlock-extension/src/extension.ts @@ -3,6 +3,7 @@ import { DepNodeProvider } from './theia/deadlockPanel'; import BriefingView, { BRIEFING_ID } from './view/briefingView'; import { OPEN_BRIEFING_COMMAND } from './theia/command'; import UserConfigTheia from './theia/userConfigTheia'; +import { error } from './recorder/utils'; export function initViews() { new BriefingView(); @@ -16,7 +17,7 @@ export async function activate(context: vscode.ExtensionContext) { try { await userConfig.init(); } catch (e) { - console.error('Cannot init userConfig'); + error('Cannot init userConfig'); } initViews(); diff --git a/deadlock-plugins/deadlock-extension/src/recorder/index.ts b/deadlock-plugins/deadlock-extension/src/recorder/index.ts index fc876d2bd433bd08f17dff4afca352dc23d49eeb..0c3b2f4fb93db23a51145554b72e066aee6c5a9b 100644 --- a/deadlock-plugins/deadlock-extension/src/recorder/index.ts +++ b/deadlock-plugins/deadlock-extension/src/recorder/index.ts @@ -1,43 +1,63 @@ -import CommandRecorder from "./command-recorder" +import CommandRecorder from './command-recorder'; import GitMission from '../core/gitMission'; -import UserConfigNode from "./userConfigNode"; +import UserConfigNode from './userConfigNode'; import { PROJECT_SRC_PATH, PROJECT_THEIA_PATH } from '../core/config'; -import { copyProjectSources, clearFilesExceptGit, log } from "./utils"; +import { copyProjectSources, clearFilesExceptGit, log, error } from './utils'; +import UserConfig from '../core/userConfig'; export default class Recorder { + async setupProject(userConfig: UserConfig, gitMission?: GitMission) { + log('Setup user project..'); + + if (!userConfig.isProfessor()) { + await copyProjectSources(PROJECT_SRC_PATH, PROJECT_THEIA_PATH, ['.git/']); + if (gitMission) { + log('Starting CommandRecorder..'); + new CommandRecorder(gitMission).run(); + } else { + error('Cannot start command recorder, gitMission not found'); + } + } else { + await copyProjectSources(PROJECT_SRC_PATH, PROJECT_THEIA_PATH); + } + } + + async setupFromRemoteRepo(gitMission: GitMission) { + log('Check if remote repo exist'); + const isRemoteRepoExist = await gitMission.isRemoteRepoExist(); + if (isRemoteRepoExist) { + // rm all except git directory pull remote code and setup + log('Cleaning files to pull repo'); + + await clearFilesExceptGit(PROJECT_SRC_PATH); + + log('Pulling user repo'); + await gitMission.pull(); + } + } + async run() { const userConfig = new UserConfigNode(); + let gitMission; + try { log('Init User config'); await userConfig.init(); log('Init GitMission'); - const gitMission = await new GitMission(userConfig).init(); - log('Check if remote repo exist'); - const isRemoteRepoExist = await gitMission.isRemoteRepoExist(); - if (isRemoteRepoExist) { - // rm all except git directory pull remote code and setup - log('Cleaning files to pull repo'); - - await clearFilesExceptGit(PROJECT_SRC_PATH); - - log('Pulling user repo'); - await gitMission.pull(); - } - log('Setup user project..'); - - if (!userConfig.isProfessor()) { - await copyProjectSources(PROJECT_SRC_PATH, PROJECT_THEIA_PATH, ['.git/']); - log('Starting CommandRecorder..'); - new CommandRecorder(gitMission).run(); - } else { - await copyProjectSources(PROJECT_SRC_PATH, PROJECT_THEIA_PATH); - } + gitMission = await new GitMission(userConfig).init(); + await this.setupFromRemoteRepo(gitMission); + } catch (e) { + error('Cannot setup user repo.'); + error(e); + } + try { + await this.setupProject(userConfig, gitMission); } catch (e) { - console.error('Cannot setup user repo.'); - console.error(e); + error('Error while setup project sources'); + error(e); } } } diff --git a/deadlock-plugins/deadlock-extension/src/recorder/utils.ts b/deadlock-plugins/deadlock-extension/src/recorder/utils.ts index 88e8e126a48cc3809638aa6c73ef2bad62a306e6..b5eff5aef50a53ed2bd718cc75347bc166e0b183 100644 --- a/deadlock-plugins/deadlock-extension/src/recorder/utils.ts +++ b/deadlock-plugins/deadlock-extension/src/recorder/utils.ts @@ -12,22 +12,27 @@ const Path = require('path'); const PREFIX = '[DEADLOCK-RECORDER]'; -export const log = (message, args?) => { +export const log = (message: any, args?: any[]) => { if (args) { console.log(`${PREFIX} ${message}`, args); } else { console.log(`${PREFIX} ${message}`); } -} -export const error = (message, args?) => { +}; + +export const error = (message: any, args?: any[]) => { if (args) { console.error(`${PREFIX} ${message}`, args); } else { console.error(`${PREFIX} ${message}`); } -} +}; -export async function copyProjectSources(srcPath: string, theiaPath: string, excludes: Array<string> = []) { +export async function copyProjectSources( + srcPath: string, + theiaPath: string, + excludes: Array<string> = []) +{ const excludeCmd = excludes.map((current) => `--exclude ${current}`).join(' '); return exec(`rsync -a ${srcPath}/ ${theiaPath} ${excludeCmd} && chown -R theia:theia /home/project`); }