|
| 1 | +name: Publish multi-arch debian-based Docker images |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + tags: |
| 6 | + - "release/*" |
| 7 | + - "main/*" |
| 8 | + - "devel/*" |
| 9 | + - "feature/*" |
| 10 | + - "daily/*" |
| 11 | + |
| 12 | +jobs: |
| 13 | + release: |
| 14 | + runs-on: ubuntu-latest |
| 15 | + strategy: |
| 16 | + fail-fast: false |
| 17 | + matrix: |
| 18 | + base: ["bullseye", "bookworm"] |
| 19 | + |
| 20 | + steps: |
| 21 | + - name: Checkout |
| 22 | + uses: actions/checkout@v3 |
| 23 | + - name: Prepare for docker build |
| 24 | + run: | |
| 25 | + ref_type=${{ github.ref_type }} |
| 26 | + echo "REF_TYPE: ["$ref_type"]" |
| 27 | +
|
| 28 | + ref_name=${{ github.ref_name }} |
| 29 | + echo "REF_NAME: ["$ref_name"]" |
| 30 | +
|
| 31 | + ref=${{ github.ref }} |
| 32 | + echo "REF: ["$ref"]" |
| 33 | +
|
| 34 | + distro_id=${{ matrix.base }} |
| 35 | + image_name=${{secrets.DOCKER_USERNAME}}/mpd-alsa |
| 36 | +
|
| 37 | + declare -A mpd_compiler_base_images |
| 38 | + mpd_compiler_base_images[bullseye]="giof71/mpd-compiler:bullseye" |
| 39 | + mpd_compiler_base_images[bookworm]="giof71/mpd-compiler:bookworm" |
| 40 | +
|
| 41 | + select_compiler_image=${mpd_compiler_base_images[${{ matrix.base }}]} |
| 42 | +
|
| 43 | + declare -A libfmt_dict |
| 44 | + libfmt_dict[bullseye]=libfmt7 |
| 45 | + libfmt_dict[bookworm]=libfmt9 |
| 46 | +
|
| 47 | + select_libfmt_package_name=${libfmt_dict[${{ matrix.base }}]} |
| 48 | +
|
| 49 | + declare -A base_image_from_matrix |
| 50 | + base_image_from_matrix[bookworm]=debian:bookworm-slim |
| 51 | + base_image_from_matrix[bullseye]=debian:bullseye-slim |
| 52 | + base_image_from_matrix[buster]=debian:buster-slim |
| 53 | +
|
| 54 | + declare -A special_tags |
| 55 | + special_tags[bullseye]="${image_name}:stable,${image_name}:latest" |
| 56 | + special_tags[bookworm]="${image_name}:edge" |
| 57 | + special_tags[buster]="${image_name}:legacy,${image_name}:old-stable" |
| 58 | +
|
| 59 | + base_image=${base_image_from_matrix[${{ matrix.base }}]} |
| 60 | +
|
| 61 | + # mpd version is 0.23.12 (compiled) |
| 62 | + mpd_version=0.23.12 |
| 63 | +
|
| 64 | + tags="" |
| 65 | + if [ "${ref_type}" = "branch" ]; then |
| 66 | + echo "branch mode"; |
| 67 | + if [ "${ref_name}" = "main" ]; then |
| 68 | + echo "main branch"; |
| 69 | + tags="${image_name}:main-${distro_id}"; |
| 70 | + tags="$tags,${image_name}:main-${distro_id}-${mpd_version}"; |
| 71 | + elif [ "${ref_name}" = "devel" ]; then |
| 72 | + echo "devel branch"; |
| 73 | + tags="${image_name}:devel-${distro_id}-${mpd_version}" |
| 74 | + else |
| 75 | + echo "other branch ["${ref_name}"]"; |
| 76 | + tags="${image_name}:branch-${ref_name}-${distro_id}-${mpd_version}"; |
| 77 | + fi |
| 78 | + elif [ "${ref_type}" = "tag" ]; then |
| 79 | + echo "tag mode"; |
| 80 | + echo "tag is ["${ref_name}"]"; |
| 81 | +
|
| 82 | + tag_type=$(echo ${ref_name} | cut -d '/' -f 1) |
| 83 | + tag_name=$(echo ${ref_name} | cut -d '/' -f 2) |
| 84 | +
|
| 85 | + if [ "${tag_type}" = "release" ]; then |
| 86 | + echo "release tag"; |
| 87 | + echo "Building now: ["$distro_id"]"; |
| 88 | + tags="${tags},$image_name:${distro_id}"; |
| 89 | + tags="${tags},$image_name:${distro_id}-${mpd_version}" |
| 90 | + tags="$tags,$image_name:${distro_id}-${mpd_version}-${tag_name}" |
| 91 | + select_special_tags=${special_tags["${distro_id}"]}; |
| 92 | + if [[ -n "${select_special_tags}" ]]; then |
| 93 | + echo "Found special tags for ["${distro_id}"]=["${select_special_tags}"]"; |
| 94 | + tags="$tags,${select_special_tags}"; |
| 95 | + else |
| 96 | + echo "No special tag found for ["${distro_id}"]"; |
| 97 | + fi |
| 98 | + elif [ "${tag_type}" = "main" ]; then |
| 99 | + echo "main tag"; |
| 100 | + tags="${image_name}:main-${tag_name}-${distro_id}-${mpd_version}"; |
| 101 | + elif [ "${tag_type}" = "devel" ]; then |
| 102 | + echo "devel tag"; |
| 103 | + tags="${image_name}:devel-${tag_name}-${distro_id}-${mpd_version}"; |
| 104 | + elif [ "${tag_type}" = "feature" ]; then |
| 105 | + echo "feature tag"; |
| 106 | + tags="${image_name}:feature-${tag_name}-${distro_id}-${mpd_version}"; |
| 107 | + elif [ "${tag_type}" = "daily" ]; then |
| 108 | + echo "daily build"; |
| 109 | + tags="${tags},${image_name}:daily-${distro_id}"; |
| 110 | + tags="${tags},${image_name}:daily-${distro_id}-${mpd_version}"; |
| 111 | + fi |
| 112 | + fi |
| 113 | + echo "Building tags: ["${tags}"]" |
| 114 | + echo "RELEASE_TAGS=${tags}" >> $GITHUB_ENV |
| 115 | + echo "BASE_IMAGE=${select_compiler_image}" >> $GITHUB_ENV |
| 116 | + echo "INTEGER_UPSAMPLING_SUPPORT=yes" >> $GITHUB_ENV |
| 117 | + echo "LIBFMT_PACKAGE_NAME=${select_libfmt_package_name}" >> $GITHUB_ENV |
| 118 | +
|
| 119 | + - name: Set up QEMU |
| 120 | + uses: docker/setup-qemu-action@v2 |
| 121 | + with: |
| 122 | + platforms: all |
| 123 | + |
| 124 | + - name: Set up Docker Buildx |
| 125 | + id: buildx |
| 126 | + uses: docker/setup-buildx-action@v2 |
| 127 | + |
| 128 | + - name: Login to DockerHub |
| 129 | + uses: docker/login-action@v2 |
| 130 | + with: |
| 131 | + username: ${{ secrets.DOCKER_USERNAME }} |
| 132 | + password: ${{ secrets.DOCKER_PASSWORD }} |
| 133 | + |
| 134 | + - name: Build and push |
| 135 | + uses: docker/build-push-action@v3 |
| 136 | + with: |
| 137 | + context: . |
| 138 | + build-args: | |
| 139 | + BASE_IMAGE=${{ env.BASE_IMAGE }} |
| 140 | + INTEGER_UPSAMPLING_SUPPORT=${{ env.INTEGER_UPSAMPLING_SUPPORT }} |
| 141 | + LIBFMT_PACKAGE_NAME=${{ env.LIBFMT_PACKAGE_NAME }} |
| 142 | + platforms: linux/amd64,linux/arm/v6,linux/arm/v7,linux/arm64/v8 |
| 143 | + push: true |
| 144 | + tags: ${{ env.RELEASE_TAGS }} |
0 commit comments