From df5a69a2112b94b2f76fa6df42373260542b1fde Mon Sep 17 00:00:00 2001 From: Junmin Ahn Date: Tue, 7 Mar 2023 21:04:56 -0800 Subject: [PATCH] feat: add initial action --- .gitignore | 0 .pre-commit-config.yaml | 27 +++++++++++++ .tool-versions | 2 + LICENSE | 21 ++++++++++ README.md | 1 + action.yml | 89 +++++++++++++++++++++++++++++++++++++++++ requirements.txt | 1 + 7 files changed, 141 insertions(+) create mode 100644 .gitignore create mode 100644 .pre-commit-config.yaml create mode 100644 .tool-versions create mode 100644 LICENSE create mode 100644 README.md create mode 100644 action.yml create mode 100644 requirements.txt diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..e69de29 diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml new file mode 100644 index 0000000..9bedaa0 --- /dev/null +++ b/.pre-commit-config.yaml @@ -0,0 +1,27 @@ +repos: +- repo: https://github.com/pre-commit/pre-commit-hooks + rev: v4.4.0 + hooks: + - id: check-added-large-files + - id: check-case-conflict + - id: check-executables-have-shebangs + files: \.sh + - id: check-json + - id: check-merge-conflict + - id: check-shebang-scripts-are-executable + - id: check-symlinks + - id: check-vcs-permalinks + - id: check-xml + - id: check-yaml + - id: detect-aws-credentials + - id: detect-private-key + - id: end-of-file-fixer + - id: fix-byte-order-marker + - id: forbid-submodules + - id: trailing-whitespace +- repo: https://github.com/macisamuele/language-formatters-pre-commit-hooks + rev: v2.7.0 + hooks: + - id: pretty-format-yaml + args: [--autofix, --indent, '2'] +default_stages: [commit] diff --git a/.tool-versions b/.tool-versions new file mode 100644 index 0000000..c359f99 --- /dev/null +++ b/.tool-versions @@ -0,0 +1,2 @@ +python 3.11.2 +semtag 0.1.1 diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..d0049e0 --- /dev/null +++ b/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) Junmin Ahn + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/README.md b/README.md new file mode 100644 index 0000000..52945f4 --- /dev/null +++ b/README.md @@ -0,0 +1 @@ +# GitHub Action - docker-build-push diff --git a/action.yml b/action.yml new file mode 100644 index 0000000..87becc7 --- /dev/null +++ b/action.yml @@ -0,0 +1,89 @@ +name: Docker Image Build & Push +description: Build Docker image and push to a container registry + +inputs: + registry-url: + description: Docker container registry server URL + required: true + registry-username: + description: Docker container registry username + required: true + registry-password: + description: Docker container registry password + required: true + image-name: + description: Docker image name + required: true + metadata-tags: + description: List of tags as key-value pair attributes + required: true + metadata-labels: + description: List of tags as key-value pair attributes + required: false + docker-context: + description: Docker build's context + required: false + docker-file: + description: Path to the Dockerfile + required: false + docker-args: + description: Docker image build args + required: false + +runs: + using: composite + steps: + - name: Log in to Docker Container Registry + # see https://github.com/docker/login-action/commit/f4ef78c080cd8ba55a85445d5b36e214a81df20a + uses: docker/login-action@f4ef78c080cd8ba55a85445d5b36e214a81df20a + with: + registry: ${{ inputs.registry-url }} + username: ${{ inputs.registry-username }} + password: ${{ inputs.registry-password }} + + - name: Extract metadata + id: meta + # see https://github.com/docker/metadata-action/commit/507c2f2dc502c992ad446e3d7a5dfbe311567a96 + uses: docker/metadata-action@507c2f2dc502c992ad446e3d7a5dfbe311567a96 + with: + images: ${{ inputs.registry-url }}/${{ inputs.image-name }} + tags: ${{ inputs.metadata-tags }} + labels: ${{ inputs.metadata-labels }} + + - name: Set up Docker Buildx + # see https://github.com/docker/setup-buildx-action/commit/f03ac48505955848960e80bbb68046aa35c7b9e7 + uses: docker/setup-buildx-action@f03ac48505955848960e80bbb68046aa35c7b9e7 + + - name: Set Environment variables + run: | + DOCKER_LAYERS_PATH="/tmp/.buildx-cache-${{ inputs.image-name }}" + echo "DOCKER_LAYERS_PATH=${DOCKER_LAYERS_PATH}" >> $GITHUB_ENV + shell: bash + + # see https://github.com/docker/build-push-action/issues/252#issuecomment-744400434 + - name: Cache Docker layers + # see https://github.com/actions/cache/commit/69d9d449aced6a2ede0bc19182fadc3a0a42d2b0 + uses: actions/cache@69d9d449aced6a2ede0bc19182fadc3a0a42d2b0 + with: + path: ${{ env.DOCKER_LAYERS_PATH }} + key: ${{ runner.os }}-buildx-${{ inputs.image-name }}-${{ github.sha }} + restore-keys: ${{ runner.os }}-buildx-${{ inputs.image-name }} + + - name: Build and push Docker image + # see https://github.com/docker/build-push-action/commit/3b5e8027fcad23fda98b2e3ac259d8d67585f671 + uses: docker/build-push-action@3b5e8027fcad23fda98b2e3ac259d8d67585f671 + with: + context: ${{ inputs.docker-context }} + file: ${{ inputs.docker-file }} + push: true + tags: ${{ steps.meta.outputs.tags }} + build-args: ${{ inputs.docker-args }} + labels: ${{ steps.meta.outputs.labels }} + cache-from: type=local,src=${{ env.DOCKER_LAYERS_PATH }} + cache-to: type=local,dest=${{ env.DOCKER_LAYERS_PATH }}-new + + - name: Move Docker layers cache + run: | + rm -rf ${{ env.DOCKER_LAYERS_PATH }} + mv ${{ env.DOCKER_LAYERS_PATH }}-new ${{ env.DOCKER_LAYERS_PATH }} + shell: bash diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..d2c3143 --- /dev/null +++ b/requirements.txt @@ -0,0 +1 @@ +pre-commit==3.1.1