Skip to content

Commit c069ece

Browse files
authored
Merge pull request localstack#220 from localstack/feat/fat-jar
Refactor install script and put java libs into a single jar
2 parents 1b9d2c3 + 4ba124e commit c069ece

File tree

7 files changed

+49
-61
lines changed

7 files changed

+49
-61
lines changed

Makefile

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ publish: ## Publish the library to the central PyPi repository
2222
($(VENV_RUN) && ./setup.py sdist upload)
2323

2424
publish-maven: ## Publish artifacts to Maven Central
25-
(cd localstack/ext/java/; mvn clean javadoc:jar source:jar deploy)
25+
(cd localstack/ext/java/; mvn -Pfatjar clean javadoc:jar source:jar package deploy)
2626

2727
coveralls: ## Publish coveralls metrics
2828
($(VENV_RUN); coveralls)

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -295,6 +295,7 @@ localstack web
295295

296296
## Change Log
297297

298+
* v0.7.3: Extract proxy listeners into (sub-)classes; put java libs into a single "fat" jar; fix issue with non-daemonized threads; refactor code to start flask services
298299
* v0.7.2: Fix DATA_DIR config when running in Docker; fix Maven dependencies; return 'ConsumedCapacity' from DynamoDB get-item; use Queue ARN instead of URL for S3 bucket notifications
299300
* v0.7.1: Fix S3 API to GET bucket notifications; release Java artifacts to Maven Central; fix S3 file access from Spark; create DDB stream on UpdateTable; remove AUI dependency, optimize size of Docker image
300301
* v0.7.0: Support for Kinesis in CloudFormation; extend and integrate Java tests in CI; publish Docker image under new name; update READMEs and license agreements

localstack/constants.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
import sys
33

44
# LocalStack version
5-
VERSION = '0.7.2'
5+
VERSION = '0.7.3'
66

77
# default AWS region
88
if 'DEFAULT_REGION' not in os.environ:

localstack/ext/java/pom.xml

+37-16
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<groupId>cloud.localstack</groupId>
66
<artifactId>localstack-utils</artifactId>
77
<packaging>jar</packaging>
8-
<version>0.1.2</version>
8+
<version>0.1.3</version>
99
<name>localstack-utils</name>
1010

1111
<description>Java utilities for the LocalStack platform.</description>
@@ -105,6 +105,19 @@
105105
</dependency>
106106
</dependencies>
107107

108+
<profiles>
109+
<profile>
110+
<id>fatjar</id>
111+
<dependencies>
112+
<dependency>
113+
<groupId>com.amazonaws</groupId>
114+
<artifactId>aws-java-sdk</artifactId>
115+
<version>1.11.86</version>
116+
</dependency>
117+
</dependencies>
118+
</profile>
119+
</profiles>
120+
108121
<build>
109122
<plugins>
110123
<plugin>
@@ -115,22 +128,10 @@
115128
<additionalparam>-Xdoclint:none</additionalparam>
116129
</configuration>
117130
</plugin>
118-
<!-- <plugin>
131+
<plugin>
119132
<groupId>org.apache.maven.plugins</groupId>
120133
<artifactId>maven-shade-plugin</artifactId>
121134
<version>3.0.0</version>
122-
<configuration>
123-
<minimizeJar>true</minimizeJar>
124-
<outputFile>${project.artifactId}-${project.version}-shaded</outputFile>
125-
<finalName>${project.artifactId}-${project.version}-shaded</finalName>
126-
<createDependencyReducedPom>false</createDependencyReducedPom>
127-
<relocations>
128-
<relocation>
129-
<pattern>com.amazonaws</pattern>
130-
<shadedPattern>shaded.com.amazonaws</shadedPattern>
131-
</relocation>
132-
</relocations>
133-
</configuration>
134135
<executions>
135136
<execution>
136137
<phase>package</phase>
@@ -139,7 +140,28 @@
139140
</goals>
140141
</execution>
141142
</executions>
142-
</plugin> -->
143+
<configuration>
144+
<minimizeJar>true</minimizeJar>
145+
<createDependencyReducedPom>false</createDependencyReducedPom>
146+
<shadedArtifactAttached>true</shadedArtifactAttached>
147+
<shadedClassifierName>fat</shadedClassifierName>
148+
<artifactSet>
149+
<includes>
150+
<include>com.amazonaws:aws-java-sdk-lambda</include>
151+
<include>com.amazonaws:aws-lambda-java-events</include>
152+
<include>com.amazonaws:aws-lambda-java-core</include>
153+
<include>commons-*:*</include>
154+
<include>net.*:*</include>
155+
<include>org.*:*</include>
156+
<include>junit:junit</include>
157+
<include>com.fasterxml.*:*</include>
158+
<include>joda-time:*</include>
159+
<include>com.jayway.*:*</include>
160+
<include>software.*:*</include>
161+
</includes>
162+
</artifactSet>
163+
</configuration>
164+
</plugin>
143165
<plugin>
144166
<groupId>org.apache.maven.plugins</groupId>
145167
<artifactId>maven-jar-plugin</artifactId>
@@ -170,7 +192,6 @@
170192
</goals>
171193
</execution>
172194
</executions>
173-
174195
</plugin>
175196
<plugin>
176197
<groupId>org.sonatype.plugins</groupId>

localstack/ext/java/src/main/java/cloud/localstack/LambdaExecutor.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ public class LambdaExecutor {
2828
public static void main(String[] args) throws Exception {
2929
if(args.length < 2) {
3030
System.err.println("Usage: java " + LambdaExecutor.class.getSimpleName() +
31-
"<lambdaClass> <recordsFilePath>");
31+
" <lambdaClass> <recordsFilePath>");
3232
System.exit(1);
3333
}
3434

localstack/services/awslambda/lambda_api.py

+2-5
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
from localstack import config
2323
from localstack.constants import *
2424
from localstack.services import generic_proxy
25-
from localstack.services.install import M2_HOME, JAR_DEPENDENCIES, INSTALL_PATH_LOCALSTACK_JAR
25+
from localstack.services.install import INSTALL_PATH_LOCALSTACK_FAT_JAR
2626
from localstack.utils.common import *
2727
from localstack.utils.aws import aws_stack
2828
from localstack.utils.analytics import event_publisher
@@ -34,7 +34,7 @@
3434
ARCHIVE_FILE_PATTERN = '%s/lambda.handler.*.jar' % config.TMP_FOLDER
3535
EVENT_FILE_PATTERN = '%s/lambda.event.*.json' % config.TMP_FOLDER
3636
LAMBDA_SCRIPT_PATTERN = '%s/lambda_script_*.py' % config.TMP_FOLDER
37-
LAMBDA_EXECUTOR_JAR = INSTALL_PATH_LOCALSTACK_JAR
37+
LAMBDA_EXECUTOR_JAR = INSTALL_PATH_LOCALSTACK_FAT_JAR
3838
LAMBDA_EXECUTOR_CLASS = 'cloud.localstack.LambdaExecutor'
3939

4040
LAMBDA_RUNTIME_PYTHON27 = 'python2.7'
@@ -430,9 +430,6 @@ def execute(event, context):
430430
TMP_FILES.append(event_file)
431431
class_name = lambda_arn_to_handler[arn].split('::')[0]
432432
classpath = '%s:%s' % (LAMBDA_EXECUTOR_JAR, main_file)
433-
for jar in JAR_DEPENDENCIES:
434-
jar_path = '%s/repository/%s' % (M2_HOME, jar)
435-
classpath += ':%s' % (jar_path)
436433
cmd = 'java -cp %s %s %s %s' % (classpath, LAMBDA_EXECUTOR_CLASS, class_name, event_file)
437434
result, log_output = run_lambda_executor(cmd)
438435
LOG.info('Lambda output: %s' % log_output.replace('\n', '\n> '))

localstack/services/install.py

+6-37
Original file line numberDiff line numberDiff line change
@@ -17,38 +17,17 @@
1717
INSTALL_DIR_ES = '%s/elasticsearch' % INSTALL_DIR_INFRA
1818
INSTALL_DIR_DDB = '%s/dynamodb' % INSTALL_DIR_INFRA
1919
INSTALL_DIR_KCL = '%s/amazon-kinesis-client' % INSTALL_DIR_INFRA
20-
INSTALL_PATH_LOCALSTACK_JAR = '%s/localstack-utils.jar' % INSTALL_DIR_INFRA
20+
INSTALL_PATH_LOCALSTACK_FAT_JAR = '%s/localstack-utils-fat.jar' % INSTALL_DIR_INFRA
2121
TMP_ARCHIVE_ES = os.path.join(tempfile.gettempdir(), 'localstack.es.zip')
2222
TMP_ARCHIVE_DDB = os.path.join(tempfile.gettempdir(), 'localstack.ddb.zip')
2323
TMP_ARCHIVE_STS = os.path.join(tempfile.gettempdir(), 'aws-java-sdk-sts.jar')
2424
URL_STS_JAR = 'http://central.maven.org/maven2/com/amazonaws/aws-java-sdk-sts/1.11.14/aws-java-sdk-sts-1.11.14.jar'
25-
URL_LOCALSTACK_JAR = ('http://central.maven.org/maven2/' +
26-
'cloud/localstack/localstack-utils/0.1.2/localstack-utils-0.1.2.jar')
25+
URL_LOCALSTACK_FAT_JAR = ('http://central.maven.org/maven2/' +
26+
'cloud/localstack/localstack-utils/0.1.3/localstack-utils-0.1.3-fat.jar')
2727

2828
# list of additional pip packages to install
2929
EXTENDED_PIP_LIBS = ['amazon-kclpy==1.4.5']
3030

31-
# local maven repository path
32-
M2_HOME = os.path.expanduser('~/.m2')
33-
34-
# hack required for Docker because our base image uses $HOME/.m2 as a volume (see Dockerfile)
35-
# TODO still needed?
36-
if '/root/.m2_persistent' in os.environ.get('MAVEN_OPTS', ''):
37-
M2_HOME = '/root/.m2_persistent'
38-
39-
# TODO: temporary hack! Remove all hardcoded paths (and move to lamb-ci Docker for Java once it's available)
40-
JAR_DEPENDENCIES = [
41-
'com/amazonaws/aws-lambda-java-core/1.1.0/aws-lambda-java-core-1.1.0.jar',
42-
'com/amazonaws/aws-lambda-java-events/1.3.0/aws-lambda-java-events-1.3.0.jar',
43-
'com/amazonaws/aws-java-sdk-kinesis/1.11.86/aws-java-sdk-kinesis-1.11.86.jar',
44-
'com/fasterxml/jackson/core/jackson-databind/2.6.6/jackson-databind-2.6.6.jar',
45-
'com/fasterxml/jackson/core/jackson-core/2.6.6/jackson-core-2.6.6.jar',
46-
'com/fasterxml/jackson/core/jackson-annotations/2.6.0/jackson-annotations-2.6.0.jar',
47-
'commons-codec/commons-codec/1.9/commons-codec-1.9.jar',
48-
'commons-io/commons-io/2.5/commons-io-2.5.jar',
49-
'org/apache/commons/commons-lang3/3.5/commons-lang3-3.5.jar'
50-
]
51-
5231
# set up logger
5332
LOGGER = logging.getLogger(os.path.basename(__file__))
5433

@@ -124,22 +103,12 @@ def install_amazon_kinesis_libs():
124103
class_files = '%s/utils/kinesis/java/com/atlassian/*.class' % ROOT_PATH
125104
if not glob.glob(class_files):
126105
run('javac -cp "%s" %s' % (classpath, java_files))
127-
# TODO needed?
128-
ext_java_dir = '%s/ext/java' % ROOT_PATH
129-
if not glob.glob('%s/target/*.jar' % ext_java_dir):
130-
run('cd "%s"; mvn -DskipTests package' % (ext_java_dir))
131106

132107

133108
def install_lambda_java_libs():
134-
for jar in JAR_DEPENDENCIES:
135-
jar_path = '%s/repository/%s' % (M2_HOME, jar)
136-
if not os.path.exists(jar_path):
137-
jar_url = ('http://central.maven.org/maven2/%s' % jar)
138-
mkdir(os.path.dirname(jar_path))
139-
download(jar_url, jar_path)
140-
# install LocalStack JAR file
141-
if not os.path.exists(INSTALL_PATH_LOCALSTACK_JAR):
142-
download(URL_LOCALSTACK_JAR, INSTALL_PATH_LOCALSTACK_JAR)
109+
# install LocalStack "fat" JAR file (contains all dependencies)
110+
if not os.path.exists(INSTALL_PATH_LOCALSTACK_FAT_JAR):
111+
download(URL_LOCALSTACK_FAT_JAR, INSTALL_PATH_LOCALSTACK_FAT_JAR)
143112

144113

145114
def install_component(name):

0 commit comments

Comments
 (0)