Skip to content

Commit

Permalink
Add github action
Browse files Browse the repository at this point in the history
  • Loading branch information
urbanogilson committed Feb 11, 2024
1 parent 32809d4 commit ca0edd2
Show file tree
Hide file tree
Showing 2 changed files with 116 additions and 0 deletions.
40 changes: 40 additions & 0 deletions .github/workflows/actions.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
name: actions
on:
push:
paths:
- 'update.sh'
- '.github/workflows/actions.yml'
schedule:
- cron: '0 0 15 * *'
workflow_dispatch:

jobs:
debian-debootstrap-ports:
runs-on: ubuntu-latest
strategy:
matrix:
QEMU_VER: [v7.2.0-1]
DOCKER_REPO: [docker.io/urbanogilson/debian-debootstrap-ports]
VERSION: [sid]
UNAME_ARCH: [alpha, hppa, m68k, powerpc, ppc64, sh4]
include:
- {ARCH: alpha, QEMU_ARCH: alpha, UNAME_ARCH: alpha}
- {ARCH: hppa, QEMU_ARCH: hppa, UNAME_ARCH: hppa}
- {ARCH: m68k, QEMU_ARCH: m68k, UNAME_ARCH: m68k}
- {ARCH: powerpc, QEMU_ARCH: ppc, UNAME_ARCH: powerpc}
- {ARCH: ppc64, QEMU_ARCH: ppc64, UNAME_ARCH: ppc64}
- {ARCH: sh4, QEMU_ARCH: sh4, UNAME_ARCH: sh4}
steps:
- uses: actions/checkout@v4
- name: Build
run: |
sudo apt update && sudo apt install -y qemu-user-static debootstrap
./update.sh -a ${{ matrix.ARCH }} -v ${{ matrix.VERSION }} -q ${{ matrix.QEMU_ARCH }} -u ${{ matrix.QEMU_VER }} -d ${{ matrix.DOCKER_REPO }} -o ${{ matrix.UNAME_ARCH }}
- name: Login to Docker Hub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Publish Docker images
run: |
docker push -a ${{ matrix.DOCKER_REPO }}
76 changes: 76 additions & 0 deletions update.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
#!/bin/bash
set -eo pipefail

# A POSIX variable
OPTIND=1 # Reset in case getopts has been used previously in the shell.

while getopts "a:v:q:u:d:s:i:o:" opt; do
case "$opt" in
a) ARCH=$OPTARG
;;
v) VERSION=$OPTARG
;;
q) QEMU_ARCH=$OPTARG
;;
u) QEMU_VER=$OPTARG
;;
d) DOCKER_REPO=$OPTARG
;;
o) UNAME_ARCH=$OPTARG
;;
esac
done

shift $((OPTIND-1))

[ "$1" = "--" ] && shift

dir="$VERSION-$ARCH"
VARIANT="minbase"
args=( -d "$dir" debootstrap --no-check-gpg --variant="$VARIANT" --include="wget" --arch="$ARCH" "$VERSION" https://deb.debian.org/debian-ports)

mkdir -p mkimage $dir
curl https://raw.githubusercontent.com/moby/moby/6f78b438b88511732ba4ac7c7c9097d148ae3568/contrib/mkimage.sh > mkimage.sh
curl https://raw.githubusercontent.com/moby/moby/6f78b438b88511732ba4ac7c7c9097d148ae3568/contrib/mkimage/debootstrap > mkimage/debootstrap
chmod +x mkimage.sh mkimage/debootstrap

mkimage="$(readlink -f "${MKIMAGE:-"mkimage.sh"}")"
{
echo "$(basename "$mkimage") ${args[*]/"$dir"/.}"
echo
echo 'https://github.com/moby/moby/blob/6f78b438b88511732ba4ac7c7c9097d148ae3568/contrib/mkimage.sh'
} > "$dir/build-command.txt"

sudo DEBOOTSTRAP="debootstrap" nice ionice -c 2 "$mkimage" "${args[@]}" 2>&1 | tee "$dir/build.log"
cat "$dir/build.log"
sudo chown -R "$(id -u):$(id -g)" "$dir"

xz -d < $dir/rootfs.tar.xz | gzip -c > $dir/rootfs.tar.gz
sed -i /^ENV/d "${dir}/Dockerfile"
echo "ENV ARCH=${UNAME_ARCH} UBUNTU_SUITE=${VERSION} DOCKER_REPO=${DOCKER_REPO}" >> "${dir}/Dockerfile"

if [ "$DOCKER_REPO" ]; then
docker build -t "${DOCKER_REPO}:${ARCH}-${VERSION}-slim" "${dir}"
mkdir -p "${dir}/full"
(
cd "${dir}/full"
if [ ! -f x86_64_qemu-${QEMU_ARCH}-static.tar.gz ]; then
wget -N https://github.com/multiarch/qemu-user-static/releases/download/${QEMU_VER}/x86_64_qemu-${QEMU_ARCH}-static.tar.gz
fi
tar xf x86_64_qemu-*.gz
)
cat > "${dir}/full/Dockerfile" <<EOF
FROM ${DOCKER_REPO}:${ARCH}-${VERSION}-slim
ADD qemu-*-static /usr/bin/
EOF
docker build -t "${DOCKER_REPO}:${ARCH}-${VERSION}" "${dir}/full"
fi

CONTAINER=`docker run --rm ${DOCKER_REPO}:${ARCH}-${VERSION} /bin/bash -c "uname -a; cat /etc/debian_version"`
echo "${CONTAINER}"
NEW_VERSION=`echo "${CONTAINER}" | tail -1 | tr "/" "-"`

docker image tag "${DOCKER_REPO}:${ARCH}-${VERSION}" "${DOCKER_REPO}:${ARCH}-${NEW_VERSION}"
docker rmi "${DOCKER_REPO}:${ARCH}-${VERSION}"
docker image tag "${DOCKER_REPO}:${ARCH}-${VERSION}-slim" "${DOCKER_REPO}:${ARCH}-${NEW_VERSION}-slim"
docker rmi "${DOCKER_REPO}:${ARCH}-${VERSION}-slim"

0 comments on commit ca0edd2

Please sign in to comment.