mirror of
https://github.com/Lifailon/lazyjournal.git
synced 2026-11-11 01:09:46 +01:00
188 lines
7.3 KiB
YAML
188 lines
7.3 KiB
YAML
name: Docker build and push
|
||
|
||
on:
|
||
workflow_dispatch:
|
||
inputs:
|
||
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: "Docker build only check"
|
||
required: false
|
||
type: boolean
|
||
Latest:
|
||
description: 'Push latest image on Docker Hub'
|
||
default: false
|
||
type: boolean
|
||
Push:
|
||
description: 'Push custom tag on Docker Hub'
|
||
default: false
|
||
type: boolean
|
||
Container:
|
||
description: 'Docker run container check'
|
||
default: false
|
||
type: boolean
|
||
|
||
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@v6
|
||
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" .
|
||
|
||
- name: Dockerfile hadolint check
|
||
id: hadolint
|
||
if: ${{ github.event.inputs.Hadolint == 'true' }}
|
||
run: docker run --rm -i hadolint/hadolint:latest < Dockerfil
|
||
|
||
- name: Docker build only check
|
||
id: build
|
||
if: ${{ github.event.inputs.Build == 'true' }}
|
||
run: docker build -t lifailon/lazyjournal:test .
|
||
|
||
- name: Install Go
|
||
if: ${{ github.event.inputs.Push == 'true' && github.event.inputs.Tag == '' }}
|
||
uses: actions/setup-go@v6
|
||
with:
|
||
go-version: 1.25
|
||
|
||
- name: Install dependencies
|
||
if: ${{ github.event.inputs.Push == 'true' && github.event.inputs.Tag == '' }}
|
||
run: |
|
||
go fmt ./...
|
||
go vet ./...
|
||
go get ./...
|
||
go mod tidy
|
||
go mod verify
|
||
go build -v ./...
|
||
|
||
- name: Get tag for build and push
|
||
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: Login to Docker Hub
|
||
if: ${{ github.event.inputs.Push == 'true' }}
|
||
uses: docker/login-action@v3
|
||
with:
|
||
username: ${{ secrets.DOCKER_USERNAME }}
|
||
password: ${{ secrets.DOCKER_PASSWORD }}
|
||
|
||
- name: Install Docker Buildx
|
||
if: ${{ github.event.inputs.Push == 'true' }}
|
||
uses: docker/setup-buildx-action@v3
|
||
with:
|
||
driver: docker-container
|
||
install: true
|
||
|
||
- 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 .
|
||
|
||
- 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 .
|
||
|
||
- 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: Docker run container check
|
||
id: containerCheck
|
||
if: ${{ github.event.inputs.Container == 'true' }}
|
||
run: |
|
||
# mkdir lazyjournal && cd lazyjournal
|
||
# curl -sS https://raw.githubusercontent.com/Lifailon/lazyjournal/refs/heads/main/docker-compose.yml -o docker-compose.yml
|
||
docker compose up -d
|
||
docker exec lazyjournal lazyjournal -v
|
||
script -e -c "timeout 10s docker exec -t lazyjournal lazyjournal" interface.log || [ $? -eq 124 ]
|
||
cat interface.log
|
||
|
||
- name: Short commit sha
|
||
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.build.outcome == 'success' && '✅' || (steps.build.outcome == 'skipped' && '➖' || '❌') }} **Docker build only check**: ${{ steps.build.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 }}
|
||
${{ steps.containerCheck.outcome == 'success' && '✅' || (steps.containerCheck.outcome == 'skipped' && '➖' || '❌') }} **Docker run container check**: ${{ steps.containerCheck.outcome }} |