Actions, a CI/CD tool provided by GitHub. If you can master this tool, it seems that deploying the theme of this blog can be simplified, so I tried what it is.
Execute the workflow using the Dockerfile prepared by yourself. There is an official action creation sample, so let's create a custom action while referring to that.
Create an action for a Docker container (https://docs.github.com/ja/free-pro-team@latest/actions/creating-actions/creating-a-docker-container-action#write-the-action-code)
Create main.yml to define the workflow, create action.yml to run in the Docker container, and create the action code in Dockerfile and entrypoint.sh.
Directory structure including the configuration file created this time. The file that describes the workflow is placed in .github/workflows. The file name is main.yaml, but there is no particular specification.
.
├── .github
│ └── workflows
│ └── main.yaml
├── Dockerfile
├── README.md
├── action.yml
└── entrypoint.sh
This time we will run the task in the repository where this file is, so run checkout.
on: [push]
jobs:
hello_world_job:
runs-on: ubuntu-latest
name: A job to say hello
steps:
# To use this repository's private action, you must check out the repository
- name: Checkout
uses: actions/checkout@v1
- name: Hello world action step
id: hello
uses: ./
with:
who-to-greet: 'Mona the Octocat'
# Use the output from the `hello` step
- name: Get the output time
run: echo "The time was ${{ steps.hello.outputs.time }}"
jobs.<job_id>.steps.uses
This property specifies the directory of action.yml
or Dockerfile
. An error will occur if you specify the file name directly
##[error]Can't find 'action.yml' or 'Dockerfile' under '/home/runner/work/actions/actions/.github/action.yml'.
Since it is executed in the Docker container, specify docker in runs.using.
name: 'Hello World'
description: 'Greet someone and record the time'
inputs:
who-to-greet: # id of input
description: 'Who to greet'
required: true
default: 'World'
outputs:
time: # id of output
description: 'The time we greeted you'
runs:
using: 'docker'
image: 'Dockerfile'
args:
- ${{ inputs.who-to-greet }}
Just run entrypoint.sh.
FROM alpine:3.10
COPY entrypoint.sh /entrypoint.sh
ENTRYPOINT [ "/entrypoint.sh" ]
Receives and outputs arguments.
#!/bin/sh -l
echo "Hello $1"
time=$(date)
echo ::set-output name=time::$time
If you prepare the above file and push it, the workflow will be executed. If the execution is successful, a check mark will be added to each task as shown below.
Refference
Workflow syntax for GitHub Actions (https://docs.github.com/ja/free-pro-team@latest/actions/reference/workflow-syntax-for-github-actions)
GitHub Actions Metadata Syntax (https://docs.github.com/ja/free-pro-team@latest/actions/creating-actions/metadata-syntax-for-github-actions)
Recommended Posts