-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
support multiple versions of openTofu (#62)
- Loading branch information
Showing
28 changed files
with
1,084 additions
and
74 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,7 +15,16 @@ on: | |
- Major Version | ||
- Minor Version | ||
- Patch Version | ||
|
||
DEFAULT_OPENTOFU_VERSION: | ||
type: string | ||
description: Input the default version of OpenTofu to install | ||
required: true | ||
default: '1.6.0' | ||
OPENTOFU_VERSIONS: | ||
type: string | ||
description: Input the multiple versions of OpenTofu to install | ||
required: true | ||
default: '1.6.0,1.7.0,1.8.0' | ||
env: | ||
BOT_USER_NAME: eclipse-xpanse-bot | ||
BOT_EMAIL_ID: [email protected] | ||
|
@@ -103,6 +112,9 @@ 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: | | ||
DEFAULT_OPENTOFU_VERSION=${{ github.event.inputs.DEFAULT_OPENTOFU_VERSION }} | ||
OPENTOFU_VERSIONS=${{ github.event.inputs.OPENTOFU_VERSIONS }} | ||
- name: Push POM updates with release version | ||
uses: EndBug/add-and-commit@v9 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
#!/bin/sh | ||
if [ -z "$1" ] || [ -z "$2" ]; then | ||
echo "Error:OPENTOFU_INSTALL_PATH and DEFAULT_OPENTOFU_VERSION could not be empty." | ||
exit 1 | ||
fi | ||
OPENTOFU_INSTALL_PATH="$1" | ||
DEFAULT_OPENTOFU_VERSION="$2" | ||
OPENTOFU_VERSIONS="$3" | ||
|
||
mkdir -p "${OPENTOFU_INSTALL_PATH}" | ||
# install default version of OpenTofu into system path and custom path | ||
echo "Start installing OpenTofu with default version ${DEFAULT_OPENTOFU_VERSION}"; | ||
wget -c "https://github.com/opentofu/opentofu/releases/download/v${DEFAULT_OPENTOFU_VERSION}/tofu_${DEFAULT_OPENTOFU_VERSION}_linux_amd64.zip"; | ||
if [ -f "tofu_${DEFAULT_OPENTOFU_VERSION}_linux_amd64.zip" ]; then | ||
unzip -o "tofu_${DEFAULT_OPENTOFU_VERSION}_linux_amd64.zip"; | ||
cp -f tofu /usr/bin/tofu; | ||
chmod +x /usr/bin/tofu; | ||
mv -f tofu "${OPENTOFU_INSTALL_PATH}/tofu-${DEFAULT_OPENTOFU_VERSION}"; | ||
chmod +x "${OPENTOFU_INSTALL_PATH}/tofu-${DEFAULT_OPENTOFU_VERSION}"; | ||
rm "tofu_${DEFAULT_OPENTOFU_VERSION}_linux_amd64.zip"; | ||
echo "Installed OpenTofu with default version ${DEFAULT_OPENTOFU_VERSION} into path ${OPENTOFU_INSTALL_PATH} successfully." | ||
else | ||
echo "Failed to download zip package of OpenTofu with default version tofu_${DEFAULT_OPENTOFU_VERSION}_linux_amd64.zip" | ||
fi | ||
if [ -z "$OPENTOFU_VERSIONS" ]; then | ||
echo "No OpenTofu versions specified, skip installing OpenTofu versions." | ||
exit 0 | ||
fi | ||
# Install versions of OpenTofu specified in OPENTOFU_VERSIONS into custom path | ||
VERSIONS=$(echo "$OPENTOFU_VERSIONS" | tr ',' '\n' | tr -d ' ') | ||
for version in $VERSIONS; do | ||
echo "Start installing OpenTofu with version ${version} into path ${OPENTOFU_INSTALL_PATH}"; | ||
wget -c "https://github.com/opentofu/opentofu/releases/download/v${version}/tofu_${version}_linux_amd64.zip"; | ||
if [ ! -f "tofu_${version}_linux_amd64.zip" ]; then | ||
echo "Failed to download zip package of OpenTofu with version tofu_${version}_linux_amd64.zip" | ||
continue | ||
fi | ||
unzip -o "tofu_${version}_linux_amd64.zip"; | ||
mv -f tofu "${OPENTOFU_INSTALL_PATH}/tofu-${version}"; | ||
chmod +x "${OPENTOFU_INSTALL_PATH}/tofu-${version}"; | ||
rm -rf "tofu_${version}_linux_amd64.zip"; | ||
echo "Installed OpenTofu with version ${version} into path ${OPENTOFU_INSTALL_PATH} successfully." | ||
done |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43 changes: 43 additions & 0 deletions
43
src/main/java/org/eclipse/xpanse/tofu/maker/cache/CaffeineCacheConfig.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
/* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
* SPDX-FileCopyrightText: Huawei Inc. | ||
* | ||
*/ | ||
|
||
package org.eclipse.xpanse.tofu.maker.cache; | ||
|
||
import com.github.benmanes.caffeine.cache.Cache; | ||
import com.github.benmanes.caffeine.cache.Caffeine; | ||
import lombok.extern.slf4j.Slf4j; | ||
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 OPENTOFU_VERSIONS_CACHE_NAME = "OPENTOFU_VERSIONS_CACHE"; | ||
|
||
/** | ||
* Config cache manager with caffeine. | ||
* | ||
* @return caffeineCacheManager | ||
*/ | ||
@Bean | ||
public CacheManager caffeineCacheManager() { | ||
CaffeineCacheManager cacheManager = new CaffeineCacheManager(); | ||
cacheManager.registerCustomCache(OPENTOFU_VERSIONS_CACHE_NAME, | ||
getOpenTofuVersionsCache()); | ||
return cacheManager; | ||
} | ||
|
||
|
||
private Cache<Object, Object> getOpenTofuVersionsCache() { | ||
return Caffeine.newBuilder().build(); | ||
} | ||
|
||
} |
16 changes: 16 additions & 0 deletions
16
...in/java/org/eclipse/xpanse/tofu/maker/models/exceptions/InvalidOpenTofuToolException.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
/* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
* SPDX-FileCopyrightText: Huawei Inc. | ||
*/ | ||
|
||
package org.eclipse.xpanse.tofu.maker.models.exceptions; | ||
|
||
/** | ||
* Defines possible exceptions returned by OpenTofu version invalid. | ||
*/ | ||
public class InvalidOpenTofuToolException extends RuntimeException { | ||
|
||
public InvalidOpenTofuToolException(String message) { | ||
super(message); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.