Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: package aliases for snapshots #21960

Merged
merged 9 commits into from
Oct 21, 2020
22 changes: 22 additions & 0 deletions .ci/packaging.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -193,8 +193,12 @@ def pushCIDockerImages(){

def tagAndPush(name){
def libbetaVer = sh(label: 'Get libbeat version', script: 'grep defaultBeatVersion ${BASE_DIR}/libbeat/version/version.go|cut -d "=" -f 2|tr -d \\"', returnStdout: true)?.trim()
def aliasVersion = ""
if("${env.SNAPSHOT}" == "true"){
aliasVersion = libbetaVer.substring(0, libbetaVer.lastIndexOf(".")) // remove third number in version

libbetaVer += "-SNAPSHOT"
aliasVersion += "-SNAPSHOT"
}

def tagName = "${libbetaVer}"
Expand Down Expand Up @@ -227,6 +231,24 @@ def tagAndPush(name){
log(level: 'WARN', text: "${name} doesn't have ${variant} docker images. See https://github.com/elastic/beats/pull/21621")
}
}

if (aliasVersion != "") {
def aliasName = "${DOCKER_REGISTRY}/observability-ci/${name}${variant}:${aliasVersion}"
def iterations = 0
retryWithSleep(retries: 3, seconds: 5, backoff: true) {
iterations++
def status = sh(label:'Change tag and push', script: """
docker tag ${oldName} ${aliasName}
docker push ${newName}
""", returnStatus: true)

if ( status > 0 && iterations < 3) {
error('tag and push failed, retry')
} else if ( status > 0 ) {
log(level: 'WARN', text: "${name} doesn't have ${variant} docker images. See https://github.com/elastic/beats/pull/21621")
}
}
}
}
}

Expand Down
15 changes: 14 additions & 1 deletion dev-tools/mage/dockerbuilder.go
Original file line number Diff line number Diff line change
Expand Up @@ -182,13 +182,26 @@ func (b *dockerBuilder) expandDockerfile(templatesDir string, data map[string]in

func (b *dockerBuilder) dockerBuild() (string, error) {
tag := fmt.Sprintf("%s:%s", b.imageName, b.Version)
aliasTag := ""
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jsoriano I was not able to easily execute this locally (create the elastic-agent docker image) with one single command. Do you know the build steps?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

mage package in the elastic-agent directory should generate all the packages, including the docker images. There is no command to generate only the docker images.
You may want to select the platforms with the PLATFORM environment variable, if not it will generate all the packages for all the platforms, what will probably take a while.

if b.Snapshot {
tag = tag + "-SNAPSHOT"
// remove third number in version
aliasTag = fmt.Sprintf("%s:%s-SNAPSHOT", b.imageName, b.Version[0:strings.LastIndex(b.Version, ".")])
}
if repository, _ := b.ExtraVars["repository"]; repository != "" {
tag = fmt.Sprintf("%s/%s", repository, tag)
aliasTag = fmt.Sprintf("%s/%s", repository, aliasTag)
}
return tag, sh.Run("docker", "build", "-t", tag, b.buildDir)

args := []string{
"build", "-t", tag,
}
if aliasTag != "" {
args = append(args, "-t", aliasTag)
}
args = append(args, b.buildDir)

return tag, sh.Run("docker", args...)
}

func (b *dockerBuilder) dockerSave(tag string) error {
Expand Down