支持构建目录 context,内置 dotnet.Dockerfile,构建改用 docker-build-push

This commit is contained in:
2026-10-20 21:45:51 +08:00
parent 08d1e667db
commit 8c5466c52b
2 changed files with 16 additions and 25 deletions
+11 -25
View File
@@ -2,39 +2,25 @@
name: "build docker image and push to code" name: "build docker image and push to code"
description: "build docker image and push to simcu code" description: "build docker image and push to simcu code"
inputs: inputs:
dockerfile: context:
description: "if set, will use this to build" description: "构建目录(相对仓库根目录,默认 .)。例如后端在 dotnet 目录下时填 dotnet"
required: false required: false
default: "" default: "."
runs: runs:
using: "composite" using: "composite"
steps: steps:
- name: build .net app - name: build .net app
uses: docker://mcr.microsoft.com/dotnet/sdk:10.0 uses: docker://mcr.microsoft.com/dotnet/sdk:10.0
with:
args: dotnet publish -r linux-x64 -c Release --self-contained -o dist -p:AssemblyName=App -p:Version=${{ github.ref_name }}
- name: create dockerfile
if: ${{ inputs.dockerfile == '' }}
uses: docker://ubuntu:latest
with: with:
entrypoint: "/bin/bash" entrypoint: "/bin/bash"
args: | args: |
-c 'echo "FROM mcr.microsoft.com/dotnet/runtime:10.0" > Dockerfile && \ -c 'cd "${{ inputs.context }}" && \
echo "ENV TZ Asia/Shanghai" >> Dockerfile && \ dotnet publish -r linux-x64 -c Release --self-contained -o dist -p:AssemblyName=App -p:Version=${{ github.ref_name }}'
echo "COPY dist /home" >> Dockerfile && \
echo "WORKDIR /home" >> Dockerfile && \
echo "ENTRYPOINT [\"./App\"]" >> Dockerfile && \
echo "已经构建完DOCKERFILE了" && \
cat Dockerfile'
- name: build docker image use custom dockerfile # -f 直接指向本 action 内置的 dotnet.Dockerfile,不用再准备/拷贝文件;
uses: docker://docker:git # 构建上下文仍是 context,所以 Dockerfile 里的 COPY dist 取的是构建目录下的发布产物
- name: build docker image and push
uses: actions/docker-build-push@main
with: with:
entrypoint: "/bin/sh" context: ${{ inputs.context }}
args: | dockerfile: ${{ github.action_path }}/dotnet.Dockerfile
-c 'cat ${{ inputs.dockerfile || 'Dockerfile' }} && docker build -t ${{vars.DOCKER_REGISTRY}}/${{github.repository}}:${{ github.ref_name }} -f ${{ inputs.dockerfile || 'Dockerfile' }} . && \
echo ${{vars.DOCKER_REGISTRY}}/${{github.repository}}:${{ github.ref_name }}已经构建完了 && \
docker login ${{vars.DOCKER_REGISTRY}} -u ${{vars.DOCKER_USER}} -p ${{vars.DOCKER_PASS}} && \
docker push ${{vars.DOCKER_REGISTRY}}/${{github.repository}}:${{ github.ref_name }} && \
echo ${{vars.DOCKER_REGISTRY}}/${{github.repository}}:${{ github.ref_name }}推送成功'
+5
View File
@@ -0,0 +1,5 @@
FROM mcr.microsoft.com/dotnet/runtime:10.0
ENV TZ Asia/Shanghai
COPY dist /home
WORKDIR /home
ENTRYPOINT ["./App"]