[shrinkwrap-issues] [JBoss JIRA] (SHRINKWRAP-523) Support creation of AWS Lambda .zip archives

Ian Brandt (JIRA) issues at jboss.org
Mon Sep 3 13:14:00 EDT 2018


     [ https://issues.jboss.org/browse/SHRINKWRAP-523?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Ian Brandt updated SHRINKWRAP-523:
----------------------------------
    Description: 
AWS Lambda supports deployments of Java functions in [a simple ZIP format|https://docs.aws.amazon.com/lambda/latest/dg/create-deployment-pkg-zip-java.html].  

As with standard JARs, the class files, resources, manifest resources, and service provider configurations are all included from the root of the archive.  Unlike standard JARs, dependent JARs are included under a 'lib/' folder.

Currently, to create ad-hoc Lambda deployments for testing I'm starting with a {{JavaArchive}}.  I add the standard JAR assets, and then use the [{{Archive.add(Archive, ArchivePath, StreamExporter)}}|https://repository.jboss.org/nexus/content/repositories/unzip/org/jboss/shrinkwrap/shrinkwrap-api/1.2.6/shrinkwrap-api-1.2.6-javadoc.jar-unzip/index.html] API (as used by [{{ContainerBase.addAsLibraries(Archive...)}}|https://repository.jboss.org/nexus/content/repositories/unzip/org/jboss/shrinkwrap/shrinkwrap-impl-base/1.2.6/shrinkwrap-impl-base-1.2.6-javadoc.jar-unzip/index.html] to add the dependencies.  Finally, I export it to a temp file with a '.zip' extension for upload:

{code:java}
final JavaArchive lambdaZip = ShrinkWrap.create(JavaArchive.class);
lambdaZip.addClasses(handlerClass);
final ArchivePath archiveLibraryPath = ArchivePaths.create("/lib");
Maven.resolver()
    .loadPomFromFile("pom.xml")
    .importCompileAndRuntimeDependencies()
    .resolve()
    .withTransitivity()
    .asList(JavaArchive.class)
    .forEach(javaArchive -> lambdaZip.add(javaArchive, archiveLibraryPath, ZipExporter.class));
lambdaZip.as(ZipExporter.class).exportTo(tempZipFile, overwrite);
{code}

It would be nice to be able to use the [{{LibraryContainer}}|https://repository.jboss.org/nexus/content/repositories/unzip/org/jboss/shrinkwrap/shrinkwrap-api/1.2.6/shrinkwrap-api-1.2.6-javadoc.jar-unzip/index.html] API directly instead.

I can think of a few ways to accomplish this (and there are likely others):

# Make {{JavaArchive}} a {{LibraryContainer}}.  The library path would be defaulted to 'lib/'.
#* Easy to do since {{JavaArchiveImpl}} extends {{ContainerBase}}, which already has the all the necessary implementation.
#* The API would now extend the [JAR File Specification|https://docs.oracle.com/javase/8/docs/technotes/guides/jar/jar.html], so there's the question of utility vs. conformance.
#* There's also the issue that the default archive name will have a '.jar' extension instead of '.zip', per the service descriptor properties file for {{JavaArchive}}.
# Add {{LibraryContainer}} and {{ServiceProviderContainer}} to the list of interfaces extended by {{GenericArchive}}.
#* Easy again with the underlying implementation being {{ContainerBase}}.
#* There's no presumption of a spec with {{GenericArchive}}, so presumably there's no harm in the additional API, though that also makes defaulting the library path to 'lib/' a bit more assuming.
#* I was a bit surprised to find the default extension for {{GenericArchive}} is '.jar' as well, as that implies the JAR spec.  I would have guessed '.zip'.  I'd propose changing that as part of this approach, but that would be a breaking change for anyone that's come to depend on it being '.jar'.
#* Another issue here is if you further say the {{WebContainer}}, {{EnterpriseContainer}}, and {{ResourceAdapterContainer}} API might as well be added too.  Their respective implementation classes extend {{ContainerBase}}, creating a multiple inheritance situation on the implementation side.  There's also conflict between the standard paths, e.g. 'lib/' vs. 'WEB-INF/lib/'.
# Add a new {{LambdaArchive}} interface and implementation to ShrinkWrap proper.
#* It would be the equivalent of approach #1, but with a default extension of '.zip'.
#* On one hand, AWS Lambda seems here to stay.
#* I would think it better to take this as an opportunity to make the base API more generic, rather than to specialize with a new subtype.
# Create the same {{LambdaArchive}}, but in a ShrinkWrap extension project.

I'm happy to create a pull request given guidance on the preferred approach.  For myself I'd lean towards #2 if changing the default extension is deemed acceptable.

  was:
AWS Lambda supports deployments of Java functions in [a simple ZIP format|https://docs.aws.amazon.com/lambda/latest/dg/create-deployment-pkg-zip-java.html].  

As with standard JARs, the class files, resources, manifest resources, and service provider configurations are all included from the root of the archive.  Unlike standard JARs, dependent JARs are included under a 'lib/' folder.

Currently, to create ad-hoc Lambda deployments for testing I'm starting with a {{JavaArchive}}.  I add the standard JAR assets, and then use the [{{Archive.add(Archive, ArchivePath, StreamExporter)}}|https://repository.jboss.org/nexus/content/repositories/unzip/org/jboss/shrinkwrap/shrinkwrap-api/1.2.6/shrinkwrap-api-1.2.6-javadoc.jar-unzip/index.html] API (as used by [{{ContainerBase.addAsLibraries(Archive...)}}|https://repository.jboss.org/nexus/content/repositories/unzip/org/jboss/shrinkwrap/shrinkwrap-impl-base/1.2.6/shrinkwrap-impl-base-1.2.6-javadoc.jar-unzip/index.html] to add the dependencies.  Finally, I export it to a temp file with a '.zip' extension for upload:

{code:java}
final JavaArchive lambdaZip = ShrinkWrap.create(JavaArchive.class);
lambdaZip.addClasses(handlerClass);
final ArchivePath archiveLibraryPath = ArchivePaths.create("/lib");
Maven.resolver()
    .loadPomFromFile("pom.xml")
    .importCompileAndRuntimeDependencies()
    .resolve()
    .withTransitivity()
    .asList(JavaArchive.class)
    .forEach(javaArchive -> lambdaZip.add(javaArchive, archiveLibraryPath, ZipExporter.class));
lambdaZip.as(ZipExporter.class).exportTo(tempZipFile, overwrite);
{code}

It would be nice to be able to use the [{{LibraryContainer}}|https://repository.jboss.org/nexus/content/repositories/unzip/org/jboss/shrinkwrap/shrinkwrap-api/1.2.6/shrinkwrap-api-1.2.6-javadoc.jar-unzip/index.html] API directly instead.

I can think of a few ways to accomplish this (and there are likely others):

# Make {{JavaArchive}} a {{LibraryContainer}}.  The library path would be defaulted to 'lib/'.
#* Easy to do since {{JavaArchiveImpl}} extends {{ContainerBase}}, which already has the all the necessary implementation.
#* The API would now extend the [JAR File Specification|https://docs.oracle.com/javase/8/docs/technotes/guides/jar/jar.html], so there's the question of utility vs. conformance.
#* There's also the issue that the default archive name will have a '.jar' extension instead of '.zip', per the service descriptor properties file for {{JavaArchive}}.
# Add {{LibraryContainer}} and {{ServiceProviderContainer}} to the list of interfaces extended by {{GenericArchive}}.
#* Easy again with the underlying implementation being {{ContainerBase}}.
#* There's no presumption of a spec with {{GenericArchive}}, so presumably there's no harm in the additional API, though that also makes defaulting the library path to 'lib/' a bit more assuming.
#* I was a bit surprised to find the default extension for {{GenericArchive}} is '.jar' as well, as that implies the JAR spec.  I would have guessed '.zip'.  I'd propose changing that as part of this approach, but that would be a breaking change for anyone that has come to depend on it being '.jar'.
#* Another issue here is if you further say the {{WebContainer}}, {{EnterpriseContainer}}, and {{ResourceAdapterContainer}} API might as well be added too.  Their respective implementation classes extend {{ContainerBase}}, creating a multiple inheritance situation on the implementation side.  There's also conflict between the standard paths, e.g. 'lib/' vs. 'WEB-INF/lib/'.
# Add a new {{LambdaArchive}} interface and implementation to ShrinkWrap proper.
#* It would be the equivalent of approach #1, but with a default extension of '.zip'.
#* On one hand, AWS Lambda seems here to stay.
#* I would think it better to take this as an opportunity to make the base API more generic, rather than to specialize with a new subtype.
# Create the same {{LambdaArchive}}, but in a ShrinkWrap extension project.

I'm happy to create a pull request given guidance on the preferred approach.  For myself I'd lean towards #2 if changing the default extension is deemed acceptable.



> Support creation of AWS Lambda .zip archives
> --------------------------------------------
>
>                 Key: SHRINKWRAP-523
>                 URL: https://issues.jboss.org/browse/SHRINKWRAP-523
>             Project: ShrinkWrap
>          Issue Type: Feature Request
>          Components: api, impl-base
>    Affects Versions: 1.2.6
>            Reporter: Ian Brandt
>            Priority: Optional
>
> AWS Lambda supports deployments of Java functions in [a simple ZIP format|https://docs.aws.amazon.com/lambda/latest/dg/create-deployment-pkg-zip-java.html].  
> As with standard JARs, the class files, resources, manifest resources, and service provider configurations are all included from the root of the archive.  Unlike standard JARs, dependent JARs are included under a 'lib/' folder.
> Currently, to create ad-hoc Lambda deployments for testing I'm starting with a {{JavaArchive}}.  I add the standard JAR assets, and then use the [{{Archive.add(Archive, ArchivePath, StreamExporter)}}|https://repository.jboss.org/nexus/content/repositories/unzip/org/jboss/shrinkwrap/shrinkwrap-api/1.2.6/shrinkwrap-api-1.2.6-javadoc.jar-unzip/index.html] API (as used by [{{ContainerBase.addAsLibraries(Archive...)}}|https://repository.jboss.org/nexus/content/repositories/unzip/org/jboss/shrinkwrap/shrinkwrap-impl-base/1.2.6/shrinkwrap-impl-base-1.2.6-javadoc.jar-unzip/index.html] to add the dependencies.  Finally, I export it to a temp file with a '.zip' extension for upload:
> {code:java}
> final JavaArchive lambdaZip = ShrinkWrap.create(JavaArchive.class);
> lambdaZip.addClasses(handlerClass);
> final ArchivePath archiveLibraryPath = ArchivePaths.create("/lib");
> Maven.resolver()
>     .loadPomFromFile("pom.xml")
>     .importCompileAndRuntimeDependencies()
>     .resolve()
>     .withTransitivity()
>     .asList(JavaArchive.class)
>     .forEach(javaArchive -> lambdaZip.add(javaArchive, archiveLibraryPath, ZipExporter.class));
> lambdaZip.as(ZipExporter.class).exportTo(tempZipFile, overwrite);
> {code}
> It would be nice to be able to use the [{{LibraryContainer}}|https://repository.jboss.org/nexus/content/repositories/unzip/org/jboss/shrinkwrap/shrinkwrap-api/1.2.6/shrinkwrap-api-1.2.6-javadoc.jar-unzip/index.html] API directly instead.
> I can think of a few ways to accomplish this (and there are likely others):
> # Make {{JavaArchive}} a {{LibraryContainer}}.  The library path would be defaulted to 'lib/'.
> #* Easy to do since {{JavaArchiveImpl}} extends {{ContainerBase}}, which already has the all the necessary implementation.
> #* The API would now extend the [JAR File Specification|https://docs.oracle.com/javase/8/docs/technotes/guides/jar/jar.html], so there's the question of utility vs. conformance.
> #* There's also the issue that the default archive name will have a '.jar' extension instead of '.zip', per the service descriptor properties file for {{JavaArchive}}.
> # Add {{LibraryContainer}} and {{ServiceProviderContainer}} to the list of interfaces extended by {{GenericArchive}}.
> #* Easy again with the underlying implementation being {{ContainerBase}}.
> #* There's no presumption of a spec with {{GenericArchive}}, so presumably there's no harm in the additional API, though that also makes defaulting the library path to 'lib/' a bit more assuming.
> #* I was a bit surprised to find the default extension for {{GenericArchive}} is '.jar' as well, as that implies the JAR spec.  I would have guessed '.zip'.  I'd propose changing that as part of this approach, but that would be a breaking change for anyone that's come to depend on it being '.jar'.
> #* Another issue here is if you further say the {{WebContainer}}, {{EnterpriseContainer}}, and {{ResourceAdapterContainer}} API might as well be added too.  Their respective implementation classes extend {{ContainerBase}}, creating a multiple inheritance situation on the implementation side.  There's also conflict between the standard paths, e.g. 'lib/' vs. 'WEB-INF/lib/'.
> # Add a new {{LambdaArchive}} interface and implementation to ShrinkWrap proper.
> #* It would be the equivalent of approach #1, but with a default extension of '.zip'.
> #* On one hand, AWS Lambda seems here to stay.
> #* I would think it better to take this as an opportunity to make the base API more generic, rather than to specialize with a new subtype.
> # Create the same {{LambdaArchive}}, but in a ShrinkWrap extension project.
> I'm happy to create a pull request given guidance on the preferred approach.  For myself I'd lean towards #2 if changing the default extension is deemed acceptable.



--
This message was sent by Atlassian JIRA
(v7.5.0#75005)


More information about the shrinkwrap-issues mailing list