Skip to content

Commit

Permalink
feat:update build scripts.
Browse files Browse the repository at this point in the history
  • Loading branch information
SkyeBeFreeman committed Jun 26, 2024
1 parent 27fbb19 commit 567a385
Show file tree
Hide file tree
Showing 13 changed files with 40 additions and 276 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/docker.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Release
name: Agent DockerHub Release

on:
release:
Expand Down Expand Up @@ -33,7 +33,7 @@ jobs:

- name: Install xmllint
run: sudo apt-get install libxml2-utils

- name: Get version
id: get_version
run: echo ::set-output name=VERSION::${GITHUB_REF/refs\/tags\//}
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/example.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Release
name: Example DockerHub Release

on:
workflow_dispatch:
Expand Down Expand Up @@ -36,7 +36,7 @@ jobs:

- name: Install xmllint
run: sudo apt-get install libxml2-utils

- name: Get version
id: get_version
run: echo ::set-output name=VERSION::${GITHUB_REF/refs\/tags\//}
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/maven-publish.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Release
name: Assets Release

on:
release:
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -43,3 +43,4 @@ backup/
*.tar.gz
*.zip
polaris-java-agent-*
*/version.txt
7 changes: 7 additions & 0 deletions polaris-agent-build/bin/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,13 @@ for plugin_folder in ${plugin_folders}; do
cp -r "${plugin_folder}/src/main/conf/." "../${folder_name}/conf/"
fi
done
plugin_config_folders=$(find . -maxdepth 2 | grep -E ".+-plugin-common$")
for plugin_config_folder in ${plugin_config_folders}; do
file_name=${plugin_config_folder##*/}
if [ -d "${plugin_config_folder}/src/main/conf" ]; then
cp -r "${plugin_config_folder}/src/main/conf/." "../${folder_name}/conf/"
fi
done
popd

# do package
Expand Down
46 changes: 3 additions & 43 deletions polaris-agent-build/bin/build_docker.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,50 +12,10 @@ cd ../..
workdir=$(pwd)
echo "workdir is ${workdir}"

# init variables
folder_name=polaris-java-agent-"${version}"
package_name="${folder_name}".zip
cd polaris-agent-build/bin
bash ./build.sh

echo "start to create build dir ${folder_name}"
rm -rf "${folder_name}"
mkdir -p "${folder_name}"
mkdir -p "${folder_name}/conf"
mkdir -p "${folder_name}/plugins"
mkdir -p "${folder_name}/lib"
mkdir -p "${folder_name}/lib/java9"
mkdir -p "${folder_name}/boot"

cp "polaris-agent-build/conf/polaris-agent.config" "${folder_name}/conf"

echo "start to build package"

if [[ "${use_docker_env}" == "true" ]]; then
docker run --rm -u root -v "$(pwd)":/home/maven/project -w /home/maven/project maven:3.8.6-openjdk-8 mvn clean -B package --file pom.xml
else
mvn clean -B package --file pom.xml
fi

cp "polaris-agent-core/polaris-agent-core-bootstrap/target/polaris-agent-core-bootstrap.jar" "${folder_name}/"
cp "polaris-agent-core/polaris-agent-core-bootstrap-common/target/polaris-agent-core-bootstrap-common-${version}.jar" "${folder_name}/lib/"
cp "polaris-agent-core/polaris-agent-core-asm-java9/target/polaris-agent-core-asm-java9-${version}.jar" "${folder_name}/lib/java9/"
cp "polaris-agent-core/polaris-agent-core-optional-java9/target/polaris-agent-core-optional-java9-${version}.jar" "${folder_name}/lib/java9/"
cp "polaris-agent-core/polaris-agent-core-optional-java17/target/polaris-agent-core-optional-java17-${version}.jar" "${folder_name}/lib/java9/"
cp "polaris-agent-core/polaris-agent-core-extension/target/polaris-agent-core-extension-${version}.jar" "${folder_name}/boot/"

pushd "polaris-agent-plugins"
plugin_folders=$(find . -maxdepth 2 | grep -E ".+-plugin$")
for plugin_folder in ${plugin_folders}; do
file_name=${plugin_folder##*/}
cp "${plugin_folder}/target/${file_name}-${version}.jar" "../${folder_name}/plugins/"
if [ -d "${plugin_folder}/src/main/conf" ]; then
cp -r "${plugin_folder}/src/main/conf/." "../${folder_name}/conf/"
fi
done
popd

# do package
echo "start to zip package"
zip -r "${package_name}" "${folder_name}"
cd ${workdir}

docker_tag=$1

Expand Down
30 changes: 22 additions & 8 deletions polaris-agent-build/bin/start.sh
Original file line number Diff line number Diff line change
Expand Up @@ -20,24 +20,38 @@ cp -f /app/version.txt ${java_agent_dir}/
cd ${java_agent_dir}
unzip ${polaris_agent_dir_name}.zip

echo "inject with framework ${JAVA_AGENT_FRAMEWORK_NAME} and version ${JAVA_AGENT_FRAMEWORK_VERSION}"
check_string_not_empty() {
local string_to_check="$1"
local trimmed

# 删除所有空白字符后检查字符串是否为空
trimmed=$(echo "$string_to_check" | tr -d '[:space:]')

if test -n "$trimmed"; then
return 0 # 变量非空且不全是空格,返回0(成功)
else
return 1 # 变量为空或全是空格,返回1(失败)
fi
}

# 第一步,需要确定 agent-plugin 启用哪个
custom_plugin_id="${JAVA_AGENT_FRAMEWORK_NAME}-${JAVA_AGENT_FRAMEWORK_VERSION}-plugin"
custom_plugin_id=""
if check_string_not_empty "${JAVA_AGENT_FRAMEWORK_NAME}" && check_string_not_empty "${JAVA_AGENT_FRAMEWORK_VERSION}"; then
custom_plugin_id="${JAVA_AGENT_FRAMEWORK_NAME}-${JAVA_AGENT_FRAMEWORK_VERSION}-plugin"
echo "inject with framework ${JAVA_AGENT_FRAMEWORK_NAME} and version ${JAVA_AGENT_FRAMEWORK_VERSION}"
else
echo "JAVA_AGENT_FRAMEWORK_NAME [${JAVA_AGENT_FRAMEWORK_NAME}] or JAVA_AGENT_FRAMEWORK_VERSION [${JAVA_AGENT_FRAMEWORK_VERSION}] is empty"
fi
echo "plugins.enable=${custom_plugin_id}" > ${polaris_agent_dir_name}/conf/polaris-agent.config

# 第二步,将 plugin 所需要的配置注入到 plugin 对应的目录中去
java_agent_config_dir="${JAVA_AGENT_FRAMEWORK_NAME}-${JAVA_AGENT_FRAMEWORK_VERSION}"
echo "inject with config dir ${java_agent_config_dir}"
echo "inject with default config ${JAVA_AGENT_PLUGIN_CONF}"

custom_plugin_properties=${JAVA_AGENT_PLUGIN_CONF}
echo "${custom_plugin_properties}" > ${polaris_agent_dir_name}/conf/plugin/${java_agent_config_dir}/application.properties
target_config_file=${polaris_agent_dir_name}/conf/plugin/spring-cloud/application.properties
echo "${custom_plugin_properties}" > "${target_config_file}"

# 第三步,将地域信息拉取并设置进配置文件
# 腾讯云不能拿到大区,因此腾讯云上的region对应的是北极星的zone,zone对应北极星的campus
target_config_file=${polaris_agent_dir_name}/conf/plugin/${java_agent_config_dir}/application.properties

echo "start to fetch region, target config file ${target_config_file}"
region="$(curl -s --connect-timeout 10 -m 10 http://metadata.tencentyun.com/latest/meta-data/placement/region)"
region_code=$?
Expand Down

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
# the application name for spring cloud, register as the service name in registry center
spring.application.name=application-name
# polaris server address
spring.cloud.polaris.address=grpc\://106.55.74.24\:8091
spring.cloud.polaris.address=grpc\://127.0.0.1\:8091
# switch for spring cloud polaris all features
spring.cloud.polaris.enabled=true
# switch for spring cloud discovery feature
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public static List<PropertiesPropertySource> loadPropertiesSource() {
String configPath = Paths.get(System.getProperty(Constant.AGENT_CONF_PATH), "conf").toString();
LOGGER.info("load property sources from config path " + configPath);
Properties properties = new Properties();
String confPath = Paths.get(configPath, "plugin", "spring-cloud-2022", "application.properties").toString();
String confPath = Paths.get(configPath, "plugin", "spring-cloud", "application.properties").toString();
String cmdVal = System.getProperty("polaris.agent.user.application.conf");
if (null != cmdVal && !cmdVal.isEmpty()) {
confPath = cmdVal;
Expand Down

0 comments on commit 567a385

Please sign in to comment.