Skip to content

Commit 98d7e5f

Browse files
committed
feat: build compose
1 parent 6febc20 commit 98d7e5f

4 files changed

Lines changed: 49 additions & 40 deletions

File tree

solution/build_solution.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -368,8 +368,8 @@ def main(solution_file, out_path, git=None):
368368

369369
generated_roles_file = os.path.join(out_path,"generated-roles.json")
370370
system_roles_file = os.path.join(file_path,"roles-data.json")
371-
generate_role_fixtures(generated_roles_file, system_roles_file, out_path)
372-
generate_menu_fixtures(out_path)
371+
#generate_role_fixtures(generated_roles_file, system_roles_file, out_path)
372+
#generate_menu_fixtures(out_path)
373373
print("Processing completed.")
374374

375375
def get_absolute_path(file_path, path=None):

solution/compose.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
include:
2+
- path: compose.base.yml
3+
- path: compose.mssql.yml
4+
- path: compose.postgresql.yml
5+
- path: compose.openSearch.yml
6+
- path: compose.cache.yml

solutionBuilder.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -241,6 +241,21 @@ async function mergeAndSortFixtures(inputFiles, output) {
241241
return output;
242242
}
243243

244+
function transformComposeContent(composeContent) {
245+
let object = {'include': []}
246+
// Iterate through each key in the composeContent object
247+
for (const [key, value] of Object.entries(composeContent)) {
248+
const line = {'path': value.path};
249+
// Handle env_file section
250+
if (value.env_file && value.env_file.length > 0) {
251+
line['env_file'] = [...value.env_file];
252+
}
253+
object['include'].push(line)
254+
}
255+
256+
return object;
257+
}
258+
244259
async function processSolutions(
245260
solutionFile,
246261
directoryPath,
@@ -325,6 +340,10 @@ async function processSolutions(
325340
]
326341
};
327342
}
343+
if(services){
344+
output['compose.yml'] = transformComposeContent(services);
345+
}
346+
328347
if(PIPModules.size>0){
329348
output['be-openimis.json'] ={"modules": [...PIPModules]};
330349
}

workbench.js

Lines changed: 22 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -123,30 +123,11 @@ async function ensureDistDkrRepo(branch = 'develop') {
123123
console.log(`🔀 Checking out branch '${branch}'`);
124124
await git.checkout(branch);
125125
}
126+
git.pull();
126127

127128
return distDkrRepoPath;
128129
}
129130

130-
// Generate the compose.yml based on the solutionName or any specific config
131-
function generateComposeYml(solutionName) {
132-
const composeConfig = {
133-
include: [
134-
{ path: 'compose.base.yml' },
135-
{ path: `compose.mssql.yml` },
136-
{ path: `compose.postgresql.yml` },
137-
{ path: 'compose.openSearch.yml' },
138-
{ path: 'compose.cache.yml' }
139-
]
140-
};
141-
142-
const composeContent = yaml.dump(composeConfig);
143-
const composeFilePath = path.resolve(`./solution/compose.yml`);
144-
145-
// Write the generated compose.yml to the solution directory
146-
fs.writeFileSync(composeFilePath, composeContent, 'utf8');
147-
console.log(`✔️ Generated compose.yml for solution: ${solutionName}`);
148-
return composeFilePath;
149-
}
150131

151132
// Get the paths from compose.yml
152133
function getComposeFilePaths(composePath) {
@@ -167,30 +148,19 @@ function getComposeFilePaths(composePath) {
167148
}
168149

169150
// Copy files defined in compose.yml from the dist-dkr repo
170-
async function copyDistDkrAssetsFromCompose(composeFilePath, branch = 'develop') {
171-
if (!fs.existsSync(composeFilePath)) {
172-
console.warn('⚠️ compose.yml not found in the solution folder, skipping...');
173-
return {};
174-
}
151+
async function copyDistDkrAssetsFromCompose(composeContent, branch = 'develop') {
152+
153+
// Read and parse the compose content to get the file paths
175154

176-
// Read and parse the compose.yml to get the file paths
177-
const composeFile = fs.readFileSync(composeFilePath, 'utf8');
178-
let composeConfig;
179-
try {
180-
composeConfig = yaml.load(composeFile); // Parse the YAML file
181-
} catch (error) {
182-
console.error('⚠️ Error reading compose.yml', error);
183-
return {};
184-
}
185155

186156
// Ensure dist-dkr repo is cloned and checked out to the right branch
187157
const distDkrRepoPath = await ensureDistDkrRepo(branch);
188158

189159
const outputFiles = {};
190160

191161
// Ensure we are getting the paths from composeConfig
192-
if (composeConfig.include && Array.isArray(composeConfig.include)) {
193-
for (const item of composeConfig.include) {
162+
if (composeContent.include && Array.isArray(composeContent.include)) {
163+
for (const item of composeContent.include) {
194164
if (item.path) {
195165
// Resolve path within dist-dkr repo
196166
const filePath = item.path.replace('${DB_DEFAULT:-postgresql}', 'postgresql'); // Resolve dynamic paths
@@ -209,7 +179,22 @@ async function copyDistDkrAssetsFromCompose(composeFilePath, branch = 'develop')
209179
console.warn(`⚠️ File ${item.path} not found at path: ${srcPath}`);
210180
}
211181
}
182+
// Handle env files and their .example equivalents
183+
if (item.env_file && Array.isArray(item.env_file)) {
184+
for (const envFile of item.env_file) {
185+
// Process the .env file itself
186+
const envSrcPath = path.join(distDkrRepoPath, envFile + '.example');
187+
if (fs.existsSync(envSrcPath)) {
188+
const envContent = fs.readFileSync(envSrcPath, 'utf8');
189+
outputFiles[envFile] = envContent;
190+
console.log(`✔️ Copied ${envFile} from dist-dkr`);
191+
} else {
192+
console.warn(`⚠️ File ${envFile} not found at path: ${envSrcPath}`);
193+
}
194+
}
195+
}
212196
}
197+
213198
} else {
214199
console.warn('⚠️ No include array found in compose.yml.');
215200
}
@@ -269,7 +254,6 @@ async function main() {
269254
const permission = fs.readFileSync('./solution/permissions_map.json', 'utf8');
270255
const permissionMap = JSON.parse(permission);
271256

272-
const composeFilePath = generateComposeYml(solutionName);
273257

274258
const output = await processSolutions(
275259
solution_path,
@@ -278,7 +262,7 @@ async function main() {
278262
);
279263

280264
// Get dist-dkr files from compose.yml and merge them into output
281-
const composeFiles = await copyDistDkrAssetsFromCompose(composeFilePath, 'develop');
265+
const composeFiles = await copyDistDkrAssetsFromCompose(output['compose.yml'], 'develop');
282266
Object.assign(output, composeFiles);
283267

284268
// Create zip

0 commit comments

Comments
 (0)