|
| 1 | +--- |
| 2 | +name: native-dev-tools-build |
| 3 | + |
| 4 | + |
| 5 | +on: |
| 6 | + workflow_call: |
| 7 | + inputs: |
| 8 | + build_arch: |
| 9 | + required: false |
| 10 | + type: string |
| 11 | + default: 'x86_64' |
| 12 | + workflow_dispatch: |
| 13 | + inputs: |
| 14 | + build_arch: |
| 15 | + type: choice |
| 16 | + description: Build architecture |
| 17 | + default: 'x86_64' |
| 18 | + options: |
| 19 | + - all |
| 20 | + - x86_64 |
| 21 | + - arm64 |
| 22 | + push: |
| 23 | + paths: |
| 24 | + - 'prod/native/building/dockerized/**' |
| 25 | + branches: |
| 26 | + - main |
| 27 | + |
| 28 | +jobs: |
| 29 | + setup-build-matrix: |
| 30 | + uses: ./.github/workflows/build-arch-matrix-generator.yml |
| 31 | + with: |
| 32 | + build_arch: ${{ inputs.build_arch }} |
| 33 | + |
| 34 | + build-compiler-image: |
| 35 | + runs-on: ${{ matrix.goarch == 'arm64' && 'oracle-4cpu-16gb-arm64' || 'ubuntu-latest' }} |
| 36 | + needs: setup-build-matrix |
| 37 | + env: |
| 38 | + DOCKER_BUILDKIT: 1 |
| 39 | + strategy: |
| 40 | + fail-fast: false |
| 41 | + matrix: ${{ fromJson(needs.setup-build-matrix.outputs.matrix-combinations) }} |
| 42 | + steps: |
| 43 | + - name: Checkout repository |
| 44 | + uses: actions/checkout@v6 |
| 45 | + |
| 46 | + - name: Set up Docker Buildx |
| 47 | + if: contains(matrix.arch, 'arm64') |
| 48 | + id: buildx |
| 49 | + uses: docker/setup-buildx-action@v3 |
| 50 | + with: |
| 51 | + driver-opts: | |
| 52 | + image=moby/buildkit:latest |
| 53 | + network=host |
| 54 | +
|
| 55 | + - name: Set up Docker Compose |
| 56 | + uses: docker/setup-compose-action@v1 |
| 57 | + |
| 58 | + - name: Log into Docker.io |
| 59 | + if: github.event_name == 'push' || github.event.pull_request.head.repo.full_name == github.repository |
| 60 | + uses: docker/login-action@5e57cd118135c172c3672efd75eb46360885c0ef # v3.6.0 |
| 61 | + with: |
| 62 | + username: ${{ vars.DOCKER_USERNAME }} |
| 63 | + password: ${{ secrets.DOCKER_TOKEN_PHP_DISTRO }} |
| 64 | + |
| 65 | + - name: Extract image names from docker-compose.yml |
| 66 | + id: images |
| 67 | + working-directory: prod/native/building/dockerized |
| 68 | + run: | |
| 69 | + echo "::group::Extracting image names for architecture: ${{ matrix.arch }}" |
| 70 | +
|
| 71 | + COMPILER_IMAGE=$(docker compose config --images | grep ${{ matrix.arch }} | grep -v conancache) |
| 72 | + CONANCACHE_IMAGE=$(docker compose config --images | grep conancache | grep ${{ matrix.arch }}) |
| 73 | +
|
| 74 | + echo "gcc_image=${COMPILER_IMAGE}" >> $GITHUB_OUTPUT |
| 75 | + echo "conan_cache_image=${CONANCACHE_IMAGE}" >> $GITHUB_OUTPUT |
| 76 | +
|
| 77 | + echo "Compiler image: ${COMPILER_IMAGE}" |
| 78 | + echo "Conan cache image: ${CONANCACHE_IMAGE}" |
| 79 | +
|
| 80 | + - name: Check if GCC base image exists |
| 81 | + id: check-gcc |
| 82 | + run: | |
| 83 | + IMAGE_NAME="${{ steps.images.outputs.gcc_image }}" |
| 84 | + echo "Checking for image: ${IMAGE_NAME}" |
| 85 | +
|
| 86 | + if docker manifest inspect ${IMAGE_NAME} > /dev/null 2>&1; then |
| 87 | + echo "exists=true" >> $GITHUB_OUTPUT |
| 88 | + echo "✓ Image already exists on Docker Hub" |
| 89 | + else |
| 90 | + echo "exists=false" >> $GITHUB_OUTPUT |
| 91 | + echo "✗ Image does not exist, will build" |
| 92 | + fi |
| 93 | +
|
| 94 | + - name: Build GCC base image |
| 95 | + if: steps.check-gcc.outputs.exists == 'false' |
| 96 | + working-directory: prod/native/building/dockerized |
| 97 | + env: |
| 98 | + BUILDX_BAKE_ENTITLEMENTS_FS: 0 |
| 99 | + run: | |
| 100 | + echo "Building GCC base image for ${{ matrix.arch }}" |
| 101 | +
|
| 102 | + # For fork PRs on ARM64, use --load to make image available locally |
| 103 | + # For same-repo or push to main, build normally (will be pushed later) |
| 104 | + if [[ "${{ github.event_name }}" == "pull_request" ]] && [[ "${{ github.event.pull_request.head.repo.full_name }}" != "${{ github.repository }}" ]] && [[ "${{ matrix.arch }}" == *"arm64"* ]]; then |
| 105 | + echo "Fork PR on ARM64: building with --load to make image available locally" |
| 106 | + docker buildx bake --load build_${{ matrix.arch }} |
| 107 | + else |
| 108 | + docker compose build build_${{ matrix.arch }} |
| 109 | + fi |
| 110 | +
|
| 111 | + - name: Push GCC base image to Docker Hub |
| 112 | + if: steps.check-gcc.outputs.exists == 'false' && (github.event_name == 'push' || github.event.pull_request.head.repo.full_name == github.repository) |
| 113 | + working-directory: prod/native/building/dockerized |
| 114 | + run: | |
| 115 | + echo "Pushing GCC base image for ${{ matrix.arch }}" |
| 116 | + docker compose push build_${{ matrix.arch }} |
| 117 | +
|
| 118 | + - name: Check if Conan cache image exists |
| 119 | + id: check-conan |
| 120 | + run: | |
| 121 | + IMAGE_NAME="${{ steps.images.outputs.conan_cache_image }}" |
| 122 | + echo "Checking for image: ${IMAGE_NAME}" |
| 123 | +
|
| 124 | + if docker manifest inspect ${IMAGE_NAME} > /dev/null 2>&1; then |
| 125 | + echo "exists=true" >> $GITHUB_OUTPUT |
| 126 | + echo "✓ Conan cache image already exists on Docker Hub" |
| 127 | + else |
| 128 | + echo "exists=false" >> $GITHUB_OUTPUT |
| 129 | + echo "✗ Conan cache image does not exist, will build" |
| 130 | + fi |
| 131 | + - name: Build Conan cache image |
| 132 | + if: steps.check-conan.outputs.exists == 'false' |
| 133 | + working-directory: prod/native/building/dockerized |
| 134 | + env: |
| 135 | + BUILDX_BAKE_ENTITLEMENTS_FS: 0 |
| 136 | + run: | |
| 137 | + echo "Building Conan cache image for ${{ matrix.arch }}" |
| 138 | +
|
| 139 | + # For fork PRs on ARM64, use --load to ensure image is available locally |
| 140 | + if [[ "${{ github.event_name }}" == "pull_request" ]] && [[ "${{ github.event.pull_request.head.repo.full_name }}" != "${{ github.repository }}" ]] && [[ "${{ matrix.arch }}" == *"arm64"* ]]; then |
| 141 | + echo "Fork PR on ARM64: building with --load" |
| 142 | + docker buildx bake --load build_${{ matrix.arch }}_conan |
| 143 | + else |
| 144 | + docker compose build build_${{ matrix.arch }}_conan |
| 145 | + fi |
| 146 | +
|
| 147 | + - name: Push Conan cache image |
| 148 | + if: steps.check-conan.outputs.exists == 'false' && (github.event_name == 'push' || github.event.pull_request.head.repo.full_name == github.repository) |
| 149 | + working-directory: prod/native/building/dockerized |
| 150 | + run: | |
| 151 | + echo "Pushing Conan cache image for ${{ matrix.arch }}" |
| 152 | + docker compose push build_${{ matrix.arch }}_conan |
0 commit comments