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