ソースを参照

chore: docker-latest tag can be create automatically in cut.sh

Ivan Dyachkov 2 年 前
コミット
7a154e4d58

+ 16 - 20
.github/workflows/build_and_push_docker_images.yaml

@@ -43,9 +43,10 @@ jobs:
 
       - name: Get profiles to build
         id: get_profile
+        env:
+          INPUTS_PROFILE: ${{ github.event.inputs.profile }}
         run: |
           cd source
-          tag=${{ github.ref }}
           # tag docker-latest-ce or docker-latest-ee
           if git describe --tags --exact --match 'docker-latest-*' 2>/dev/null; then
             echo 'is_latest=true due to docker-latest-* tag'
@@ -57,38 +58,33 @@ jobs:
             echo 'is_latest=false'
             is_latest=false
           fi
-          if git describe --tags --match "[v|e]*" --exact; then
+          # resolve profile
+          if git describe --tags --match "v*" --exact; then
+            echo "This is an exact git tag, will publish images"
+            is_exact='true'
+            PROFILE=emqx
+          elif git describe --tags --match "e*" --exact; then
             echo "This is an exact git tag, will publish images"
             is_exact='true'
+            PROFILE=emqx-enterprise
           else
             echo "This is NOT an exact git tag, will not publish images"
             is_exact='false'
           fi
-          case $tag in
-            refs/tags/v*)
-              PROFILE='emqx'
+
+          case "${PROFILE:-$INPUTS_PROFILE}" in
+            emqx)
               EDITION='Opensource'
               ;;
-            refs/tags/e*)
-              PROFILE=emqx-enterprise
+            emqx-enterprise)
               EDITION='Enterprise'
               ;;
             *)
-              PROFILE=${{ github.event.inputs.profile }}
-              case "$PROFILE" in
-                emqx)
-                  EDITION='Opensource'
-                  ;;
-                emqx-enterprise)
-                  EDITION='Enterprise'
-                  ;;
-                *)
-                  echo "ERROR: Failed to resolve build profile"
-                  exit 1
-                  ;;
-              esac
+              echo "ERROR: Failed to resolve build profile"
+              exit 1
               ;;
           esac
+
           VSN="$(./pkg-vsn.sh "$PROFILE")"
           echo "Building emqx/$PROFILE:$VSN image (latest=$is_latest)"
           echo "Push = $is_exact"

+ 37 - 14
scripts/rel/cut.sh

@@ -19,15 +19,23 @@ RELEASE_GIT_TAG is a 'v*' or 'e*' tag for example:
   e5.0.0-beta.6
 
 options:
-  -h|--help: Print this usage.
-  -b|--base: Specify the current release base branch, can be one of
-             release-50
-             NOTE: this option should be used when --dryrun.
-  --dryrun:  Do not actually create the git tag.
-  --skip-appup: Skip checking appup
-                Useful when you are sure that appup is already updated'
-  --prev-tag: Provide the prev tag to automatically generate changelogs
-              If this option is absent, the tag found by git describe will be used
+  -h|--help:         Print this usage.
+
+  -b|--base:         Specify the current release base branch, can be one of
+                     release-50
+                     NOTE: this option should be used when --dryrun.
+
+  --dryrun:          Do not actually create the git tag.
+
+  --skip-appup:      Skip checking appup
+                     Useful when you are sure that appup is already updated'
+
+  --prev-tag <tag>:  Provide the prev tag to automatically generate changelogs
+                     If this option is absent, the tag found by git describe will be used
+
+  --docker-latest:   Set this option to assign :latest tag on the corresponding docker image
+                     in addition to regular :<version> one
+
 
 NOTE: For 5.0 series the current working branch must be 'release-50' for opensource edition
       and 'release-e50' for enterprise edition.
@@ -45,18 +53,21 @@ logmsg() {
 }
 
 TAG="${1:-}"
+DOCKER_LATEST_TAG=
 
 case "$TAG" in
     v*)
         TAG_PREFIX='v'
         PROFILE='emqx'
         SKIP_APPUP='yes'
+        DOCKER_LATEST_TAG='docker-latest-ce'
         ;;
     e*)
         TAG_PREFIX='e'
         PROFILE='emqx-enterprise'
         #TODO change to no when we are ready to support hot-upgrade
         SKIP_APPUP='yes'
+        DOCKER_LATEST_TAG='docker-latest-ee'
         ;;
     -h|--help)
         usage
@@ -72,6 +83,7 @@ esac
 shift 1
 
 DRYRUN='no'
+DOCKER_LATEST='no'
 while [ "$#" -gt 0 ]; do
     case $1 in
         -h|--help)
@@ -99,6 +111,10 @@ while [ "$#" -gt 0 ]; do
             PREV_TAG="$1"
             shift
             ;;
+        --docker-latest)
+            DOCKER_LATEST='yes'
+            shift
+            ;;
         *)
             logerr "Unknown option $1"
             exit 1
@@ -180,11 +196,11 @@ assert_release_version() {
 assert_release_version "$TAG"
 
 ## Check if all upstream branches are merged
-if [ -z "${BASE_BR:-}" ]; then
-    ./scripts/rel/sync-remotes.sh
-else
-    ./scripts/rel/sync-remotes.sh --base "$BASE_BR"
-fi
+SYNC_REMOTES_ARGS=
+[ -n "${BASE_BR:-}" ] && SYNC_REMOTES_ARGS="--base $BASE_BR $SYNC_REMOTES_ARGS"
+[ "$DRYRUN" = 'yes' ] && SYNC_REMOTES_ARGS="--dryrun $SYNC_REMOTES_ARGS"
+# shellcheck disable=SC2086
+./scripts/rel/sync-remotes.sh $SYNC_REMOTES_ARGS
 
 ## Check if the Chart versions are in sync
 ./scripts/rel/check-chart-vsn.sh "$PROFILE"
@@ -231,6 +247,9 @@ generate_changelog () {
 
 if [ "$DRYRUN" = 'yes' ]; then
     logmsg "Release tag is ready to be created with command: git tag $TAG"
+    if [ "$DOCKER_LATEST" = 'yes' ]; then
+        logmsg "Docker latest tag is ready to be created with command: git tag --force $DOCKER_LATEST_TAG"
+    fi
 else
     case "$TAG" in
         *rc*)
@@ -252,4 +271,8 @@ else
     esac
     git tag "$TAG"
     logmsg "$TAG is created OK."
+    if [ "$DOCKER_LATEST" = 'yes' ]; then
+        git tag --force "$DOCKER_LATEST_TAG"
+        logmsg "$DOCKER_LATEST_TAG is created OK."
+    fi
 fi

+ 15 - 2
scripts/rel/sync-remotes.sh

@@ -33,6 +33,10 @@ options:
     Without this option, the script executes 'git merge' command
     with '--ff-only' option which conveniently pulls remote
     updates if there is any, and fails when fast-forward is not possible
+
+  --dryrun:
+    Do not perform merge. Run the checks, fetch from remote,
+    and show what's going to happen.
 EOF
 }
 
@@ -48,6 +52,7 @@ logmsg() {
 }
 
 INTERACTIVE='no'
+DRYRUN='no'
 while [ "$#" -gt 0 ]; do
     case $1 in
         -h|--help)
@@ -63,6 +68,10 @@ while [ "$#" -gt 0 ]; do
             BASE_BRANCH="$1"
             shift
             ;;
+        --dryrun)
+            shift
+            DRYRUN='yes'
+            ;;
         *)
             logerr "Unknown option $1"
             exit 1
@@ -151,6 +160,10 @@ upstream_branches() {
 }
 
 for remote_ref in $(upstream_branches "$BASE_BRANCH"); do
-    logmsg "Merging $remote_ref"
-    git merge $MERGE_OPTS "$remote_ref"
+    if [ "$DRYRUN" = 'yes' ]; then
+        logmsg "Merge with this command: git merge $MERGE_OPTS $remote_ref"
+    else
+        logmsg "Merging $remote_ref"
+        git merge $MERGE_OPTS "$remote_ref"
+    fi
 done