From 970355a0fb1e6d6fe5c8e99127481d77762b63c1 Mon Sep 17 00:00:00 2001 From: yutaoj <105471132+yutaoj@users.noreply.github.com> Date: Mon, 3 Jun 2024 15:34:32 +0800 Subject: [PATCH] support sapmachine 22 (java22) and Deprecated java8 from docker images (#1118) * support sapmachine 22 (java22) * Enhancement to MANIFEST.MF Generation in Cloud MTA Build Tool --------- Co-authored-by: Jiang, Yu-tao --- .circleci/config.yml | 205 +++++++++++----------------- internal/artifacts/manifest.go | 22 ++- internal/artifacts/manifest_test.go | 33 ++++- scripts/common_image | 2 +- 4 files changed, 134 insertions(+), 128 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 3da867536..2fd4b447b 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -275,102 +275,6 @@ jobs: goreleaser release #curl -sfL https://goreleaser.com/static/run | bash - publish-to-dockerhub-java8-node14: - docker: - - image: cimg/go:1.19 - working_directory: ~/go/src/github.com/SAP/cloud-mta-build-tool - steps: - - checkout - - setup_remote_docker: - version: 20.10.6 - - run: - name: build image pre-setup - command: | - #Make sure HEAD points to master - git checkout master - git fetch - git rebase - - run: - name: build Java 8.1.095 & Node 14.21.1 image - command: | - MBT_VERSION=$(cat ./VERSION) - sh $PWD/scripts/build_image 8.1.095 14.21.1 ${MBT_VERSION} - - run: - name: publish Java 8.1.095 & Node 14.21.1 image - command: | - MBT_VERSION=$(cat ./VERSION) - echo "Image release: ${MBT_VERSION}" - #Push to Docker Hub - echo "$DOCKER_HUB_TOKEN" | docker login --username $DOCKER_HUB_USER --password-stdin - sh $PWD/scripts/publish_image 8.1.095 14.21.1 ${MBT_VERSION} "devxci" - #Push to GitHub Container Registry - echo "$CLOUD_MTA_BOT_GITHUB_TOKEN" | docker login "ghcr.io" --username $CLOUD_MTA_BOT_USER --password-stdin - sh $PWD/scripts/publish_image 8.1.095 14.21.1 ${MBT_VERSION} "ghcr.io/sap" - - publish-to-dockerhub-java8-node16: - docker: - - image: cimg/go:1.19 - working_directory: ~/go/src/github.com/SAP/cloud-mta-build-tool - steps: - - checkout - - setup_remote_docker: - version: 20.10.6 - - run: - name: build image pre-setup - command: | - #Make sure HEAD points to master - git checkout master - git fetch - git rebase - - run: - name: build Java 8.1.095 & Node 16.18.1 image - command: | - MBT_VERSION=$(cat ./VERSION) - sh $PWD/scripts/build_image 8.1.095 16.18.1 ${MBT_VERSION} - - run: - name: publish Java 8.1.095 & Node 16.18.1 image - command: | - MBT_VERSION=$(cat ./VERSION) - echo "Image release: ${MBT_VERSION}" - #Push to Docker Hub - echo "$DOCKER_HUB_TOKEN" | docker login --username $DOCKER_HUB_USER --password-stdin - sh $PWD/scripts/publish_image 8.1.095 16.18.1 ${MBT_VERSION} "devxci" - #Push to GitHub Container Registry - echo "$CLOUD_MTA_BOT_GITHUB_TOKEN" | docker login "ghcr.io" --username $CLOUD_MTA_BOT_USER --password-stdin - sh $PWD/scripts/publish_image 8.1.095 16.18.1 ${MBT_VERSION} "ghcr.io/sap" - - publish-to-dockerhub-java8-node18: - docker: - - image: cimg/go:1.19 - working_directory: ~/go/src/github.com/SAP/cloud-mta-build-tool - steps: - - checkout - - setup_remote_docker: - version: 20.10.6 - - run: - name: build image pre-setup - command: | - #Make sure HEAD points to master - git checkout master - git fetch - git rebase - - run: - name: build Java 8.1.095 & Node 18.20.2 image - command: | - MBT_VERSION=$(cat ./VERSION) - sh $PWD/scripts/build_image 8.1.095 18.20.2 ${MBT_VERSION} - - run: - name: publish Java 8.1.095 & Node 18.20.2 image - command: | - MBT_VERSION=$(cat ./VERSION) - echo "Image release: ${MBT_VERSION}" - #Push to Docker Hub - echo "$DOCKER_HUB_TOKEN" | docker login --username $DOCKER_HUB_USER --password-stdin - sh $PWD/scripts/publish_image 8.1.095 18.20.2 ${MBT_VERSION} "devxci" - #Push to GitHub Container Registry - echo "$CLOUD_MTA_BOT_GITHUB_TOKEN" | docker login "ghcr.io" --username $CLOUD_MTA_BOT_USER --password-stdin - sh $PWD/scripts/publish_image 8.1.095 18.20.2 ${MBT_VERSION} "ghcr.io/sap" - publish-to-dockerhub-java11-node14: docker: - image: cimg/go:1.19 @@ -754,7 +658,6 @@ jobs: #Push to GitHub Container Registry echo "$CLOUD_MTA_BOT_GITHUB_TOKEN" | docker login "ghcr.io" --username $CLOUD_MTA_BOT_USER --password-stdin sh $PWD/scripts/publish_image 21.0.1 16.18.1 ${MBT_VERSION} "ghcr.io/sap" - publish-to-dockerhub-java21-node18: docker: - image: cimg/go:1.19 @@ -818,6 +721,69 @@ jobs: #Push to GitHub Container Registry echo "$CLOUD_MTA_BOT_GITHUB_TOKEN" | docker login "ghcr.io" --username $CLOUD_MTA_BOT_USER --password-stdin sh $PWD/scripts/publish_image 21.0.1 20.9.0 ${MBT_VERSION} "ghcr.io/sap" + publish-to-dockerhub-java22-node18: + docker: + - image: cimg/go:1.19 + working_directory: ~/go/src/github.com/SAP/cloud-mta-build-tool + steps: + - checkout + - setup_remote_docker: + version: 20.10.6 + - run: + name: build image pre-setup + command: | + #Make sure HEAD points to master + git checkout master + git fetch + git rebase + - run: + name: build Java 22.0.1 & Node 18.20.2 image + command: | + MBT_VERSION=$(cat ./VERSION) + sh $PWD/scripts/build_image 22.0.1 18.20.2 ${MBT_VERSION} + - run: + name: publish Java 22.0.1 & Node 18.20.2 image + command: | + MBT_VERSION=$(cat ./VERSION) + echo "Image release: ${MBT_VERSION}" + #Push to Docker Hub + echo "$DOCKER_HUB_TOKEN" | docker login --username $DOCKER_HUB_USER --password-stdin + sh $PWD/scripts/publish_image 22.0.1 18.20.2 ${MBT_VERSION} "devxci" + #Push to GitHub Container Registry + echo "$CLOUD_MTA_BOT_GITHUB_TOKEN" | docker login "ghcr.io" --username $CLOUD_MTA_BOT_USER --password-stdin + sh $PWD/scripts/publish_image 22.0.1 18.20.2 ${MBT_VERSION} "ghcr.io/sap" + + publish-to-dockerhub-java22-node20: + docker: + - image: cimg/go:1.19 + working_directory: ~/go/src/github.com/SAP/cloud-mta-build-tool + steps: + - checkout + - setup_remote_docker: + version: 20.10.6 + - run: + name: build image pre-setup + command: | + #Make sure HEAD points to master + git checkout master + git fetch + git rebase + - run: + name: build Java 22.0.1 & Node 20.9.0 image + command: | + MBT_VERSION=$(cat ./VERSION) + sh $PWD/scripts/build_image 22.0.1 20.9.0 ${MBT_VERSION} + - run: + name: publish Java 22.0.1 & Node 20.9.0 image + command: | + MBT_VERSION=$(cat ./VERSION) + echo "Image release: ${MBT_VERSION}" + #Push to Docker Hub + echo "$DOCKER_HUB_TOKEN" | docker login --username $DOCKER_HUB_USER --password-stdin + sh $PWD/scripts/publish_image 22.0.1 20.9.0 ${MBT_VERSION} "devxci" + #Push to GitHub Container Registry + echo "$CLOUD_MTA_BOT_GITHUB_TOKEN" | docker login "ghcr.io" --username $CLOUD_MTA_BOT_USER --password-stdin + sh $PWD/scripts/publish_image 22.0.1 20.9.0 ${MBT_VERSION} "ghcr.io/sap" remove-github-release-tag: docker: @@ -1026,30 +992,6 @@ workflows: only: /release/ branches: ignore: /.*/ - - publish-to-dockerhub-java8-node14: - requires: - - publish-to-npm - filters: - tags: - only: /release/ - branches: - ignore: /.*/ - - publish-to-dockerhub-java8-node16: - requires: - - publish-to-npm - filters: - tags: - only: /release/ - branches: - ignore: /.*/ - - publish-to-dockerhub-java8-node18: - requires: - - publish-to-npm - filters: - tags: - only: /release/ - branches: - ignore: /.*/ - publish-to-dockerhub-java11-node14: requires: - publish-to-npm @@ -1162,11 +1104,24 @@ workflows: only: /release/ branches: ignore: /.*/ + - publish-to-dockerhub-java22-node18: + requires: + - publish-to-npm + filters: + tags: + only: /release/ + branches: + ignore: /.*/ + - publish-to-dockerhub-java22-node20: + requires: + - publish-to-npm + filters: + tags: + only: /release/ + branches: + ignore: /.*/ - remove-github-release-tag: requires: - - publish-to-dockerhub-java8-node14 - - publish-to-dockerhub-java8-node16 - - publish-to-dockerhub-java8-node18 - publish-to-dockerhub-java11-node14 - publish-to-dockerhub-java11-node16 - publish-to-dockerhub-java11-node18 @@ -1181,6 +1136,8 @@ workflows: - publish-to-dockerhub-java21-node16 - publish-to-dockerhub-java21-node18 - publish-to-dockerhub-java21-node20 + - publish-to-dockerhub-java22-node18 + - publish-to-dockerhub-java22-node20 filters: tags: only: /release/ diff --git a/internal/artifacts/manifest.go b/internal/artifacts/manifest.go index 52d1166ef..0ee05971d 100644 --- a/internal/artifacts/manifest.go +++ b/internal/artifacts/manifest.go @@ -12,7 +12,7 @@ import ( "github.com/SAP/cloud-mta/mta" - "github.com/SAP/cloud-mta-build-tool/internal/archive" + dir "github.com/SAP/cloud-mta-build-tool/internal/archive" "github.com/SAP/cloud-mta-build-tool/internal/buildops" "github.com/SAP/cloud-mta-build-tool/internal/commands" "github.com/SAP/cloud-mta-build-tool/internal/conttype" @@ -76,6 +76,9 @@ func mergeDuplicateEntries(entries []entry) []entry { // To keep a consistent sort order for the map entries we must keep another data structure (slice of keys by order of addition here) pathsOrder := make([]string, 0) + required := make(map[string]entry) + requriredEntryOrder := make([]string, 0) + // Add module entries to modules. Add non-module entries to mergedEntries. for index, entry := range entries { if entry.EntryType == moduleEntry { @@ -86,11 +89,28 @@ func mergeDuplicateEntries(entries []entry) []entry { modules[entry.EntryPath] = entries[index] pathsOrder = append(pathsOrder, entry.EntryPath) } + } else if entry.EntryType == requiredEntry { + if existing, ok := required[entry.EntryPath]; ok { + existing.EntryName += ", " + entry.EntryName + required[entry.EntryPath] = existing + } else { + required[entry.EntryPath] = entries[index] + requriredEntryOrder = append(requriredEntryOrder, entry.EntryPath) + } + } else { mergedEntries = append(mergedEntries, entry) } } + // Sort required entries by order of insertion + requiredTypeEntries := make([]entry, 0) + for _, entryType := range requriredEntryOrder { + requiredTypeEntries = append(requiredTypeEntries, required[entryType]) + } + // Add the required entries first to the merged entries + mergedEntries = append(requiredTypeEntries, mergedEntries...) + // Sort module entries by order of insertion moduleEntries := make([]entry, 0) for _, path := range pathsOrder { diff --git a/internal/artifacts/manifest_test.go b/internal/artifacts/manifest_test.go index 4848f50ce..ee6668a6f 100644 --- a/internal/artifacts/manifest_test.go +++ b/internal/artifacts/manifest_test.go @@ -10,7 +10,7 @@ import ( . "github.com/onsi/gomega" "github.com/pkg/errors" - "github.com/SAP/cloud-mta-build-tool/internal/archive" + dir "github.com/SAP/cloud-mta-build-tool/internal/archive" "github.com/SAP/cloud-mta-build-tool/internal/buildops" "github.com/SAP/cloud-mta-build-tool/internal/commands" "github.com/SAP/cloud-mta-build-tool/internal/conttype" @@ -349,8 +349,8 @@ bad config {EntryName: "e3", EntryPath: "b", EntryType: resourceEntry, ContentType: "t"}, {EntryName: "e4", EntryPath: "b", EntryType: resourceEntry, ContentType: "t"}, }, []entry{ - {EntryName: "e1", EntryPath: "a", EntryType: resourceEntry, ContentType: "t"}, {EntryName: "e2", EntryPath: "a", EntryType: requiredEntry, ContentType: "t"}, + {EntryName: "e1", EntryPath: "a", EntryType: resourceEntry, ContentType: "t"}, {EntryName: "e3", EntryPath: "b", EntryType: resourceEntry, ContentType: "t"}, {EntryName: "e4", EntryPath: "b", EntryType: resourceEntry, ContentType: "t"}, }, @@ -368,6 +368,19 @@ bad config {EntryName: "e6", EntryPath: "c", EntryType: moduleEntry, ContentType: "t6"}, }, ), + Entry("merges required entries with the same path and keeps the entries order", []entry{ + {EntryName: "e1", EntryPath: "a", EntryType: requiredEntry, ContentType: "t1"}, + {EntryName: "e2", EntryPath: "a", EntryType: requiredEntry, ContentType: "t2"}, + {EntryName: "e3", EntryPath: "a", EntryType: requiredEntry, ContentType: "t3"}, + {EntryName: "e4", EntryPath: "b", EntryType: requiredEntry, ContentType: "t4"}, + {EntryName: "e5", EntryPath: "b", EntryType: requiredEntry, ContentType: "t5"}, + {EntryName: "e6", EntryPath: "c", EntryType: requiredEntry, ContentType: "t6"}, + }, []entry{ + {EntryName: "e1, e2, e3", EntryPath: "a", EntryType: requiredEntry, ContentType: "t1"}, + {EntryName: "e4, e5", EntryPath: "b", EntryType: requiredEntry, ContentType: "t4"}, + {EntryName: "e6", EntryPath: "c", EntryType: requiredEntry, ContentType: "t6"}, + }, + ), Entry("merges module entries and keeps non-module entries unchanged at the end", []entry{ {EntryName: "e1", EntryPath: "a", EntryType: resourceEntry, ContentType: "t1"}, {EntryName: "e2", EntryPath: "a", EntryType: moduleEntry, ContentType: "t2"}, @@ -377,8 +390,24 @@ bad config }, []entry{ {EntryName: "e2, e3", EntryPath: "a", EntryType: moduleEntry, ContentType: "t2"}, {EntryName: "e4", EntryPath: "b", EntryType: moduleEntry, ContentType: "t4"}, + {EntryName: "e5", EntryPath: "b", EntryType: requiredEntry, ContentType: "t5"}, {EntryName: "e1", EntryPath: "a", EntryType: resourceEntry, ContentType: "t1"}, + }, + ), + Entry("merges module&required entries and keeps the other entries unchanged at the end", []entry{ + {EntryName: "e1", EntryPath: "a", EntryType: resourceEntry, ContentType: "t1"}, + {EntryName: "e2", EntryPath: "a", EntryType: moduleEntry, ContentType: "t2"}, + {EntryName: "e3", EntryPath: "a", EntryType: moduleEntry, ContentType: "t3"}, + {EntryName: "e4", EntryPath: "b", EntryType: moduleEntry, ContentType: "t4"}, {EntryName: "e5", EntryPath: "b", EntryType: requiredEntry, ContentType: "t5"}, + {EntryName: "e6", EntryPath: "b", EntryType: requiredEntry, ContentType: "t6"}, + {EntryName: "e7", EntryPath: "c", EntryType: requiredEntry, ContentType: "t7"}, + }, []entry{ + {EntryName: "e2, e3", EntryPath: "a", EntryType: moduleEntry, ContentType: "t2"}, + {EntryName: "e4", EntryPath: "b", EntryType: moduleEntry, ContentType: "t4"}, + {EntryName: "e5, e6", EntryPath: "b", EntryType: requiredEntry, ContentType: "t5"}, + {EntryName: "e7", EntryPath: "c", EntryType: requiredEntry, ContentType: "t7"}, + {EntryName: "e1", EntryPath: "a", EntryType: resourceEntry, ContentType: "t1"}, }, ), ) diff --git a/scripts/common_image b/scripts/common_image index 8216e9f66..1bd99e43c 100644 --- a/scripts/common_image +++ b/scripts/common_image @@ -11,7 +11,7 @@ export NODE_MAJOR_VERSION="$(echo ${NODE_VERSION_TEMPLATE}|awk -F. '{printf "%d" echo "Java major version: ${JAVA_MAJOR_VERSION}, Node major version: ${NODE_MAJOR_VERSION}" -if ([ "$JAVA_MAJOR_VERSION" -ne "8" ] && [ "$JAVA_MAJOR_VERSION" -ne "11" ] && [ "$JAVA_MAJOR_VERSION" -ne "17" ] && [ "$JAVA_MAJOR_VERSION" -ne "19" ] && [ "$JAVA_MAJOR_VERSION" -ne "21" ]) || \ +if ([ "$JAVA_MAJOR_VERSION" -ne "11" ] && [ "$JAVA_MAJOR_VERSION" -ne "17" ] && [ "$JAVA_MAJOR_VERSION" -ne "19" ] && [ "$JAVA_MAJOR_VERSION" -ne "21" ] && [ "$JAVA_MAJOR_VERSION" -ne "22" ]) || \ ([ "$NODE_MAJOR_VERSION" -ne "14" ] && [ "$NODE_MAJOR_VERSION" -ne "16" ] && [ "$NODE_MAJOR_VERSION" -ne "18" ] && [ "$NODE_MAJOR_VERSION" -ne "20" ]) then echo "Java: ${JAVA_MAJOR_VERSION}, Node: ${NODE_MAJOR_VERSION} combination is not supported!"