Skip to content

Commit

Permalink
[FLINK-20632] Add script to publish docker images to Docker Hub (apac…
Browse files Browse the repository at this point in the history
…he/flink)
  • Loading branch information
rmetzger committed Jan 8, 2021
1 parent fb04fbd commit f47f4a2
Show file tree
Hide file tree
Showing 4 changed files with 157 additions and 51 deletions.
11 changes: 9 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ Apache Flink Docker Images
==========================

This repo contains Dockerfiles for building Docker images for Apache Flink, and are used to build
the "official" [`flink`](https://hub.docker.com/_/flink) images hosted on Docker Hub.
the "official" [`flink`](https://hub.docker.com/_/flink) images hosted on Docker Hub (reviewed and build by Docker), as well as the images published on [`apache/flink` DockerHub](https://hub.docker.com/r/apache/flink) (maintained by Flink committers).

These Dockerfiles are maintained by the Apache Flink community, but the Docker community is
responsible for building and hosting the images on Docker Hub.
Expand Down Expand Up @@ -83,7 +83,14 @@ Updating the Dockerfiles involves the following steps:
https://github.com/apache/flink-docker/commit/5920fd775ca1a8d03ee959d79bceeb5d6e8f35a1)]</sup>
* Create a pull request against the `master` branch containing this commit.

Once the pull request has been merged, a new manifest should be generated and a pull request opened
Once the pull request has been merged, we can release the new docker images:

For **publishing to DockerHub: apache/flink** , you need to perform the following steps:

1. Make sure that you are authenticated with your Docker ID, and that your Docker ID has access to `apache/flink`. If not, request access by INFRA (see [also](https://issues.apache.org/jira/browse/INFRA-21276): `docker login -u <username>`.
2. Generate and upload the new images: `./publish-to-dockerhub.sh`.

For **publishing as an official image**, a new manifest should be generated and a pull request opened
on the Docker Library [`official-images`](https://github.com/docker-library/official-images) repo.

1. Run `./generate-stackbrew-library.sh` to output the new manifest (see note [below](
Expand Down
69 changes: 69 additions & 0 deletions common.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
#!/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.
#


# get the most recent commit which modified any of "$@"
fileCommit() {
git log -1 --format='format:%H' HEAD -- "$@"
}

# get the most recent commit which modified "$1/Dockerfile" or any file COPY'd from "$1/Dockerfile"
dirCommit() {
local dir="$1"; shift
(
cd "$dir"
fileCommit \
Dockerfile \
$(git show HEAD:./Dockerfile | awk '
toupper($1) == "COPY" {
for (i = 2; i < NF; i++) {
print $i
}
}
')
)
}

# Inputs:
# - tags: comma-seprated list of image tags
# - latestVersion: latest version
# Output: comma-separated list of tags with "latest" removed if not latest version
pruneTags() {
local tags=$1
local latestVersion=$2
if [[ $tags =~ $latestVersion ]]; then
# tags contains latest version. keep "latest" tag
echo $tags
else
# remove "latest", any "scala_" or "javaXX" tag, unless it is the latest version
# the "scala" / "java" tags have a similar semantic as the "latest" tag in docker registries.
echo $tags | sed -E 's|, (scala\|latest\|java[0-9]{1,2})[-_.[:alnum:]]*||g'
fi
}

extractValue() {
local key="$1"
local file="$2"
local line=$(cat $file | grep "$key:")
echo $line | sed "s/${key}: //g"
}

# get latest flink version
latest_version=`ls -1a | grep -E "[0-9]+.[0-9]+" | sort -V -r | head -n 1`
67 changes: 18 additions & 49 deletions generate-stackbrew-library.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,22 @@
#!/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 generates a manifest compatibile with the expectations set forth
# by docker-library/official-images.
#
Expand All @@ -11,55 +28,7 @@ set -eu
self="$(basename "$BASH_SOURCE")"
cd "$(dirname "$(readlink -f "$BASH_SOURCE")")"


# get the most recent commit which modified any of "$@"
fileCommit() {
git log -1 --format='format:%H' HEAD -- "$@"
}

# get the most recent commit which modified "$1/Dockerfile" or any file COPY'd from "$1/Dockerfile"
dirCommit() {
local dir="$1"; shift
(
cd "$dir"
fileCommit \
Dockerfile \
$(git show HEAD:./Dockerfile | awk '
toupper($1) == "COPY" {
for (i = 2; i < NF; i++) {
print $i
}
}
')
)
}

# Inputs:
# - tags: comma-seprated list of image tags
# - latestVersion: latest version
# Output: comma-separated list of tags with "latest" removed if not latest version
pruneTags() {
local tags=$1
local latestVersion=$2
if [[ $tags =~ $latestVersion ]]; then
# tags contains latest version. keep "latest" tag
echo $tags
else
# remove "latest", any "scala_" or "javaXX" tag, unless it is the latest version
# the "scala" / "java" tags have a similar semantic as the "latest" tag in docker registries.
echo $tags | sed -E 's|, (scala\|latest\|java[0-9]{1,2})[-_.[:alnum:]]*||g'
fi
}

extractValue() {
local key="$1"
local file="$2"
local line=$(cat $file | grep "$key:")
echo $line | sed "s/${key}: //g"
}

# get latest flink version
latest_version=`ls -1a | grep -E "[0-9]+.[0-9]+" | sort -V -r | head -n 1`
source common.sh

cat <<-EOH
# this file is generated via https://github.com/apache/flink-docker/blob/$(fileCommit "$self")/$self
Expand Down
61 changes: 61 additions & 0 deletions publish-to-dockerhub.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
#!/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 publishes the Flink docker images to any Docker registry. By default it's configured to the apache/flink DockerHub account.

self="$(basename "$BASH_SOURCE")"
cd "$(dirname "$(readlink -f "$BASH_SOURCE")")"

source common.sh

TARGET_REGISTRY=${TARGET_REGISTRY:-"apache/flink"}

echo "Publishing to target registry: $TARGET_REGISTRY"

for dockerfile in $(find . -name "Dockerfile"); do
dir=$(dirname $dockerfile)

metadata="$dir/release.metadata"
tags=$(extractValue "Tags" $metadata)
tags=$(pruneTags "$tags" $latest_version)

echo "Building image in $dir"

DOCKER_BUILD_CMD="docker build"
DOCKER_PUSH_CMDS=()
IFS=',' read -ra TAGS_ARRAY <<< "$tags"
for raw_tag in "${TAGS_ARRAY[@]}"; do
# trim whitespace
tag=`echo $raw_tag | xargs`
DOCKER_BUILD_CMD+=" -t $TARGET_REGISTRY:$tag"
DOCKER_PUSH_CMDS+=( "docker push $TARGET_REGISTRY:$tag")
done
DOCKER_BUILD_CMD+=" $dir"
echo -e "\tBuilding docker image using command"
echo -e "\t\t$DOCKER_BUILD_CMD"
eval $DOCKER_BUILD_CMD
echo -e "\tPushing tags"
for push_cmd in "${DOCKER_PUSH_CMDS[@]}"; do
echo -e "\t\tPushing using $push_cmd"
eval $push_cmd
done

#newline
echo
done

0 comments on commit f47f4a2

Please sign in to comment.