-
Notifications
You must be signed in to change notification settings - Fork 13
Home
This repository manages the @ohmyzsh Docker images.
Each top-level directory contains the code for an image, which has the same name as the directory.
Required files:
-
Dockerfile
: read by thedocker buildx
command. -
build.sh
: script to build all the tags of the Docker image. Must usedocker buildx
. -
.dockerignore
: lists all files that aren't required to build the image (build.sh
andREADME.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.
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.
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"
- Write in bash and properly set the shebang to
#!/bin/bash
. - Get the image username passed as the first argument (
DOCKERHUB_ORG
GitHub Actions secret). - Run the logic for getting all tags for the image.
- For each tag, run
docker buildx build
and tag the image accoordingly. - Finally, tag with
latest
the appropriate Docker image. In the example, that's the last version as obtained bysort -V
.