Files
lazyjournal/.github/workflows/ci-docker.yml

198 lines
7.9 KiB
YAML
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
name: "[CI] Build docker image and push to Docker Hub"
on:
workflow_dispatch:
inputs:
Dockerfile:
description: "Dockerfile path for build"
required: true
default: 'docker/debian/Dockerfile'
Commit:
description: "Commit sha for git checkout"
required: false
default: ''
Tag:
description: "Custom tag for docker image"
required: false
default: ''
Lint:
description: 'Dockerfile basic linters check'
default: false
type: boolean
Hadolint:
description: 'Dockerfile hadolint check'
default: false
type: boolean
Build:
description: "Check build image"
required: false
type: boolean
Container:
description: 'Check run container'
default: false
type: boolean
Latest:
description: 'Push latest tag on Docker Hub'
default: false
type: boolean
Push:
description: 'Push custom tag on Docker Hub'
default: false
type: boolean
permissions:
contents: read
jobs:
build:
name: Docker build on ubuntu-latest
runs-on: ubuntu-latest
env:
VERSION: ''
SHORT_SHA: ''
CUSTOM_SHORT_SHA: ''
steps:
- name: Checkout repository (custom branch and all commits)
uses: actions/checkout@v7
with:
fetch-depth: 0
- name: Checkout the specified commit
if: ${{ github.event.inputs.Commit != '' }}
run: git checkout ${{ github.event.inputs.Commit }}
- name: Dockerfile basic linters check
id: lint
if: ${{ github.event.inputs.Lint == 'true' }}
run: docker build --check --build-arg "BUILDKIT_DOCKERFILE_CHECK=experimental=all" -f ${{ github.event.inputs.Dockerfile }} .
- name: Dockerfile hadolint check
id: hadolint
if: ${{ github.event.inputs.Hadolint == 'true' }}
run: docker run --rm -i hadolint/hadolint:latest < ${{ github.event.inputs.Dockerfile }}
- name: Check build image
id: buildCheck
if: ${{ github.event.inputs.Build == 'true' }}
run: docker build -t lifailon/lazyjournal:test -f ${{ github.event.inputs.Dockerfile }} .
- name: Install Docker Compose
if: ${{ github.event.inputs.Container == 'true' }}
run: |
mkdir -p $HOME/.local/bin
version=$(curl -s https://api.github.com/repos/docker/compose/releases/latest | jq -r .tag_name)
curl -sSL "https://github.com/docker/compose/releases/download/$version/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
sudo chmod +x /usr/local/bin/docker-compose
mkdir -p $HOME/.docker/cli-plugins
cp /usr/local/bin/docker-compose $HOME/.docker/cli-plugins/docker-compose
docker compose version
- name: Check run container
id: runContainerCheck
if: ${{ github.event.inputs.Container == 'true' }}
run: |
cd docker/debian && docker compose up -d
sleep 5
docker exec lazyjournal lazyjournal -v
export TERM=xterm-256color
export COLUMNS=150
export LINES=50
script -e -q -c "stty cols 160 rows 60 && timeout 10s docker exec -e TERM=xterm-256color -e COLUMNS=150 -e LINES=50 -t lazyjournal lazyjournal" interface.log || [ $? -eq 124 ]
sed -ri 's/\x1b\[[0-9;?]*[a-zA-Z]//g' interface.log
sed -i '1d;$d' interface.log
cat interface.log
grep -ai "System unit list" interface.log && echo "Container started successfully" || echo "Error reading interface"
- name: Install Go
if: ${{ github.event.inputs.Push == 'true' && github.event.inputs.Tag == '' }}
uses: actions/setup-go@v7
with:
go-version: 1.25
- name: Code verify and check build
if: ${{ github.event.inputs.Push == 'true' && github.event.inputs.Tag == '' }}
run: |
go vet ./...
go build -v -o /dev/null ./...
- name: Get tag from app version for build
if: ${{ github.event.inputs.Push == 'true' }}
env:
TAG: ${{ github.event.inputs.Tag }}
run: |
if [ -n "$TAG" ]; then
version="$TAG"
else
version=$(go run main.go -v)
fi
echo "VERSION=$version" >> $GITHUB_ENV
- name: Install Docker Buildx
if: ${{ github.event.inputs.Push == 'true' }}
uses: docker/setup-buildx-action@v4
with:
driver: docker-container
install: true
- name: Login to Docker Hub
if: ${{ github.event.inputs.Push == 'true' }}
uses: docker/login-action@v4
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
- name: Docker image build and push on Docker Hub using latest tag
id: latestPush
if: ${{ github.event.inputs.Push == 'true' && github.event.inputs.Latest == 'true' }}
run: |
docker buildx build \
--platform linux/amd64,linux/arm64 \
-t lifailon/lazyjournal:latest \
--push \
-f ${{ github.event.inputs.Dockerfile }} .
- name: Docker image build and push on Docker Hub using current version or custom tag
id: customPush
if: ${{ github.event.inputs.Push == 'true' && env.VERSION != '' }}
run: |
docker buildx build \
--platform linux/amd64,linux/arm64 \
-t lifailon/lazyjournal:$VERSION \
--push \
-f ${{ github.event.inputs.Dockerfile }} .
- name: Short commit sha for report
run: |
echo "SHORT_SHA=${GITHUB_SHA::7}" >> $GITHUB_ENV
if [ -n "${{ github.event.inputs.Commit }}" ]; then
echo "CUSTOM_SHORT_SHA=$(echo ${{ github.event.inputs.Commit }} | cut -c1-7)" >> $GITHUB_ENV
fi
- name: Send report to Telegram
uses: appleboy/telegram-action@master
with:
token: ${{ secrets.TELEGRAM_API_TOKEN }}
to: ${{ secrets.TELEGRAM_CHANNEL_ID }}
debug: true
format: markdown
message: |
🔔 **Action**: Docker CI/CD
📁 **Repository**: ${{ github.repository }}
👤 **User**: ${{ github.actor }}
Parameters:
**Current commit sha**: ${{ format('[{1}](https://github.com/{0}/commit/{1})', github.repository, env.SHORT_SHA) }}
**Custom commit sha**: ${{ env.CUSTOM_SHORT_SHA != '' && format('[{1}](https://github.com/{0}/commit/{1})', github.repository, env.CUSTOM_SHORT_SHA) || '➖' }}
**Custom tag for docker image**: ${{ env.VERSION != '' && format('[{0}](https://hub.docker.com/layers/lifailon/lazyjournal/{0})', env.VERSION) || '➖' }}
Results:
${{ steps.lint.outcome == 'success' && '✅' || (steps.lint.outcome == 'skipped' && '➖' || '❌') }} **Dockerfile basic linters check**: ${{ steps.lint.outcome }}
${{ steps.hadolint.outcome == 'success' && '✅' || (steps.hadolint.outcome == 'skipped' && '➖' || '❌') }} **Dockerfile hadolint check**: ${{ steps.hadolint.outcome }}
${{ steps.buildCheck.outcome == 'success' && '✅' || (steps.buildCheck.outcome == 'skipped' && '➖' || '❌') }} **Docker build only check**: ${{ steps.buildCheck.outcome }}
${{ steps.runContainerCheck.outcome == 'success' && '✅' || (steps.runContainerCheck.outcome == 'skipped' && '➖' || '❌') }} **Docker run container check**: ${{ steps.runContainerCheck.outcome }}
${{ steps.latestPush.outcome == 'success' && '✅' || (steps.latestPush.outcome == 'skipped' && '➖' || '❌') }} **Docker image build and push using latest tag**: ${{ steps.latestPush.outcome }}
${{ steps.customPush.outcome == 'success' && '✅' || (steps.customPush.outcome == 'skipped' && '➖' || '❌') }} **Docker image build and push using custom tag**: ${{ steps.customPush.outcome }}