Skip to content

Commit

Permalink
Build Java Sample App with different language versions (#247)
Browse files Browse the repository at this point in the history
*Issue description:*
In order to meet our requirement of ADOT java supporting all java
versions 8+, we are planning on testing ADOT Java on the currently
available Java versions before release. The test coverage will include
Java 8, 11, 17, 21, 22. This PR will aim to build the Java sample apps
on different language versions, and once we validate that the new
.jar/images are available, we will merge another PR to make the canaries
use the new changes

*Description of changes:*
**Build Sample App For Java 8**
Our current sample app is built on Java 11, however, some of the
libraries that are used to make http calls are not available in Java 8.
Built another sample app for Java 8 that uses older libraries.

**Upgrade Gradle to 8.10**
We use Gradle 8.5 to built our sample app, which doesn't support Java
21+. Upgrading gradle to the latest version 8.10.

**Add plugin to use Kotlin 2.0**
Gradle 8.10 uses Kotlin 1.x.x, however, Java 22 is supported by Kotlin
2.0. Added plugin in gradle.setting.ts to use the latest Kotlin version.

**Refactor java sample app workflows**
Updated the workflow files to use the latest secrets for AWS credentials
and ECR ARN

**Add jobs to build other language versions**
Currently, we build Java 11 sample app and deploy to all regions. The
other language versions are only required in us-east-1 since it will be
used by main-build.yml in ADOT Java repo. Therefore, we made two new
jobs in the workflow files to build and deploy new sample apps to
us-east-1 only.

*Rollback procedure:*
Doesn't affect existing image which uses :latest tag. This PR should not
affect any existing workflows.

By submitting this pull request, I confirm that my contribution is made
under the terms of the Apache 2.0 license.
  • Loading branch information
harrryr authored Sep 26, 2024
1 parent 8e06a16 commit d50fe77
Show file tree
Hide file tree
Showing 14 changed files with 297 additions and 133 deletions.
109 changes: 88 additions & 21 deletions .github/workflows/java-sample-app-ecr-deploy.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
## Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
## SPDX-License-Identifier: Apache-2.0

# This workflow is for building and uploading the Java sample application to ECR.
# Java 11 will be built and uploaded to all regions to be used by the canary while
# other versions (8, 17, 21, 22) will be uploaded to us-east-1 for the purpose of
# testing ADOT Java
name: Sample App Deployment - Java ECR
on:
workflow_dispatch: # be able to run the workflow on demand
Expand All @@ -9,8 +13,12 @@ permissions:
id-token: write
contents: read

env:
E2E_TEST_ACCOUNT_ID: ${{ secrets.APPLICATION_SIGNALS_E2E_TEST_ACCOUNT_ID }}
E2E_TEST_ROLE_NAME: ${{ secrets.APPLICATION_SIGNALS_E2E_TEST_ROLE_NAME }}

jobs:
upload-main-service-image:
java-v11-main:
strategy:
fail-fast: false
matrix:
Expand All @@ -27,31 +35,29 @@ jobs:
- name: Configure AWS Credentials
uses: aws-actions/configure-aws-credentials@v4
with:
role-to-assume: ${{ secrets.E2E_IAD_TEST_ACCOUNT_ARN }}
role-to-assume: arn:aws:iam::${{ env.E2E_TEST_ACCOUNT_ID }}:role/${{ env.E2E_TEST_ROLE_NAME }}
aws-region: us-east-1

- name: Retrieve account
uses: aws-actions/aws-secretsmanager-get-secrets@v1
with:
secret-ids:
secret-ids: |
ACCOUNT_ID, region-account/${{ matrix.aws-region }}
JAVA_MAIN_SAMPLE_APP_IMAGE, e2e-test/java-main-sample-app-image
- name: Configure AWS Credentials
uses: aws-actions/configure-aws-credentials@v4
with:
role-to-assume: arn:aws:iam::${{ env.ACCOUNT_ID }}:role/${{ secrets.E2E_TEST_ROLE_ARN }}
role-to-assume: arn:aws:iam::${{ env.ACCOUNT_ID }}:role/${{ env.E2E_TEST_ROLE_NAME }}
aws-region: ${{ matrix.aws-region }}

- name: Update ECR URI
working-directory: sample-apps/springboot
- name: Build and Upload Main Service Image
working-directory: sample-apps/java/springboot-main-service
run: |
sed -i 's#"<ECR_IMAGE_LINK>:<TAG>"#"${{ env.ACCOUNT_ID }}.dkr.ecr.${{ matrix.aws-region }}.amazonaws.com/${{ secrets.APP_SIGNALS_E2E_FE_SA_IMG }}:latest"#g' build.gradle.kts
- name: Upload Main Service Image
working-directory: sample-apps/springboot
run: gradle jib
sed -i 's#"{{ECR_IMAGE_URI}}"#"${{ env.E2E_TEST_ACCOUNT_ID }}.dkr.ecr.us-east-1.amazonaws.com/${{ env.JAVA_MAIN_SAMPLE_APP_IMAGE }}:v11"#g' build.gradle.kts
gradle jib -P javaVersion=11
upload-remote-service-image:
java-v11-remote:
strategy:
fail-fast: false
matrix:
Expand All @@ -68,27 +74,88 @@ jobs:
- name: Configure AWS Credentials
uses: aws-actions/configure-aws-credentials@v4
with:
role-to-assume: ${{ secrets.E2E_IAD_TEST_ACCOUNT_ARN }}
role-to-assume: arn:aws:iam::${{ env.E2E_TEST_ACCOUNT_ID }}:role/${{ env.E2E_TEST_ROLE_NAME }}
aws-region: us-east-1

- name: Retrieve account
uses: aws-actions/aws-secretsmanager-get-secrets@v1
with:
secret-ids:
secret-ids: |
ACCOUNT_ID, region-account/${{ matrix.aws-region }}
JAVA_REMOTE_SAMPLE_APP_IMAGE, e2e-test/java-remote-sample-app-image
- name: Configure AWS Credentials
uses: aws-actions/configure-aws-credentials@v4
with:
role-to-assume: arn:aws:iam::${{ env.ACCOUNT_ID }}:role/${{ secrets.E2E_TEST_ROLE_ARN }}
role-to-assume: arn:aws:iam::${{ env.ACCOUNT_ID }}:role/${{ env.E2E_TEST_ROLE_NAME }}
aws-region: ${{ matrix.aws-region }}

- name: Update ECR URI
working-directory: sample-apps/springboot-remote-service
- name: Build and Upload Remote Service Image
working-directory: sample-apps/java/springboot-remote-service
run: |
sed -i 's#"{{ECR_IMAGE_URI}}"#"${{ env.E2E_TEST_ACCOUNT_ID }}.dkr.ecr.us-east-1.amazonaws.com/${{ env.JAVA_REMOTE_SAMPLE_APP_IMAGE }}:v11"#g' build.gradle.kts
gradle jib -P javaVersion=11
java-main:
strategy:
fail-fast: false
matrix:
java-version: [ '8', '17', '21', '22' ]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-java@v4
with:
distribution: 'temurin'
java-version: ${{ matrix.java-version }}
check-latest: true

- name: Configure AWS Credentials
uses: aws-actions/configure-aws-credentials@v4
with:
role-to-assume: arn:aws:iam::${{ env.E2E_TEST_ACCOUNT_ID }}:role/${{ env.E2E_TEST_ROLE_NAME }}
aws-region: us-east-1

- name: Retrieve account
uses: aws-actions/aws-secretsmanager-get-secrets@v2
with:
secret-ids: |
JAVA_MAIN_SAMPLE_APP_IMAGE, e2e-test/java-main-sample-app-image
- name: Build and Upload Main Service Image
working-directory: sample-apps/java/springboot-main-service
run: |
sed -i 's#"<ECR_IMAGE_LINK>:<TAG>"#"${{ env.ACCOUNT_ID }}.dkr.ecr.${{ matrix.aws-region }}.amazonaws.com/${{ secrets.APP_SIGNALS_E2E_RE_SA_IMG }}:latest"#g' build.gradle.kts
sed -i 's#"{{ECR_IMAGE_URI}}"#"${{ env.E2E_TEST_ACCOUNT_ID }}.dkr.ecr.us-east-1.amazonaws.com/${{ env.JAVA_MAIN_SAMPLE_APP_IMAGE }}:v${{ matrix.java-version }}"#g' build.gradle.kts
gradle jib -P javaVersion=${{ matrix.java-version }}
java-remote:
strategy:
fail-fast: false
matrix:
java-version: [ '8', '17', '21', '22' ]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-java@v4
with:
distribution: 'temurin'
java-version: ${{ matrix.java-version }}
check-latest: true

- name: Upload Remote Service Image
working-directory: sample-apps/springboot-remote-service
run: gradle jib
- name: Configure AWS Credentials
uses: aws-actions/configure-aws-credentials@v4
with:
role-to-assume: arn:aws:iam::${{ env.E2E_TEST_ACCOUNT_ID }}:role/${{ env.E2E_TEST_ROLE_NAME }}
aws-region: us-east-1

- name: Retrieve account
uses: aws-actions/aws-secretsmanager-get-secrets@v2
with:
secret-ids: |
JAVA_REMOTE_SAMPLE_APP_IMAGE, e2e-test/java-remote-sample-app-image
- name: Build and Upload Remote Service Image
working-directory: sample-apps/java/springboot-remote-service
run: |
sed -i 's#"{{ECR_IMAGE_URI}}"#"${{ env.E2E_TEST_ACCOUNT_ID }}.dkr.ecr.us-east-1.amazonaws.com/${{ env.JAVA_REMOTE_SAMPLE_APP_IMAGE }}:v${{ matrix.java-version }}"#g' build.gradle.kts
gradle jib -P javaVersion=${{ matrix.java-version }}
119 changes: 95 additions & 24 deletions .github/workflows/java-sample-app-s3-deploy.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
## Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
## SPDX-License-Identifier: Apache-2.0

# This workflow is for building and uploading the Java sample application to S3 bucket. Java 11 will be built and uploaded to all regions to be used by the canary while other versions (8, 17, 21, 22)
# will be uploaded to us-east-1 for the purpose of testing ADOT Java
name: Sample App Deployment - Java S3
on:
workflow_dispatch: # be able to run the workflow on demand
Expand All @@ -9,15 +11,19 @@ permissions:
id-token: write
contents: read

env:
E2E_TEST_ACCOUNT_ID: ${{ secrets.APPLICATION_SIGNALS_E2E_TEST_ACCOUNT_ID }}
E2E_TEST_ROLE_NAME: ${{ secrets.APPLICATION_SIGNALS_E2E_TEST_ROLE_NAME }}

jobs:
upload-main-service-jar:
java-v11-main:
strategy:
fail-fast: false
matrix:
aws-region: [ 'af-south-1','ap-east-1','ap-northeast-1','ap-northeast-2','ap-northeast-3','ap-south-1','ap-south-2','ap-southeast-1',
'ap-southeast-2','ap-southeast-3','ap-southeast-4','ca-central-1','eu-central-1','eu-central-2','eu-north-1',
'eu-south-1','eu-south-2','eu-west-1','eu-west-2','eu-west-3','il-central-1','me-central-1','me-south-1', 'sa-east-1',
'us-east-1','us-east-2', 'us-west-1', 'us-west-2' ]
'us-east-1','us-east-2','us-west-1','us-west-2' ]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
Expand All @@ -27,7 +33,7 @@ jobs:
- name: Configure AWS Credentials
uses: aws-actions/configure-aws-credentials@v4
with:
role-to-assume: ${{ secrets.E2E_IAD_TEST_ACCOUNT_ARN }}
role-to-assume: arn:aws:iam::${{ env.E2E_TEST_ACCOUNT_ID }}:role/${{ env.E2E_TEST_ROLE_NAME }}
aws-region: us-east-1

- name: Retrieve account
Expand All @@ -39,25 +45,23 @@ jobs:
- name: Configure AWS Credentials
uses: aws-actions/configure-aws-credentials@v4
with:
role-to-assume: arn:aws:iam::${{ env.ACCOUNT_ID }}:role/${{ secrets.E2E_TEST_ROLE_ARN }}
role-to-assume: arn:aws:iam::${{ env.ACCOUNT_ID }}:role/${{ env.E2E_TEST_ROLE_NAME }}
aws-region: ${{ matrix.aws-region }}

- name: Build Main Jar
working-directory: sample-apps/springboot
run: gradle build

- name: Upload to S3
working-directory: sample-apps/springboot
run: aws s3api put-object --bucket ${{ secrets.APP_SIGNALS_E2E_EC2_JAR }}-prod-${{ matrix.aws-region }} --body ./build/libs/springboot-*-SNAPSHOT.jar --key main-service.jar
- name: Build and Upload Main Jar
working-directory: sample-apps/java/springboot-main-service
run: |
gradle build -P javaVersion=11
aws s3api put-object --bucket aws-appsignals-sample-app-prod-${{ matrix.aws-region }} --body ./build/libs/springboot-*-SNAPSHOT.jar --key java-main-service-v11.jar
upload-remote-service-jar:
java-v11-remote:
strategy:
fail-fast: false
matrix:
aws-region: [ 'af-south-1','ap-east-1','ap-northeast-1','ap-northeast-2','ap-northeast-3','ap-south-1','ap-south-2','ap-southeast-1',
'ap-southeast-2','ap-southeast-3','ap-southeast-4','ca-central-1','eu-central-1','eu-central-2','eu-north-1',
'eu-south-1','eu-south-2','eu-west-1','eu-west-2','eu-west-3','il-central-1','me-central-1','me-south-1', 'sa-east-1',
'us-east-1','us-east-2','us-west-1', 'us-west-2' ]
aws-region: [ 'af-south-1','ap-east-1','ap-northeast-1','ap-northeast-2','ap-northeast-3','ap-south-1','ap-south-2','ap-southeast-1',
'ap-southeast-2','ap-southeast-3','ap-southeast-4','ca-central-1','eu-central-1','eu-central-2','eu-north-1',
'eu-south-1','eu-south-2','eu-west-1','eu-west-2','eu-west-3','il-central-1','me-central-1','me-south-1', 'sa-east-1',
'us-east-1','us-east-2','us-west-1','us-west-2' ]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
Expand All @@ -67,7 +71,7 @@ jobs:
- name: Configure AWS Credentials
uses: aws-actions/configure-aws-credentials@v4
with:
role-to-assume: ${{ secrets.E2E_IAD_TEST_ACCOUNT_ARN }}
role-to-assume: arn:aws:iam::${{ env.E2E_TEST_ACCOUNT_ID }}:role/${{ env.E2E_TEST_ROLE_NAME }}
aws-region: us-east-1

- name: Retrieve account
Expand All @@ -79,14 +83,81 @@ jobs:
- name: Configure AWS Credentials
uses: aws-actions/configure-aws-credentials@v4
with:
role-to-assume: arn:aws:iam::${{ env.ACCOUNT_ID }}:role/${{ secrets.E2E_TEST_ROLE_ARN }}
role-to-assume: arn:aws:iam::${{ env.ACCOUNT_ID }}:role/${{ env.E2E_TEST_ROLE_NAME }}
aws-region: ${{ matrix.aws-region }}

- name: Build Main Jar
working-directory: sample-apps/springboot-remote-service
run: gradle build
- name: Build and Upload Main Jar
working-directory: sample-apps/java/springboot-remote-service
run: |
gradle build -P javaVersion=11
aws s3api put-object --bucket aws-appsignals-sample-app-prod-${{ matrix.aws-region }} --body build/libs/springboot-remote-service-*-SNAPSHOT.jar --key java-remote-service-v11.jar
java-main:
strategy:
fail-fast: false
matrix:
java-version: [ '8', '17', '21', '22' ]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-java@v4
with:
distribution: 'temurin'
java-version: ${{ matrix.java-version }}
check-latest: true

- name: Configure AWS Credentials
uses: aws-actions/configure-aws-credentials@v4
with:
role-to-assume: arn:aws:iam::${{ env.E2E_TEST_ACCOUNT_ID }}:role/${{ env.E2E_TEST_ROLE_NAME }}
aws-region: us-east-1

- name: Build and Upload Main Jar
working-directory: sample-apps/java/springboot-main-service
run: |
# For Java 8, springboot must be lower than version 3
# For Java 11,17,21, they are compatible with both springboot version
# For Java 22 and above, springboot must be version 3 or higher
if [ "${{ matrix.java-version }}" = "22" ]; then
sed -i 's/id("org.springframework.boot")/id("org.springframework.boot") version "3.3.4"/' build.gradle.kts
cat build.gradle.kts
fi
gradle build -P javaVersion=${{ matrix.java-version }}
aws s3api put-object --bucket aws-appsignals-sample-app-prod-us-east-1 --body ./build/libs/springboot-*-SNAPSHOT.jar --key java-main-service-v${{ matrix.java-version }}.jar
java-remote:
strategy:
fail-fast: false
matrix:
java-version: [ '8', '17', '21', '22' ]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-java@v4
with:
distribution: 'temurin'
java-version: ${{ matrix.java-version }}
check-latest: true

- name: Configure AWS Credentials
uses: aws-actions/configure-aws-credentials@v4
with:
role-to-assume: arn:aws:iam::${{ env.E2E_TEST_ACCOUNT_ID }}:role/${{ env.E2E_TEST_ROLE_NAME }}
aws-region: us-east-1

- name: Build and Upload Remote Jar
working-directory: sample-apps/java/springboot-remote-service
run: |
# For Java 8, springboot must be lower than version 3
# For Java 11,17,21, they are compatible with both springboot version
# For Java 22 and above, springboot must be version 3 or higher
if [ "${{ matrix.java-version }}" = "22" ]; then
sed -i 's/id("org.springframework.boot")/id("org.springframework.boot") version "3.3.4"/' build.gradle.kts
cat build.gradle.kts
fi
gradle build -P javaVersion=${{ matrix.java-version }}
aws s3api put-object --bucket aws-appsignals-sample-app-prod-us-east-1 --body ./build/libs/springboot-remote-service-*-SNAPSHOT.jar --key java-remote-service-v${{ matrix.java-version }}.jar
- name: Upload to S3
working-directory: sample-apps/springboot-remote-service
run: aws s3api put-object --bucket ${{ secrets.APP_SIGNALS_E2E_EC2_JAR }}-prod-${{ matrix.aws-region }} --body build/libs/springboot-remote-service-*-SNAPSHOT.jar --key remote-service.jar
Binary file modified gradle/wrapper/gradle-wrapper.jar
Binary file not shown.
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.5-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.10.1-bin.zip
networkTimeout=10000
validateDistributionUrl=true
zipStoreBase=GRADLE_USER_HOME
Expand Down
7 changes: 5 additions & 2 deletions gradlew
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
# See the License for the specific language governing permissions and
# limitations under the License.
#
# SPDX-License-Identifier: Apache-2.0
#

##############################################################################
#
Expand Down Expand Up @@ -55,7 +57,7 @@
# Darwin, MinGW, and NonStop.
#
# (3) This script is generated from the Groovy template
# https://github.com/gradle/gradle/blob/HEAD/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt
# https://github.com/gradle/gradle/blob/HEAD/platforms/jvm/plugins-application/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt
# within the Gradle project.
#
# You can find Gradle at https://github.com/gradle/gradle/.
Expand Down Expand Up @@ -84,7 +86,8 @@ done
# shellcheck disable=SC2034
APP_BASE_NAME=${0##*/}
# Discard cd standard output in case $CDPATH is set (https://github.com/gradle/gradle/issues/25036)
APP_HOME=$( cd "${APP_HOME:-./}" > /dev/null && pwd -P ) || exit
APP_HOME=$( cd -P "${APP_HOME:-./}" > /dev/null && printf '%s
' "$PWD" ) || exit

# Use the maximum available, or set MAX_FD != -1 to use that value.
MAX_FD=maximum
Expand Down
Loading

0 comments on commit d50fe77

Please sign in to comment.