Skip to content

Instantly share code, notes, and snippets.

@Embraser01
Created May 12, 2020 10:56
Show Gist options
  • Save Embraser01/de9ab4e46f00bdcc725568233ab4cb38 to your computer and use it in GitHub Desktop.
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 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