Logo

dev-resources.site

for different kinds of informations.

Creating a GitHub Action for a Docker Image

Published at
8/6/2023
Categories
docker
dockerfile
github
Author
blugreenspace
Categories
3 categories in total
docker
open
dockerfile
open
github
open
Author
13 person written this
blugreenspace
open
Creating a GitHub Action for a Docker Image

What are GitHub Actions anyway?

Actions are one of the the smallest executable steps of a job, or you can say a job is composed of steps which can be actions or commands. You can create GitHub Actions based on docker images. More details.

Creating a Github Action for an existing Dockerfile

Mainly three files are required, Dockerfile, entrypoint.sh, and actions.yml.

Let's start with creating a Dockerfile for our action, I'll use my Android CI Dockerfile. It's a simple Dockerfile, which includes all Android build-related tools, recent SDKs, Java, etc.

The Dockerfile for action uses the existing Docker image and extends it to include entrypoint script. The idea for the script is basically to pass the input from a step in workflow to runtime of the Docker in the Github environment.

Dockerfile

# Container image that runs your code
FROM code0987/android-ci:latest
# Copy your code to the filesystem path `/` of the container
COPY entrypoint.sh /
# Grant executable permission to entrypoint file
RUN ["chmod", "+x", "/entrypoint.sh"]
# Code file to execute when the docker container starts up (`entrypoint.sh`)
ENTRYPOINT ["/entrypoint.sh"]
Enter fullscreen mode Exit fullscreen mode

entrypoint.sh

This script runs all the input passed from GitHub Workflow, as a set of commands in non-interactive sh spawned inside Docker runtime.

#!/bin/sh
set -eu
sh -c "$*"
Enter fullscreen mode Exit fullscreen mode

Now let's define the action metadata so that GitHub can recognize this action. The specifics for Dockerfile based actions are, defining -

runs:
 using: 'docker'
 image: 'Dockerfile'
 args: 
Enter fullscreen mode Exit fullscreen mode

actions.yml

name: 'Hello World'
description: 'Greet someone and record the time'
runs:
  using: 'docker'
  image: 'Dockerfile'
Enter fullscreen mode Exit fullscreen mode

Using above action in a GitHub Workflow

name: Android CI
on: [push]
jobs:
  android-ci:
    runs-on: ubuntu-latest
    steps:
    - uses: actions/checkout@v1
    - name: "Android CI Github Action"
      uses: code0987/android-ci-github-action@master
      with:
        args: |
          chmod 755 gradlew 
          gradlew check
Enter fullscreen mode Exit fullscreen mode

Example


References

GitHub repo for action used as example, android-ci-github-action.

https://help.github.com/en/actions/building-actions/creating-a-docker-container-action

dockerfile Article's
30 articles in total
Favicon
Docker 101: A Guide to Docker Commands, Terminologies & Dockerfile
Favicon
Understanding Docker Compose File Format: Structure, Options, and Best Practices
Favicon
Mastering Dockerfile Syntax: A Complete Guide for Creating Custom Docker Images
Favicon
Understanding Docker Image Layers: Best Practices for Building Efficient Docker Images
Favicon
Best Practices for Writing Efficient and Maintainable Dockerfiles
Favicon
Dockerfile Explain
Favicon
Getting Started with Docker.
Favicon
Building and Deploying a Dockerized Web Application
Favicon
Dive Into Docker: A Hands-On Lab For Getting Started
Favicon
Dockerfile for PHP Laravel
Favicon
Container Files and Dockerfiles: A Comprehensive Guide
Favicon
Understanding Dockerfile: The Blueprint of Docker Containers and Images
Favicon
How to Create Docker Image for HTTPD service, including portfolio web site.
Favicon
Optimized Keycloak build
Favicon
Fun with Avatars: Containerize the app for deployment & distribution | Part. 2
Favicon
The Comprehensive Guide to Dockerfiles
Favicon
[Go Tour ] 2. Optimize Dockerfile
Favicon
Docker II: 5 tópicos para iniciar o mais rápido possível
Favicon
Mastering Dockerfile ️🐳: 10 Advanced Tips and Best Practices ⚔
Favicon
hadolint - Dockerfile linter
Favicon
Dockerfile
Favicon
Creating a GitHub Action for a Docker Image
Favicon
🐳 Boost Your Docker Workflow: Introducing Docker Init for Python Developers 🚀
Favicon
3 Tips to Improve Your Dockerfile Build Time
Favicon
Abrindo mares: Dockerfile, o que precisamos saber!
Favicon
Failed to Read Dockerfile
Favicon
Why i use a smaller docker image
Favicon
Differences Between a DockerFile, Docker Image, and Docker Container
Favicon
Clear up the confusions with Dockerfile instructions
Favicon
How to Create a Dockerfile?

Featured ones: