Skip to content

build and deploy images #314

build and deploy images

build and deploy images #314

Workflow file for this run

---
name: 'build and deploy images'
on:
push:
branches:
- master
schedule:
- cron: '15 4 * * sun'
jobs:
alpine-based:
runs-on: ubuntu-latest
strategy:
max-parallel: 8
fail-fast: false
matrix:
alpine-version:
- edge
name:
- bc
- curl
- dropbear
- grep
- less
- iptables
- jq
- lftp
- nmap
# - openjdk8-jre
# - openjdk11-jre # TODO add arch seletor per image
# - openjdk17-jre
- openssh-server
- patch
- perl
- perl-utils
- rtorrent
- screen
- sed
- cmatrix
- sensors
- socat
- svn
- tor
- xmlstarlet
include:
- name: curl
files: 'etc/ssl/cert.pem etc/ssl/certs/ca-certificates.crt'
- name: grep
entrypoint: '[ "/bin/grep" ]'
- name: dropbear
packages: dropbear busybox-binsh
entrypoint: '[ "/usr/sbin/dropbear" ]'
command: '[ "-V" ]'
- name: iptables
entrypoint: '[ "/usr/sbin/iptables" ]'
# All openjdk versions are experimental, please use official ones
# - name: openjdk8-jre
# files: 'etc/ssl/cert.pem etc/ssl/certs/ca-certificates.crt'
# entrypoint: '[ "java" ]'
# command: '[ "-version" ]'
# dockerfile-bottom: |
# ENV JAVA_HOME=/usr/lib/jvm/java-1.8-openjdk/jre
# ENV PATH=/usr/lib/jvm/java-1.8-openjdk/jre/bin:/usr/lib/jvm/java-1.8-openjdk/bin
# - name: openjdk11-jre
# entrypoint: '[ "java" ]'
# command: '[ "-version" ]'
# dockerfile-bottom: |
# ENV JAVA_HOME=/usr/lib/jvm/java-11-openjdk
# ENV PATH=/usr/lib/jvm/java-11-openjdk/bin
# - name: openjdk17-jre
# entrypoint: '[ "java" ]'
# command: '[ "-version" ]'
- name: openssh-server
packages: openssh-server busybox-binsh
files: '/var/empty'
entrypoint: '[ ]'
command: '[ "ssh-keygen", "-A" ]'
dockerfile-bottom: |
RUN umask 0137 && echo 'root:*::0:::::' > /etc/shadow\
&& echo 'sshd:!::0:::::' >> /etc/shadow\
&& umask 0133 && echo 'root:x:0:0:root:/root:/bin/sh' > /etc/passwd\
&& echo 'sshd:x:22:22:sshd:/dev/null:/sbin/nologin' >> /etc/passwd
- name: perl-utils
packages: perl perl-utils build-base perl-dev perl-doc
entrypoint: '[ "/usr/bin/perl" ]'
- name: rtorrent
command: '[ "-h" ]'
- name: sed
entrypoint: '[ "/bin/sed" ]'
- name: sensors
packages: lm-sensors
- name: socat
command: '[ "-h" ]'
- name: svn
packages: subversion
files: 'etc/ssl/cert.pem etc/ssl/certs/ca-certificates.crt'
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Prepare
id: prep
run: |
set -x
DOCKER_IMAGE=${{ secrets.DOCKERHUB_USER }}/tiny
# Calculate packages list
PACKAGES='${{matrix.name}}'
[ -z '${{matrix.packages}}' ] || PACKAGES='${{matrix.packages}}'
# Convert packages list to bash array
IFS=' ' read -r -a PACKAGES_LIST <<< "${PACKAGES}"
# get first (main) package version to use it as an image TAG
MAIN_PACKAGE_VERSION=$(podman run -i --rm alpine:${{ matrix.alpine-version }} ash -c\
"apk update --quiet && apk search --exact ${PACKAGES_LIST[0]} | sed -ne '1s/'^${PACKAGES_LIST[0]}-'//p'")
test '!' -z "${MAIN_PACKAGE_VERSION}"
# Replace first element in packages to fix the first package version while build
PACKAGES_LIST[0]="${PACKAGES_LIST[0]}=${MAIN_PACKAGE_VERSION}"
# Convert bash array back to packages list
PACKAGES=$(printf '%s ' "${PACKAGES_LIST[*]}" )
unset PACKAGES_LIST
# Find out main image TAG
TAGS="${DOCKER_IMAGE}:${{matrix.name}}-${MAIN_PACKAGE_VERSION}"
[[ "${MAIN_PACKAGE_VERSION}" =~ -r[0-9]*$ ]] && TAGS="${DOCKER_IMAGE}:${{matrix.name}}-${MAIN_PACKAGE_VERSION%-*}"
TEST_TAG=${TAGS}
# Calculate additional TAGs
TAGS="${DOCKER_IMAGE}:${{matrix.name}},${TAGS}"
# Check if looking like numbered major.minor.patch
if [[ "${MAIN_PACKAGE_VERSION}" =~ ^[0-9]*\.[0-9]*\.[0-9]*.* ]]
then
# cut trailing minus sign and everything else after it, wtire to bash array
IFS='.' read -r -a VERSION_LIST <<< "${MAIN_PACKAGE_VERSION%-*}"
# add version tags
TAGS="${TAGS},${DOCKER_IMAGE}:${{matrix.name}}-${VERSION_LIST[0]}.${VERSION_LIST[1]}.${VERSION_LIST[2]}"
TAGS="${TAGS},${DOCKER_IMAGE}:${{matrix.name}}-${VERSION_LIST[0]}.${VERSION_LIST[1]}"
unset VERSION_LIST
fi
# Do the tinyimage magic here
{
# Set default entrypoint?
if [ -z '${{ matrix.entrypoint }}' ]; then
echo ENTRYPOINT "[ \"/usr/bin/${{matrix.name}}\" ]"
else echo ENTRYPOINT '${{ matrix.entrypoint }}'
fi
# Set default comand?
if [ -z '${{ matrix.command }}' ]; then
echo CMD '[ "--help" ]'
else echo CMD '${{ matrix.command }}'
fi
# Print custom rest of the Dockerfile
echo '${{ matrix.dockerfile-bottom }}';
} >> ./Dockerfile-alpine
# Set output parameters.
echo "tags=${TAGS}" >> $GITHUB_OUTPUT
echo "test_tag=${TEST_TAG}" >> $GITHUB_OUTPUT
echo "packages=${PACKAGES}" >> $GITHUB_OUTPUT
- name: Set up QEMU
uses: docker/setup-qemu-action@v2
with:
platforms: all
- name: Set up Docker Buildx
id: buildx
uses: docker/setup-buildx-action@v2
- name: Login to DockerHub
if: github.event_name != 'pull_request'
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKERHUB_USER }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Simple build and run test
env:
COMPOSE_FILE: ./tests/compose-sut.yaml:./tests/compose-build-sut.yaml
IMAGE_NAME: test:${{matrix.name}}
ALPINE_VERSION: ${{ matrix.alpine-version }}
PACKAGES: ${{ steps.prep.outputs.packages }}
ADDFILES: ${{ matrix.files }}
run: |
set -x
TEST_LOG="$(mktemp)"
docker compose up --build sut | tee "${TEST_LOG}"
docker compose down
tail --lines=1 ${TEST_LOG} | grep 'sut-1 exited with code 0'
rm "${TEST_LOG}"
- name: Build
uses: docker/build-push-action@v3
with:
builder: ${{ steps.buildx.outputs.name }}
context: .
file: ./Dockerfile-alpine
platforms: linux/386,linux/amd64,linux/arm/v6,linux/arm/v7,linux/arm64/v8
push: true
tags: ${{ steps.prep.outputs.tags }}
build-args: |
ALPINE_VERSION=${{ matrix.alpine-version }}
PACKAGES=${{ steps.prep.outputs.packages }}
ADDFILES=${{ matrix.files }}
- name: After push default arch test
env:
COMPOSE_FILE: ./tests/compose-sut.yaml
IMAGE_NAME: ${{ steps.prep.outputs.test_tag }}
run: |
set -x
TEST_LOG="$(mktemp)"
docker compose up sut | tee "${TEST_LOG}"
docker compose down
tail --lines=1 ${TEST_LOG} | grep 'sut-1 exited with code 0'
rm "${TEST_LOG}"
docker run -i "${IMAGE_NAME}"
podman run -i "${IMAGE_NAME}"