Skip to content

Commit

Permalink
update README and description
Browse files Browse the repository at this point in the history
  • Loading branch information
kengo-k committed Jun 1, 2024
1 parent 356b844 commit 8757596
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 22 deletions.
69 changes: 60 additions & 9 deletions REAEME.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,64 @@
GitHubActionsの仕様を簡単に書くので英語ドキュメントしてまとめてください。GitHubのREADME.mdとして使うのでマークダウンのソースファイルとして書いてください。なお、私が書く形式に従う必要はないので、適切なドキュメントとして適切な表現になおしてください。
# Docker Image Builder

このアクションが行うこと。
This GitHub Action automatically builds Docker images and pushes them to the GitHub Container Registry (GHCR) whenever a Dockerfile is committed to a repository and a branch or tag is pushed.

- リポジトリ内のDockerfileを自動的にビルドしてイメージをGHCRにPUSHする。
## Usage

定義されている引数
To use this action in your workflow, add the following step to your `.github/workflows/main.yml` file:

token: GHCRにアクセスするためのトークン(必須)
branch: 対象となるブランチ名(必須)。このブランチがPUSHされた場合にのみ動作する
only_changed: trueの場合は前回のコミットにDockerfileが含まれていればビルドおよびPUSHを行う(オプショナル。default=true)
with_branch: trueの場合イメージ名にブランチ名を含める(オプショナル。default=false)
width_timestamp: trueの場合イメージ名にタイムスタンプを含める()
```yaml
name: 'Test to publish Docker image'
on:
push:
branches:
- main
tags:
- '*'

jobs:
test:
runs-on: ubuntu-22.04
steps:
- name: 'Test'
uses: kengo-k/docker-build@v1
with:
token: ${{ secrets.GHCR_TOKEN }}
timezone: 'Asia/Tokyo'
args: |
- path: .github/workflows/Dockerfile
name: helloworld
on_branch_pushed: true
on_branch_changed: true
on_tag_pushed: true
include_branch_name: true
include_timestamp: true
include_commit_sha: true
```
### Input Arguments
- `token` (required): A token with permissions to access the GitHub repository information and push images to GHCR.
- `timezone` (optional): The timezone used for generating timestamps in the image tags. Default is UTC.
- `args` (required): An array of objects specifying the configuration values for building Dockerfiles. Each object should contain the following properties:
- `path` (required): The path to the Dockerfile.
- `name` (required): The name of the built image.
- `on_branch_pushed` (optional): Whether to build the image when a branch is pushed. Default is `true`.
- `on_branch_changed` (optional): If `on_branch_pushed` is `true`, only build the image if the Dockerfile is included in the commit. Default is `true`.
- `on_tag_pushed` (optional): Whether to build the image when a tag is pushed. Default is `true`.
- `include_branch_name` (optional): Whether to include the branch name in the image tag when a branch is pushed. Default is `true`.
- `include_timestamp` (optional): Whether to include a timestamp in the image tag when a branch is pushed. Default is `true`.
- `include_commit_sha` (optional): Whether to include the commit ID in the image tag when a branch is pushed. Default is `true`.

## How It Works

When a branch or tag is pushed to the repository, this action will:

1. Check if a Dockerfile is present in the repository based on the provided `path` in the `args` configuration.
2. If `on_branch_pushed` is `true` and the push event is for a branch, build the Docker image.
3. If `on_branch_changed` is `true`, only build the image if the Dockerfile is included in the commit.
4. If `on_tag_pushed` is `true` and the push event is for a tag, build the Docker image.
5. Generate an image tag based on the specified options (`include_branch_name`, `include_timestamp`, `include_commit_sha`).
6. Build the Docker image using the provided Dockerfile and image name.
7. Push the built image to the GitHub Container Registry (GHCR) using the generated tag.

This action simplifies the process of building and pushing Docker images to GHCR, making it easier to automate your container deployment workflow.
16 changes: 8 additions & 8 deletions action.yaml
Original file line number Diff line number Diff line change
@@ -1,38 +1,38 @@
name: 'Hello World'
description: 'Greet someone and record the time'
name: 'docker-build'
description: 'Build and Push Docker Images automatically'
inputs:
token:
description: 'GitHub Token'
required: true
timezone:
description: 'Timezone'
description: 'Timezone for creating timestamps to include in image tag'
required: true
default: 'UTC'
args:
description: 'Who to greet'
description: 'Configuration values for building images'
required: true
runs:
using: 'composite'
steps:
- name: 'Call Another Action'
- name: 'Get docker build args'
id: js_action
uses: kengo-k/docker-build/internal/get@main
with:
token: ${{ inputs.token }}
timezone: ${{ inputs.timezone }}
args: ${{ inputs.args }}

- name: login to ghcr
- name: Login to ghcr
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ inputs.token }}

- name: checkout latest commit
- name: Checkout latest commit
uses: actions/checkout@v4

- name: 'Display Output'
- name: 'Build and Push Docker Images'
shell: bash
run: |
build_args='${{ steps.js_action.outputs.build_args }}'
Expand Down
10 changes: 5 additions & 5 deletions internal/get/action.yaml
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
name: 'Hello World'
description: 'Greet someone and record the time'
name: 'get'
description: 'Get information for building Docker images'
inputs:
token:
description: 'GitHub Token'
required: true
timezone:
description: 'Timezone'
description: 'Timezone for creating timestamps to include in image tag'
required: true
default: 'UTC'
args:
description: 'Who to greet'
description: 'Configuration values for building images'
required: true
outputs:
build_args:
description: 'The generated docker command'
description: 'Arguments to pass to the docker build command'
runs:
using: 'docker'
image: 'Dockerfile'

0 comments on commit 8757596

Please sign in to comment.