This is my TypeScript function.
@func()
async publish(
repository: string,
tag: string = 'latest',
src: Directory,
username: string,
password: string
): Promise<string> {
// currently we only use docker.io
// TODO: need to make this dynamic at some point
const registry: string = 'docker.io'
// Build container image first
const container: Container = await this.build(src)
if (!container) {
throw new Error("No container built. See error messages and use build to fix any issues.");
}
const dagPassword = dag.setSecret("DOCKERHUB_PASSWORD", password)
// Login to DockerHub
container
.withRegistryAuth(
registry,
username,
dagPassword
);
// Publish the container
return await container.publish(`${registry}/${repository}:${tag}`)
}