Build 3CX SBC Docker image #13474
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Build 3CX SBC Docker image | |
| on: | |
| push: | |
| branches: | |
| - "main" | |
| schedule: | |
| - cron: "0 * * * *" | |
| workflow_dispatch: | |
| inputs: | |
| version: | |
| description: "3CX SBC version to build" | |
| required: true | |
| env: | |
| GHCR_REGISTRY: ghcr.io | |
| IMAGE_NAME: ${{ github.repository }} | |
| DEBIAN_VERSION: bookworm | |
| jobs: | |
| check: | |
| runs-on: ubuntu-latest | |
| outputs: | |
| isNew: ${{ steps.check-new-version.outputs.isNew }} | |
| version: ${{ steps.fetch-latest-version.outputs.version }} | |
| steps: | |
| - name: Fetch latest version | |
| id: fetch-latest-version | |
| run: | | |
| VERSION=$(curl -s http://repo.3cx.com/3cx/dists/${{ env.DEBIAN_VERSION }}/main/binary-amd64/Packages | sed -n '/Package: 3cxsbc$/,/^$/p' | grep Version | sed 's/Version: //g' | sort -Vr | head -n 1) | |
| [ -z $VERSION ] && { echo "Could not find a package version"; exit 1; } | |
| echo "version=$VERSION" >> $GITHUB_OUTPUT | |
| - name: Check if new version | |
| id: check-new-version | |
| run: | | |
| IS_NEW=$(docker manifest inspect ${{ env.GHCR_REGISTRY }}/${{ env.IMAGE_NAME }}:${{ steps.fetch-latest-version.outputs.version }} >/dev/null 2>&1 && echo false || echo true) | |
| echo "isNew=$IS_NEW" >> $GITHUB_OUTPUT | |
| - name: Print information | |
| run: | | |
| echo "Latest version found: ${{ steps.fetch-latest-version.outputs.version }}" | |
| echo "Found version is new: ${{ steps.check-new-version.outputs.isNew }}" | |
| build: | |
| needs: check | |
| if: github.event_name != 'schedule' || needs.check.outputs.isNew == 'true' | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout | |
| uses: actions/checkout@v4 | |
| - name: Set up QEMU | |
| uses: docker/setup-qemu-action@v3 | |
| - name: Set up Docker Buildx | |
| uses: docker/setup-buildx-action@v3 | |
| - name: Login to Docker Hub | |
| uses: docker/login-action@v3 | |
| with: | |
| username: ${{ secrets.DOCKERHUB_USERNAME }} | |
| password: ${{ secrets.DOCKERHUB_TOKEN }} | |
| - name: Login to GitHub Container Registry | |
| uses: docker/login-action@v3 | |
| with: | |
| registry: ${{ env.GHCR_REGISTRY }} | |
| username: ${{ github.actor }} | |
| password: ${{ secrets.GITHUB_TOKEN }} | |
| - name: Select version | |
| id: select-version | |
| run: | | |
| if [ ${{ github.event_name }} == 'workflow_dispatch' ] | |
| then | |
| echo "version=${{ github.event.inputs.version }}" >> $GITHUB_OUTPUT | |
| else | |
| echo "version=${{ needs.check.outputs.version }}" >> $GITHUB_OUTPUT | |
| fi | |
| - name: Get image tags | |
| id: get-tags | |
| uses: docker/metadata-action@v5 | |
| with: | |
| images: | | |
| ${{ env.IMAGE_NAME }} | |
| ${{ env.GHCR_REGISTRY }}/${{ env.IMAGE_NAME }} | |
| tags: | | |
| type=raw,value=latest,enable=true | |
| type=semver,pattern={{version}},value=${{ steps.select-version.outputs.version }} | |
| type=semver,pattern={{major}}.{{minor}},value=${{ steps.select-version.outputs.version }} | |
| type=semver,pattern={{major}},value=${{ steps.select-version.outputs.version }} | |
| - name: Build and push | |
| uses: docker/build-push-action@v6 | |
| env: | |
| DOCKER_IMAGE: ${{ env.GHCR_REGISTRY }}/${{ env.IMAGE_NAME }} | |
| with: | |
| context: . | |
| platforms: linux/amd64,linux/armhf,linux/arm64 | |
| push: true | |
| tags: ${{ steps.get-tags.outputs.tags }} | |
| build-args: | | |
| SBC_VERSION=${{ steps.select-version.outputs.version }} | |
| DEBIAN_VERSION=${{ env.DEBIAN_VERSION }} | |
| cache-from: type=registry,ref=${{ env.DOCKER_IMAGE }}:buildcache | |
| cache-to: type=registry,ref=${{ env.DOCKER_IMAGE }}:buildcache,mode=max |