-
-
Save oliverisaac/7fb4811c82126ded3765d3bea77b8eb5 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| // jenkinsLibraries/src/com/wealthfront/jenkins/DockerReleaseTarget.groovy | |
| package com.wealthfront.jenkins | |
| class DockerReleaseTarget { | |
| String target | |
| String owner | |
| private String region = 'us-west-2' | |
| private String awsAccount = '1234567890' | |
| DockerReleaseTarget() { | |
| this.target = 'release' | |
| this.name = '' | |
| } | |
| DockerReleaseTarget setName(String name) { | |
| this.name = name | |
| return this | |
| } | |
| DockerReleaseTarget withTarget(String s) { | |
| this.target = s | |
| return this | |
| } | |
| DockerReleaseTarget withOwner(String s) { | |
| def allowedOwners = [ 'devops', 'trading', 'etc....' ] | |
| if (!s) { | |
| throw new IllegalStateException('Owner must be non-empty.') | |
| } | |
| if (!allowedOwners.contains(s)) { | |
| throw new IllegalStateException("Invalid owner: '${s}'. Must be one of: ${allowedOwners.join(', ')}") | |
| } | |
| this.owner = s | |
| return this | |
| } | |
| void runValidation() { | |
| if (!this.owner?.trim()) { | |
| throw new IllegalStateException("The 'owner' field must not be empty, use withOwner(owner).") | |
| } | |
| if (!this.target.trim()) { | |
| throw new IllegalStateException('The target must not be empty, use withTarget("targetName")') | |
| } | |
| if (!this.name.trim()) { | |
| throw new IllegalStateException('The name must not be empty, this is an issue with the dockerReleasePipeline.') | |
| } | |
| } | |
| String getEcrRepo() { | |
| return "${this.awsAccount}.dkr.ecr.${this.region}.amazonaws.com/${this.name}" | |
| } | |
| String ecrRepoLoginScript() { | |
| return "aws ecr get-login-password --region ${this.region} | docker login --username AWS --password-stdin ${this.getEcrRepo()}" | |
| } | |
| String createEcrScript() { | |
| return "aws ecr create-repository --region=${this.region} --repository-name=${this.name} --tags 'Key=owner,Value=${this.owner}'" | |
| } | |
| String dockerBuildScript() { | |
| return "docker buildx build --target='${this.target}' ${this.name} ." | |
| } | |
| String dockerPushScript() { | |
| return "docker push ${this.name}" | |
| } | |
| } | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment