diff --git a/.github/workflows/ghcr.yml b/.github/workflows/ghcr.yml index 9d91fe8..8a64a45 100644 --- a/.github/workflows/ghcr.yml +++ b/.github/workflows/ghcr.yml @@ -1,50 +1,77 @@ name: Multi-Arch CI + CD on: - push: - branches: [ master, main ] - paths-ignore: - - '**.md' release: types: [published] workflow_dispatch: env: REGISTRY: ghcr.io + CROSS_SYSROOT: /mnt/alpine jobs: build: runs-on: ubuntu-latest + strategy: + matrix: + arch: [x86_64, aarch64] outputs: HEPLIFY_VERSION: ${{ steps.version.outputs.HEPLIFY_VERSION }} steps: - - uses: actions/checkout@v3 - - - name: Set up Go - uses: actions/setup-go@v3 + - uses: actions/checkout@v4 + - name: Set up Alpine Linux for x86_64 (build arch) + uses: jirutka/setup-alpine@v1 with: - go-version: 1.18 - - - name: Libraries - run: sudo apt-get install -y libpcap-dev libluajit-5.1-dev - - - name: LuaJIT - run: git clone https://luajit.org/git/luajit-2.0.git && cd luajit-2.0 && git checkout v2.1 && make CCOPT="-static -fPIC" BUILDMODE="static" && sudo make install - - - name: Build + arch: ${{ matrix.arch }} + id: alpine-root + packages: > + build-base + pkgconf + linux-headers + musl-dev + gcc + libpcap-dev + ca-certificates + git + go + sudo + + - name: Install LuaJit 2.1 ${{ matrix.arch }} run: | - go mod tidy - make all + git clone https://luajit.org/git/luajit-2.0.git \ + && cd luajit-2.0 \ + && git checkout v2.1 \ + && make CCOPT="-static -fPIC" BUILDMODE="static" && sudo make install + shell: alpine.sh {0} + + - name: Build ${{ matrix.arch }} + run: CGO_ENABLED=1 GOOS=linux go build -a --ldflags '-linkmode external -extldflags "-static -s -w"' -o heplify-server${{ matrix.arch == 'aarch64' && '-arm64' || '' }} ./cmd/heplify-server + shell: alpine.sh {0} - name: Retrieve version run: | echo "HEPLIFY_VERSION=$(cat config/config.go | sed -n 's/^.*heplify-server \([0-9.]*\).*/\1/p')" >> $GITHUB_OUTPUT id: version + - name: Package for ${{ matrix.arch }} + if: ${{ matrix.arch != 'aarch64' }} + run: ./scripts/build_package.sh + env: + ARCH: ${{ matrix.arch == 'aarch64' && 'arm64' || 'amd64' }} + RELEASE: ${{ steps.version.outputs.HEPLIFY_VERSION }} + + - name: Upload Artifacts for ${{ matrix.arch }} + if: ${{ github.event_name != 'workflow_dispatch' }} + uses: skx/github-action-publish-binaries@master + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + with: + args: 'heplify-server*' + - docker-push: - if: github.event_name != 'pull_request' + docker-ghcr-push: + if: github.event_name != 'pull_request' || github.event_name != 'workflow_dispatch' runs-on: ubuntu-latest needs: build permissions: @@ -78,8 +105,49 @@ jobs: file: ./docker/Dockerfile push: true tags: | - ghcr.io/sipcapture/heplify-server:multiarch - ghcr.io/sipcapture/heplify-server:${{ needs.build.outputs.HEPLIFY_VERSION || github.event.release.tag_name }}-multiarch + ghcr.io/sipcapture/heplify-server:latest + ghcr.io/sipcapture/heplify-server:${{ needs.build.outputs.HEPLIFY_VERSION || github.event.release.tag_name }} + labels: | + dev.heplify-server.image.title=heplify-server + dev.heplify-server.image.version=${{needs.build.outputs.HEPLIFY_VERSION || github.event.release.tag_name }} + + docker-hub-push: + if: github.event_name != 'pull_request' || github.event_name != 'workflow_dispatch' + runs-on: ubuntu-latest + needs: build + permissions: + packages: write + contents: read + + steps: + - uses: actions/checkout@v3 + - name: Version Check + run: | + echo "${{ needs.build.outputs.HEPLIFY_VERSION }}" + - name: Set up Docker QEMU + uses: docker/setup-qemu-action@v3.0.0 + with: + platforms: amd64, arm64 + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3.0.0 + + - name: Login to DockerHub + if: ${{ steps.checkdocker.outputs.secretspresent }} + uses: docker/login-action@v3.2.0 + with: + username: ${{ secrets.DOCKERHUB_USERNAME }} + password: ${{ secrets.DOCKERHUB_TOKEN }} + + - name: Build and push to DockerHub + uses: docker/build-push-action@v5.0.0 + with: + platforms: linux/amd64, linux/arm64 + file: ./docker/Dockerfile + push: true + tags: | + qxip/heplify-server:latest + qxip/heplify-server:${{ needs.build.outputs.HEPLIFY_VERSION || github.event.release.tag_name }} labels: | dev.heplify-server.image.title=heplify-server dev.heplify-server.image.version=${{needs.build.outputs.HEPLIFY_VERSION || github.event.release.tag_name }}