diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml
index 1d46f2b..aed5610 100644
--- a/.github/workflows/release.yml
+++ b/.github/workflows/release.yml
@@ -21,6 +21,9 @@ env:
BOT_EMAIL_ID: xpanse-bot@eclipse.org
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository }}
+ TERRAFORM_INSTALL_PATH: /opt/terraform
+ DEFAULT_TERRAFORM_VERSION: 1.6.0
+ TERRAFORM_VERSIONS: 1.6.0,1.6.1,1.7.0,1.8.0,1.9.0
jobs:
release:
@@ -103,6 +106,10 @@ jobs:
tags: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:latest,${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ steps.new_version.outputs.next-version }}
labels: ${{ steps.meta.outputs.labels }}
provenance: false
+ build-args: |
+ TERRAFORM_INSTALL_PATH=${{ env.TERRAFORM_INSTALL_PATH }}
+ DEFAULT_TERRAFORM_VERSION=${{ env.DEFAULT_TERRAFORM_VERSION }}
+ TERRAFORM_VERSIONS=${{ env.TERRAFORM_VERSIONS }}
- name: Push POM updates with release version
uses: EndBug/add-and-commit@v9
diff --git a/Dockerfile b/Dockerfile
index b9197b2..de64db0 100644
--- a/Dockerfile
+++ b/Dockerfile
@@ -3,10 +3,15 @@ FROM eclipse-temurin:21-jre-alpine
RUN addgroup -S terraform-boot && adduser -S -G terraform-boot terraform-boot
RUN apk update && \
apk add --no-cache unzip wget
-ENV TERRAFORM_VERSION=1.4.4
-RUN wget https://releases.hashicorp.com/terraform/${TERRAFORM_VERSION}/terraform_${TERRAFORM_VERSION}_linux_amd64.zip
-RUN unzip terraform_${TERRAFORM_VERSION}_linux_amd64.zip
-RUN mv terraform /usr/bin/terraform
+
+ENV TERRAFORM_INSTALL_PATH=/opt/terraform
+ENV DEFAULT_TERRAFORM_VERSION=1.6.0
+ENV TERRAFORM_VERSIONS=1.6.0,1.7.0,1.8.0,1.9.0
+COPY install_terraform.sh /install_terraform.sh
+RUN chmod +x /install_terraform.sh
+RUN echo "Downloading and installing Terraform with multiple versions $TERRAFORM_VERSIONS into path $TERRAFORM_INSTALL_PATH"; \
+ /install_terraform.sh "$TERRAFORM_INSTALL_PATH" "$DEFAULT_TERRAFORM_VERSION" "$TERRAFORM_VERSIONS"
+
COPY target/terraform-boot-*.jar terraform-boot.jar
USER terraform-boot
-ENTRYPOINT ["java","-jar","terraform-boot.jar"]
\ No newline at end of file
+ENTRYPOINT ["java","-Dterraform.install.dir=${TERRAFORM_INSTALL_PATH}", "-jar","terraform-boot.jar"]
diff --git a/install_terraform.sh b/install_terraform.sh
new file mode 100644
index 0000000..82d3030
--- /dev/null
+++ b/install_terraform.sh
@@ -0,0 +1,42 @@
+#!/bin/sh
+if [ -z "$1" ] || [ -z "$2" ]; then
+ echo "Error:TERRAFORM_INSTALL_PATH and DEFAULT_OPENTOFU_VERSION could not be empty."
+ exit 1
+fi
+TERRAFORM_INSTALL_PATH="$1"
+DEFAULT_TERRAFORM_VERSION="$2"
+TERRAFORM_VERSIONS="$3"
+mkdir -p "${TERRAFORM_INSTALL_PATH}"
+# Install default version of Terraform in system path and custom path
+echo "Start installing Terraform with default version ${DEFAULT_TERRAFORM_VERSION}"
+wget -c "https://releases.hashicorp.com/terraform/${DEFAULT_TERRAFORM_VERSION}/terraform_${DEFAULT_TERRAFORM_VERSION}_linux_amd64.zip"
+if [ -f "terraform_${DEFAULT_TERRAFORM_VERSION}_linux_amd64.zip" ]; then
+ unzip -o "terraform_${DEFAULT_TERRAFORM_VERSION}_linux_amd64.zip"
+ cp -f terraform /usr/bin/terraform
+ chmod +x /usr/bin/terraform
+ mv -f terraform "${TERRAFORM_INSTALL_PATH}/terraform-${DEFAULT_TERRAFORM_VERSION}"
+ chmod +x "${TERRAFORM_INSTALL_PATH}/terraform-${DEFAULT_TERRAFORM_VERSION}"
+ rm -f "terraform_${DEFAULT_TERRAFORM_VERSION}_linux_amd64.zip"
+ echo "Installed Terraform with default version ${DEFAULT_TERRAFORM_VERSION} into path ${TERRAFORM_INSTALL_PATH} successfully."
+else
+ echo "Failed to download zip package of Terraform with default version terraform_${DEFAULT_TERRAFORM_VERSION}_linux_amd64.zip."
+fi
+if [ -z "$TERRAFORM_VERSIONS" ]; then
+ echo "No Terraform versions specified, skip installing Terraform versions."
+ exit 0
+fi
+# Install versions of Terraform specified in TERRAFORM_VERSIONS into custom path
+VERSIONS=$(echo "$TERRAFORM_VERSIONS" | tr ',' '\n' | tr -d ' ')
+for version in $VERSIONS; do
+ echo "Start installing Terraform with version ${version} into path ${TERRAFORM_INSTALL_PATH}"
+ wget -c "https://releases.hashicorp.com/terraform/${version}/terraform_${version}_linux_amd64.zip"
+ if [ ! -f "terraform_${version}_linux_amd64.zip" ]; then
+ echo "Failed to download zip package of Terraform with version terraform_${version}_linux_amd64.zip."
+ continue
+ fi
+ unzip -o "terraform_${version}_linux_amd64.zip"
+ mv -f terraform "${TERRAFORM_INSTALL_PATH}/terraform-${version}"
+ chmod +x "${TERRAFORM_INSTALL_PATH}/terraform-${version}"
+ rm -f "terraform_${version}_linux_amd64.zip"
+ echo "Installed Terraform with version ${version} into path ${TERRAFORM_INSTALL_PATH} successfully."
+done
diff --git a/pom.xml b/pom.xml
index b128e87..5d2d349 100644
--- a/pom.xml
+++ b/pom.xml
@@ -30,7 +30,6 @@
1.1.0
7.0.0.202409031743-r
5.4.0
- 1.18.1
3.13.0
3.5.0
3.5.0
@@ -54,7 +53,14 @@
org.springframework.boot
spring-boot-starter-web
-
+
+ org.springframework.boot
+ spring-boot-starter-cache
+
+
+ com.github.ben-manes.caffeine
+ caffeine
+
org.projectlombok
lombok
@@ -118,11 +124,6 @@
semver4j
${semver4j.version}
-
- org.jsoup
- jsoup
- ${jsoup.version}
-
diff --git a/src/main/java/org/eclipse/xpanse/terraform/boot/TerraformBootApplication.java b/src/main/java/org/eclipse/xpanse/terraform/boot/TerraformBootApplication.java
index 65d6349..5972166 100644
--- a/src/main/java/org/eclipse/xpanse/terraform/boot/TerraformBootApplication.java
+++ b/src/main/java/org/eclipse/xpanse/terraform/boot/TerraformBootApplication.java
@@ -8,6 +8,7 @@
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.security.servlet.SecurityAutoConfiguration;
+import org.springframework.cache.annotation.EnableCaching;
import org.springframework.retry.annotation.EnableRetry;
import org.springframework.scheduling.annotation.EnableAsync;
@@ -16,6 +17,7 @@
*/
@EnableRetry
@EnableAsync
+@EnableCaching
@SpringBootApplication(exclude = {SecurityAutoConfiguration.class})
public class TerraformBootApplication {
diff --git a/src/main/java/org/eclipse/xpanse/terraform/boot/cache/CaffeineCacheConfig.java b/src/main/java/org/eclipse/xpanse/terraform/boot/cache/CaffeineCacheConfig.java
new file mode 100644
index 0000000..894d435
--- /dev/null
+++ b/src/main/java/org/eclipse/xpanse/terraform/boot/cache/CaffeineCacheConfig.java
@@ -0,0 +1,52 @@
+/*
+ * SPDX-License-Identifier: Apache-2.0
+ * SPDX-FileCopyrightText: Huawei Inc.
+ *
+ */
+
+package org.eclipse.xpanse.terraform.boot.cache;
+
+import com.github.benmanes.caffeine.cache.Cache;
+import com.github.benmanes.caffeine.cache.Caffeine;
+import java.util.concurrent.TimeUnit;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.beans.factory.annotation.Value;
+import org.springframework.cache.CacheManager;
+import org.springframework.cache.caffeine.CaffeineCacheManager;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+
+/**
+ * Caffeine cache configuration class.
+ */
+@Slf4j
+@Configuration
+public class CaffeineCacheConfig {
+ public static final String TERRAFORM_VERSIONS_CACHE_NAME = "TERRAFORM_VERSIONS_CACHE";
+
+ public static final int DEFAULT_CACHE_EXPIRE_TIME_IN_MINUTES = 60;
+
+ @Value("${terraform.versions.cache.expire.time.in.minutes:60}")
+ private long terraformVersionCacheDuration;
+
+ /**
+ * Config cache manager with caffeine.
+ *
+ * @return caffeineCacheManager
+ */
+ @Bean
+ public CacheManager caffeineCacheManager() {
+ CaffeineCacheManager cacheManager = new CaffeineCacheManager();
+ cacheManager.registerCustomCache(TERRAFORM_VERSIONS_CACHE_NAME,
+ getTerraformVersionsCache());
+ return cacheManager;
+ }
+
+
+ private Cache