Skip to content
Marc Cornellà edited this page Nov 22, 2021 · 4 revisions

This repository manages the @ohmyzsh Docker images.

Structure

Each top-level directory contains the code for an image, which has the same name as the directory.

Required files:

  • Dockerfile: read by the docker buildx command.
  • build.sh: script to build all the tags of the Docker image. Must use docker buildx.
  • .dockerignore: lists all files that aren't required to build the image (build.sh and README.md, if present).

Optionally, the directory can have a README.md file which will be shown in the Docker Hub page.

Sample image (ohmyzsh/zsh):

$ tree -a zsh
zsh
├── .dockerignore
├── build.sh
├── Dockerfile
└── README.md

$ cat .dockerignore
build.sh
README.md

NOTE: if a directory does not contain a Dockerfile image it will not be considered an image and the build system will ignore it. Therefore, you can add as many directories as you need (e.g. for utilities) as long as they do not have a Dockerfile image.

Build system

The current workflow (main.yml) is triggered via the schedule event on Mondays, Wednesdays and Fridays.

First, it calls all build.sh scripts for all found image directories (those that contain Dockerfile files), which have the logic to build all tags of the image. The build script for ohmyzsh/zsh, for instance, dynamically fetches all tags of zshusers/zsh and builds ohmyzsh/zsh for all of them. The script should properly register the tags as well, including the latest tag, which is the default when doing docker pull <image-name>.

After that, the workflow logs into Docker Hub and pushes all the generated images. This is possible because the environment that built the Docker images is the same, so the previously built images are still present.

Lastly, if the image directories contain a README.md file, those are updated in the Docker Hub page as well, using the .github/scripts/update-image-readme.js script. Note that for this to work, the environment needs a DH_USERNAME and DH_PASSWORD that is supported by the API.

Requirements for Docker Hub image README updates:

  • Valid username: it should be a member of the Docker Hub ohmyzsh organization.
  • Valid password for the README update API: needs to be a password. Personal Access Tokens (PAT) are not supported.
  • The user needs to have owner permission over the Docker Hub images.

build.sh script

Example for ohmyzsh/zsh:

#!/bin/bash

# Enter the directory
cd "$(dirname "${BASH_SOURCE[0]}")" >/dev/null 2>&1

# Get image username
USERNAME="$1"
# Get image from directory name
IMAGE="$(basename "$(pwd)")"

# List of published zshusers/zsh Docker images
versions="$(wget -qO- https://registry.hub.docker.com/v1/repositories/zshusers/zsh/tags | sed 's/[^0-9.]*"name": "\([^"]*\)"[^0-9.]*/\n\1\n/g;s/^\n//')"

# Build images
for version in $versions; do
    docker buildx build -t "$USERNAME/$IMAGE:$version" --build-arg ZSH_VERSION="$version" .
done

# Tag latest image
latest=$(tr ' ' '\n' <<< "$versions" | sed '/^$/d' | sort -V | tail -2 | head -1)
docker tag "$USERNAME/$IMAGE:$latest" "$USERNAME/$IMAGE:latest"
  1. Write in bash and properly set the shebang to #!/bin/bash.
  2. Get the image username passed as the first argument (DOCKERHUB_ORG GitHub Actions secret).
  3. Run the logic for getting all tags for the image.
  4. For each tag, run docker buildx build and tag the image accoordingly.
  5. Finally, tag with latest the appropriate Docker image. In the example, that's the last version as obtained by sort -V.
Clone this wiki locally