From a8fdf7e5d34cfddeffa6464aa512c853858c4373 Mon Sep 17 00:00:00 2001 From: Giovanni Fulco Date: Mon, 27 Mar 2023 20:00:13 +0200 Subject: [PATCH] 3 feature add force arch variable (#4) * [Feature] Add FORCE_ARCH variable #3 --- .../workflows/docker-debian-multi-arch.yml | 126 ++++++++++++++++++ .github/workflows/sync-readme.yml | 25 ++++ Dockerfile | 2 +- README.md | 6 + app/bin/run-bridge.sh | 3 + 5 files changed, 161 insertions(+), 1 deletion(-) create mode 100644 .github/workflows/docker-debian-multi-arch.yml create mode 100644 .github/workflows/sync-readme.yml diff --git a/.github/workflows/docker-debian-multi-arch.yml b/.github/workflows/docker-debian-multi-arch.yml new file mode 100644 index 0000000..52be9c9 --- /dev/null +++ b/.github/workflows/docker-debian-multi-arch.yml @@ -0,0 +1,126 @@ +name: Publish multi-arch debian-based Docker images + +on: + push: + tags: + - "release/*" + - "main/*" + - "devel/*" + - "feature/*" + - "daily/*" + +jobs: + release: + runs-on: ubuntu-latest + strategy: + fail-fast: false + matrix: + base: ["bullseye"] + + steps: + - name: Checkout + uses: actions/checkout@v3 + - name: Prepare for docker build + run: | + ref_type=${{ github.ref_type }} + echo "REF_TYPE: ["$ref_type"]" + + ref_name=${{ github.ref_name }} + echo "REF_NAME: ["$ref_name"]" + + ref=${{ github.ref }} + echo "REF: ["$ref"]" + + distro_id=${{ matrix.base }} + image_name=${{secrets.DOCKER_USERNAME}}/roon-bridge + + declare -A base_images_dict + base_images_dict[bullseye]="debian:bullseye-slim" + + select_base_image=${base_images_dict[${{ matrix.base }}]} + + declare -A upstream_image_from_matrix + upstream_image_from_matrix[bookworm]=debian:bookworm-slim + upstream_image_from_matrix[bullseye]=debian:bullseye-slim + upstream_image_from_matrix[buster]=debian:buster-slim + upstream_image_from_matrix[vanilla-bookworm]=debian:bookworm-slim + upstream_image_from_matrix[vanilla-bullseye]=debian:bullseye-slim + upstream_image_from_matrix[vanilla-buster]=debian:buster-slim + + declare -A special_tags + special_tags[bullseye]="${image_name}:stable,${image_name}:latest" + + tags="" + if [ "${ref_type}" = "branch" ]; then + echo "branch mode"; + if [ "${ref_name}" = "main" ]; then + echo "main branch"; + tags="${image_name}:main-${distro_id}"; + elif [ "${ref_name}" = "devel" ]; then + echo "devel branch"; + tags="${image_name}:devel-${distro_id}" + else + echo "other branch ["${ref_name}"]"; + tags="${image_name}:branch-${ref_name}-${distro_id}"; + fi + elif [ "${ref_type}" = "tag" ]; then + echo "tag mode"; + echo "tag is ["${ref_name}"]"; + + tag_type=$(echo ${ref_name} | cut -d '/' -f 1) + tag_name=$(echo ${ref_name} | cut -d '/' -f 2) + + if [ "${tag_type}" = "release" ]; then + echo "release tag"; + echo "Building now: ["$distro_id"]"; + tags="${tags},$image_name:${distro_id}"; + tags="$tags,$image_name:${distro_id}-${tag_name}" + select_special_tags=${special_tags["${distro_id}"]}; + if [[ -n "${select_special_tags}" ]]; then + echo "Found special tags for ["${distro_id}"]=["${select_special_tags}"]"; + tags="$tags,${select_special_tags}"; + else + echo "No special tag found for ["${distro_id}"]"; + fi + elif [ "${tag_type}" = "main" ]; then + echo "main tag"; + tags="${image_name}:main-${tag_name}-${distro_id}"; + elif [ "${tag_type}" = "devel" ]; then + echo "devel tag"; + tags="${image_name}:devel-${tag_name}-${distro_id}"; + elif [ "${tag_type}" = "feature" ]; then + echo "feature tag"; + tags="${image_name}:feature-${tag_name}-${distro_id}"; + elif [ "${tag_type}" = "daily" ]; then + echo "daily build"; + tags="${tags},${image_name}:daily-${distro_id}"; + fi + fi + echo "Building tags: ["${tags}"]" + echo "RELEASE_TAGS=${tags}" >> $GITHUB_ENV + echo "BASE_IMAGE=${select_base_image}" >> $GITHUB_ENV + + - 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 + uses: docker/login-action@v2 + with: + username: ${{ secrets.DOCKER_USERNAME }} + password: ${{ secrets.DOCKER_PASSWORD }} + + - name: Build and push + uses: docker/build-push-action@v3 + with: + context: . + build-args: | + BASE_IMAGE=${{ env.BASE_IMAGE }} + platforms: linux/amd64,linux/arm/v7,linux/arm64/v8 + push: true + tags: ${{ env.RELEASE_TAGS }} diff --git a/.github/workflows/sync-readme.yml b/.github/workflows/sync-readme.yml new file mode 100644 index 0000000..a3f6073 --- /dev/null +++ b/.github/workflows/sync-readme.yml @@ -0,0 +1,25 @@ +name: Sync README.md to Docker Hub + +on: + push: + tags: + - "release/*" + - "doc/*" + +jobs: + sync-readme: + runs-on: ubuntu-latest + strategy: + fail-fast: false + + steps: + - name: Checkout + uses: actions/checkout@v3 + - name: Docker Hub README & description sync + uses: meeDamian/sync-readme@v1.0.6 + with: + user: ${{ secrets.DOCKER_USERNAME }} + pass: ${{ secrets.DOCKER_PASSWORD }} + slug: ${{ secrets.DOCKER_USERNAME }}/roon-bridge + readme: ./README.md + description: Easily run roon bridge. diff --git a/Dockerfile b/Dockerfile index 3249173..5496c98 100644 --- a/Dockerfile +++ b/Dockerfile @@ -36,7 +36,7 @@ RUN mkdir -p /app RUN mkdir -p /app/bin RUN mkdir -p /app/doc -ENV STARTUP_DELAY_SEC "" +ENV FORCE_ARCH "" COPY app/bin/run-bridge.sh /app/bin/ RUN chmod +x /app/bin/*.sh diff --git a/README.md b/README.md index 24e1492..67c68dd 100644 --- a/README.md +++ b/README.md @@ -24,3 +24,9 @@ docker run \ --device /dev/snd \ giof71/roon-bridge:local-bullseye ``` + +## Environment Variables + +Variable|Description +:---|:--- +FORCE_ARCH|If set, we are not using `uname -m` to select architecture. Useful for example with LibreElec, which reports `aarch64` even when if should report `armv7l`. Possible values are `aarch64`, `armv7l` and `x86_64` \ No newline at end of file diff --git a/app/bin/run-bridge.sh b/app/bin/run-bridge.sh index 72c1769..0efe8cb 100644 --- a/app/bin/run-bridge.sh +++ b/app/bin/run-bridge.sh @@ -11,6 +11,9 @@ if [[ ! -d "RoonBridge" ]]; then file_dict[armv7l]=RoonBridge_linuxarmv7hf.tar.bz2 file_dict[aarch64]=RoonBridge_linuxarmv8.tar.bz2 ARCH=`uname -m` + if [[ -n "${FORCE_ARCH}" ]]; then + ARCH="${FORCE_ARCH}" + fi FILENAME=${file_dict["${ARCH}"]} FILE="/roon/$FILENAME" curl -O "$URL_DIR/$FILENAME"