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

Add note to sanitize tags #426

Merged
merged 1 commit into from Aug 5, 2021
Merged

Conversation

crazy-max
Copy link
Member

@crazy-max crazy-max commented Aug 5, 2021

Closes #424

Signed-off-by: CrazyMax crazy-max@users.noreply.github.com

Signed-off-by: CrazyMax <crazy-max@users.noreply.github.com>
@crazy-max crazy-max merged commit 6484a61 into docker:master Aug 5, 2021
@crazy-max crazy-max deleted the doc-sanitize-ref branch August 5, 2021 06:12
@PromoFaux
Copy link

Just a note - and maybe I was doing it wrong somehow - but this didn't actually work for me. I kept getting:

image

I ended up using:

- name: lowercase repo name for tag
        uses: ASzc/change-string-case-action@v1
        id: reponame
        with:
          string: ghcr.io/${{ github.repository }}

and referencing as : ${{ steps.reponame.outputs.lowercase }}

@crazy-max
Copy link
Member Author

@PromoFaux Looking at your workflow, I suggest to use the metadata action which will automatically sanitize tags:

name: Docker

on:
  push:
    branches: main

jobs:
  docker:
    runs-on: ubuntu-latest
    steps:
      - name: Checkout
        uses: actions/checkout@v2

      - name: Set up QEMU
        uses: docker/setup-qemu-action@v1

      - name: Set up Docker Buildx
        uses: docker/setup-buildx-action@v1

      - name: Cache Docker layers
        uses: actions/cache@v2.1.6
        with:
          path: /tmp/.docker-buildx-cache
          key: ${{ runner.os }}-docker-buildx-${{ github.sha }}
          restore-keys: ${{ runner.os }}-docker-buildx-

      - name: Login to Github Packages
        uses: docker/login-action@v1
        with:
          registry: ghcr.io
          username: ${{ github.repository_owner }}
          password: ${{ secrets.GITHUB_TOKEN }}

      - name: Docker meta
        id: meta
        uses: docker/metadata-action@v3
        with:
          images: ghcr.io/${{ github.repository }}
          tags: |
            sha_${{ github.sha }}
            latest

      - name: Build
        id: docker_build
        uses: docker/build-push-action@v2
        with:
          push: true
          tags: ${{ steps.meta.outputs.tags }}
          labels: ${{ steps.meta.outputs.labels }}
          cache-from: type=local,src=/tmp/.docker-buildx-cache
          cache-to: type=local,dest=/tmp/.docker-buildx-cache

@PromoFaux
Copy link

Thanks for the tips, I'll take a look!

@crazy-max
Copy link
Member Author

@PromoFaux

but this didn't actually work for me.

And yes indeed there is an issue with the syntax. It should be: script: return '${{ github.repository }}'.toLowerCase(). Will fix that in a follow-up and also add a note about the metadata action to sanitize tags.

@PromoFaux
Copy link

AH. I came really close to that solution myself! Rather I tried ${{ github.repository.toLowerCase() }}, which also didn't work - so I gave up and found another action. I'm not lazy, honest.

@PromoFaux
Copy link

Also, yeah, metadata action works well! I am already using it over on pi-hole/docker-pi-hole - I don't know why I didn't use it in this case.

@crazy-max
Copy link
Member Author

Yeah you can do a bunch of thing with the metadata-action. For example you could merge both nightly and release workflows and the metadata action will take care of tagging properly based on scheduled events, git tag and so on.

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.

Repository/image name should be lowercased automatically in cache parameters.
2 participants