Building docker image questions (OD-2365)
Artur opened 9 months ago

Hi,

I am trying to create buildspec to build docker image for the project and push it to Packages on my OneDev instance docker registry.

Now for the tag number I would like to use the most recent tag from the git repository tags. I know how to get the tag from the git repo:

TAG_NO=$(git describe --tags --abbrev=0)
  1. But the question is how to use this value in the Docker Image\Build Image step?
  2. What should be exact settings in the stop to push the image to the OneDev Packages registry?
  • Artur commented 9 months ago

    Hi,

    I figured out how to push to OneDev registry. It turns out it does not need any special settings.

    Bu the tag number question remains. How to automate the process of tagging/numbering builds. Ideally I would like to use last git tag, this way docker images tags and git tags would stay in sync.

  • Artur removed comment 9 months ago
  • Artur commented 9 months ago

    Is it possible to programmatically from job script to modify Job properties? If this is possible, I could add one step Execute Command and calculate the desired TAG for the docker image and store it in the Job properties and then reuse them in docker build step. Is this possible?

  • Robin Shen commented 9 months ago
    1. Write the tag into a file inside job workspace

      TAG_NO=$(git describe --tags --abbrev=0)
      echo $TAG_NO > $ONEDEV_WORKSPACE/tag_no
      
    2. When build or push image, use the tag @file:tag_no@

  • jbauer commented 9 months ago

    I tend to use two steps at the very beginning:

    • Detect build version: uses git to write tag/version information to a file
    • OneDev's Set build version step to tell OneDev about the build version using @file:<filename>@. The build version then also appears in the list of builds in OneDev UI.

    Then all other steps which require a build version use OneDev's @build_version@ property.

  • Artur commented 9 months ago

    Sounds good, thank you.

    Just one more question. This would be "execute commands" step, what docker image do you use for such simple commands?

  • Artur removed comment 9 months ago
  • Artur commented 9 months ago

    I have just tried this solution and there seems to be problem. Maybe you can help. The command:

    git describe --tags --abbrev=0
    

    results in error message:

    fatal: No names found, cannot describe anything.
    

    I executed ls during build and can confirm that .git and all other files are there but there seems to be no information about tags. Should I checkout code differently?

  • Artur commented 9 months ago

    Ok, found solution for my last question. For future reference adding command:

    git fetch --tags
    

    retrieved tags for the repo and then all worked as expected.

    And I use alpine/git docker image for this step. Please let me know if you have a better suggestion.

    Otherwise this ticket can be closed.

    Thank you for all your help.

  • Artur removed comment 9 months ago
  • Robin Shen commented 9 months ago

    alpine/git is a good image for this task

  • Robin Shen changed state to 'Closed' 9 months ago
    Previous Value Current Value
    Open
    Closed
issue 1/1
Type
Question
Priority
Normal
Assignee
Labels
No labels
Issue Votes (0)
Watchers (3)
Reference
OD-2365
Please wait...
Connection lost or session expired, reload to recover
Page is in error, reload to recover