-
Notifications
You must be signed in to change notification settings - Fork 5
/
docker-compose.yml
98 lines (87 loc) · 3.75 KB
/
docker-compose.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
# Licensed to Muhammad Hamadto
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
# http://www.apache.org/licenses/LICENSE-2.0
#
# See the NOTICE file distributed with this work for additional information regarding copyright ownership.
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
version: "3.9"
services:
spring-native-aws-lambda-function-infra:
image: muhamadto/spring-native-amazonlinux2-builder:21-amazonlinux2-awscliv2
volumes:
- ./:/app
- ${M2_REPO}:/home/worker/.m2
working_dir: /app
user: worker
environment:
AWS_DEFAULT_REGION: ap-southeast-2
AWS_REGION: ap-southeast-2
AWS_ACCESS_KEY_ID: local
AWS_SECRET_ACCESS_KEY: local
AWS_ENDPOINT_URL: http://localstack:4566
BUILD_ARTIFACT: 'true'
FUNCTION_NAME: spring-native-aws-lambda-function
STAGE: compose
MAVEN_OPTS: |
-DskipTests=true
-Dcheckstyle.skip=true
-Djacoco.skip=true
-Dsonar.skip=true
-Dskip.it=true
-Dmaven.javadoc.skip=true
-Dmaven.source.skip=true
-Dspring-boot.run.profiles=local
entrypoint:
- bash
- -c
command: |
'
function package_spring_native_lambda() {
if [ "$$BUILD_ARTIFACT" = "true" ]; then
./mvnw -ntp clean -Pnative -DskipTests native:compile package -pl "$$FUNCTION_NAME"
else
print_info_message "plain" "BUILD_ARTIFACT environment variable is not set. Skipping Maven build."
fi
}
aws --version &&
source /usr/local/bin/awscliv2-util/aws &&
print_info_message "block" "Creating '"$$FUNCTION_NAME"'" &&
print_info_message "divider" "Package GraalVM function" &&
package_spring_native_lambda &&
print_info_message "divider" "Creating LAMBDA function" &&
lambda_create_function "$$FUNCTION_NAME" provided.al2023 512 ./"$$FUNCTION_NAME"/target/"$$FUNCTION_NAME"-native-zip.zip "$$FUNCTION_NAME" &&
lambda_wait_for_function "$$FUNCTION_NAME" &&
lambda_list_functions &&
LAMBDA_ARN="$(lambda_get_function_arn "$$FUNCTION_NAME")" &&
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" "$$LAMBDA_ARN" "ap-southeast-2" &&
apigateway_create_deployment "$$REST_API_ID" "$$STAGE" &&
apigateway_list_restapis &&
print_info_message "plain" "Endpoint available at: http://localhost:4566/restapis/$$REST_API_ID/$$STAGE/_user_request_/somePathId" &&
print_info_message "block" "Successfully creating '"$$FUNCTION_NAME"'"
'
depends_on:
- localstack
localstack:
container_name: "${LOCALSTACK_DOCKER_NAME:-localstack-main}"
image: localstack/localstack
ports:
- "127.0.0.1:4566:4566" # LocalStack Gateway
- "127.0.0.1:4510-4559:4510-4559" # external services port range
environment:
# LocalStack configuration: https://docs.localstack.cloud/references/configuration/
- DEBUG=${DEBUG:-0}
volumes:
- "${LOCALSTACK_VOLUME_DIR:-./volume}:/var/lib/localstack"
- "/var/run/docker.sock:/var/run/docker.sock"