|
| 1 | +name: Build and Push TSan Image |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: [main] |
| 6 | + tags: ['v*'] |
| 7 | + paths: |
| 8 | + - 'tsan/**' |
| 9 | + - '.github/workflows/build-push-tsan.yml' |
| 10 | + pull_request: |
| 11 | + branches: [main] |
| 12 | + paths: |
| 13 | + - 'tsan/**' |
| 14 | + workflow_run: |
| 15 | + workflows: ["Build and Push Images"] |
| 16 | + types: [completed] |
| 17 | + branches: [main] |
| 18 | + workflow_dispatch: |
| 19 | + |
| 20 | +env: |
| 21 | + DOCKER_HUB_TSAN: ${{ secrets.DOCKERHUB_USERNAME }}/ocaml-devcontainer-tsan |
| 22 | + GHCR_TSAN: ghcr.io/${{ github.repository_owner }}/ocaml-devcontainer-tsan |
| 23 | + GHCR_DEV: ghcr.io/${{ github.repository_owner }}/ocaml-devcontainer |
| 24 | + |
| 25 | +jobs: |
| 26 | + # ============================================================================ |
| 27 | + # Build TSan Images (parallel per architecture) |
| 28 | + # ============================================================================ |
| 29 | + build-tsan-amd64: |
| 30 | + if: github.event_name != 'workflow_run' || github.event.workflow_run.conclusion == 'success' |
| 31 | + runs-on: ubuntu-latest |
| 32 | + permissions: |
| 33 | + contents: read |
| 34 | + packages: write |
| 35 | + |
| 36 | + steps: |
| 37 | + - name: Checkout |
| 38 | + uses: actions/checkout@v6 |
| 39 | + |
| 40 | + - name: Reduce ASLR entropy for TSan build |
| 41 | + run: sudo sysctl -w vm.mmap_rnd_bits=28 |
| 42 | + |
| 43 | + - name: Set up Docker Buildx |
| 44 | + uses: docker/setup-buildx-action@v3 |
| 45 | + |
| 46 | + - name: Login to Docker Hub |
| 47 | + if: github.event_name != 'pull_request' |
| 48 | + uses: docker/login-action@v3 |
| 49 | + with: |
| 50 | + username: ${{ secrets.DOCKERHUB_USERNAME }} |
| 51 | + password: ${{ secrets.DOCKERHUB_TOKEN }} |
| 52 | + |
| 53 | + - name: Login to GitHub Container Registry |
| 54 | + if: github.event_name != 'pull_request' |
| 55 | + uses: docker/login-action@v3 |
| 56 | + with: |
| 57 | + registry: ghcr.io |
| 58 | + username: ${{ github.actor }} |
| 59 | + password: ${{ secrets.GITHUB_TOKEN }} |
| 60 | + |
| 61 | + - name: Build and push TSan image (amd64) |
| 62 | + uses: docker/build-push-action@v6 |
| 63 | + with: |
| 64 | + context: ./tsan |
| 65 | + file: ./tsan/Dockerfile |
| 66 | + platforms: linux/amd64 |
| 67 | + push: ${{ github.event_name != 'pull_request' }} |
| 68 | + tags: | |
| 69 | + ${{ env.GHCR_TSAN }}:latest-amd64 |
| 70 | + ${{ env.DOCKER_HUB_TSAN }}:latest-amd64 |
| 71 | + labels: | |
| 72 | + org.opencontainers.image.source=https://github.com/${{ github.repository }} |
| 73 | + org.opencontainers.image.revision=${{ github.sha }} |
| 74 | + build-args: | |
| 75 | + BASE_IMAGE=${{ env.GHCR_DEV }}:latest-amd64 |
| 76 | + cache-from: type=gha,scope=tsan-amd64 |
| 77 | + cache-to: type=gha,mode=max,scope=tsan-amd64 |
| 78 | + |
| 79 | + build-tsan-arm64: |
| 80 | + if: github.event_name != 'workflow_run' || github.event.workflow_run.conclusion == 'success' |
| 81 | + runs-on: ubuntu-24.04-arm |
| 82 | + permissions: |
| 83 | + contents: read |
| 84 | + packages: write |
| 85 | + |
| 86 | + steps: |
| 87 | + - name: Checkout |
| 88 | + uses: actions/checkout@v6 |
| 89 | + |
| 90 | + - name: Reduce ASLR entropy for TSan build |
| 91 | + run: sudo sysctl -w vm.mmap_rnd_bits=28 |
| 92 | + |
| 93 | + - name: Set up Docker Buildx |
| 94 | + uses: docker/setup-buildx-action@v3 |
| 95 | + |
| 96 | + - name: Login to Docker Hub |
| 97 | + if: github.event_name != 'pull_request' |
| 98 | + uses: docker/login-action@v3 |
| 99 | + with: |
| 100 | + username: ${{ secrets.DOCKERHUB_USERNAME }} |
| 101 | + password: ${{ secrets.DOCKERHUB_TOKEN }} |
| 102 | + |
| 103 | + - name: Login to GitHub Container Registry |
| 104 | + if: github.event_name != 'pull_request' |
| 105 | + uses: docker/login-action@v3 |
| 106 | + with: |
| 107 | + registry: ghcr.io |
| 108 | + username: ${{ github.actor }} |
| 109 | + password: ${{ secrets.GITHUB_TOKEN }} |
| 110 | + |
| 111 | + - name: Build and push TSan image (arm64) |
| 112 | + uses: docker/build-push-action@v6 |
| 113 | + with: |
| 114 | + context: ./tsan |
| 115 | + file: ./tsan/Dockerfile |
| 116 | + platforms: linux/arm64 |
| 117 | + push: ${{ github.event_name != 'pull_request' }} |
| 118 | + tags: | |
| 119 | + ${{ env.GHCR_TSAN }}:latest-arm64 |
| 120 | + ${{ env.DOCKER_HUB_TSAN }}:latest-arm64 |
| 121 | + labels: | |
| 122 | + org.opencontainers.image.source=https://github.com/${{ github.repository }} |
| 123 | + org.opencontainers.image.revision=${{ github.sha }} |
| 124 | + build-args: | |
| 125 | + BASE_IMAGE=${{ env.GHCR_DEV }}:latest-arm64 |
| 126 | + cache-from: type=gha,scope=tsan-arm64 |
| 127 | + cache-to: type=gha,mode=max,scope=tsan-arm64 |
| 128 | + |
| 129 | + # ============================================================================ |
| 130 | + # Merge TSan Image Tags into Multi-Arch Manifest |
| 131 | + # ============================================================================ |
| 132 | + merge-tsan: |
| 133 | + needs: [build-tsan-amd64, build-tsan-arm64] |
| 134 | + if: | |
| 135 | + always() && |
| 136 | + needs.build-tsan-amd64.result == 'success' && |
| 137 | + needs.build-tsan-arm64.result == 'success' && |
| 138 | + github.event_name != 'pull_request' |
| 139 | + runs-on: ubuntu-latest |
| 140 | + permissions: |
| 141 | + contents: read |
| 142 | + packages: write |
| 143 | + |
| 144 | + steps: |
| 145 | + - name: Set up Docker Buildx |
| 146 | + uses: docker/setup-buildx-action@v3 |
| 147 | + |
| 148 | + - name: Login to Docker Hub |
| 149 | + uses: docker/login-action@v3 |
| 150 | + with: |
| 151 | + username: ${{ secrets.DOCKERHUB_USERNAME }} |
| 152 | + password: ${{ secrets.DOCKERHUB_TOKEN }} |
| 153 | + |
| 154 | + - name: Login to GitHub Container Registry |
| 155 | + uses: docker/login-action@v3 |
| 156 | + with: |
| 157 | + registry: ghcr.io |
| 158 | + username: ${{ github.actor }} |
| 159 | + password: ${{ secrets.GITHUB_TOKEN }} |
| 160 | + |
| 161 | + - name: Create and push multi-arch manifest (GHCR) |
| 162 | + run: | |
| 163 | + docker buildx imagetools create -t ${{ env.GHCR_TSAN }}:latest \ |
| 164 | + ${{ env.GHCR_TSAN }}:latest-amd64 \ |
| 165 | + ${{ env.GHCR_TSAN }}:latest-arm64 |
| 166 | +
|
| 167 | + # Add version tag if this is a release |
| 168 | + if [[ "${{ github.ref }}" == refs/tags/v* ]]; then |
| 169 | + VERSION=${GITHUB_REF#refs/tags/} |
| 170 | + docker buildx imagetools create -t ${{ env.GHCR_TSAN }}:${VERSION} \ |
| 171 | + ${{ env.GHCR_TSAN }}:latest-amd64 \ |
| 172 | + ${{ env.GHCR_TSAN }}:latest-arm64 |
| 173 | + fi |
| 174 | +
|
| 175 | + - name: Create and push multi-arch manifest (Docker Hub) |
| 176 | + run: | |
| 177 | + docker buildx imagetools create -t ${{ env.DOCKER_HUB_TSAN }}:latest \ |
| 178 | + ${{ env.DOCKER_HUB_TSAN }}:latest-amd64 \ |
| 179 | + ${{ env.DOCKER_HUB_TSAN }}:latest-arm64 |
| 180 | +
|
| 181 | + # Add version tag if this is a release |
| 182 | + if [[ "${{ github.ref }}" == refs/tags/v* ]]; then |
| 183 | + VERSION=${GITHUB_REF#refs/tags/} |
| 184 | + docker buildx imagetools create -t ${{ env.DOCKER_HUB_TSAN }}:${VERSION} \ |
| 185 | + ${{ env.DOCKER_HUB_TSAN }}:latest-amd64 \ |
| 186 | + ${{ env.DOCKER_HUB_TSAN }}:latest-arm64 |
| 187 | + fi |
| 188 | +
|
| 189 | + - name: Verify multi-arch manifest |
| 190 | + run: | |
| 191 | + echo "=== GHCR TSan Image ===" |
| 192 | + docker buildx imagetools inspect ${{ env.GHCR_TSAN }}:latest |
| 193 | + echo "" |
| 194 | + echo "=== Docker Hub TSan Image ===" |
| 195 | + docker buildx imagetools inspect ${{ env.DOCKER_HUB_TSAN }}:latest |
0 commit comments