Skip to content

Commit

Permalink
Run native:compile in prepare-package so `spring-native-aws-lambd…
Browse files Browse the repository at this point in the history
…a-function.jar.original` would include `spring-native-aws-lambda-function` file

Signed-off-by: matto <muhamadto@gmail.com>
  • Loading branch information
muhamadto committed Dec 31, 2023
1 parent c96de34 commit 32ac86e
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 25 deletions.
2 changes: 2 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
.idea/
badges/
**/target/
cdk.out/
volume/
.gitignore
CODE_OF_CONDUCT.md
HELP.md
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ jobs:
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
ENV: ${{ env.ENV }}
COST_CENTRE: ${{ env.COST_CENTRE }}
run: ./mvnw -ntp -Pnative clean package -DskipTests=true
run: ./mvnw -ntp clean package -U -Pnative -DskipTests native:compile
- name: cdk diff
uses: muhamadto/aws-cdk-github-actions@v3
with:
Expand Down
10 changes: 4 additions & 6 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
target/
!spring-native-aws-lambda-function/.mvn/wrapper/maven-wrapper.jar
!**/src/main/**/target/
!**/src/test/**/target/
**/target/
cdk.out/
volume/
**/maven-wrapper.jar

### STS ###
.apt_generated
Expand Down Expand Up @@ -30,5 +30,3 @@ build/

### VS Code ###
.vscode/

**/maven-wrapper.jar
11 changes: 6 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ $ ./mvnw -ntp clean verify -U
$ curl --location --request POST 'http://localhost:4566/restapis/<restApiId>/test/_user_request_/test' \
--header 'Content-Type: application/json' \
--data-raw '{
"name": "CoffeeBeans"
"body": "{ \"name\": \"CoffeeBeans\" }"
}'
```
The service responds
Expand All @@ -52,10 +52,11 @@ $ ./mvnw -ntp clean verify -U
```

#### Using `mvnw`
1. Set `spring.main.web-application-type` to `servlet` for local development
2. Run the following commands

1. Run the following commands
```shell
$ ./mvnw -ntp clean package -U -Pnative -pl spring-native-aws-lambda-function
$ export SPRING_PROFILES_ACTIVE=local
$ ./mvnw -ntp clean package -U -Pnative -DskipTests -pl spring-native-aws-lambda-function
$ ./spring-native-aws-lambda-function/target/spring-native-aws-lambda-function
```
The service starts in less than 100 ms
Expand All @@ -76,7 +77,7 @@ $ ./mvnw -ntp clean verify -U
$ curl --location --request POST 'http://localhost:8080' \
--header 'Content-Type: application/json' \
--data-raw '{
"name": "CoffeeBeans"
"body": "{ \"name\": \"CoffeeBeans\" }"
}'
```
The service responds
Expand Down
20 changes: 10 additions & 10 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
version: "3.9"
services:
spring-native-aws-lambda-function-infra:
image: muhamadto/spring-native-amazonlinux2-builder:21-amazonlinux2-awscliv2
image: ghcr.io/muhamadto/spring-native-amazonlinux2-builder:21-amazonlinux2-awscliv2
volumes:
- ./:/app
- ${M2_REPO}:/home/worker/.m2
Expand Down Expand Up @@ -51,22 +51,22 @@ services:
print_info_message "divider" "Package GraalVM function" &&
./mvnw -ntp clean package -U -Pnative -pl spring-native-aws-lambda-function &&
./mvnw -ntp clean package -U -Pnative -DskipTests -pl spring-native-aws-lambda-function &&
print_info_message "divider" "Creating LAMBDA function" &&
lambda_create_function lambda-FUNCTION provided.al2023 512 ./spring-native-aws-lambda-function/target/spring-native-aws-lambda-function-native-zip.zip spring-native-aws-lambda-function &&
lambda_wait_for_function lambda-FUNCTION &&
lambda_list_functions &&
print_info_message "divider" "Creating API Gateway" &&
REST_API_ID="$(apigateway_create_restApi "somerestapiname")" &&
RESOURCE_ID="$(apigateway_create_resource "$$REST_API_ID" "somePathId")"
apigateway_create_method "$$REST_API_ID" "$$RESOURCE_ID" "POST" &&
apigateway_create_lambda_integration "$$REST_API_ID" "$$RESOURCE_ID" "POST" "arn:aws:apigateway:ap-southeast-2:lambda:path/2015-03-31/functions/arn:aws:lambda:ap-southeast-2:000000000000:function:lambda-FUNCTION/invocations" &&
apigateway_create_deployment "$$REST_API_ID" "test" &&
--rest-api-id &&
REST_API_ID="$(aws apigateway --endpoint-url="http://localstack:4566" create-rest-api --name 'someapigateway' --query 'id' --output text)" &&
ROOT_RESOURCE_ID=$(aws apigateway --endpoint-url="http://localstack:4566" get-resources --rest-api-id "$$REST_API_ID" --query 'items[0].id' --output text)
RESOURCE_ID=$(aws apigateway --endpoint-url="http://localstack:4566" create-resource --rest-api-id $$REST_API_ID --parent-id $$ROOT_RESOURCE_ID --path-part '{somethingPathId}' --query 'id' --output text)
aws apigateway --endpoint-url="http://localstack:4566" put-method --rest-api-id $$REST_API_ID --resource-id $$RESOURCE_ID --http-method POST --request-parameters 'method.request.path.somethingPathId=true' --authorization-type 'NONE' &&
aws apigateway --endpoint-url="http://localstack:4566" put-integration --rest-api-id $$REST_API_ID --resource-id $$RESOURCE_ID --http-method POST --type AWS_PROXY --integration-http-method POST --uri arn:aws:apigateway:us-east-1:lambda:path/2015-03-31/functions/arn:aws:lambda:ap-southeast-2:000000000000:function:lambda-FUNCTION/invocations --passthrough-behavior WHEN_NO_MATCH &&
aws apigateway --endpoint-url="http://localstack:4566" create-deployment --rest-api-id $$REST_API_ID --stage-name test &&
print_info_message "plain" "http://localhost:4566/restapis/$$REST_API_ID/test/_user_request_/test" &&
print_info_message "plain" "Endpoint available at: http://localhost:4566/restapis/$$REST_API_ID/test/_user_request_/test" &&
print_info_message "block" "Successfully creating 'spring-native-aws-lambda-function'"
'
Expand Down
6 changes: 3 additions & 3 deletions spring-native-aws-lambda-function/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@
<buildArg>--verbose</buildArg>
<buildArg>--no-fallback</buildArg>
<buildArg>--enable-preview</buildArg>
<buildArg>--gc=G1</buildArg>
<!-- <buildArg>&#45;&#45;gc=G1</buildArg>-->
<buildArg>-march=native</buildArg>
<buildArg>--strict-image-heap</buildArg>
<buildArg>--enable-url-protocols=http</buildArg>
Expand All @@ -178,10 +178,10 @@
<executions>
<execution>
<id>build-native</id>
<phase>prepare-package</phase>
<goals>
<goal>compile-no-fork</goal>
<goal>compile</goal>
</goals>
<phase>package</phase>
</execution>
</executions>
</plugin>
Expand Down

0 comments on commit 32ac86e

Please sign in to comment.