Skip to content

Use a more robust tag for docker#42

Open
j-rivero wants to merge 1 commit intojazzyfrom
jazzy_tag
Open

Use a more robust tag for docker#42
j-rivero wants to merge 1 commit intojazzyfrom
jazzy_tag

Conversation

@j-rivero
Copy link
Collaborator

The docker image tags are not linked to a particular code version, that could end up in build one branch or code and using a different one. The PR builds tags using the branch and the HEAD sha.

Signed-off-by: Jose Luis Rivero <jrivero@honurobotics.com>
Copy link
Owner

@AndrejOrsula AndrejOrsula left a comment

Choose a reason for hiding this comment

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

Thank you @j-rivero for the PR and taking care of the updates!

This PR currently results in Docker images tagged as:

  • panda_gz_moveit2-jazzy_tag-6911abf:latest

I am wondering if the following tag wouldn't be preferable:

  • <DOCKER USER>/panda_gz_moveit2:jazzy_tag-6911abf
  • OR panda_gz_moveit2:jazzy_tag-6911abf if the user is not logged into Docker

The following diff of build.bash would result in such behaviour (the same logic could be applied to run.bash):

diff --git a/.docker/build.bash b/.docker/build.bash
index 9b0a344..2a4a15c 100755
--- a/.docker/build.bash
+++ b/.docker/build.bash
@@ -3,9 +3,9 @@
 SCRIPT_DIR="$(cd "$(dirname "$(readlink -f "${BASH_SOURCE[0]}")")" &>/dev/null && pwd)"
 PROJECT_DIR="$(dirname "${SCRIPT_DIR}")"
 
-TAG=$(git -C "${PROJECT_DIR}" remote get-url origin | sed 's/.*\///; s/\.git$//')
-TAG=${TAG}-$(git -C "${PROJECT_DIR}" branch --show-current)
-TAG=${TAG}-$(git -C "${PROJECT_DIR}" rev-parse --short HEAD)
+DOCKERHUB_USER="$(${WITH_SUDO} docker info 2>/dev/null | sed '/Username:/!d;s/.* //')"
+PROJECT_NAME="$(git -C "${PROJECT_DIR}" remote get-url origin | sed 's/.*\///; s/\.git$//')"
+TAG="${DOCKERHUB_USER:+${DOCKERHUB_USER}/}${PROJECT_NAME,,}"
 
 if [ "${#}" -gt "0" ]; then
     if [[ "${1}" != "-"* ]]; then
@@ -15,6 +15,9 @@ if [ "${#}" -gt "0" ]; then
         BUILD_ARGS=${*:1}
     fi
 fi
+if [[ "${TAG}" != *":"* ]]; then
+    TAG="${TAG}:$(git -C "${PROJECT_DIR}" branch --show-current)-$(git -C "${PROJECT_DIR}" rev-parse --short HEAD)"
+fi
 
 DOCKER_BUILD_CMD=(
     docker build

$PROJECT_NAME could also be PROJECT_NAME="$(basename "${REPOSITORY_DIR}")" to let the end-user rename the project if desired.

In either case, the tag can still be overriden via .docker/build.bash custom_tag, which results in panda_gz_moveit2:custom_tag

What do you think?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants