Created
May 12, 2020 10:56
-
-
Save Embraser01/de9ab4e46f00bdcc725568233ab4cb38 to your computer and use it in GitHub Desktop.
Simple node script used to generate a k8s compatible docker `config.json`
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* This script will create a base64 string that will be used by K8S to pull | |
* images from the Docker Registry. | |
* | |
* More info here: https://kubernetes.io/fr/docs/tasks/configure-pod-container/pull-image-private-registry/ | |
*/ | |
const encodeToBase64 = (str) => Buffer.from(str).toString('base64'); | |
const createFinalString = (obj) => encodeToBase64(JSON.stringify(obj)); | |
function main({ | |
registry = 'https://index.docker.io/v1/', | |
username, | |
password, | |
email, | |
}) { | |
return createFinalString({ | |
auths: { | |
[registry]: { | |
username, | |
password, | |
email, | |
auth: encodeToBase64(`${username}:${password}`), | |
}, | |
}, | |
}); | |
} | |
const [, , username, password, email, registry] = process.argv; | |
console.log(main({ username, password, email, registry })); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment