Skip to content

Commit

Permalink
feat: add initial action
Browse files Browse the repository at this point in the history
  • Loading branch information
junminahn committed Mar 8, 2023
0 parents commit df5a69a
Show file tree
Hide file tree
Showing 7 changed files with 141 additions and 0 deletions.
Empty file added .gitignore
Empty file.
27 changes: 27 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -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]
2 changes: 2 additions & 0 deletions .tool-versions
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
python 3.11.2
semtag 0.1.1
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -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.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# GitHub Action - docker-build-push
89 changes: 89 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
@@ -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
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
pre-commit==3.1.1

0 comments on commit df5a69a

Please sign in to comment.