Skip to content

Commit

Permalink
feat(agora): centralize the task definition build-image (ARCH-307) (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
tschaffter authored Oct 11, 2024
1 parent da04231 commit e2ecb1f
Show file tree
Hide file tree
Showing 8 changed files with 12 additions and 82 deletions.
11 changes: 0 additions & 11 deletions apps/agora/apex/project.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,6 @@
"command": "docker/agora/serve-detach.sh agora-apex"
}
},
"build-image": {
"executor": "@nx-tools/nx-container:build",
"options": {
"context": "apps/agora/apex",
"metadata": {
"images": ["ghcr.io/sage-bionetworks/agora-apex"],
"tags": ["type=edge,branch=main", "type=raw,value=local", "type=sha"]
},
"push": false
}
},
"publish-image": {
"executor": "@nx-tools/nx-container:build",
"options": {
Expand Down
12 changes: 0 additions & 12 deletions apps/agora/api-docs/project.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,18 +30,6 @@
"command": "docker/agora/serve-detach.sh agora-api-docs"
}
},
"build-image": {
"executor": "@nx-tools/nx-container:build",
"options": {
"context": "apps/agora/api-docs",
"metadata": {
"images": ["ghcr.io/sage-bionetworks/agora-api-docs"],
"tags": ["type=edge,branch=main", "type=raw,value=local", "type=sha"]
},
"push": false
},
"dependsOn": ["build"]
},
"publish-image": {
"executor": "@nx-tools/nx-container:build",
"options": {
Expand Down
12 changes: 0 additions & 12 deletions apps/agora/api/project.json
Original file line number Diff line number Diff line change
Expand Up @@ -60,18 +60,6 @@
"fix": true
}
},
"build-image": {
"executor": "@nx-tools/nx-container:build",
"options": {
"context": ".",
"metadata": {
"images": ["ghcr.io/sage-bionetworks/agora-api"],
"tags": ["type=edge,branch=main", "type=raw,value=local", "type=sha"]
},
"push": false
},
"dependsOn": ["build"]
},
"publish-image": {
"executor": "@nx-tools/nx-container:build",
"options": {
Expand Down
12 changes: 0 additions & 12 deletions apps/agora/app/project.json
Original file line number Diff line number Diff line change
Expand Up @@ -156,18 +156,6 @@
},
"defaultConfiguration": "development"
},
"build-image": {
"executor": "@nx-tools/nx-container:build",
"options": {
"context": ".",
"metadata": {
"images": ["ghcr.io/sage-bionetworks/agora-app"],
"tags": ["type=edge,branch=main", "type=raw,value=local", "type=sha"]
},
"push": false
},
"dependsOn": ["server"]
},
"publish-image": {
"executor": "@nx-tools/nx-container:build",
"options": {
Expand Down
16 changes: 0 additions & 16 deletions apps/agora/data/project.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,22 +31,6 @@
"command": "docker/agora/serve-detach.sh {projectName}"
}
},
"build-image": {
"executor": "@nx-tools/nx-container:build",
"options": {
"context": "{projectRoot}",
"metadata": {
"images": ["ghcr.io/sage-bionetworks/{projectName}"],
"tags": [
"type=edge,branch=main",
"type=raw,value=local",
"type=sha",
"type=raw,value=$DATA_FILE.$DATA_VERSION"
]
},
"push": false
}
},
"publish-image": {
"executor": "@nx-tools/nx-container:build",
"options": {
Expand Down
11 changes: 0 additions & 11 deletions apps/agora/mongo/project.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,6 @@
"command": "docker/agora/serve-detach.sh {projectName}"
}
},
"build-image": {
"executor": "@nx-tools/nx-container:build",
"options": {
"context": "apps/agora/mongo",
"metadata": {
"images": ["ghcr.io/sage-bionetworks/{projectName}"],
"tags": ["type=edge,branch=main", "type=raw,value=local", "type=sha"]
},
"push": false
}
},
"publish-image": {
"executor": "@nx-tools/nx-container:build",
"options": {
Expand Down
8 changes: 4 additions & 4 deletions libs/sage-monorepo/nx-plugin/src/plugins/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@ import { buildProjectConfiguration } from './build-project-configuration';
import { ProjectConfigurationBuilderOptions } from './project-configuration-builder-options';
import { inferProjectMetadata } from './project-metadata';

function readProjectCOnfigurationsCache(
function readProjectConfigurationsCache(
cachePath: string,
): Record<string, SageMonorepoProjectConfiguration> {
console.log(`cachePath: ${cachePath}`);
// console.log(`cachePath: ${cachePath}`);
return existsSync(cachePath) ? readJsonFile(cachePath) : {};
}

Expand All @@ -34,7 +34,7 @@ function writeProjectConfigurationsToCache(
writeJsonFile(cachePath, results);
}

const projectFilePattern = '{apps,libs}/openchallenges/**/project.json';
const projectFilePattern = '{apps,libs}/{openchallenges,agora}/**/project.json';

export const createNodesV2: CreateNodesV2<SageMonorepoPluginOptions> = [
projectFilePattern,
Expand All @@ -44,7 +44,7 @@ export const createNodesV2: CreateNodesV2<SageMonorepoPluginOptions> = [

// Reads the cached targets for all the projects
const cachePath = join(workspaceDataDirectory, `sage-monorepo-${optionsHash}.hash`);
const projectConfigurationsCache = readProjectCOnfigurationsCache(cachePath);
const projectConfigurationsCache = readProjectConfigurationsCache(cachePath);
try {
return await createNodesFromFiles(
(configFile, options, context) => {
Expand Down
12 changes: 8 additions & 4 deletions libs/sage-monorepo/nx-plugin/src/plugins/project-metadata.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ function inferProjectType(projectRoot: string): ProjectType {
} else if (projectRoot.startsWith('libs/')) {
return 'library';
}

throw new Error(`Unknown project type for project root: ${projectRoot}`);
}

Expand All @@ -55,16 +56,19 @@ function inferBuilder(
): Builder | null {
if (siblingFiles.includes('poetry.lock')) return 'poetry';
if (siblingFiles.includes('build.gradle')) return 'gradle';
if (
localProjectConfiguration?.targets?.['build']?.executor ===
'@angular-devkit/build-angular:browser'
) {

const executor = localProjectConfiguration?.targets?.['build']?.executor ?? '';
const webpackExecutors = ['@angular-devkit/build-angular:browser', '@nx/webpack:webpack'];

if (webpackExecutors.includes(executor)) {
return 'webpack';
}

return null;
}

function inferContainerType(siblingFiles: string[]): ContainerType | null {
if (siblingFiles.includes('Dockerfile')) return 'Docker';

return null;
}

0 comments on commit e2ecb1f

Please sign in to comment.