diff --git a/.github/workflows/build-and-publish.yml b/.github/workflows/build-and-publish.yml index 01d6fe3..7bc2a05 100644 --- a/.github/workflows/build-and-publish.yml +++ b/.github/workflows/build-and-publish.yml @@ -86,72 +86,36 @@ jobs: name: ${{ env.BINARY_NAME }}_${{ matrix.platform_name }} path: target/${{ matrix.build_target }}/release/${{ env.BINARY_NAME }} - prepare_docker_matrix: - name: Prepare Docker Matrix + build_docker: + name: Build and Publish Multi-arch Docker Image needs: build runs-on: ubuntu-latest - outputs: - platforms: ${{ steps.set-matrix.outputs.platforms }} - platform-list: ${{ steps.set-matrix.outputs.platform-list }} - steps: - - name: Set matrix based on available artifacts - id: set-matrix - run: | - # Get list of built platforms from build job matrix - BUILT_PLATFORMS="" - if [[ "${{ contains(needs.build.result, 'success') }}" == "true" ]]; then - # Check which platforms were actually built - # Include both amd64 and arm64 - BUILT_PLATFORMS="linux/amd64,linux/arm64" - fi - - if [[ -n "$BUILT_PLATFORMS" ]]; then - echo "platforms=${BUILT_PLATFORMS}" >> $GITHUB_OUTPUT - echo "platform-list=[\"linux/amd64\",\"linux/arm64\"]" >> $GITHUB_OUTPUT - else - echo "No platforms built successfully" - exit 1 - fi - - build_docker: - name: Build and Publish Docker Image - needs: [build, prepare_docker_matrix] - runs-on: ubuntu-latest - strategy: - matrix: - platform: ${{ fromJson(needs.prepare_docker_matrix.outputs.platform-list) }} steps: - uses: actions/checkout@v4 - - name: Set platform variables - id: platform - run: | - platform=${{ matrix.platform }} - if [[ "$platform" == "linux/arm64" ]]; then - echo "arch=arm64" >> $GITHUB_OUTPUT - echo "arch_name=arm64" >> $GITHUB_OUTPUT - else - echo "arch=amd64" >> $GITHUB_OUTPUT - echo "arch_name=amd64" >> $GITHUB_OUTPUT - fi - - - name: Download artifact for platform + - name: Download all artifacts uses: actions/download-artifact@v4 with: - name: ${{ env.BINARY_NAME }}_linux-${{ steps.platform.outputs.arch }} - path: bin/linux_${{ steps.platform.outputs.arch }}/ - continue-on-error: true + path: artifacts/ - - name: Prepare binary + - name: Prepare binaries run: | - if [[ -f "bin/linux_${{ steps.platform.outputs.arch }}/${{ env.BINARY_NAME }}" ]]; then - chmod +x bin/linux_${{ steps.platform.outputs.arch }}/${{ env.BINARY_NAME }} - ls -la bin/*/ - else - echo "Binary not found for ${{ matrix.platform }}" - exit 1 + mkdir -p bin/linux_amd64 bin/linux_arm64 + + # Move and make binaries executable + if [[ -f "artifacts/${BINARY_NAME}_linux-amd64/${BINARY_NAME}" ]]; then + mv artifacts/${BINARY_NAME}_linux-amd64/${BINARY_NAME} bin/linux_amd64/ + chmod +x bin/linux_amd64/${BINARY_NAME} fi + if [[ -f "artifacts/${BINARY_NAME}_linux-arm64/${BINARY_NAME}" ]]; then + mv artifacts/${BINARY_NAME}_linux-arm64/${BINARY_NAME} bin/linux_arm64/ + chmod +x bin/linux_arm64/${BINARY_NAME} + fi + + # List files to verify + ls -la bin/*/ + - name: Set up Docker Buildx uses: docker/setup-buildx-action@v3 @@ -165,8 +129,8 @@ jobs: username: ${{ secrets.DOCKERHUB_USERNAME }} password: ${{ secrets.DOCKERHUB_TOKEN }} - - name: Set outputs - id: vars + - name: Extract metadata + id: meta run: | echo "sha_short=$(git rev-parse --short HEAD)" >> $GITHUB_OUTPUT @@ -191,23 +155,20 @@ jobs: echo "push=false" >> $GITHUB_OUTPUT fi - - name: Check outputs + - name: Check metadata run: | - echo "Platform: ${{ matrix.platform }}" - echo "Architecture: ${{ steps.platform.outputs.arch }}" - echo "Short SHA: ${{ steps.vars.outputs.sha_short }}" - echo "Docker Tags: ${{ steps.vars.outputs.docker_tags }}" - echo "Push: ${{ steps.vars.outputs.push }}" + echo "Short SHA: ${{ steps.meta.outputs.sha_short }}" + echo "Cargo Version: ${{ steps.meta.outputs.cargo_version }}" + echo "Docker Tags: ${{ steps.meta.outputs.docker_tags }}" + echo "Push: ${{ steps.meta.outputs.push }}" - - name: Build and push Docker image + - name: Build and push multi-arch Docker image uses: docker/build-push-action@v5 with: context: . file: ./Dockerfile.prebuilt - platforms: ${{ matrix.platform }} - push: ${{ steps.vars.outputs.push == 'true' }} - tags: ${{ steps.vars.outputs.docker_tags }} - build-args: | - TARGETARCH=${{ steps.platform.outputs.arch }} - cache-from: type=registry,ref=${{ secrets.DOCKERHUB_USERNAME }}/k8s-secrets:buildcache-${{ steps.platform.outputs.arch }} - cache-to: type=registry,ref=${{ secrets.DOCKERHUB_USERNAME }}/k8s-secrets:buildcache-${{ steps.platform.outputs.arch }},mode=max \ No newline at end of file + platforms: linux/amd64,linux/arm64 + push: ${{ steps.meta.outputs.push == 'true' }} + tags: ${{ steps.meta.outputs.docker_tags }} + cache-from: type=registry,ref=${{ secrets.DOCKERHUB_USERNAME }}/k8s-secrets:buildcache + cache-to: type=registry,ref=${{ secrets.DOCKERHUB_USERNAME }}/k8s-secrets:buildcache,mode=max \ No newline at end of file