commit f0d50f85060fa76f4c75971deb35dcc0a078982a Author: qxa Date: Tue Mar 25 18:23:07 2025 +0800 first commit diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..1ff0c42 --- /dev/null +++ b/.gitattributes @@ -0,0 +1,63 @@ +############################################################################### +# Set default behavior to automatically normalize line endings. +############################################################################### +* text=auto + +############################################################################### +# Set default behavior for command prompt diff. +# +# This is need for earlier builds of msysgit that does not have it on by +# default for csharp files. +# Note: This is only used by command line +############################################################################### +#*.cs diff=csharp + +############################################################################### +# Set the merge driver for project and solution files +# +# Merging from the command prompt will add diff markers to the files if there +# are conflicts (Merging from VS is not affected by the settings below, in VS +# the diff markers are never inserted). Diff markers may cause the following +# file extensions to fail to load in VS. An alternative would be to treat +# these files as binary and thus will always conflict and require user +# intervention with every merge. To do so, just uncomment the entries below +############################################################################### +#*.sln merge=binary +#*.csproj merge=binary +#*.vbproj merge=binary +#*.vcxproj merge=binary +#*.vcproj merge=binary +#*.dbproj merge=binary +#*.fsproj merge=binary +#*.lsproj merge=binary +#*.wixproj merge=binary +#*.modelproj merge=binary +#*.sqlproj merge=binary +#*.wwaproj merge=binary + +############################################################################### +# behavior for image files +# +# image files are treated as binary by default. +############################################################################### +#*.jpg binary +#*.png binary +#*.gif binary + +############################################################################### +# diff behavior for common document formats +# +# Convert binary document formats to text before diffing them. This feature +# is only available from the command line. Turn it on by uncommenting the +# entries below. +############################################################################### +#*.doc diff=astextplain +#*.DOC diff=astextplain +#*.docx diff=astextplain +#*.DOCX diff=astextplain +#*.dot diff=astextplain +#*.DOT diff=astextplain +#*.pdf diff=astextplain +#*.PDF diff=astextplain +#*.rtf diff=astextplain +#*.RTF diff=astextplain diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..bd8a7d1 --- /dev/null +++ b/.gitignore @@ -0,0 +1,6 @@ +################################################################################ +# 此 .gitignore 文件已由 Microsoft(R) Visual Studio 自动创建。 +################################################################################ + +.vs +.vscode diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..25ac0f0 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,15 @@ +FROM alpine + +COPY entrypoint.sh /bin/entrypoint.sh + +RUN chmod +x /bin/entrypoint.sh + +RUN sed -i 's/dl-cdn.alpinelinux.org/mirrors.aliyun.com/g' /etc/apk/repositories +RUN apk update +RUN apk add bash +RUN apk add uuidgen +RUN apk add docker-compose +RUN apk add docker-cli +RUN apk add docker-cli-buildx + +CMD /bin/entrypoint.sh diff --git a/action.yml b/action.yml new file mode 100644 index 0000000..18fb7ed --- /dev/null +++ b/action.yml @@ -0,0 +1,36 @@ +name: docker +description: docker and docker-compose +author: qxa + +inputs: + registry: + description: 镜像仓库地址 + required: true + username: + description: 仓库登陆账号 + required: false + password: + description: 仓库员登录密码 + required: false + image: + description: 镜像名称 + required: true + tags: + description: 标签名称名称 + required: false + default: latest + context: + description: 打包文件所在路径 + required: false + default: ./ + dockerfile: + description: 打包的文件名 + required: false + default: Dockerfile + platform: + description: 要编译的平台,可选值linux/arm,linux/arm64,linux/amd64 + required: false + +runs: + using: docker + image: Dockerfile diff --git a/entrypoint.sh b/entrypoint.sh new file mode 100644 index 0000000..3a67372 --- /dev/null +++ b/entrypoint.sh @@ -0,0 +1,55 @@ +#! /bin/bash + +docker -v + +if [ -n "$INPUT_USERNAME" ]; then + echo "$INPUT_PASSWORD" | docker login $INPUT_REGISTRY -u $INPUT_USERNAME --password-stdin + + if [ ! -f /root/.docker/config.json ] || ! cat /root/.docker/config.json | grep -q "$INPUT_REGISTRY"; then + echo "登录失败" + exit 1 + fi +fi + +echo $INPUT_TAGS + +tags=(${INPUT_TAGS//,/ }) + +echo $tags + +cd $INPUT_CONTEXT + +tmp_image_name=$(uuidgen) +tmp_image_name=${tmp_image_name//-/} + +if [ -n "$INPUT_PLATFORM" ]; then + #开启实验特性 + DOCKER_CLI_EXPERIMENTAL=enabled + + docker buildx create --platform $INPUT_PLATFORM --use --name build + echo "docker buildx build -t $tmp_image_name -f $INPUT_DOCKERFILE --load --platform $INPUT_PLATFORM ." + docker buildx build -t $tmp_image_name -f $INPUT_DOCKERFILE --load --platform $INPUT_PLATFORM . +else + echo "docker build -t $tmp_image_name -f $INPUT_DOCKERFILE ." + docker build -t $tmp_image_name -f $INPUT_DOCKERFILE . +fi + +if docker images --format "{{.Repository}}:{{.Tag}}" | grep -q $tmp_image_name; then + echo "镜像存在" + + for tag in ${tags[@]}; do + image_name="$INPUT_REGISTRY/$INPUT_IMAGE:$tag" + echo "docker tag $tmp_image_name $image_name" + docker tag $tmp_image_name $image_name + docker push $image_name + + docker rmi $image_name + done + + docker rmi $tmp_image_name + + echo "删除所有构建镜像完成" +else + echo "镜像不存在" + exit 1 +fi