Skip to content

Commit

Permalink
Merge pull request #356 from Hubs-Foundation/docker-image-override-su…
Browse files Browse the repository at this point in the history
…pport

Docker image override support
  • Loading branch information
Exairnous authored Sep 10, 2024
2 parents 598a3e3 + 67e6e29 commit 35752a0
Show file tree
Hide file tree
Showing 2 changed files with 89 additions and 0 deletions.
78 changes: 78 additions & 0 deletions community-edition/generate_script/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,82 @@ function generatePersistentVolumes(processedConfig, replacedContent) {
return `${yamlDocuments.map(doc => YAML.stringify(doc, {"lineWidth": 0, "directives": false})).join('---\n')}`;
}

function handleImageOverrides(processedConfig, replacedContent) {
const yamlDocuments = YAML.parseAllDocuments(replacedContent);

// Override the default images with custom ones if specified in the config
yamlDocuments.forEach((doc, index) => {
const jsDoc = doc.toJS();
if (jsDoc.kind === "Deployment") {
if (jsDoc.metadata.name === "reticulum") {
if (processedConfig.OVERRIDE_RETICULUM_IMAGE) {
jsDoc.spec.template.spec.containers[0].image = processedConfig.OVERRIDE_RETICULUM_IMAGE;
if (processedConfig.OVERRIDE_POSTGREST_IMAGE) {
jsDoc.spec.template.spec.containers[1].image = processedConfig.OVERRIDE_POSTGREST_IMAGE;
}
yamlDocuments[index] = new YAML.Document(jsDoc);
}
}
else if (jsDoc.metadata.name === "pgsql") {
if (processedConfig.OVERRIDE_POSTGRES_IMAGE) {
jsDoc.spec.template.spec.containers[0].image = processedConfig.OVERRIDE_POSTGRES_IMAGE;
yamlDocuments[index] = new YAML.Document(jsDoc);
}
}
else if (jsDoc.metadata.name === "pgbouncer" || jsDoc.metadata.name === "pgbouncer-t") {
if (processedConfig.OVERRIDE_PGBOUNCER_IMAGE) {
jsDoc.spec.template.spec.containers[0].image = processedConfig.OVERRIDE_PGBOUNCER_IMAGE;
yamlDocuments[index] = new YAML.Document(jsDoc);
}
}
else if (jsDoc.metadata.name === "hubs") {
if (processedConfig.OVERRIDE_HUBS_IMAGE) {
jsDoc.spec.template.spec.containers[0].image = processedConfig.OVERRIDE_HUBS_IMAGE;
yamlDocuments[index] = new YAML.Document(jsDoc);
}
}
else if (jsDoc.metadata.name === "spoke") {
if (processedConfig.OVERRIDE_SPOKE_IMAGE) {
jsDoc.spec.template.spec.containers[0].image = processedConfig.OVERRIDE_SPOKE_IMAGE;
yamlDocuments[index] = new YAML.Document(jsDoc);
}
}
else if (jsDoc.metadata.name === "nearspark") {
if (processedConfig.OVERRIDE_NEARSPARK_IMAGE) {
jsDoc.spec.template.spec.containers[0].image = processedConfig.OVERRIDE_NEARSPARK_IMAGE;
yamlDocuments[index] = new YAML.Document(jsDoc);
}
}
else if (jsDoc.metadata.name === "photomnemonic") {
if (processedConfig.OVERRIDE_PHOTOMNEMONIC_IMAGE) {
jsDoc.spec.template.spec.containers[0].image = processedConfig.OVERRIDE_PHOTOMNEMONIC_IMAGE;
yamlDocuments[index] = new YAML.Document(jsDoc);
}
}
else if (jsDoc.metadata.name === "dialog") {
if (processedConfig.OVERRIDE_DIALOG_IMAGE) {
jsDoc.spec.template.spec.containers[0].image = processedConfig.OVERRIDE_DIALOG_IMAGE;
yamlDocuments[index] = new YAML.Document(jsDoc);
}
}
else if (jsDoc.metadata.name === "coturn") {
if (processedConfig.OVERRIDE_COTURN_IMAGE) {
jsDoc.spec.template.spec.containers[0].image = processedConfig.OVERRIDE_COTURN_IMAGE;
yamlDocuments[index] = new YAML.Document(jsDoc);
}
}
else if (jsDoc.metadata.name === "haproxy") {
if (processedConfig.OVERRIDE_HAPROXY_IMAGE) {
jsDoc.spec.template.spec.containers[0].image = processedConfig.OVERRIDE_HAPROXY_IMAGE;
yamlDocuments[index] = new YAML.Document(jsDoc);
}
}
}
});

return `${yamlDocuments.map(doc => YAML.stringify(doc, {"lineWidth": 0, "directives": false})).join('---\n')}`;
}

// Main function to handle the script
function main() {
try {
Expand All @@ -112,6 +188,8 @@ function main() {
replacedContent = generatePersistentVolumes(processedConfig, replacedContent);
}

replacedContent = handleImageOverrides(processedConfig, replacedContent)

utils.writeOutputFile(replacedContent, "", "hcce.yaml");

} catch (error) {
Expand Down
11 changes: 11 additions & 0 deletions community-edition/input-values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,14 @@ SKETCHFAB_API_KEY: "?"
TENOR_API_KEY: "?"
GENERATE_PERSISTENT_VOLUMES: "Yes"
PERSISTENT_VOLUME_SIZE: "10Gi"
OVERRIDE_RETICULUM_IMAGE: "hubsfoundation/ret:$Container_Tag"
OVERRIDE_POSTGREST_IMAGE: "No"
OVERRIDE_POSTGRES_IMAGE: "No"
OVERRIDE_PGBOUNCER_IMAGE: "No"
OVERRIDE_HUBS_IMAGE: "hubsfoundation/hubs:$Container_Tag"
OVERRIDE_SPOKE_IMAGE: "hubsfoundation/spoke:$Container_Tag"
OVERRIDE_NEARSPARK_IMAGE: "No"
OVERRIDE_PHOTOMNEMONIC_IMAGE: "No"
OVERRIDE_DIALOG_IMAGE: "No"
OVERRIDE_COTURN_IMAGE: "No"
OVERRIDE_HAPROXY_IMAGE: "No"

0 comments on commit 35752a0

Please sign in to comment.