|
| 1 | +# Licensed to the Apache Software Foundation (ASF) under one or more |
| 2 | +# contributor license agreements. See the NOTICE file distributed with |
| 3 | +# this work for additional information regarding copyright ownership. |
| 4 | +# The ASF licenses this file to You under the Apache License, Version 2.0 |
| 5 | +# (the "License"); you may not use this file except in compliance with |
| 6 | +# the License. You may obtain a copy of the License at |
| 7 | +# |
| 8 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | +# |
| 10 | +# Unless required by applicable law or agreed to in writing, software |
| 11 | +# distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | +# See the License for the specific language governing permissions and |
| 14 | +# limitations under the License. |
| 15 | + |
| 16 | +name: "Build and Push Docker Images" |
| 17 | + |
| 18 | +on: |
| 19 | + workflow_dispatch: |
| 20 | + push: |
| 21 | + branches: |
| 22 | + - master |
| 23 | + - 'dev-*' |
| 24 | + tags: |
| 25 | + - '*-*.*' |
| 26 | + pull_request: |
| 27 | + branches: |
| 28 | + - master |
| 29 | + - 'dev-*' |
| 30 | + |
| 31 | +env: |
| 32 | + REGISTRY: ghcr.io |
| 33 | + OWNER: ${{ github.repository_owner }} |
| 34 | + IMAGE_REPO: flink-docker |
| 35 | + |
| 36 | +jobs: |
| 37 | + build_and_push: |
| 38 | + runs-on: ubuntu-latest |
| 39 | + permissions: |
| 40 | + contents: read |
| 41 | + packages: write |
| 42 | + strategy: |
| 43 | + fail-fast: false |
| 44 | + matrix: |
| 45 | + include: |
| 46 | + # Flink 1.20.x |
| 47 | + - flink_version: "1.20" |
| 48 | + java_version: "8" |
| 49 | + dockerfile: "1.20/scala_2.12-java8-ubuntu/Dockerfile" |
| 50 | + - flink_version: "1.20" |
| 51 | + java_version: "11" |
| 52 | + dockerfile: "1.20/scala_2.12-java11-ubuntu/Dockerfile" |
| 53 | + - flink_version: "1.20" |
| 54 | + java_version: "17" |
| 55 | + dockerfile: "1.20/scala_2.12-java17-ubuntu/Dockerfile" |
| 56 | + # Flink 2.0.x |
| 57 | + - flink_version: "2.0" |
| 58 | + java_version: "11" |
| 59 | + dockerfile: "2.0/scala_2.12-java11-ubuntu/Dockerfile" |
| 60 | + - flink_version: "2.0" |
| 61 | + java_version: "17" |
| 62 | + dockerfile: "2.0/scala_2.12-java17-ubuntu/Dockerfile" |
| 63 | + - flink_version: "2.0" |
| 64 | + java_version: "21" |
| 65 | + dockerfile: "2.0/scala_2.12-java21-ubuntu/Dockerfile" |
| 66 | + # Flink 2.1.x (Latest) |
| 67 | + - flink_version: "2.1" |
| 68 | + java_version: "11" |
| 69 | + dockerfile: "2.1/scala_2.12-java11-ubuntu/Dockerfile" |
| 70 | + - flink_version: "2.1" |
| 71 | + java_version: "17" |
| 72 | + dockerfile: "2.1/scala_2.12-java17-ubuntu/Dockerfile" |
| 73 | + - flink_version: "2.1" |
| 74 | + java_version: "21" |
| 75 | + dockerfile: "2.1/scala_2.12-java21-ubuntu/Dockerfile" |
| 76 | + |
| 77 | + steps: |
| 78 | + - name: Check out the repo |
| 79 | + uses: actions/checkout@v4 |
| 80 | + |
| 81 | + - name: Set up QEMU |
| 82 | + uses: docker/setup-qemu-action@v3 |
| 83 | + |
| 84 | + - name: Set up Docker Buildx |
| 85 | + uses: docker/setup-buildx-action@v3 |
| 86 | + |
| 87 | + - name: Log in to the Container registry |
| 88 | + uses: docker/login-action@v3 |
| 89 | + with: |
| 90 | + registry: ${{ env.REGISTRY }} |
| 91 | + username: ${{ github.actor }} |
| 92 | + password: ${{ secrets.GITHUB_TOKEN }} |
| 93 | + |
| 94 | + - name: Determine image tags |
| 95 | + id: meta |
| 96 | + run: | |
| 97 | + FLINK_VERSION="${{ matrix.flink_version }}" |
| 98 | + JAVA_VERSION="${{ matrix.java_version }}" |
| 99 | +
|
| 100 | + # Read full version from Dockerfile (e.g., 2.1.1) |
| 101 | + # Extract from FLINK_TGZ_URL which contains the version |
| 102 | + DOCKERFILE_PATH="${{ matrix.dockerfile }}" |
| 103 | + FULL_VERSION=$(grep "FLINK_TGZ_URL=" "$DOCKERFILE_PATH" | head -1 | sed -E 's/.*flink-([0-9]+\.[0-9]+\.[0-9]+).*/\1/') |
| 104 | +
|
| 105 | + if [ -z "$FULL_VERSION" ]; then |
| 106 | + echo "ERROR: Could not extract version from $DOCKERFILE_PATH" |
| 107 | + exit 1 |
| 108 | + fi |
| 109 | +
|
| 110 | + echo "full_version=$FULL_VERSION" >> $GITHUB_OUTPUT |
| 111 | +
|
| 112 | + # Build base image name |
| 113 | + BASE_TAG="${FULL_VERSION}-scala_2.12-java${JAVA_VERSION}" |
| 114 | +
|
| 115 | + # Determine tags based on event type |
| 116 | + TAGS="${REGISTRY}/${OWNER}/${IMAGE_REPO}:${BASE_TAG}" |
| 117 | +
|
| 118 | + # Add branch-specific tags for branch pushes |
| 119 | + if [ "${{ github.event_name }}" = "push" ] && [ "${{ github.ref_type }}" = "branch" ]; then |
| 120 | + BRANCH_NAME=$(echo "${{ github.ref_name }}" | sed 's/\//-/g') |
| 121 | + TAGS="${TAGS},${REGISTRY}/${OWNER}/${IMAGE_REPO}:${BRANCH_NAME}-java${JAVA_VERSION}" |
| 122 | + TAGS="${TAGS},${REGISTRY}/${OWNER}/${IMAGE_REPO}:${BRANCH_NAME}-${FLINK_VERSION}-java${JAVA_VERSION}" |
| 123 | + fi |
| 124 | +
|
| 125 | + # Add git sha tag |
| 126 | + SHORT_SHA=$(echo "${{ github.sha }}" | cut -c1-7) |
| 127 | + TAGS="${TAGS},${REGISTRY}/${OWNER}/${IMAGE_REPO}:${BASE_TAG}-${SHORT_SHA}" |
| 128 | +
|
| 129 | + echo "tags=$TAGS" >> $GITHUB_OUTPUT |
| 130 | + echo "Image tags: $TAGS" |
| 131 | +
|
| 132 | + - name: Build and push Docker image |
| 133 | + uses: docker/build-push-action@v5 |
| 134 | + with: |
| 135 | + context: ${{ matrix.flink_version }}/scala_2.12-java${{ matrix.java_version }}-ubuntu |
| 136 | + file: ${{ matrix.dockerfile }} |
| 137 | + platforms: linux/amd64,linux/arm64/v8 |
| 138 | + push: ${{ github.event_name != 'pull_request' }} |
| 139 | + tags: ${{ steps.meta.outputs.tags }} |
| 140 | + cache-from: type=gha |
| 141 | + cache-to: type=gha,mode=max |
| 142 | + |
| 143 | + - name: Summary |
| 144 | + if: github.event_name != 'pull_request' |
| 145 | + run: | |
| 146 | + echo "✅ Successfully built and pushed Flink ${{ steps.meta.outputs.full_version }} with Java ${{ matrix.java_version }}" |
| 147 | + echo "Tags:" |
| 148 | + echo "${{ steps.meta.outputs.tags }}" | tr ',' '\n' | sed 's/^/ - /' |
0 commit comments