Skip to content

Commit

Permalink
Merge pull request #16 from essentialkaos/develop
Browse files Browse the repository at this point in the history
Add improved workflow for pushing Docker images
  • Loading branch information
andyone authored May 27, 2022
2 parents ae2fb30 + 3dda785 commit 9bc9b5f
Show file tree
Hide file tree
Showing 5 changed files with 125 additions and 64 deletions.
122 changes: 122 additions & 0 deletions .github/workflows/docker-push.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
name: "Docker Push"

on:
release:
types: [published]
schedule:
- cron: '30 12 * * *'

permissions:
packages: write
contents: read

env:
IMAGE_NAME: ${{ github.repository }}

jobs:
Docker:
name: Docker Build & Publish
runs-on: ubuntu-latest

steps:
- name: Checkout
uses: actions/checkout@v3
with:
fetch-depth: 0

- name: Login to DockerHub
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}

- name: Login to GitHub Container Registry
uses: docker/login-action@v2
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Prepare metadata for build
id: metadata
run: |
rev=$(git rev-list --tags --max-count=1)
version=$(git describe --tags "$rev" | tr -d 'v')
if [[ -z "$version" ]] ; then
echo "::error::Can't find version info"
exit 1
fi
docker_file="Dockerfile"
base_image=$(grep 'FROM ' $docker_file | tail -1 | cut -f2 -d' ')
if [[ -z "$base_image" ]] ; then
echo "::error::Can't extract base image info"
exit 1
fi
echo "::set-output name=version::$version"
echo "::set-output name=dockerfile::$docker_file"
echo "::set-output name=baseimage::$base_image"
echo -e "\033[34mVersion:\033[0m $version"
echo -e "\033[34mDockerfile:\033[0m $docker_file"
echo -e "\033[34mBase image:\033[0m $base_image"
- name: Check if build/rebuild is required
id: build_check
run: |
if [[ "${{github.event_name}}" == "release" ]] ; then
echo "::set-output name=build::true"
exit 0
fi
echo -e "::group::\033[34mDownloading built image…\033[0m"
if ! docker pull ghcr.io/${{env.IMAGE_NAME}}:latest ; then
echo "::error::Can't download image ghcr.io/${{env.IMAGE_NAME}}:latest"
exit 1
fi
echo "::endgroup::"
echo -e "::group::\033[34mDownloading base image…\033[0m"
if ! docker pull ${{steps.metadata.outputs.baseimage}} ; then
echo "::error::Can't download image ${{steps.metadata.outputs.baseimage}}"
exit 1
fi
echo "::endgroup::"
base_layer=$(docker inspect "${{steps.metadata.outputs.baseimage}}" | jq -r '.[0].RootFS.Layers[-1]')
if [[ -z "$base_layer" ]] ; then
echo "::error::Can't extract layers info from base image"
exit 1
fi
if ! docker inspect "ghcr.io/${{env.IMAGE_NAME}}:latest" | jq -r '.[0].RootFS.Layers' | grep -q "$base_layer" ; then
echo "::warning::Rebuild image (reason: base image rebuilt)"
echo "::set-output name=build::true"
exit 0
fi
- name: Build and push Docker image
if: ${{ steps.build_check.outputs.build == 'true' }}
uses: docker/build-push-action@v3
with:
push: true
context: .
file: ${{steps.metadata.outputs.dockerfile}}
tags: |
ghcr.io/${{env.IMAGE_NAME}}:${{steps.metadata.outputs.version}}
ghcr.io/${{env.IMAGE_NAME}}:latest
${{env.IMAGE_NAME}}:${{steps.metadata.outputs.version}}
${{env.IMAGE_NAME}}:latest
- name: Show info about built Docker image
uses: essentialkaos/docker-info-action@v1
with:
image: ${{env.IMAGE_NAME}}:latest
show-labels: true
59 changes: 0 additions & 59 deletions .github/workflows/ghcr.yml

This file was deleted.

2 changes: 0 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,12 @@ bash <(curl -fsSL https://apps.kaos.st/get) rsz
The latest version of `rsz` also available as Docker image on [Docker Hub](https://kaos.sh/d/rsz) and [GitHub Container Registry](https://kaos.sh/p/rsz):

```bash
docker pull essentialkaos/rsz:latest
docker run --rm -it essentialkaos/rsz:latest image.png 0.55 thumbnail.png
```

or

```bash
docker pull ghcr.io/essentialkaos/rsz:latest
docker run --rm -it ghcr.io/essentialkaos/rsz:latest image.png 0.55 thumbnail.png
```

Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ go 1.17

require (
github.com/disintegration/imaging v1.6.2
github.com/essentialkaos/ek/v12 v12.45.0
github.com/essentialkaos/ek/v12 v12.46.0
)

require (
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ github.com/disintegration/imaging v1.6.2/go.mod h1:44/5580QXChDfwIclfc/PCwrr44am
github.com/essentialkaos/check v1.2.1/go.mod h1:PhxzfJWlf5L/skuyhzBLIvjMB5Xu9TIyDIsqpY5MvB8=
github.com/essentialkaos/check v1.3.0 h1:ria+8o22RCLdt2D/1SHQsEH5Mmy5S+iWHaGHrrbPUc0=
github.com/essentialkaos/check v1.3.0/go.mod h1:PhxzfJWlf5L/skuyhzBLIvjMB5Xu9TIyDIsqpY5MvB8=
github.com/essentialkaos/ek/v12 v12.45.0 h1:5KVZl5MAsPwxfjda+wb+cCxneQ747lU9zA5mjCA5Fyg=
github.com/essentialkaos/ek/v12 v12.45.0/go.mod h1:uQUkpvaZHWR9aI8GfknZqOG5FC+G2PYJLFyMw9fdjbo=
github.com/essentialkaos/ek/v12 v12.46.0 h1:TNw9YmKPf67E9L886EzhH9xUO49bROqvqHR4bzOqf/E=
github.com/essentialkaos/ek/v12 v12.46.0/go.mod h1:uQUkpvaZHWR9aI8GfknZqOG5FC+G2PYJLFyMw9fdjbo=
github.com/essentialkaos/go-linenoise/v3 v3.3.5/go.mod h1:g4X3LhT83XT4h7xwrCLclAdMkJvS9qWBQTGNdS6y4vo=
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
github.com/kr/pretty v0.3.0 h1:WgNl7dwNpEZ6jJ9k1snq4pZsg7DOEN8hP9Xw0Tsjwk0=
Expand Down

0 comments on commit 9bc9b5f

Please sign in to comment.