Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add auth to compose pull #40

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft

Conversation

AndreasHeine
Copy link
Contributor

@AndreasHeine AndreasHeine commented Sep 28, 2023

hey,

i will tackle the auth topic in the next weeks!

i started working around it by using just dockerode:

    const requiredImages: string[] = []
    for (const [_, value] of Object.entries(getServiceInstance().recipe.services)) {
        requiredImages.push((value as any).image)
    }
    await Promise.all(requiredImages.map(async (image: string) => {
        try {
            console.log("pulling image:", image)
            if (image.startsWith("localhost:15004/")) {
                const options = {
                    // authconfig: {
                    //     username: config.regestryUser,
                    //     password: config.registryPw,
                    // }
                }
                await pullImage(image, options)
            } else {
                await pullImage(image)
            }
        } catch (error: any) {
            console.error(image, "-->", error)
        }
    }))

but this has some flavour ;)

just passing the auth options like in this PR will probably not be enough because not all images of a service are exclusively from one Registry...

so for beeing able to use it in a common way we probably need to pass a array of auth options to the compose pull function so we can try to figure out from which registry we need to pull with the correct auth options.

#28

@AndreasHeine
Copy link
Contributor Author

small update on the subject:

i tested the following with two private registries!

export async function pullImage(image: string, options?: any): Promise<void> {
    if (options === undefined) {
        if (image.includes("myregistry1.com")) {
            options = {
                authconfig: {
                    username: "myregistry1-user",
                    password: "myregistry1-pw",
                    auth: '',
                    email: '[email protected]',
                    serveraddress: 'https://myregistry1.com/v2/'
                }
            }
        }
        if ( image.includes("myregistry2.com")) {
            options = {
                authconfig: {
                    username: "myregistry2-user",
                    password: "myregistry2-pw",
                    auth: '',
                    email: '[email protected]',
                    serveraddress: 'https://myregistry2.com/v2/'
                }
            }
        }
    }
    const pullStream = await docker.pull(image, options)
    await new Promise(res => docker.modem.followProgress(pullStream, res))
}

what that means in order to make a compose pull to a mix of registrys:

const registry = {
    "myregistry1.com": {
        username: "",
        password: "",
        email: "",
        serveraddress: ""        
    },
    "myregistry2.com": {
        username: "",
        password: "",
        email: "",
        serveraddress: ""
    },
}

compose.pull(serviceN, options, registry)

/* 
inside compose.pull() we look if a prefix fits (myregistry1.com or myregistry2.com) and select to correct auth options

maybe like:
Object.keys(registry).map((key) => {
    if (imageName.includes(key)) {
        return registry[key]
    }
})
*/

PR update follows soon!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant