-
Notifications
You must be signed in to change notification settings - Fork 216
Expand file tree
/
Copy pathpublish-to-dockerhub.sh
More file actions
executable file
Β·196 lines (172 loc) Β· 6.65 KB
/
publish-to-dockerhub.sh
File metadata and controls
executable file
Β·196 lines (172 loc) Β· 6.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
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
#!/usr/bin/env bash
#
# 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.
#
# This script copies Flink docker images from GHCR to Docker Hub.
# It uses crane to efficiently copy images without pulling them locally.
#
# Prerequisites:
# - crane installed (https://github.com/google/go-containerregistry/blob/main/cmd/crane/doc/crane.md)
# - Authentication to Docker Hub (docker login)
#
# Usage:
# ./publish-to-dockerhub.sh [--dry-run]
# SOURCE_REGISTRY=ghcr.io/myorg/flink-docker TARGET_REGISTRY=myorg/flink ./publish-to-dockerhub.sh
# ./publish-to-dockerhub.sh --dry-run # Test without actually copying
set -euo pipefail
# Parse command line arguments
DRY_RUN=false
for arg in "$@"; do
case $arg in
--dry-run|-n)
DRY_RUN=true
shift
;;
--help|-h)
echo "Usage: $0 [--dry-run]"
echo ""
echo "Options:"
echo " --dry-run, -n Show what would be copied without actually copying"
echo " --help, -h Show this help message"
echo ""
echo "Environment variables:"
echo " SOURCE_REGISTRY Source registry (default: ghcr.io/apache/flink-docker)"
echo " TARGET_REGISTRY Target registry (default: apache/flink)"
exit 0
;;
*)
echo "Unknown option: $arg"
echo "Use --help for usage information"
exit 1
;;
esac
done
self="$(basename "$BASH_SOURCE")"
cd "$(dirname "$(readlink -f "$BASH_SOURCE")")"
source common.sh
# Configuration
SOURCE_REGISTRY=${SOURCE_REGISTRY:-"ghcr.io/apache/flink-docker"}
TARGET_REGISTRY=${TARGET_REGISTRY:-"apache/flink"}
echo "============================================"
echo "Publishing Flink Docker Images"
if [ "$DRY_RUN" = true ]; then
echo "π DRY RUN MODE - No images will be copied"
fi
echo "============================================"
echo "Source: $SOURCE_REGISTRY"
echo "Target: $TARGET_REGISTRY"
echo "============================================"
echo ""
# Confirmation check
if [ "$DRY_RUN" = false ]; then
echo "β οΈ IMPORTANT: Before running this script, ensure that:"
echo ""
echo "1. The GitHub Actions workflow 'Build and Push Docker Images' has"
echo " completed successfully for the release you want to publish"
echo ""
echo "2. All Docker images are available in GHCR at:"
echo " https://github.com/orgs/apache/packages?repo_name=flink-docker"
echo " (or https://github.com/users/${USER}/packages if using a fork)"
echo ""
echo "3. The images were built from the correct branch/tag"
echo " - For releases: master branch"
echo " - For testing: dev-* branches"
echo ""
echo "4. You are authenticated to Docker Hub:"
echo " docker login"
echo ""
read -p "Have you verified the above? (yes/no): " -r
echo ""
if [[ ! $REPLY =~ ^[Yy][Ee][Ss]$ ]]; then
echo "β Aborted. Please verify the build workflow completed successfully first."
exit 1
fi
echo "β
Proceeding with image publication..."
echo ""
else
echo "π Dry-run mode: Will verify images exist and show what would be copied"
echo ""
fi
# Check if crane is installed
if ! command -v crane &> /dev/null; then
echo "ERROR: crane is not installed"
echo "Please install crane from: https://github.com/google/go-containerregistry/blob/main/cmd/crane/doc/crane.md"
echo ""
echo "Quick install:"
echo " macOS: brew install crane"
echo " Linux: go install github.com/google/go-containerregistry/cmd/crane@latest"
exit 1
fi
# Process each Dockerfile
for dockerfile in $(find . -name "Dockerfile" | sort); do
dir=$(dirname "$dockerfile")
# Extract version and java version from Dockerfile
FLINK_VERSION=$(grep "FLINK_TGZ_URL=" "$dockerfile" | head -1 | sed -E 's/.*flink-([0-9]+\.[0-9]+\.[0-9]+).*/\1/')
# Extract java version from directory name (e.g., scala_2.12-java11-ubuntu -> java11)
JAVA_VERSION=$(basename "$dir" | sed -E 's/.*-java([0-9]+)-.*/\1/')
if [ -z "$FLINK_VERSION" ] || [ -z "$JAVA_VERSION" ]; then
echo "β οΈ Skipping $dir - could not extract version info"
continue
fi
# Construct source image tag
SOURCE_TAG="${FLINK_VERSION}-scala_2.12-java${JAVA_VERSION}"
SOURCE_IMAGE="${SOURCE_REGISTRY}:${SOURCE_TAG}"
# Read target tags from metadata
metadata="$dir/release.metadata"
if [ ! -f "$metadata" ]; then
echo "β οΈ Skipping $dir - no metadata file found"
continue
fi
tags=$(extractValue "Tags" "$metadata")
tags=$(pruneTags "$tags" "$latest_version")
echo "π¦ Processing Flink ${FLINK_VERSION} Java ${JAVA_VERSION}"
echo " Source: ${SOURCE_IMAGE}"
# Check if source image exists
if ! crane manifest "$SOURCE_IMAGE" &> /dev/null; then
echo " β ERROR: Source image not found in GHCR"
echo " Please ensure the image was built and pushed by the CI workflow"
echo ""
echo "Aborting: Cannot proceed with missing images"
exit 1
fi
# Copy to each target tag
IFS=',' read -ra TAGS_ARRAY <<< "$tags"
for raw_tag in "${TAGS_ARRAY[@]}"; do
# Trim whitespace
tag=$(echo "$raw_tag" | xargs)
TARGET_IMAGE="${TARGET_REGISTRY}:${tag}"
if [ "$DRY_RUN" = true ]; then
echo " π Would copy to ${TARGET_IMAGE}"
else
echo " π€ Copying to ${TARGET_IMAGE}"
if crane copy "$SOURCE_IMAGE" "$TARGET_IMAGE"; then
echo " β
Success"
else
echo " β Failed"
exit 1
fi
fi
done
echo ""
done
echo "============================================"
if [ "$DRY_RUN" = true ]; then
echo "π Dry-run completed successfully!"
echo "Run without --dry-run to actually copy images."
else
echo "β
All images published successfully!"
fi
echo "============================================"