From 9a5b82b628a9c1fefa53b1be53beb8baa9cd18c2 Mon Sep 17 00:00:00 2001 From: lkddi Date: Tue, 2 Dec 2025 17:50:00 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0GitHub=20Actions=E8=87=AA?= =?UTF-8?q?=E5=8A=A8=E6=9E=84=E5=BB=BADocker=E9=95=9C=E5=83=8F=E5=B7=A5?= =?UTF-8?q?=E4=BD=9C=E6=B5=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 创建了自动构建和推送Docker镜像的GitHub Actions工作流 - 支持多架构构建 (linux/amd64, linux/arm64) - 自动推送到Docker Hub和阿里云容器镜像服务 - 更新Dockerfile以优化构建过程 - 更新README.md包含Docker镜像信息 --- .github/workflows/docker-build.yml | 58 ++++++++++++++++++++++++++++++ Dockerfile | 21 +++++++---- README.md | 9 +++++ 3 files changed, 81 insertions(+), 7 deletions(-) create mode 100644 .github/workflows/docker-build.yml diff --git a/.github/workflows/docker-build.yml b/.github/workflows/docker-build.yml new file mode 100644 index 0000000..d1e97ae --- /dev/null +++ b/.github/workflows/docker-build.yml @@ -0,0 +1,58 @@ +name: Build and Push Docker Image + +on: + push: + branches: [ master ] + pull_request: + branches: [ master ] + +jobs: + build: + runs-on: ubuntu-latest + + steps: + - name: Checkout code + uses: actions/checkout@v3 + + - name: Set up QEMU + uses: docker/setup-qemu-action@v2 + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v2 + + - name: Login to DockerHub + uses: docker/login-action@v2 + with: + username: ${{ secrets.DOCKERHUB_USERNAME }} + password: ${{ secrets.DOCKERHUB_TOKEN }} + + - name: Login to Alibaba Cloud Container Registry + uses: docker/login-action@v2 + with: + registry: registry.cn-huhehaote.aliyuncs.com + username: ${{ secrets.ALIBABA_USERNAME }} + password: ${{ secrets.ALIBABA_PASSWORD }} + + - name: Extract metadata (tags, labels) for Docker + id: meta + uses: docker/metadata-action@v4 + with: + images: | + joestar817/dell-fans-controller-docker + registry.cn-huhehaote.aliyuncs.com/lkddi_image/dell-fans-controller-docker + tags: | + type=ref,event=branch + type=ref,event=pr + type=sha,prefix={{branch}}- + latest + + - name: Build and push Docker image + uses: docker/build-push-action@v4 + with: + context: . + platforms: linux/amd64,linux/arm64 + push: true + tags: ${{ steps.meta.outputs.tags }} + labels: ${{ steps.meta.outputs.labels }} + cache-from: type=gha + cache-to: type=gha,mode=max \ No newline at end of file diff --git a/Dockerfile b/Dockerfile index f0e5cb4..ae099e2 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,19 +1,26 @@ FROM ubuntu:22.04 LABEL maintainer="joestar817@foxmail.com" - +# 安装依赖并设置时区 RUN apt update && apt install -y \ ipmitool \ python3 \ - python3-pip && \ - rm -rf /var/lib/apt/lists/* + python3-pip \ + && rm -rf /var/lib/apt/lists/* \ + && ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime \ + && echo 'Asia/Shanghai' > /etc/timezone +# 复制应用文件 COPY . /dell-fans-controller-docker WORKDIR /dell-fans-controller-docker -ENV TZ=Asia/Shanghai -RUN ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime -RUN echo 'Asia/Shanghai' >/etc/timezone +# 如果有requirements.txt则安装Python依赖 +# COPY requirements.txt . +# RUN pip3 install --no-cache-dir -r requirements.txt -CMD ["python3","start.py"] +# 暴露可能需要的端口(虽然这个应用不需要) +# EXPOSE 80 + +# 设置启动命令 +CMD ["python3", "start.py"] diff --git a/README.md b/README.md index 54c0a1a..3758bad 100644 --- a/README.md +++ b/README.md @@ -28,6 +28,15 @@ docker run -d --name=dell-fans-controller-docker -e HOST=10.10.11.11 -e USERNAM 脚本首先通过ipmitool来获取 **进出口温度和CPU核心温度**,再通过其中的最大值来判断调整服务器的风扇转速 +### Docker 镜像构建 + +本项目通过 GitHub Actions 自动构建 Docker 镜像,并推送到 Docker Hub 和阿里云容器镜像服务。 + +- Docker Hub: `joestar817/dell-fans-controller-docker:latest` +- 阿里云: `registry.cn-huhehaote.aliyuncs.com/lkddi_image/dell-fans-controller-docker:latest` + +镜像支持多架构 (linux/amd64, linux/arm64) + 运行间隔为每60秒运行一次 | 温度(℃) | 风扇转速(%) |