pyaction: A Docker container with Python, git, and the GitHub CLI
Tags: github, docker, python, devops
Published: 2022-12-28 16:22:23

## What is pyaction? 

The [pyaction](https://github.com/cicirello/pyaction) container is a [Python slim image](https://hub.docker.com/_/python) on top of which I've added git and the [GitHub CLI](https://cli.github.com/), as well as gpg and curl. For the motivating usecases, I mainly need Python, git, and the GitHub CLI. The pyaction image includes gpg and curl because they are needed to install the GitHub CLI, and I saw no point in uninstalling them afterwards as part of the container build. It is available from both [Docker Hub](https://hub.docker.com/r/cicirello/pyaction) and the [GitHub Container Registry](https://github.com/cicirello/pyaction/pkgs/container/pyaction).

The latest release, [4.14.0](https://github.com/cicirello/pyaction/releases/tag/v4.14.0), includes the following versions:
* Python 3.11.1
* GitHub CLI 2.21.1
* git 2.30.2
* curl 7.74.0
* gpg 2.2.27

I use [GitHub's dependabot](https://github.com/dependabot) to monitor for updates to the Python Docker slim image, and a custom script to monitor for new releases of the GitHub CLI. And I regularly create new releases of pyaction when either the official Python slim Docker image or the GitHub CLI publishes a new release. 

pyaction is a multiplatform image supporting the following platforms:
* linux/386
* linux/amd64
* linux/arm/v7
* linux/arm64

The GitHub repository is (please consider starring it):

{% github cicirello/pyaction %}

__Table of Contents:__
* [What is pyaction?](#what-is-pyaction)
* [Original Motivation](#original-motivation)
* [Docker Tags and Versioning Scheme](#docker-tags-and-versioning-scheme)
* [Installing](#installing)
  * [Docker Pull Command](#docker-pull-command)
  * [Use as a base image in a Dockerfile](#use-as-a-base-image-in-a-dockerfile)
* [More Information](#more-information)
* [Where You Can Find Me](#where-you-can-find-me)


## Original Motivation

I maintain several GitHub Actions that are implemented in Python as [container actions](https://docs.github.com/en/actions/creating-actions/creating-a-docker-container-action). To speed up loading of those Actions, I maintain a Docker container with all of the tools those Actions may need preinstalled. This way, when a workflow run references one of my Actions, the container build for the Action only needs to add the layer with the source code of the Action itself without the need to install various tools during each workflow run. The pyaction container is certainly not limited to such usage.


## Docker Tags and Versioning Scheme

I push images to both Docker Hub and the GitHub Container Registry.

I use [Semantic Versioning](https://semver.org/) for the tags. [Semantic Versioning](https://semver.org/) uses version numbers of the form: MAJOR.MINOR.PATCH, where differences in MAJOR correspond to incompatible changes, differences in MINOR correspond to introduction of backwards compatible new functionality, and PATCH corresponds to backwards compatible bug fixes. 

In this case, if a release includes only patch level updates to the GitHub CLI, Python, etc, then I simply bump the patch part of the version number. If a release includes any minor updates to the GitHub CLI, Python, etc, then I bump the minor part of pyaction's version. If the GitHub CLI, Python, etc includes any breaking changes, then I'll bump the major part of the version number.

Each image pushed to Docker Hub and the Github Container Registry is tagged as follows:
* The tag `latest` indicates, well, the latest image.
* Tags of the form MAJOR.MINOR.PATCH (e.g., 4.14.0).
* Tags of the form MAJOR.MINOR (e.g., 4.14).
* Tags of the form MAJOR (e.g., 4).


## Installing

The pre-built image is hosted on both Docker Hub and the GitHub Container Registry. You can use it in the following ways.

### Docker Pull Command

Pull the latest image from Docker Hub with the following (or replace with tag of desired version):

```Shell
docker pull cicirello/pyaction:4.14.0
```

Pull from the Github Container Registry with:

```Shell
docker pull ghcr.io/cicirello/pyaction:4.14.0
```


### Use as a base image in a Dockerfile

Use as a base image in a Dockerfile (or replace with tag of desired version):

```Dockerfile
FROM cicirello/pyaction:4.14.0

# The rest of your Dockerfile would go here.
```

Or you can use as a base image (via the Github Container Registry) with:

```Dockerfile
FROM ghcr.io/cicirello/pyaction:4.14.0

# The rest of your Dockerfile would go here.
```

## More Information

Additional information available on its website:

{% embed https://actions.cicirello.org/pyaction/ %}

## Where You Can Find Me

Follow me [here on DEV](https://dev.to/cicirello) and on [GitHub](https://github.com/cicirello):

{% user cicirello %}

Or visit my website:

{% embed https://www.cicirello.org/ %}