Skip to content

Commit

Permalink
Improve CI workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
andyone committed Sep 24, 2024
1 parent 947f4d6 commit d19633d
Show file tree
Hide file tree
Showing 5 changed files with 103 additions and 80 deletions.
4 changes: 2 additions & 2 deletions .docker/alpine.docker
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ ARG REGISTRY="docker.io"

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

FROM golang:alpine3.17 as builder
FROM golang:alpine3.20 as builder

WORKDIR /go/src/github.com/essentialkaos/rsz

Expand All @@ -15,7 +15,7 @@ RUN apk add --no-cache git make && make deps && make all

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

FROM ${REGISTRY}/essentialkaos/alpine:3.17
FROM ${REGISTRY}/essentialkaos/alpine:3.20

LABEL org.opencontainers.image.title="rsz" \
org.opencontainers.image.description="Simple utility for image resizing" \
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: "Docker Push"
name: CD (Release)

on:
release:
Expand All @@ -19,15 +19,13 @@ permissions:

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

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

env:
DOCKER_FILE: alpine

steps:
- name: Checkout
uses: actions/checkout@v4
Expand Down Expand Up @@ -92,7 +90,7 @@ jobs:
- name: Check if build/rebuild is required
id: build_check
run: |
if [[ "${{github.event_name}}" == "release" ]] ; then
if [[ "$GITHUB_EVENT_NAME" == "release" ]] ; then
echo "build=true" >> $GITHUB_OUTPUT
exit 0
fi
Expand Down
69 changes: 69 additions & 0 deletions .github/workflows/ci-pr.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
name: CI (PR)

on:
pull_request:
branches: [master]
workflow_dispatch:
inputs:
force_run:
description: 'Force workflow run'
required: true
type: choice
options: [yes, no]

permissions:
actions: read
contents: read
statuses: write

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

jobs:
CI:
uses: ./.github/workflows/ci.yml
secrets: inherit

ImageBuild:
name: Container Image Build Check
runs-on: ubuntu-latest

needs: CI

env:
REGISTRY: ghcr.io

strategy:
matrix:
image: [ 'alpine' ]

steps:
- name: Checkout
uses: actions/checkout@v4

- name: Login to DockerHub
uses: docker/login-action@v3
env:
DOCKERHUB_USERNAME: ${{ secrets.DOCKERHUB_USERNAME }}
if: ${{ env.DOCKERHUB_USERNAME != '' }}
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}

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

- name: Build Docker image
run: |
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
with:
image: ${{matrix.image}}
show-labels: true
26 changes: 26 additions & 0 deletions .github/workflows/ci-push.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
name: CI (Push)

on:
push:
branches: [master, develop]
workflow_dispatch:
inputs:
force_run:
description: 'Force workflow run'
required: true
type: choice
options: [yes, no]

permissions:
actions: read
contents: read
statuses: write

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

jobs:
CI:
uses: ./.github/workflows/ci.yml
secrets: inherit
72 changes: 1 addition & 71 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -1,27 +1,13 @@
name: CI

on:
push:
branches: [master, develop]
pull_request:
branches: [master]
workflow_dispatch:
inputs:
force_run:
description: 'Force workflow run'
required: true
type: choice
options: [yes, no]
workflow_call:

permissions:
actions: read
contents: read
statuses: write

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

jobs:
Go:
name: Go
Expand Down Expand Up @@ -74,59 +60,3 @@ jobs:
- name: Check spelling
continue-on-error: true
uses: crate-ci/typos@master

DockerBuild:
name: Docker Build Check
runs-on: ubuntu-latest

needs: Hadolint

env:
REGISTRY: ghcr.io

strategy:
matrix:
image: [ 'alpine' ]

steps:
- name: Check event type
run: |
if [[ "${{github.event_name}}" != "pull_request" ]] ; then
echo "::notice::Event type is not 'pull_request', all job actions will be skipped"
fi
# This step is a hack for needs+if issue with actions
# More info about issue: https://github.com/actions/runner/issues/491
- name: Checkout
uses: actions/checkout@v4
if: ${{ github.event_name == 'pull_request' }}

- name: Login to DockerHub
uses: docker/login-action@v3
env:
DOCKERHUB_USERNAME: ${{ secrets.DOCKERHUB_USERNAME }}
if: ${{ github.event_name == 'pull_request' && env.DOCKERHUB_USERNAME != '' }}
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}

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

- name: Build Docker image
if: ${{ github.event_name == 'pull_request' }}
run: |
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: ${{matrix.image}}
show-labels: true

0 comments on commit d19633d

Please sign in to comment.