0

While creating a CI/CD via Azure Devops, my goal is to push two tags to the artifactory:

  1. latest
  2. build version (For example 1.0.X)

My docker-compose looks like:

version: '3.4'

services:
    mycontainer:
        image: ${Image}:${Tag}
        build:
            context: .
            dockerfile: */Dockerfile
    rabbitmq:
        ...

The yml related steps are:

variables:
- name: Tag
  value: '1.0.1'
- name: 'Image'
  value: 'myartifactory/myrepo/mycontainer'

- task: DockerCompose@0
  displayName: 'Docker-Compose up data source'
  inputs:
    dockerComposeFile: 'docker-compose.yml'
    dockerComposeFileArgs: |
      Image=$(Image)
      Tag=$(Tag)
    action: 'Run a Docker Compose command'
    dockerComposeCommand: 'up --build -d'

This step successfully creates this result and I'm able to successfully push the 1.0.1's tag to artifactory:

Successfully built ############
Successfully tagged myartifactory/myrepo/myproject:1.0.1 

- task: ArtifactoryDocker@1
  displayName: 'Push tagged image to artifactory'
  inputs:
    command: 'push'
    artifactoryService: '...'
    targetRepo: '...'
    imageName: '$(DockerImage):$(Tag)'

Now, to push the latest I need to copy paste these two steps again:

- task: DockerCompose@0
  displayName: 'Docker-Compose up data source'
  inputs:
    dockerComposeFile: 'docker-compose.yml'
    dockerComposeFileArgs: |
      Image=$(Image)
      Tag=latest
    action: 'Run a Docker Compose command'
    dockerComposeCommand: 'up --build -d'

- task: ArtifactoryDocker@1
  displayName: 'Push tagged image to artifactory'
  inputs:
    command: 'push'
    artifactoryService: '...'
    targetRepo: '...'
    imageName: '$(DockerImage):latest'

Is it possible to tag the latest tag together with the 1.0.1 tag and push them together? Because docker-compose up the project with latest again takes a lot of time.

I'm trying also to avoid using script step to run docker tag ... to re-tag the image.

1 Answer 1

1

Wouldn't this be better using docker build? Not docker compose? I'm pretty sure compose is used to spin up things together, rather than your use case. In which case, yes build supports many tags

3
  • In the sake of brevity I didn't mention that there is a rabbitmq container inside the docker-compose Commented Jul 17, 2022 at 10:55
  • But you won't be pushing that, you'll only still be pushing your image. Commented Jul 18, 2022 at 11:02
  • 1
    Thank you for your help, I'll switch to docker build instead of compose. Commented Jul 21, 2022 at 18:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.