swift-aws-lambda-runtime icon indicating copy to clipboard operation
swift-aws-lambda-runtime copied to clipboard

Add support for resources when packaging using the SwiftPM plugin

Open camdenfullmer opened this issue 1 year ago • 3 comments

This change updates the SwiftPM plugin to include the executable's resources in the archive.

Motivation:

When deploying a Lambda function that generates HTML content I needed a way to package template HTML files along with the executable. Defining the resources in the Package.swift and then packaging them in the archive in a way so that Swift can access them using Bundle.main.resourceURL felt like the best way to accomplish this.

Example:

.executableTarget(
            name: "Website",
            dependencies: [
                .product(name: "AWSLambdaRuntime", package: "swift-aws-lambda-runtime"),
            ],
            resources: [
                .process("template.stencil"),
            ]),

Modifications:

Plugin code has been modified to generate a Contents/Resources directory inside the final archive which includes the resources defined in the executable's target from Package.swift.

Result:

The zip archive includes the defined resources in Package.swift.

camdenfullmer avatar Jun 21 '24 16:06 camdenfullmer

Looks like this address issue #312

sebsto avatar Jun 22 '24 09:06 sebsto

@camdenfullmer Thank you for this PR. It looks like a legitimate idea and simple implementation

I would propose to add a minimal example Lambda function to show how to use this capability and a section in the README file to document this.

Question: why Contents/Resources and not just Resources like the mac bundles ? (I know, naming things is hard)

I left comments on the code

sebsto avatar Jun 22 '24 09:06 sebsto

@swift-server-bot test this please

sebsto avatar Jun 22 '24 10:06 sebsto

@swift-server-bot test this please

sebsto avatar Aug 01 '24 15:08 sebsto

@camdenfullmer Thank you for having submitted this PR. We're considering merging it in the main branch before we start work on v2. Can you address the two suggestions left above ?

sebsto avatar Aug 01 '24 15:08 sebsto

@camdenfullmer Thank you for having submitted this PR. We're considering merging it in the main branch before we start work on v2. Can you address the two suggestions left above ?

Yep will get right on it. Will try to have changes and feedback by the end of the week!

camdenfullmer avatar Aug 01 '24 16:08 camdenfullmer

@swift-server-bot test this please

sebsto avatar Aug 01 '24 19:08 sebsto

@camdenfullmer Thank you for the update. I tested the code on different variations of your sample project. It works like a charm, Can you make sure the scripts/soundness.sh script runs without error ? It's just the license headers missing from the example project.

19:06:17    * swift-or-c... missing headers in file './Examples/ResourcePackaging/Lambda.swift'!

sebsto avatar Aug 01 '24 20:08 sebsto

@camdenfullmer Thank you for the update. I tested the code on different variations of your sample project. It works like a charm, Can you make sure the scripts/soundness.sh script runs without error ? It's just the license headers missing from the example project.

19:06:17    * swift-or-c... missing headers in file './Examples/ResourcePackaging/Lambda.swift'!

I changed the year to something that will pass, but maybe the script should be updated to allow for 2024?

camdenfullmer avatar Aug 02 '24 01:08 camdenfullmer

@swift-server-bot test this please

sebsto avatar Aug 05 '24 15:08 sebsto