Skip to content

Commit

Permalink
docker-compose
Browse files Browse the repository at this point in the history
Signed-off-by: muhamadto <muhamadto@gmail.com>
  • Loading branch information
muhamadto committed Aug 6, 2023
1 parent d8d6af2 commit dea1dfd
Show file tree
Hide file tree
Showing 8 changed files with 103 additions and 68 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ jobs:
release:
runs-on: ubuntu-latest
container:
image: ghcr.io/muhamadto/spring-native-amazonlinux2-base:20-amazonlinux2
image: ghcr.io/muhamadto/spring-native-amazonlinux2-builder:20-amazonlinux2
options: --user=worker:ci
permissions:
id-token: write
Expand Down
9 changes: 8 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,17 @@ $ ./mvnw -ntp clean verify -U --settings ./settings-spring.xml

### Locally

#### Using `docker-compose`
1. Run the following commands
```shell
$ docker-compose up
```

#### Using `mvnw`
1. Set `spring.main.web-application-type` to `servlet` for local development
2. Run the following commands
```shell
$ ./mvnw -ntp clean package -U -Pnative --settings ./settings-spring.xml
$ ./mvnw -ntp clean package -U -Pnative -pl spring-native-aws-lambda-function --settings ./settings-spring.xml
$ ./spring-native-aws-lambda-function/target/spring-native-aws-lambda-function
```
The service starts in less than 100 ms
Expand Down
2 changes: 1 addition & 1 deletion cdk.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
"app": "mvn exec:java -pl spring-native-aws-lambda-infra -Dexec.mainClass=com.coffeebeans.springnativeawslambda.infra.Application"
"app": "./mvnw exec:java -pl spring-native-aws-lambda-infra -Dexec.mainClass=com.coffeebeans.springnativeawslambda.infra.Application"
}
96 changes: 58 additions & 38 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,25 +1,36 @@
# 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:
image: ghcr.io/muhamadto/spring-native-amazonlinux2-builder:20-amazonlinux2
image: ghcr.io/muhamadto/spring-native-amazonlinux2-builder:20-amazonlinux2-awscliv2
ports:
- 8080:8080
networks:
default:
aliases:
- spring-native-aws-lambda-function
- "8080:8080"
- "5005:5005"
volumes:
- ./:/opt/build
- ${M2_REPO}:/home/ci/.m2
working_dir: /opt/build
- ./:/app
- ${M2_REPO}:/home/worker/.m2
working_dir: /app
user: worker
environment:
SPRING_MAIN_WEBAPPLICATIONTYPE: servlet
SPRING_PROFILES_ACTIVE: compose
AWS_HOST: localstack
AWS_ACCESS_KEY_ID: local
AWS_SECRET_ACCESS_KEY: local
AWS_DEFAULT_REGION: ap-southeast-2
AWS_REGION: ap-southeast-2
AWS_ACCESS_KEY_ID: local
AWS_SECRET_ACCESS_KEY: local
MAVEN_OPTS: |
-DskipTests=true
-Dcheckstyle.skip=true
Expand All @@ -28,39 +39,48 @@ services:
-Dskip.it=true
-Dmaven.javadoc.skip=true
-Dmaven.source.skip=true
-Dspring-boot.run.profiles=compose
-Dspring-boot.run.profiles=local
entrypoint:
- bash
- -c
command: >
"
./mvnw -pl spring-native-aws-lambda-function clean package -Pnative -DskipTests --settings ./settings-spring.xml &&
spring-native-aws-lambda-function/target/spring-native-aws-lambda-function
"
command: |
'
aws --version &&
source /usr/local/bin/awscliv2-util/aws &&
print_info_message "block" "Creating 'spring-native-aws-lambda-function'" &&
print_info_message "divider" "Package GraalVM function" &&
./mvnw -ntp clean package -U -Pnative -pl spring-native-aws-lambda-function --settings ./settings-spring.xml &&
lambda_create_function lambda-FUNCTION provided.al2 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 "block" "Successfully creating 'spring-native-aws-lambda-function'" &&
exit 0
'
depends_on:
- localstack

localstack:
container_name: "${LOCALSTACK_DOCKER_NAME-localstack_main}"
image: localstack/localstack:latest
logging:
driver: none
ports:
- 4576:4576
- ${EDGE_PORT-4566}:${EDGE_PORT-4566}
- ${PORT_WEB_UI-8088}:${PORT_WEB_UI-8088}
- "127.0.0.1:4566:4566" # LocalStack Gateway
- "127.0.0.1:4510-4559:4510-4559" # external services port range
environment:
AWS_DEFAULT_REGION: ap-southeast-2
AWS_ACCESS_KEY_ID: local
AWS_SECRET_ACCESS_KEY: local
SERVICES: sns,sqs,lambda, apigateway
DEBUG: 1
LS_LOG: debug # seems to give more logs than DEBUG: 1
DATA_DIR: ${DATA_DIR- }
PORT_WEB_UI: ${PORT_WEB_UI-8088}
EDGE_PORT: ${EDGE_PORT-4566}
DOCKER_HOST: unix:///var/run/docker.sock
HOSTNAME_EXTERNAL: localstack
- DEBUG=${DEBUG-}
- DOCKER_HOST=unix:///var/run/docker.sock
- LOCALSTACK_HOST=localstack
volumes:
# If you have access issues on Mac, consider using an alias docker-compose="TMPDIR=/private$TMPDIR /usr/local/bin/docker-compose"
- /${TMPDIR:-/tmp/localstack}:/tmp/localstack
- /var/run/docker.sock:/var/run/docker.sock
- "${LOCALSTACK_VOLUME_DIR:-./volume}:/var/lib/localstack"
- "/var/run/docker.sock:/var/run/docker.sock"





16 changes: 16 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,14 @@
</dependency>
<!-- JACKSON ENDS -->

<!-- AWS CDK -->
<dependency>
<groupId>software.amazon.awscdk</groupId>
<artifactId>aws-cdk-lib</artifactId>
<version>2.90.0</version>
</dependency>
<!-- AWS CDK ENDS -->

<!-- TEST -->
<dependency>
<groupId>cloud.pianola</groupId>
Expand Down Expand Up @@ -198,6 +206,14 @@
<finalName>${project.artifactId}</finalName>

<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>3.1.0</version>
<configuration>
<mainClass>com.coffeebeans.springnativeawslambda.SpringNativeAwsLambdaApplication</mainClass>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
Expand Down
26 changes: 3 additions & 23 deletions settings-spring.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,27 +19,7 @@
<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 http://maven.apache.org/xsd/settings-1.0.0.xsd">
<!-- <profiles>-->
<!-- <profile>-->
<!-- <id>spring</id>-->
<!-- <repositories>-->
<!-- <repository>-->
<!-- <id>spring-releases</id>-->
<!-- <name>Spring Releases</name>-->
<!-- <url>https://repo.spring.io/release</url>-->
<!-- </repository>-->
<!-- </repositories>-->

<!-- <pluginRepositories>-->
<!-- <pluginRepository>-->
<!-- <id>spring-releases</id>-->
<!-- <name>Spring Releases</name>-->
<!-- <url>https://repo.spring.io/release</url>-->
<!-- </pluginRepository>-->
<!-- </pluginRepositories>-->
<!-- </profile>-->
<!-- </profiles>-->
<!-- <activeProfiles>-->
<!-- <activeProfile>spring</activeProfile>-->
<!-- </activeProfiles>-->
<activeProfiles>
<activeProfile>native</activeProfile>
</activeProfiles>
</settings>
Original file line number Diff line number Diff line change
@@ -1,7 +1,22 @@
# 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.

spring:
main:
banner-mode: off
web-application-type: servlet # change to 'servlet' for development
web-application-type: none # change to 'servlet' for development
cloud:
function:
web:
Expand Down
3 changes: 0 additions & 3 deletions spring-native-aws-lambda-infra/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -45,16 +45,13 @@

<properties>
<java.version>20</java.version>

<cdk.version>2.89.0</cdk.version>
</properties>

<dependencies>
<!-- AWS CDK -->
<dependency>
<groupId>software.amazon.awscdk</groupId>
<artifactId>aws-cdk-lib</artifactId>
<version>${cdk.version}</version>
</dependency>
<!-- AWS CDK ENDS -->

Expand Down

0 comments on commit dea1dfd

Please sign in to comment.