Skip to content

Commit

Permalink
Merge pull request #36 from essentialkaos/develop
Browse files Browse the repository at this point in the history
Version 0.0.5
  • Loading branch information
andyone authored Feb 26, 2023
2 parents cae59b8 + 7ea0d93 commit 71b5c81
Show file tree
Hide file tree
Showing 11 changed files with 728 additions and 472 deletions.
13 changes: 6 additions & 7 deletions Dockerfile → .docker/alpine.docker
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## REGISTRY CONFIGURATION ######################################################

ARG REGISTRY="docker.io"

## BUILDER #####################################################################

FROM golang:alpine as builder
Expand All @@ -6,17 +10,12 @@ WORKDIR /go/src/github.com/essentialkaos/rsz

COPY . .

ENV GO111MODULE=auto

# hadolint ignore=DL3018
RUN apk add --no-cache git make upx && \
make deps && \
make all && \
upx rsz
RUN apk add --no-cache git make && make deps && make all

## FINAL IMAGE #################################################################

FROM essentialkaos/alpine:3.13
FROM ${REGISTRY}/essentialkaos/alpine:3.15

LABEL org.opencontainers.image.title="rsz" \
org.opencontainers.image.description="Simple utility for image resizing" \
Expand Down
4 changes: 1 addition & 3 deletions .github/ISSUE_TEMPLATE.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,7 @@ _Before opening an issue, search for similar bug reports or feature requests on

**System info:**

* **Version used (`rsz --version`):**
* **OS (e.g. from `/etc/*-release`):**
* **Kernel (`uname -a`):**
* **Verbose version info (`rsz -vv`):**
* **Install tools:**

**Steps to reproduce:**
Expand Down
15 changes: 9 additions & 6 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ jobs:

strategy:
matrix:
go: [ '1.17.x', '1.18.x' ]
go: [ '1.19.x', '1.20.x' ]

steps:
- name: Set up Go
Expand Down Expand Up @@ -54,7 +54,7 @@ jobs:
- name: Check dockerfiles with Hadolint
uses: essentialkaos/hadolint-action@v1
with:
files: Dockerfile
files: .docker/*.docker

DockerBuild:
name: Docker Build Check
Expand All @@ -63,8 +63,11 @@ jobs:
needs: Hadolint

env:
DOCKER_FILE: Dockerfile
IMAGE_NAME: rsz
REGISTRY: ghcr.io

strategy:
matrix:
image: [ 'alpine' ]

steps:
- name: Check event type
Expand Down Expand Up @@ -100,11 +103,11 @@ jobs:
- name: Build Docker image
if: ${{ github.event_name == 'pull_request' }}
run: |
docker build -f ${{ env.DOCKER_FILE }} -t ${{ env.IMAGE_NAME }} .
docker build --build-arg REGISTRY=${REGISTRY} -f .docker/${{matrix.image}}.docker -t ${{matrix.image}} .
- name: Show info about built Docker image
uses: essentialkaos/docker-info-action@v1
if: ${{ github.event_name == 'pull_request' }}
with:
image: ${{ env.IMAGE_NAME }}
image: ${{matrix.image}}
show-labels: true
52 changes: 41 additions & 11 deletions .github/workflows/docker-push.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,13 @@ name: "Docker Push"
on:
release:
types: [published]
workflow_dispatch:
inputs:
force_rebuild:
description: 'Force container rebuild'
required: true
type: choice
options: [yes, no]
schedule:
- cron: '30 12 * * *'

Expand All @@ -18,6 +25,9 @@ jobs:
name: Docker Build & Publish
runs-on: ubuntu-latest

env:
DOCKER_FILE: alpine

steps:
- name: Checkout
uses: actions/checkout@v3
Expand Down Expand Up @@ -63,17 +73,17 @@ jobs:
exit 1
fi
docker_file="Dockerfile"
base_image=$(grep 'FROM ' $docker_file | tail -1 | cut -f2 -d' ')
docker_file=".docker/${{env.DOCKER_FILE}}.docker"
base_image=$(grep 'FROM ' $docker_file | grep -v 'builder' | sed 's#${REGISTRY}/##' | 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 "version=$version" >> $GITHUB_OUTPUT
echo "dockerfile=$docker_file" >> $GITHUB_OUTPUT
echo "baseimage=$base_image" >> $GITHUB_OUTPUT
echo -e "\033[34mVersion:\033[0m $version"
echo -e "\033[34mDockerfile:\033[0m $docker_file"
Expand All @@ -83,7 +93,13 @@ jobs:
id: build_check
run: |
if [[ "${{github.event_name}}" == "release" ]] ; then
echo "::set-output name=build::true"
echo "build=true" >> $GITHUB_OUTPUT
exit 0
fi
if [[ "${{ github.event.inputs.force_rebuild }}" == "true" ]] ; then
echo "::warning::Rebuild is required (reason: forced rebuild)"
echo "build=true" >> $GITHUB_OUTPUT
exit 0
fi
Expand Down Expand Up @@ -113,24 +129,38 @@ jobs:
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"
echo "build=true" >> $GITHUB_OUTPUT
exit 0
fi
- name: Build and push Docker image
- name: Build and push Docker images (Docker)
if: ${{ steps.build_check.outputs.build == 'true' }}
uses: docker/build-push-action@v3
uses: docker/build-push-action@v4
with:
push: true
context: .
file: ${{steps.metadata.outputs.dockerfile}}
build-args: |
REGISTRY=docker.io
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: Build and push Docker images (GHCR)
if: ${{ steps.build_check.outputs.build == 'true' }}
uses: docker/build-push-action@v4
with:
push: true
context: .
file: ${{steps.metadata.outputs.dockerfile}}
build-args: |
REGISTRY=ghcr.io
tags: |
ghcr.io/${{env.IMAGE_NAME}}:${{steps.metadata.outputs.version}}
ghcr.io/${{env.IMAGE_NAME}}:latest
- name: Show info about built Docker image
if: ${{ steps.build_check.outputs.build == 'true' }}
uses: essentialkaos/docker-info-action@v1
with:
image: ghcr.io/${{env.IMAGE_NAME}}:latest
Expand Down
13 changes: 8 additions & 5 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
################################################################################

# This Makefile generated by GoMakeGen 2.0.0 using next command:
# This Makefile generated by GoMakeGen 2.2.0 using next command:
# gomakegen --mod .
#
# More info: https://kaos.sh/gomakegen
Expand All @@ -13,6 +13,9 @@ ifdef VERBOSE ## Print verbose information (Flag)
VERBOSE_FLAG = -v
endif

MAKEDIR = $(dir $(realpath $(firstword $(MAKEFILE_LIST))))
GITREV ?= $(shell test -s $(MAKEDIR)/.git && git rev-parse --short HEAD)

################################################################################

.DEFAULT_GOAL := help
Expand All @@ -23,7 +26,7 @@ endif
all: rsz ## Build all binaries

rsz:
go build $(VERBOSE_FLAG) rsz.go
go build $(VERBOSE_FLAG) -ldflags="-X main.gitrev=$(GITREV)" rsz.go

install: ## Install all binaries
cp rsz /usr/bin/rsz
Expand Down Expand Up @@ -65,13 +68,13 @@ else
go mod tidy $(VERBOSE_FLAG)
endif

test -d vendor && go mod vendor $(VERBOSE_FLAG) || :
test -d vendor && rm -rf vendor && go mod vendor $(VERBOSE_FLAG) || :

mod-download:
go mod download

mod-vendor:
go mod vendor $(VERBOSE_FLAG)
rm -rf vendor && go mod vendor $(VERBOSE_FLAG)

fmt: ## Format source code with gofmt
find . -name "*.go" -exec gofmt -s -w {} \;
Expand All @@ -91,6 +94,6 @@ help: ## Show this info
| sed 's/ifdef //' \
| awk 'BEGIN {FS = " .*?## "}; {printf " \033[32m%-14s\033[0m %s\n", $$1, $$2}'
@echo -e ''
@echo -e '\033[90mGenerated by GoMakeGen 2.0.0\033[0m\n'
@echo -e '\033[90mGenerated by GoMakeGen 2.2.0\033[0m\n'

################################################################################
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

#### From source

To build the `rsz` from scratch, make sure you have a working Go 1.17+ workspace (_[instructions](https://golang.org/doc/install)_), then:
To build the `rsz` from scratch, make sure you have a working Go 1.19+ workspace (_[instructions](https://golang.org/doc/install)_), then:

```
go install github.com/essentialkaos/rsz@latest
Expand Down
Loading

0 comments on commit 71b5c81

Please sign in to comment.