Thanks to visit codestin.com
Credit goes to github.com

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
12 changes: 7 additions & 5 deletions src/services/DockerService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -141,17 +141,19 @@ export default class DockerService {
/**
* Gets the source repository for the specified Docker image.
* @param imageName - The name of the Docker image.
* @param imageTag - The tag of the Docker image.
* @returns A promise that resolves to the source repository URL.
* @throws An error if the source repository could not be found.
*/
public static async getSourceRepo(imageName: string): Promise<string | null> {
public static async getSourceRepo(imageName: string, imageTag: string): Promise<string | null> {
// Check cache first
if (DockerService.SourceUrlCache.has(imageName)) {
return DockerService.SourceUrlCache.get(imageName) ?? null;
const cachedUrl = DockerService.SourceUrlCache.get(imageName) ?? DockerService.SourceUrlCache.get(imageName + ":" + imageTag);
if (cachedUrl) {
return cachedUrl;
}

// Try method 1: Check Docker labels
const labels = await DockerService.getImageInfo(imageName).then(
const labels = await DockerService.getImageInfo(imageName + ":" + imageTag).then(
(info) => info.Config.Labels
).catch((error) => {
logger.error("Error getting image info:", error
Expand All @@ -160,7 +162,7 @@ export default class DockerService {

if (labels && labels["org.opencontainers.image.source"]) {
const url = labels["org.opencontainers.image.source"];
DockerService.SourceUrlCache.set(imageName, url);
DockerService.SourceUrlCache.set(imageName + ":" + imageTag, url);
return url;
}

Expand Down
2 changes: 1 addition & 1 deletion src/services/HomeassistantService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -423,7 +423,7 @@ export default class HomeassistantService {

// Update entity payload
const updateTopic = `${config.mqtt.topic}/${formatedImage}/update`;
const sourceRepo = await DockerService.getSourceRepo(image);
const sourceRepo = await DockerService.getSourceRepo(image, tag);

if (sourceRepo) {
logger.info(`Found source repository: ${sourceRepo}`);
Expand Down