[DOCKER] Try actions on GitHub [actions]

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.

goal

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)

Things to prepare

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

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

Contents of workflow file (main.yml)

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'.

Contents of the action file (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 }}

Contents of Dockerfile

Just run entrypoint.sh.

FROM alpine:3.10

COPY entrypoint.sh /entrypoint.sh

ENTRYPOINT [ "/entrypoint.sh" ]

Contents of entrypoint.sh

Receives and outputs arguments.

#!/bin/sh -l

echo "Hello $1"
time=$(date)
echo ::set-output name=time::$time

Execute

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. actions-result.png

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

Try actions on GitHub [actions]
Try DisplayLink on Ubuntu 20.04
Try OpenLiteSpeed on CentOS8
Run Ruby on Rails RSpec tests with GitHub Actions
Try RabbitMQ + PHP on CentOS
Try Docker on Windows 10 Home
GitHub Actions Introduction to self-made actions
Try Spring Boot on Mac
[Ruby on Rails] Read try (: [],: key)
Try using Redmine on Mac docker
Try putting CentOS 8 on Raspberry Pi 3
Try Quarkus on IBM Cloud Shell
Try Docker on Windows Home (September 2020)
Try running Spring Boot on Kubernetes
Easily try C # 9 (.NET 5) on Docker
Try "Introduction to Vert.x" on Gradle
Publish Docker Image on GitHub Package Registry
Try DPDK20 SDK on CentOS7 (2) Control DPDK driver
Try using the service on Android Oreo
Try running Word2vec model on AWS Lambda
Try Health Check on Azure App Service.
Publish JAR on Gradle on GitHub Package Registry
CI for Maven project at Github Actions
Try putting Docker in ubuntu on WSL
Try the Docker environment on AWS ECS
Steps to register Java files on GitHub