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

Latest not linked to the highest version #80

Closed
xezpeleta opened this issue May 11, 2021 · 2 comments
Closed

Latest not linked to the highest version #80

xezpeleta opened this issue May 11, 2021 · 2 comments

Comments

@xezpeleta
Copy link

xezpeleta commented May 11, 2021

Behaviour

Steps to reproduce this issue

  1. I configure the metadata-action workflow in my repo with semantic version, as described in the instuctions
  2. I publish a new tag: v2.0.1 - this will trigger the action and a new Docker image will be generated with the following tags: 2.0.1, 2.0, 2 and latest
  3. Then I publish another tag: v1.9.1 - this will trigger the action and a new Docker image will be generated with the following tags: 1.9.1, 1.9, 1 and latest

Expected behaviour

I want to have the "latest" tag always linked to the highest version (v2.0.1)

Actual behaviour

If I publish a revision of an older version (v1.9.1) it will overwrite the "latest" version.

Is this deliberate? Is there any workaround?

Thanks

@xezpeleta xezpeleta changed the title Latest linked to specific version Latest not linked to the highest version May 11, 2021
@crazy-max
Copy link
Member

@xezpeleta

Is this deliberate?

This is the expected behavior if you maintain multiple versions. And indeed, this is not really wise in your case.

Is there any workaround?

You can tell the action to only create latest for v2.x.x tags will the following flavor:

flavor: |
  latest=${{ startsWith(github.ref, 'refs/tags/v2.') }}

Btw can you post your workflow or do you have a link to your repo please?

@xezpeleta
Copy link
Author

xezpeleta commented May 11, 2021

Great! that's a good workaround. I confirm it's working.

Btw can you post your workflow or do you have a link to your repo please?

I'm testing the workflow on my fork:

name: Publish Docker images
on:
  push:
    tags:
      - 'v*'

jobs:
  main:
    runs-on: ubuntu-latest
    steps:
    -
      name: Checkout
      uses: actions/checkout@v2
    -
      name: Docker meta
      id: meta
      uses: docker/metadata-action@v3
      with:
        images: |
          xezpeleta/elkarbackup
          ghcr.io/xezpeleta/elkarbackup
        # generate Docker tags based on the following events/attributes
        tags: |
          type=semver,pattern={{version}}
          type=semver,pattern={{major}}.{{minor}}
          type=semver,pattern={{major}}
        # WARNING: releasing older versions will overwrite "latest" tag
        # We can specify our preferred "latest" version manually in that case:
        flavor: |
          latest=${{ startsWith(github.ref, 'refs/tags/v2') }}
    -
      name: Set up Quemu
      uses: docker/setup-qemu-action@v1
    -
      name: Set up Docker Buildx
      uses: docker/setup-buildx-action@v1
    -
      name: Login to DockerHub
      uses: docker/login-action@v1 
      with:
        username: ${{ secrets.DOCKERHUB_USERNAME }}
        password: ${{ secrets.DOCKERHUB_TOKEN }}
    -
      name: Login to GHCR
      uses: docker/login-action@v1
      with:
        registry: ghcr.io
        username: ${{ github.repository_owner }}
        password: ${{ secrets.GITHUB_TOKEN }}
    -
      name: Build and push
      id: docker_build
      uses: docker/build-push-action@v2
      with:
        context: .
        file: ./docker/Dockerfile
        push: true
        platforms: linux/amd64,linux/arm64,linux/arm/v7
        tags: ${{ steps.meta.outputs.tags }}
        labels: ${{ steps.meta.outputs.labels }}
    -
      name: Image digest
      run: echo ${{ steps.docker_build.outputs.digest }}

https://github.com/xezpeleta/elkarbackup/blob/master/.github/workflows/publish-docker-images.yml

Thank you very much

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

No branches or pull requests

2 participants