chore: init

This commit is contained in:
seepine 2024-10-01 22:56:17 +08:00
commit e61198e414
5 changed files with 257 additions and 0 deletions

16
.editorconfig Normal file
View File

@ -0,0 +1,16 @@
# Editor configuration, see http://editorconfig.org
# 表示是最顶层的 EditorConfig 配置文件
root = true
[*] # 表示所有文件适用
charset = utf-8 # 设置文件字符集为 utf-8
indent_style = space # 缩进风格tab | space
indent_size = 2 # 缩进大小
end_of_line = lf # 控制换行类型(lf | cr | crlf)
trim_trailing_whitespace = true # 去除行首的任意空白字符
insert_final_newline = true # 始终在文件末尾插入一个新行
[*.md] # 表示仅 md 文件适用以下规则
max_line_length = off
trim_trailing_whitespace = false

35
.gitattributes vendored Normal file
View File

@ -0,0 +1,35 @@
* text=auto
# Force the following filetypes to have unix eols, so Windows does not break them
*.* text eol=lf
# Separate configuration for files without suffix
LICENSE text eol=lf
Dockerfile text eol=lf
pre-commit text eol=lf
commit-msg text eol=lf
# These files are binary and should be left untouched
# (binary is a macro for -text -diff)
*.ico binary
*.jpg binary
*.jpeg binary
*.png binary
*.pdf binary
*.doc binary
*.docx binary
*.ppt binary
*.pptx binary
*.xls binary
*.xlsx binary
*.exe binary
*.jar binary
*.ttf binary
*.woff binary
*.woff2 binary
*.eot binary
*.otf binary
# Add more binary...

30
.gitignore vendored Normal file
View File

@ -0,0 +1,30 @@
node_modules
.DS_Store
dist
dist-ssr
*.local
# local env files
.env.local
.env.*.local
# Log files
npm-debug.log*
yarn-debug.log*
yarn-error.log*
pnpm-debug.log*
# Editor directories and files
.idea
*.suo
*.ntvs*
*.njsproj
*.sln
*.sw?
# vuepress
.temp
.cache
package-lock.json
yarn.lock

67
README.md Normal file
View File

@ -0,0 +1,67 @@
# action-docker-build-push
> Setup docker, build image and push
## Usage
```yml
- name: Docker build push
uses: seepine/action-docker-build-push@v1
with:
registry: docker.io
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
platforms: linux/amd64,linux/arm64
tags: |
docker.io/${{ secrets.DOCKER_USERNAME }}/demo:latest
docker.io/${{ secrets.DOCKER_USERNAME }}/demo:1.2.3
```
## Set dockerfile
```yml
- name: Docker build push
uses: seepine/action-docker-build-push@v1
with:
registry: docker.io
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
context: . # default .
file: ./build/Dockerfile # default Dockerfile
platforms: linux/amd64,linux/arm64
tags: |
docker.io/${{ secrets.DOCKER_USERNAME }}/demo:latest
docker.io/${{ secrets.DOCKER_USERNAME }}/demo:1.2.3
```
## Set proxy
```yml
# Set into act runner config.yml also
env:
HTTP_PROXY: http://192.168.2.4:7890/
HTTPS_PROXY: http://192.168.2.4:7890/
NO_PROXY: 127.0.0.1,localhost,172.17.0.1
jobs:
build-image:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
with:
fetch-depth: 1
- name: Docker build push
uses: seepine/action-docker-build-push@v1
with:
registry: docker.io
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
platforms: linux/amd64,linux/arm64
tags: |
docker.io/${{ secrets.DOCKER_USERNAME }}/demo:latest
docker.io/${{ secrets.DOCKER_USERNAME }}/demo:1.2.3
```

109
action.yml Normal file
View File

@ -0,0 +1,109 @@
name: 'action-docker-build-push'
description: 'Setup docker, build image and push'
branding:
icon: package
color: orange
inputs:
registry:
description: 'Server address of Docker registry. If not set then will default to Docker Hub'
required: false
username:
description: 'Username used to log against the Docker registry'
required: false
password:
description: 'Password or personal access token used to log against the Docker registry'
required: false
context:
description: "Build's context is the set of files located in the specified PATH or URL"
required: false
default: '.'
file:
description: "Path to the Dockerfile"
required: false
default: 'Dockerfile'
tags:
description: "List of tags"
required: true
platforms:
description: "List of target platforms for build"
required: false
push:
description: "Push is a shorthand for --output=type=registry"
required: false
default: 'true'
runs:
using: 'composite'
steps:
- name: Set up Proxy env
run: |
echo "[$(date +'%Y-%m-%d %H:%M:%S')] ⚙️ Set up Proxy env"
if [ -n "${{ env.HTTP_PROXY }}" ]; then
echo "http_proxy=${{ env.HTTP_PROXY }}" >> $GITHUB_ENV
fi
if [ -n "${{ env.HTTPS_PROXY }}" ]; then
echo "https_proxy=${{ env.HTTPS_PROXY }}" >> $GITHUB_ENV
fi
if [ -n "${{ env.NO_PROXY }}" ]; then
echo "no_proxy=${{ env.NO_PROXY }}" >> $GITHUB_ENV
fi
echo "http_proxy=${{ env.http_proxy }}"
echo "https_proxy=${{ env.https_proxy }}"
echo "no_proxy=${{ env.no_proxy }}"
- name: echo Set up QEMU
run: echo -e "\n[$(date +'%Y-%m-%d %H:%M:%S')] ⚙️ Set up QEMU"
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
- name: echo Set up Docker BuildX
run: echo -e "\n[$(date +'%Y-%m-%d %H:%M:%S')] ⚙️ Set up Docker BuildX"
- name: Set up Docker BuildX
uses: docker/setup-buildx-action@v3
with:
driver-opts: |
env.http_proxy=${{ env.http_proxy }}
env.https_proxy=${{ env.https_proxy }}
"env.no_proxy='${{ env.no_proxy }}'"
- name: echo Login to DockerHub
run: echo -e "\n[$(date +'%Y-%m-%d %H:%M:%S')] ⚙️ Login to DockerHub"
if: ${{ inputs.username != '' }}
- name: Login to DockerHub
uses: docker/login-action@v3
if: ${{ inputs.username != '' }}
with:
registry: ${{ inputs.registry }}
username: ${{ inputs.username }}
password: ${{ inputs.password }}
- name: echo Cache docker build
run: echo -e "\n[$(date +'%Y-%m-%d %H:%M:%S')] ⚙️ Cache docker build"
- name: Cache docker build
uses: actions/cache@v3
with:
path: /opt/docker-cache/.build-cache
key: ${{ runner.os }}-docker-build-cache
- name: echo Build and push
run: echo -e "\n[$(date +'%Y-%m-%d %H:%M:%S')] ⚙️ Build and push"
- name: Build and push
uses: docker/build-push-action@v4
with:
context: ${{ inputs.context }}
file: ${{ inputs.file }}
platforms: ${{ inputs.platforms }}
push: ${{ inputs.push }}
tags: ${{ inputs.tags }}
cache-from: type=local,src=/opt/docker-cache/.build-cache
cache-to: type=local,dest=/opt/docker-cache/.build-cache,mode=max
build-args: |
"http_proxy='${{ env.http_proxy }}'"
"https_proxy='${{ env.https_proxy }}'"