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

[feature]: Slim images from the GitHub Container Registry #11

Open
T145 opened this issue Apr 20, 2024 · 2 comments
Open

[feature]: Slim images from the GitHub Container Registry #11

T145 opened this issue Apr 20, 2024 · 2 comments

Comments

@T145
Copy link

T145 commented Apr 20, 2024

I'm trying to slim my Docker image like so:

---
# https://docs.docker.com/ci-cd/github-actions/
name: Publish Docker Image

on:
  push:
    branches:
      - master
    paths:
      - "Dockerfile"
  workflow_dispatch:

permissions: read-all

jobs:
  build:
    runs-on: ubuntu-22.04
    permissions:
      packages: write
    steps:
      - name: Checkout repo
        uses: actions/checkout@9bb56186c3b09b4f86b1c65136769dd318469633
      - name: Set up QEMU
        uses: docker/setup-qemu-action@b7249025a94417def5eea224a7408d279c7becfb
      - name: Set up Docker Buildx
        id: buildx
        uses: docker/setup-buildx-action@d70bba72b1f3fd22344832f00baa16ece964efeb
      - name: Login to GitHub Container Registry
        uses: docker/login-action@e92390c5fb421da1463c202d546fed0ec5c39f20
        with:
          registry: ghcr.io
          username: ${{ github.actor }}
          password: ${{ github.token }}
      - name: Build the image
        uses: docker/build-push-action@2cdde995de11925a030ce8070c3d77a52ffcf1c0
        with:
          context: .
          builder: ${{ steps.buildx.outputs.name }}
          push: false
          tags: ghcr.io/t145/black-mirror:latest
          cache-from: type=registry,ref=ghcr.io/t145/black-mirror:buildcache
          cache-to: type=registry,ref=ghcr.io/t145/black-mirror:buildcache,mode=max
      # https://github.com/kitabisa/docker-slim-action
      - name: Slim the image
        uses: kitabisa/docker-slim-action@e641d62304259303c8557c27e10965f7348c7eb4
        env:
          DSLIM_HTTP_PROBE: false
        with:
          target: ${{ github.repository }}:latest
          tag: 'slim'
      - name: Push all tags
        run: docker image push "${{ github.repository }}" --all-tags

But I get an error message like this:

slim on target: T145/black-mirror:latest
/tmp/slim-1.40.11-linux/slim b --target T145/black-mirror:latest --continue-after 1
cmd=build state=started
cmd=build info=params continue.mode='timeout' rt.as.user='true' keep.perms='true' tags='' image-build-engine='internal' target.type='image' target.image='T145/black-mirror:latest' 
time="2024-04-20T07:12:52Z" level=error msg="image.inspector.NoImage: err=API error (400): invalid reference format: repository name must be lowercase"
time="2024-04-20T07:12:52Z" level=fatal msg="slim: failure" error="API error (400): invalid reference format: repository name must be lowercase"

If I designate ghcr.io/t145/black-mirror:latest it still can't pull the image due to not recognizing the Docker credentials. Is this a problem that can be fixed on my end?

@dwisiswant0
Copy link
Member

But I get an error message like this:

The target image is invalid, it should be ghcr.io/${{ github.repository }}:latest.

[...] it still can't pull the image due to not recognizing the Docker credentials.

What's the error?

@JostCrow
Copy link

What worked for me here is adding the load: true. This adds it to the local docker instance so that it can be used by slim.

- name: Build the image
        uses: docker/build-push-action@2cdde995de11925a030ce8070c3d77a52ffcf1c0
        with:
          context: .
          builder: ${{ steps.buildx.outputs.name }}
          push: false
          load: true
          tags: ghcr.io/t145/black-mirror:latest
          cache-from: type=registry,ref=ghcr.io/t145/black-mirror:buildcache
          cache-to: type=registry,ref=ghcr.io/t145/black-mirror:buildcache,mode=max

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

3 participants