|
| 1 | +name: Build and Push Container Images |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + tags: |
| 6 | + - 'v*' # Push events to matching v* |
| 7 | + workflow_dispatch: # Allow manual trigger |
| 8 | + inputs: |
| 9 | + tag: |
| 10 | + description: 'Tag to build (e.g., v0.13.0-mirantis.0)' |
| 11 | + required: true |
| 12 | + type: string |
| 13 | + |
| 14 | +permissions: |
| 15 | + contents: read |
| 16 | + packages: write # Required for ghcr.io |
| 17 | + |
| 18 | +env: |
| 19 | + # Mirantis registry configuration |
| 20 | + REGISTRY: ghcr.io/mirantis |
| 21 | + IMAGE_NAME: cluster-api-provider-openstack |
| 22 | + |
| 23 | +jobs: |
| 24 | + build-and-push: |
| 25 | + name: Build and push multi-arch images |
| 26 | + runs-on: ubuntu-latest |
| 27 | + steps: |
| 28 | + - name: Set tag environment |
| 29 | + run: | |
| 30 | + if [ "${{ github.event_name }}" = "workflow_dispatch" ]; then |
| 31 | + echo "TAG=${{ inputs.tag }}" >> $GITHUB_ENV |
| 32 | + else |
| 33 | + echo "TAG=${GITHUB_REF#refs/tags/}" >> $GITHUB_ENV |
| 34 | + fi |
| 35 | +
|
| 36 | + - name: Checkout code |
| 37 | + uses: actions/checkout@v4 |
| 38 | + with: |
| 39 | + fetch-depth: 0 |
| 40 | + |
| 41 | + - name: Calculate go version |
| 42 | + run: echo "go_version=$(make go-version)" >> $GITHUB_ENV |
| 43 | + |
| 44 | + - name: Set up Go |
| 45 | + uses: actions/setup-go@v5 |
| 46 | + with: |
| 47 | + go-version: ${{ env.go_version }} |
| 48 | + |
| 49 | + - name: Set up Docker Buildx |
| 50 | + uses: docker/setup-buildx-action@v3 |
| 51 | + |
| 52 | + - name: Log in to GitHub Container Registry |
| 53 | + uses: docker/login-action@v3 |
| 54 | + with: |
| 55 | + registry: ghcr.io |
| 56 | + username: ${{ github.actor }} |
| 57 | + password: ${{ secrets.GITHUB_TOKEN }} |
| 58 | + |
| 59 | + - name: Extract metadata |
| 60 | + id: meta |
| 61 | + uses: docker/metadata-action@v5 |
| 62 | + with: |
| 63 | + images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} |
| 64 | + tags: | |
| 65 | + type=ref,event=tag |
| 66 | + type=raw,value=${{ env.TAG }} |
| 67 | + type=raw,value=latest,enable={{is_default_branch}} |
| 68 | +
|
| 69 | + - name: Build and push multi-arch image |
| 70 | + uses: docker/build-push-action@v5 |
| 71 | + with: |
| 72 | + context: . |
| 73 | + file: ./Dockerfile |
| 74 | + platforms: linux/amd64,linux/arm,linux/arm64,linux/ppc64le,linux/s390x |
| 75 | + push: true |
| 76 | + tags: ${{ steps.meta.outputs.tags }} |
| 77 | + labels: ${{ steps.meta.outputs.labels }} |
| 78 | + build-args: | |
| 79 | + GO_VERSION=${{ env.go_version }} |
| 80 | + ldflags=${{ env.LDFLAGS }} |
| 81 | + cache-from: type=gha |
| 82 | + cache-to: type=gha,mode=max |
| 83 | + |
| 84 | + - name: Generate image digest summary |
| 85 | + run: | |
| 86 | + echo "## Container Images Built 🐳" >> $GITHUB_STEP_SUMMARY |
| 87 | + echo "" >> $GITHUB_STEP_SUMMARY |
| 88 | + echo "| Image | Tag | Platform |" >> $GITHUB_STEP_SUMMARY |
| 89 | + echo "|-------|-----|----------|" >> $GITHUB_STEP_SUMMARY |
| 90 | + echo "| ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} | ${{ env.TAG }} | linux/amd64, linux/arm, linux/arm64, linux/ppc64le, linux/s390x |" >> $GITHUB_STEP_SUMMARY |
| 91 | + echo "" >> $GITHUB_STEP_SUMMARY |
| 92 | + echo "### Pull command:" >> $GITHUB_STEP_SUMMARY |
| 93 | + echo '```bash' >> $GITHUB_STEP_SUMMARY |
| 94 | + echo "docker pull ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ env.TAG }}" >> $GITHUB_STEP_SUMMARY |
| 95 | + echo '```' >> $GITHUB_STEP_SUMMARY |
0 commit comments