Files
dotnet2docker/action.yml

41 lines
1.8 KiB
YAML
Raw Permalink Normal View History

2023-08-21 22:21:54 +08:00
# action.yml
2025-11-07 21:44:18 +08:00
name: "build docker image and push to code"
description: "build docker image and push to simcu code"
2024-04-16 16:18:24 +08:00
inputs:
2024-04-18 02:14:27 +08:00
dockerfile:
2025-11-07 21:44:18 +08:00
description: "if set, will use this to build"
2024-04-16 16:18:24 +08:00
required: false
2025-11-07 21:44:18 +08:00
default: ""
2023-08-21 22:21:54 +08:00
runs:
2025-11-07 21:44:18 +08:00
using: "composite"
2023-08-21 22:21:54 +08:00
steps:
2025-11-07 21:44:18 +08:00
- name: build .net app
uses: docker://mcr.microsoft.com/dotnet/sdk:9.0
with:
args: dotnet publish -r linux-x64 -c Release --self-contained -o dist -p:AssemblyName=App -p:Version=${{ github.ref_name }}
2023-08-22 14:40:17 +08:00
2025-11-07 21:44:18 +08:00
- name: create dockerfile
if: ${{ inputs.dockerfile == '' }}
uses: docker://ubuntu:latest
with:
entrypoint: "/bin/bash"
args: |
-c 'echo "FROM mcr.microsoft.com/dotnet/runtime:9.0" > Dockerfile && \
echo "ENV TZ Asia/Shanghai" >> Dockerfile && \
echo "COPY dist /home" >> Dockerfile && \
echo "WORKDIR /home" >> Dockerfile && \
echo "ENTRYPOINT [\"./App\"]" >> Dockerfile && \
echo "已经构建完DOCKERFILE了" && \
cat Dockerfile'
2023-08-22 12:57:53 +08:00
2025-11-07 21:44:18 +08:00
- name: build docker image use custom dockerfile
uses: docker://docker:git
with:
entrypoint: "/bin/sh"
args: |
-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 }}推送成功'