|
| 1 | +name: Build and Push gh-runner |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: |
| 6 | + - main |
| 7 | + workflow_dispatch: |
| 8 | + |
| 9 | +env: |
| 10 | + IMAGE_NAME: ghcr.io/${{ github.repository }} |
| 11 | + RUNNER_VERSION: 2.325.0 |
| 12 | + |
| 13 | +jobs: |
| 14 | + prepare: |
| 15 | + name: "🧰 Build Preparation" |
| 16 | + runs-on: ubuntu-latest |
| 17 | + outputs: |
| 18 | + image_name: ${{ steps.normalize.outputs.name }} |
| 19 | + short_sha: ${{ steps.sha.outputs.short }} |
| 20 | + is_tag: ${{ steps.tag.outputs.is_tag }} |
| 21 | + version: ${{ steps.tag.outputs.version }} |
| 22 | + major: ${{ steps.tag.outputs.major }} |
| 23 | + minor: ${{ steps.tag.outputs.minor }} |
| 24 | + steps: |
| 25 | + - uses: actions/checkout@v4 |
| 26 | + - name: Normalize image name |
| 27 | + id: normalize |
| 28 | + run: echo "name=${IMAGE_NAME,,}" >> "$GITHUB_OUTPUT" |
| 29 | + - name: Extract short SHA |
| 30 | + id: sha |
| 31 | + run: echo "short=$(git rev-parse --short HEAD)" >> "$GITHUB_OUTPUT" |
| 32 | + - name: Extract version from tag |
| 33 | + id: tag |
| 34 | + run: | |
| 35 | + if [[ "${GITHUB_REF}" == refs/tags/* ]]; then |
| 36 | + version="${GITHUB_REF#refs/tags/}" |
| 37 | + major=$(cut -d. -f1 <<< "$version") |
| 38 | + minor=$(cut -d. -f2 <<< "$version") |
| 39 | + echo "is_tag=true" >> "$GITHUB_OUTPUT" |
| 40 | + echo "version=$version" >> "$GITHUB_OUTPUT" |
| 41 | + echo "major=$major" >> "$GITHUB_OUTPUT" |
| 42 | + echo "minor=$minor" >> "$GITHUB_OUTPUT" |
| 43 | + else |
| 44 | + echo "is_tag=false" >> "$GITHUB_OUTPUT" |
| 45 | +
|
| 46 | + build-amd64: |
| 47 | + name: "🐳 Build Docker (AMD64)" |
| 48 | + needs: prepare |
| 49 | + runs-on: ubuntu-latest |
| 50 | + steps: |
| 51 | + - uses: actions/checkout@v4 |
| 52 | + - uses: docker/setup-buildx-action@v3 |
| 53 | + - uses: docker/login-action@v3 |
| 54 | + with: |
| 55 | + registry: ghcr.io |
| 56 | + username: ${{ github.actor }} |
| 57 | + password: ${{ secrets.GITHUB_TOKEN }} |
| 58 | + - name: Build and push AMD64 image |
| 59 | + uses: docker/build-push-action@v6 |
| 60 | + with: |
| 61 | + context: . |
| 62 | + push: true |
| 63 | + platforms: linux/amd64 |
| 64 | + tags: | |
| 65 | + ${{ needs.prepare.outputs.image_name }}:amd64 |
| 66 | + ${{ needs.prepare.outputs.image_name }}:${{ needs.prepare.outputs.short_sha }}-amd64 |
| 67 | + build-args: | |
| 68 | + RUNNER_VERSION=${{ env.RUNNER_VERSION }} |
| 69 | + cache-from: type=gha |
| 70 | + cache-to: type=gha,mode=max |
| 71 | + |
| 72 | + build-arm64: |
| 73 | + name: "🐳 Build Docker (ARM64)" |
| 74 | + needs: prepare |
| 75 | + runs-on: self-hosted |
| 76 | + steps: |
| 77 | + - uses: actions/checkout@v4 |
| 78 | + - uses: docker/setup-buildx-action@v3 |
| 79 | + - uses: docker/login-action@v3 |
| 80 | + with: |
| 81 | + registry: ghcr.io |
| 82 | + username: ${{ github.actor }} |
| 83 | + password: ${{ secrets.GITHUB_TOKEN }} |
| 84 | + - name: Build and push ARM64 image |
| 85 | + uses: docker/build-push-action@v6 |
| 86 | + with: |
| 87 | + context: . |
| 88 | + push: true |
| 89 | + platforms: linux/arm64 |
| 90 | + tags: | |
| 91 | + ${{ needs.prepare.outputs.image_name }}:arm64 |
| 92 | + ${{ needs.prepare.outputs.image_name }}:${{ needs.prepare.outputs.short_sha }}-arm64 |
| 93 | + build-args: | |
| 94 | + RUNNER_VERSION=${{ env.RUNNER_VERSION }} |
| 95 | + cache-from: type=gha |
| 96 | + cache-to: type=gha,mode=max |
| 97 | + |
| 98 | + manifest: |
| 99 | + name: "📦 Docker Manifest" |
| 100 | + needs: [build-amd64, build-arm64] |
| 101 | + runs-on: ubuntu-latest |
| 102 | + env: |
| 103 | + IMAGE_NAME: ${{ needs.prepare.outputs.image_name }} |
| 104 | + SHORT_SHA: ${{ needs.prepare.outputs.short_sha }} |
| 105 | + IS_TAG: ${{ needs.prepare.outputs.is_tag }} |
| 106 | + VERSION: ${{ needs.prepare.outputs.version }} |
| 107 | + MAJOR: ${{ needs.prepare.outputs.major }} |
| 108 | + MINOR: ${{ needs.prepare.outputs.minor }} |
| 109 | + GITHUB_REF: ${{ github.ref }} |
| 110 | + steps: |
| 111 | + - uses: docker/login-action@v3 |
| 112 | + with: |
| 113 | + registry: ghcr.io |
| 114 | + username: ${{ github.actor }} |
| 115 | + password: ${{ secrets.GITHUB_TOKEN }} |
| 116 | + - name: Create and push Docker manifest |
| 117 | + run: | |
| 118 | + docker buildx imagetools create \ |
| 119 | + --tag $IMAGE_NAME:$SHORT_SHA \ |
| 120 | + $IMAGE_NAME:amd64 \ |
| 121 | + $IMAGE_NAME:arm64 |
| 122 | +
|
| 123 | + if [[ "$GITHUB_REF" == "refs/heads/main" ]]; then |
| 124 | + docker buildx imagetools create \ |
| 125 | + --tag $IMAGE_NAME:latest \ |
| 126 | + $IMAGE_NAME:amd64 \ |
| 127 | + $IMAGE_NAME:arm64 |
| 128 | + fi |
| 129 | +
|
| 130 | + if [[ "$IS_TAG" == "true" ]]; then |
| 131 | + docker buildx imagetools create \ |
| 132 | + --tag $IMAGE_NAME:$VERSION \ |
| 133 | + --tag $IMAGE_NAME:$MAJOR \ |
| 134 | + --tag $IMAGE_NAME:$MAJOR.$MINOR \ |
| 135 | + $IMAGE_NAME:amd64 \ |
| 136 | + $IMAGE_NAME:arm64 |
0 commit comments