You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@flink.apache.org by GitBox <gi...@apache.org> on 2020/07/29 07:50:28 UTC

[GitHub] [flink-docker] zentol commented on a change in pull request #31: [FLINK-16260] Change generate-stackbrew-library.sh to support new release.metadata file

zentol commented on a change in pull request #31:
URL: https://github.com/apache/flink-docker/pull/31#discussion_r461526576



##########
File path: generate-stackbrew-library.sh
##########
@@ -8,16 +8,11 @@
 
 set -eu
 
-declare -A aliases=(
-    [1.11]='latest'
-)
-
 self="$(basename "$BASH_SOURCE")"
 cd "$(dirname "$(readlink -f "$BASH_SOURCE")")"
 
-# Identify directories matching '?.?' (e.g. '1.7') and remove trailing slashes
-versions=( ?.?/ ?.??/ )
-versions=( "${versions[@]%/}" )
+# remove "latest" and any "scala_" tag, unless it is the latest version

Review comment:
       mention that there are `scala_2.11` tags that have semantics similar to `latest`

##########
File path: generate-stackbrew-library.sh
##########
@@ -41,21 +36,39 @@ dirCommit() {
     )
 }
 
-getArches() {
-    local repo="$1"; shift
-    local officialImagesUrl='https://github.com/docker-library/official-images/raw/master/library/'
+# 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 inTagsString=$1
+    local latestVersion=$2
+    if [[ $inTagsString =~ $latestVersion ]]; then
+        # tagsString contains latest version. keep "latest" tag
+        echo $inTagsString
+    else
+        # split list of tags, remove anything containing "latest"
+        IFS=', ' read -r -a inTags <<< "$inTagsString"
+        local outString=""
+        for inTag in "${inTags[@]}"; do
+            if [[ $inTag =~ $PRUNE_FROM_NON_LATEST_VERSION ]]; then
+                continue;
+            fi
+            outString="$outString, $inTag"
+        done
+        echo ${outString:2}
+    fi
+}
 
-    eval "declare -g -A parentRepoToArches=( $(
-        find -name 'Dockerfile' -exec awk '
-                toupper($1) == "FROM" && $2 !~ /^('"$repo"'|scratch|microsoft\/[^:]+)(:|$)/ {
-                    print "'"$officialImagesUrl"'" $2
-                }
-            ' '{}' + \
-            | sort -u \
-            | xargs bashbrew cat --format '[{{ .RepoName }}:{{ .TagName }}]="{{ join " " .TagEntry.Architectures }}"'
-    ) )"
+extractValue() {
+    local key="$1"
+    local file="$2"
+    local line=$(cat $file | grep "$key:")
+    echo $line | cut -d ':' -f 2 | xargs # remove key from line, remove whitespace

Review comment:
       while this works, I think `tr -d ' '` would be more intuitive

##########
File path: generate-stackbrew-library.sh
##########
@@ -41,21 +36,39 @@ dirCommit() {
     )
 }
 
-getArches() {
-    local repo="$1"; shift
-    local officialImagesUrl='https://github.com/docker-library/official-images/raw/master/library/'
+# 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 inTagsString=$1
+    local latestVersion=$2
+    if [[ $inTagsString =~ $latestVersion ]]; then
+        # tagsString contains latest version. keep "latest" tag
+        echo $inTagsString
+    else
+        # split list of tags, remove anything containing "latest"
+        IFS=', ' read -r -a inTags <<< "$inTagsString"
+        local outString=""
+        for inTag in "${inTags[@]}"; do

Review comment:
       couldn't this branch be reduced to
   `echo $inTagsString | sed 's/, latest[-_[:alnum:]]*//g' | sed 's/, scala[-_[:alnum:]]*//g'`?

##########
File path: generate-stackbrew-library.sh
##########
@@ -41,21 +36,39 @@ dirCommit() {
     )
 }
 
-getArches() {
-    local repo="$1"; shift
-    local officialImagesUrl='https://github.com/docker-library/official-images/raw/master/library/'
+# 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 inTagsString=$1
+    local latestVersion=$2
+    if [[ $inTagsString =~ $latestVersion ]]; then
+        # tagsString contains latest version. keep "latest" tag
+        echo $inTagsString
+    else
+        # split list of tags, remove anything containing "latest"
+        IFS=', ' read -r -a inTags <<< "$inTagsString"
+        local outString=""
+        for inTag in "${inTags[@]}"; do

Review comment:
       couldn't this branch be reduced to
   `echo $inTagsString | sed 's/, latest[-_[:alnum:]]*//g' | sed 's/, scala[-_[:alnum:]]*//g'`?
   Or even
   `echo $inTagsString | sed -E 's|, (scala\|latest)[-_[:alnum:]]*||g'`

##########
File path: generate-stackbrew-library.sh
##########
@@ -41,21 +34,32 @@ dirCommit() {
     )
 }
 
-getArches() {
-    local repo="$1"; shift
-    local officialImagesUrl='https://github.com/docker-library/official-images/raw/master/library/'
+# Inputs:
+#  - tags: comma-seprated list of image tags

Review comment:
       variable name does not match (I'd use `tags`)

##########
File path: generate-stackbrew-library.sh
##########
@@ -41,21 +34,32 @@ dirCommit() {
     )
 }
 
-getArches() {
-    local repo="$1"; shift
-    local officialImagesUrl='https://github.com/docker-library/official-images/raw/master/library/'
+# 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 inTagsString=$1
+    local latestVersion=$2
+    if [[ $inTagsString =~ $latestVersion ]]; then
+        # tagsString contains latest version. keep "latest" tag
+        echo $inTagsString
+    else
+        # remove "latest" and any "scala_" tag, unless it is the latest version
+        # the "scala_" tag has a similar semantic as the "latest" tag in docker registries. 
+        echo $inTagsString | sed -E 's|,(scala\|latest)[-_[:alnum:]]*||g'
+    fi
+}
 
-    eval "declare -g -A parentRepoToArches=( $(
-        find -name 'Dockerfile' -exec awk '
-                toupper($1) == "FROM" && $2 !~ /^('"$repo"'|scratch|microsoft\/[^:]+)(:|$)/ {
-                    print "'"$officialImagesUrl"'" $2
-                }
-            ' '{}' + \
-            | sort -u \
-            | xargs bashbrew cat --format '[{{ .RepoName }}:{{ .TagName }}]="{{ join " " .TagEntry.Architectures }}"'
-    ) )"
+extractValue() {
+    local key="$1"
+    local file="$2"
+    local line=$(cat $file | grep "$key:")
+    echo $line | cut -d ':' -f 2 | tr -d ' ' # remove key from line, remove whitespace

Review comment:
       I looked at various entries in https://github.com/docker-library/official-images and they all separated tags with a comma and space `, ` 😢 
   
   We could use `sed` again: `echo $line | sed 's/[-_[:alnum:]]*: //g'`

##########
File path: generate-stackbrew-library.sh
##########
@@ -41,21 +34,32 @@ dirCommit() {
     )
 }
 
-getArches() {
-    local repo="$1"; shift
-    local officialImagesUrl='https://github.com/docker-library/official-images/raw/master/library/'
+# 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 inTagsString=$1
+    local latestVersion=$2
+    if [[ $inTagsString =~ $latestVersion ]]; then
+        # tagsString contains latest version. keep "latest" tag
+        echo $inTagsString
+    else
+        # remove "latest" and any "scala_" tag, unless it is the latest version
+        # the "scala_" tag has a similar semantic as the "latest" tag in docker registries. 
+        echo $inTagsString | sed -E 's|,(scala\|latest)[-_[:alnum:]]*||g'
+    fi
+}
 
-    eval "declare -g -A parentRepoToArches=( $(
-        find -name 'Dockerfile' -exec awk '
-                toupper($1) == "FROM" && $2 !~ /^('"$repo"'|scratch|microsoft\/[^:]+)(:|$)/ {
-                    print "'"$officialImagesUrl"'" $2
-                }
-            ' '{}' + \
-            | sort -u \
-            | xargs bashbrew cat --format '[{{ .RepoName }}:{{ .TagName }}]="{{ join " " .TagEntry.Architectures }}"'
-    ) )"
+extractValue() {
+    local key="$1"
+    local file="$2"
+    local line=$(cat $file | grep "$key:")
+    echo $line | cut -d ':' -f 2 | tr -d ' ' # remove key from line, remove whitespace

Review comment:
       I looked at various entries in https://github.com/docker-library/official-images and they all separated tags with a comma and space `, ` 😢 
   
   We could use `sed` again: `echo $line | sed "s/${key}: //g"`




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org