🤖 Automated container builds

This commit is contained in:
Philipp Schmitt 2021-11-17 19:52:32 +01:00
parent 5df5fb6b46
commit 2583464bd5
No known key found for this signature in database
GPG key ID: DC439C47EACB17F9
9 changed files with 321 additions and 0 deletions

7
.github/dependabot.yaml vendored Normal file
View file

@ -0,0 +1,7 @@
version: 2
updates:
# Maintain dependencies for GitHub Actions
- package-ecosystem: "github-actions"
directory: "/"
schedule:
interval: "daily"

99
.github/workflows/containers.yaml vendored Normal file
View file

@ -0,0 +1,99 @@
name: Build containers
on: [push, workflow_dispatch]
jobs:
build-containers-with-zsh:
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
zsh_version:
- 5.1.1
- 5.2.4
- 5.3.1
- 5.4.2
- 5.5.1
- 5.6.2
- 5.7.1
- 5.8
steps:
- name: Check out repository code
uses: actions/checkout@v2
- name: Grab git slugs (short commit id, branch etc.)
uses: rlespinasse/github-slug-action@v3.x
- name: Set up QEMU
uses: docker/setup-qemu-action@v1
- name: Set up Docker Buildx
id: buildx
uses: docker/setup-buildx-action@v1
with:
install: true
use: true
- name: Login to GitHub Container Registry
uses: docker/login-action@v1
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Build and push
id: docker_build_zsh_versions
uses: docker/build-push-action@v2
with:
push: true
file: ./docker/Dockerfile
build-args: |
VERSION=latest
ZINIT_ZSH_VERSION=${{ matrix.zsh_version }}-tcsetpgrp
tags: |
ghcr.io/${{ github.repository }}:zsh-${{ matrix.zsh_version }}
ghcr.io/${{ github.repository }}:zsh-${{ matrix.zsh_version }}-${{ env.GITHUB_SHA_SHORT }}
platforms: linux/amd64,linux/arm64/v8
cache-from: type=gha
cache-to: type=gha,mode=max
build-container-latest:
runs-on: ubuntu-latest
steps:
- name: Check out repository code
uses: actions/checkout@v2
- name: Grab git slugs (short commit id, branch etc.)
uses: rlespinasse/github-slug-action@v3.x
- name: Set up QEMU
uses: docker/setup-qemu-action@v1
- name: Set up Docker Buildx
id: buildx
uses: docker/setup-buildx-action@v1
with:
install: true
use: true
- name: Login to GitHub Container Registry
uses: docker/login-action@v1
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Build and push
id: docker_build_latest
uses: docker/build-push-action@v2
with:
push: true
file: ./docker/Dockerfile
build-args: |
VERSION=latest
tags: |
ghcr.io/${{ github.repository }}:latest
ghcr.io/${{ github.repository }}:${{ env.GITHUB_SHA_SHORT }}
ghcr.io/${{ github.repository }}:${{ env.GITHUB_REF_SLUG }}
platforms: linux/amd64,linux/arm64/v8
cache-from: type=gha
cache-to: type=gha,mode=max

35
docker/Dockerfile Normal file
View file

@ -0,0 +1,35 @@
ARG VERSION=latest
FROM alpine:${VERSION}
ARG PUSERNAME=user01
ARG PUID=1000
ARG PGID=1000
ARG ZINIT_ZSH_VERSION
ENV PUSERNAME=${PUSERNAME} PUID=${PUID} PGID=${PGID} \
ZINIT_ZSH_VERSION=${ZINIT_ZSH_VERSION}
RUN apk --no-cache --virtual base add \
zsh curl git libuser sudo && \
apk --no-cache --virtual build-tools add \
build-base autoconf ncurses-dev bash go
RUN sed -ir 's#^(root:.+):/bin/ash#\1:/bin/zsh#' /etc/passwd && \
adduser -D -s /bin/zsh -u "${PUID}" -h "/home/${PUSERNAME}" \
"${PUSERNAME}" && \
printf "${PUSERNAME} ALL=(ALL) NOPASSWD: ALL" > /etc/sudoers.d/user && \
mkdir -p /src
WORKDIR /home/${PUSERNAME}
VOLUME ["/src"]
COPY --chown=${PUSERNAME} . /src
COPY --chown=${PUSERNAME} ./docker/zshrc /home/${PUSERNAME}/.zshrc
COPY ./docker/utils.zsh /utils.zsh
COPY ./docker/entrypoint.zsh /entrypoint.zsh
USER ${PUSERNAME}
# RUN zsh -ic "ZINIT_ZSH_VERSION=${ZINIT_ZSH_VERSION}; source /home/${PUSERNAME}/.zshrc"
RUN zsh -ils -c -- '@zinit-scheduler burst'
# ENTRYPOINT ["/entrypoint.zsh"]
CMD ["/bin/zsh"]

48
docker/build.sh Normal file
View file

@ -0,0 +1,48 @@
#!/usr/bin/env bash
build() {
cd "$(cd "$(dirname "$0")" >/dev/null 2>&1; pwd -P)" || exit 9
local target="${1:-alpine}"
local version="${2:-latest}"
local zsh_version="${3}"
local tag
case "$target" in
alpine)
dockerfile=Dockerfile.alpine
tag="alpine-${version}"
;;
ubuntu)
dockerfile=Dockerfile.ubuntu
tag="ubuntu-${version}"
;;
*)
echo "Unknown build target: $target" >&2
return 2
;;
esac
if [[ -n "$zsh_version" ]]
then
tag="zsh${zsh_version}-${tag}"
fi
local image_name="zinit:${tag}"
if [[ -n "$CI" ]]
then
image_name="ghcr.io/${GITHUB_REPOSITORY}:${tag}"
fi
docker build \
--no-cache \
--build-arg "VERSION=${version}" \
--build-arg "ZINIT_ZSH_VERSION=${zsh_version}" \
--file "$dockerfile" \
--tag "$image_name" "$(realpath ../../)"
}
if [[ "${BASH_SOURCE[0]}" == "${0}" ]]
then
build "$@"
fi

3
docker/entrypoint.zsh Normal file
View file

@ -0,0 +1,3 @@
#!/usr/bin/env zsh
exec su "$PUSERNAME" -c "$@"

10
docker/run.sh Normal file
View file

@ -0,0 +1,10 @@
#!/usr/bin/env bash
if [[ "${BASH_SOURCE[0]}" == "${0}" ]]
then
cd "$(cd "$(dirname "$0")" >/dev/null 2>&1; pwd -P)" || exit 9
docker run -it --rm -v "$(realpath ../..:)/src" \
-e ZINIT_ZSH_VERSION=5.4.2 \
zinit/zinit:alpine-latest "$@"
fi

30
docker/utils.zsh Normal file
View file

@ -0,0 +1,30 @@
#!/usr/bin/env zsh
zinit::setup() {
source /src/zinit.zsh
}
zinit::setup-annexes() {
zinit light-mode for \
zdharma-continuum/z-a-as-monitor \
zdharma-continuum/z-a-bin-gem-node \
zdharma-continuum/z-a-default-ice \
zdharma-continuum/z-a-patch-dl \
zdharma-continuum/z-a-rust
}
zinit::setup-minimal() {
zinit wait lucid light-mode for \
atinit"zicompinit; zicdreplay" \
zdharma-continuum/fast-syntax-highlighting \
atload"_zsh_autosuggest_start" \
zsh-users/zsh-autosuggestions \
blockf atpull'zinit creinstall -q .' \
zsh-users/zsh-completions
}
zinit::pack-zsh() {
local version="$1"
zinit pack"$version" for zsh
}

24
docker/zshrc Normal file
View file

@ -0,0 +1,24 @@
# load zinit
source /src/zinit.zsh
# load zinit utilities
source /utils.zsh
# Add ZPFX/bin to PATH
typeset -U path
path=("${ZPFX:-${HOME}/.zinit/polaris}/bin" $path)
# Install custom zsh version
if [[ -n "$ZINIT_ZSH_VERSION" ]]
then
zinit::pack-zsh "$ZINIT_ZSH_VERSION"
fi
# Source init file
INIT_FILE="/init.zsh"
if [[ -r "$INIT_FILE" ]]
then
source "$INIT_FILE"
fi
# vim: ft=zsh et ts=2 sw=2 :

65
scripts/issue-tester.sh Executable file
View file

@ -0,0 +1,65 @@
#!/usr/bin/env bash
create_config() {
local tempfile
if [[ -z "$*" ]]
then
return
fi
tempfile=$(mktemp)
echo "$*" > "$tempfile"
echo "$tempfile"
}
run() {
local image="${1:-ghcr.io/pschmitt/zinit}"
local tag="${2:-latest}"
local init_config="${3}"
local -a args=()
if [[ -n "$init_config" ]] && [[ -r "$init_config" ]]
then
args+=(-v "${init_config}:/init.zsh")
fi
docker run -it --rm "${args[@]}" "$image:$tag"
}
if [[ "${BASH_SOURCE[0]}" == "${0}" ]]
then
CONTAINER_IMAGE=ghcr.io/pschmitt/zinit
CONTAINER_TAG=latest
INIT_CONFIG_VAL=""
while [[ -n "$*" ]]
do
case "$1" in
xsel|--xsel|-b)
INIT_CONFIG_VAL="$(xsel -b)"
shift
;;
-c|--config|--init-config|--init)
INIT_CONFIG_VAL="$2"
shift 2
;;
-i|--image)
CONTAINER_IMAGE="$2"
shift 2
;;
-t|--tag)
CONTAINER_TAG="$2"
shift 2
;;
*)
break
;;
esac
done
INIT_CONFIG="$(create_config "$INIT_CONFIG_VAL")"
trap 'rm -vf $INIT_CONFIG' EXIT INT
run "$CONTAINER_IMAGE" "$CONTAINER_TAG" "$INIT_CONFIG"
fi