Skip to content

Instantly share code, notes, and snippets.

@timmyers
Created July 14, 2020 20:48
Show Gist options
  • Save timmyers/e1c1ee31a7a85d26229a29ec732b659c to your computer and use it in GitHub Desktop.
Save timmyers/e1c1ee31a7a85d26229a29ec732b659c to your computer and use it in GitHub Desktop.
Pulumi DigitalOcean Container Registry
import * as pulumi from '@pulumi/pulumi';
import * as ocean from '@pulumi/digitalocean';
interface Options {
}
class ContainerRegistry extends pulumi.ComponentResource {
public name: pulumi.Output<string>;
public username: pulumi.Output<string>;
public password: pulumi.Output<string>;
public server: pulumi.Output<string>;
public fullCredentials: pulumi.Output<string>;
public constructor(name: string, {}: Options, opts?: pulumi.ComponentResourceOptions) {
super('cloudwaste:digitalocean:container-registry', name, { }, opts);
const defaultOpts = { parent: this };
const containerRegistry = new ocean.ContainerRegistry(name, { name }, defaultOpts);
const credentials = new ocean.ContainerRegistryDockerCredentials(name, {
registryName: name,
write: true,
}, defaultOpts);
this.name = pulumi.output(name);
this.fullCredentials = credentials.dockerCredentials;
const userPass = credentials.dockerCredentials.apply(creds => {
const credentials = JSON.parse(creds);
const base64 = Buffer.from(credentials.auths['registry.digitalocean.com'].auth, 'base64');
const userPass = base64.toString('ascii');
return userPass.split(':')
});
this.username = userPass.apply(up => up[0])
this.password = userPass.apply(up => up[1])
this.server = pulumi.output('registry.digitalocean.com')
this.registerOutputs({
name: this.name,
username: this.username,
password: this.password,
server: this.server,
fullCredentials: this.fullCredentials,
});
}
}
export default ContainerRegistry;
const image = new docker.Image('example', {
imageName: pulumi.interpolate`${containerRegistry.server}/example`,
build: './'
registry: {
server: containerRegistry.server,
username: containerRegistry.username,
password: containerRegistry.password,
},
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment