pulsar icon indicating copy to clipboard operation
pulsar copied to clipboard

[improve][build] Use project version with commit hash as docker tag

Open nodece opened this issue 7 months ago • 14 comments

Motivation

The PR #24168 introduced a regression where the pulsar:${project.version}-${git.commit.id.abbrev} Docker image cannot be pulled in the pulsar-all Dockerfile, because we didn't build and push that to the DockerHub.

We consistently pushed both the latest and ${project.version}-${git.commit.id.abbrev} tags to DockerHub in the past. However, the only tag we require is the uniquely identifiable ${project.version}-${git.commit.id.abbrev}. The latest tag can be ignored for our use case.

We recommend using the ${project.version}-${git.commit.id.abbrev} format instead of latest, providing clearer traceability and avoiding ambiguity.

Modifications

  • Removed the custom Docker tag configuration, and -Ddocker.tag=custom-tag is the right path:
     mvn install -pl docker/pulsar,docker/pulsar-all -DskipTests \
      -Pmain,docker,docker-push \
      -Ddocker.platforms=linux/amd64,linux/arm64 \
      -Ddocker.organization=nodece \
      -Ddocker.image=pulsar \
      -Ddocker.tag=pr-24325
    
  • Changed docker.tag value from latest to${project.version}-${git.commit.id.abbrev}.

Documentation

  • [ ] doc
  • [ ] doc-required
  • [x] doc-not-needed
  • [ ] doc-complete

nodece avatar May 21 '25 04:05 nodece

Please check that test image builds are also consistent.

lhotari avatar May 21 '25 06:05 lhotari

@lhotari Done.

nodece avatar May 21 '25 07:05 nodece

@nodece I remember having some problems with git-commit-id-plugin configuration in the past when someone builds the source code directly without git. Since docker.tag is now set at the top level, it would also be necessary to revisit the git-commit-id-no-git profiles in docker projects and possibly also revisit git-commit-id-plugin configuration. Please test building the docker image directly from the source package to ensure that it also works.

lhotari avatar May 21 '25 08:05 lhotari

~@lhotari Both are working fine.~

# git env
mvn install -pl docker/pulsar,docker/pulsar-all -DskipTests \
    -Pmain,docker,docker-push \
    -Ddocker.platforms=linux/amd64,linux/arm64 \
    -Ddocker.organization=nodece \
    -Ddocker.image=pulsar

# no .git
# rm -rf .git
mvn install -pl docker/pulsar,docker/pulsar-all -DskipTests \
    -Pmain,docker,docker-push,git-commit-id-no-git \
    -Ddocker.platforms=linux/amd64,linux/arm64 \
    -Ddocker.organization=xxxx \
    -Ddocker.image=pulsar

nodece avatar May 21 '25 08:05 nodece

@lhotari Both are working fine.

# git env
mvn install -pl docker/pulsar,docker/pulsar-all -DskipTests \
    -Pmain,docker,docker-push \
    -Ddocker.platforms=linux/amd64,linux/arm64 \
    -Ddocker.organization=nodece \
    -Ddocker.image=pulsar

# no-git env
mvn install -pl docker/pulsar,docker/pulsar-all -DskipTests \
    -Pmain,docker,docker-push,git-commit-id-no-git \
    -Ddocker.platforms=linux/amd64,linux/arm64 \
    -Ddocker.organization=xxxx \
    -Ddocker.image=pulsar

What I mean is that the current git-commit-id-no-git profile configuration no longer makes sense when it's in the sub projects. It should automatically get activated at the top level so that it gets properly resolved in the docker.tag property value. I don't think that manually activating the profile would create a proper tag. It's also possible that git-commit-id-no-git profile isn't needed any more and there's a better way to configure the fallback value.

lhotari avatar May 21 '25 08:05 lhotari

@lhotari git-commit-id-no-git has been removed. Makes sense.

nodece avatar May 21 '25 08:05 nodece

@lhotari git-commit-id-no-git has been removed. Makes sense.

What is the default docker.tag in this case? Please test the docker build from the source package so that we don't break that.

lhotari avatar May 21 '25 10:05 lhotari

btw. We could consider upgrading the deprecated pl.project13.maven:git-commit-id-plugin to io.github.git-commit-id:git-commit-id-maven-plugin https://github.com/git-commit-id/git-commit-id-maven-plugin.

lhotari avatar May 21 '25 10:05 lhotari

btw. We could consider upgrading the deprecated pl.project13.maven:git-commit-id-plugin to io.github.git-commit-id:git-commit-id-maven-plugin https://github.com/git-commit-id/git-commit-id-maven-plugin.

The plugin is Java 11+, so for Maven Shade Java 8 tests to work, the plugin would have to be disabled when running on Java 8 in the existing integration-test-java8 profile.

lhotari avatar May 21 '25 10:05 lhotari

@lhotari

What is the default docker.tag in this case?

${project.version}-${git.commit.id.abbrev} is default value.

Please test the docker build from the source package so that we don't break that.

If no .git, I suggest that you append -Ddocker.tag=${project.version}-custom, otherwise, you will get this error:

[ERROR] Failed to execute goal io.fabric8:docker-maven-plugin:0.45.1:build (default) on project pulsar-docker-image: Execution default of goal io.fabric8:docker-maven-plugin:0.45.1:build failed: Given Docker name 'nodece/pulsar:4.1.0-SNAPSHOT-${git.commit.id.abbrev}' is invalid:
[ERROR]    * tag part '4.1.0-SNAPSHOT-${git.commit.id.abbrev}' doesn't match allowed pattern '^[\w][\w.-]{0,127}$'
[ERROR] See http://bit.ly/docker_image_fmt for more details
[ERROR] -> [Help 1]
[ERROR] 
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR] 

Do you have any idea? Or keep git-commit-id-no-git? I prefer -Ddocker.tag.

btw. We could consider upgrading the deprecated pl.project13.maven:git-commit-id-plugin to io.github.git-commit-id:git-commit-id-maven-plugin https://github.com/git-commit-id/git-commit-id-maven-plugin.

Ok, I will open a new PR to upgrade this plugin.

nodece avatar May 21 '25 13:05 nodece

@lhotari Ping

nodece avatar May 22 '25 08:05 nodece

Ping @lhotari

nodece avatar May 26 '25 09:05 nodece

Do you have any idea? Or keep git-commit-id-no-git? I prefer -Ddocker.tag.

we could move git-commit-id-no-git profile to the main pom.xml so that things would work also in the case where the build is run for the source distribution. That would be the most obvious solution. The profile should get activated only if docker.tag isn't set.

lhotari avatar Jun 03 '25 08:06 lhotari

@lhotari Done.

nodece avatar Jun 04 '25 11:06 nodece