first commit

This commit is contained in:
qxa 2025-03-25 18:23:07 +08:00
commit f0d50f8506
5 changed files with 175 additions and 0 deletions

63
.gitattributes vendored Normal file
View File

@ -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

6
.gitignore vendored Normal file
View File

@ -0,0 +1,6 @@
################################################################################
# 此 .gitignore 文件已由 Microsoft(R) Visual Studio 自动创建。
################################################################################
.vs
.vscode

15
Dockerfile Normal file
View File

@ -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

36
action.yml Normal file
View File

@ -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

55
entrypoint.sh Normal file
View File

@ -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