From e61198e414c0ef54cf3ef1765bc28b34ab10dd99 Mon Sep 17 00:00:00 2001 From: seepine Date: Tue, 1 Oct 2024 22:56:17 +0800 Subject: [PATCH] chore: init --- .editorconfig | 16 ++++++++ .gitattributes | 35 ++++++++++++++++ .gitignore | 30 ++++++++++++++ README.md | 67 ++++++++++++++++++++++++++++++ action.yml | 109 +++++++++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 257 insertions(+) create mode 100644 .editorconfig create mode 100644 .gitattributes create mode 100644 .gitignore create mode 100644 README.md create mode 100644 action.yml diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..ddcefeb --- /dev/null +++ b/.editorconfig @@ -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 diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..ccadb89 --- /dev/null +++ b/.gitattributes @@ -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... diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..13a879a --- /dev/null +++ b/.gitignore @@ -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 diff --git a/README.md b/README.md new file mode 100644 index 0000000..8b9f293 --- /dev/null +++ b/README.md @@ -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 +``` diff --git a/action.yml b/action.yml new file mode 100644 index 0000000..6e5a831 --- /dev/null +++ b/action.yml @@ -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 }}'"