kitabisa / docker-slim-action

GitHub Action to minify container image by up to 30x (and for compiled languages even more) making it secure too!
MIT License
22 stars 5 forks source link

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

Open T145 opened 4 months ago

T145 commented 4 months ago

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 commented 1 month ago

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?