One-KVM/.github/workflows/docker-build.yaml
2025-05-11 20:21:18 +08:00

75 lines
2.3 KiB
YAML
Raw 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: Build and Push Docker Image
on:
workflow_dispatch:
inputs:
version:
description: 'Version'
required: true
type: choice
options:
- dev
- latest
jobs:
build-and-push-image:
runs-on: ubuntu-22.04
container:
image: docker:24.0-cli
env:
TZ: Asia/Shanghai
# 定义环境变量,方便管理
# 修改为你的 Docker Registry 地址,如果是 Docker Hub则为 docker.io (可以省略)
# 如果是 Gitea 内置的包管理器,则为你的 Gitea 实例地址,例如 gitea.example.com:5000
DOCKER_REGISTRY: docker.io
# 推荐使用 Gitea 的内置变量来动态生成镜像名
#IMAGE_NAME: ${{ gitea.repository_owner }}/${{ gitea.repository_name }}
IMAGE_NAME: silentwind0/kvmd:${{ inputs.version }}
steps:
- name: Print Build Information
run: |
echo "Workflow triggered for version: ${{ inputs.version }}"
echo "Current time: $(date -u +'%Y-%m-%dT%H:%M:%SZ')"
- name: Install dependencies
run: |
apt-get update
export DEBIAN_FRONTEND=noninteractive
apt-get install -y --no-install-recommends sudo tzdata node git
apt-get clean
rm -rf /var/lib/apt/lists/*
ln -snf /usr/share/zoneinfo/$TZ /etc/localtime
echo $TZ > /etc/timezone
env:
DEBIAN_FRONTEND: noninteractive
- name: Checkout Code
uses: actions/checkout@v3
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
#- name: Login to Docker Hub
# uses: docker/login-action@v3
# with:
# username: ${{ secrets.DOCKERHUB_USERNAME }}
# password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Build and Push
uses: docker/build-push-action@v5
with:
context: .
file: ./build/Dockerfile
platforms: linux/amd64,linux/arm64,linux/arm/v7
#push: true
push: false
tags: ${{ env.DOCKER_REGISTRY }}/${{ env.IMAGE_NAME }}
cache-from: type=registry,ref=${{ env.DOCKER_REGISTRY }}/${{ env.IMAGE_NAME }}:buildcache
cache-to: type=registry,ref=${{ env.DOCKER_REGISTRY }}/${{ env.IMAGE_NAME }}:buildcache,mode=max