swift-server / swift-aws-lambda-runtime

Swift implementation of AWS Lambda Runtime
Apache License 2.0
1.12k stars 101 forks source link

[plugin] Provided Examples' Package.swift does not work with the archive plugin. #275

Closed sebsto closed 2 months ago

sebsto commented 1 year ago

Expected behavior

Trying to use the archive plugin on examples is not working out of the box.

In the examples directory Package.swift must be modified as this (note the branch and not the version parameter.

    dependencies: [
        // this is the dependency on the swift-aws-lambda-runtime library
        // in real-world projects this would say
        .package(url: "https://github.com/swift-server/swift-aws-lambda-runtime.git", branch: "main")
        //.package(name: "swift-aws-lambda-runtime", path: "../.."),
    ],

Actual behavior

When in the Examples/Echo directory, the plugin fails with the error below. This is because inside the docker container /workspace maps to Examples/Echo and the examples' Package.swift refer to the swift-runtime library as ../.. which does not exist in the docker container.

.package(name: "swift-aws-lambda-runtime", path: "../.."),
-------------------------------------------------------------------------
configuration
-------------------------------------------------------------------------
{
  outputDirectory: /Users/stormacq/Documents/amazon/code/lambda/swift/swift-aws-lambda-runtime/Examples/Echo/.build/plugins/AWSLambdaPackager/outputs/AWSLambdaPackager
  products: ["MyLambda"]
  buildConfiguration: release
  baseDockerImage: swift:amazonlinux2
}
-------------------------------------------------------------------------
building "echo" in docker
-------------------------------------------------------------------------
updating "swift:amazonlinux2" docker image
  amazonlinux2: Pulling from library/swift
  Digest: sha256:0b645a7589aa5f1759f976c42a9ffba48fd930b27b3481b0ab32e271e701d444
  Status: Image is up to date for swift:amazonlinux2
  docker.io/library/swift:amazonlinux2
/usr/local/bin/docker run --rm -v /Users/stormacq/Documents/amazon/code/lambda/swift/swift-aws-lambda-runtime/Examples/Echo:/workspace -w /workspace swift:amazonlinux2 bash -cl swift build -c release --show-bin-path
  /workspace/.build/aarch64-unknown-linux-gnu/release
building "MyLambda"
/usr/local/bin/docker run --rm -v /Users/stormacq/Documents/amazon/code/lambda/swift/swift-aws-lambda-runtime/Examples/Echo:/workspace -w /workspace swift:amazonlinux2 bash -cl swift build -c release --product MyLambda --static-swift-stdlib
  error: the package manifest at '/Package.swift' cannot be accessed (/Package.swift doesn't exist in file system)
error: /usr/local/bin/docker run --rm -v /Users/stormacq/Documents/amazon/code/lambda/swift/swift-aws-lambda-runtime/Examples/Echo:/workspace -w /workspace swift:amazonlinux2 bash -cl swift build -c release --product MyLambda --static-swift-stdlib failed with code 1

Steps to reproduce

  1. git clone git@github.com:sebsto/swift-aws-lambda-runtime.git
  2. cd swift-aws-lambda-runtime/Examples/Echo
  3. swift package --disable-sandbox archive --verbose 1

If possible, minimal yet complete reproducer code (or URL to code)

n/a

SwiftAWSLambdaRuntime version/commit hash

https://github.com/swift-server/swift-aws-lambda-runtime/tree/dc64ce195b1c51356f6655935c3509e296c35696

Swift & OS version (output of swift --version && uname -a)

✗ swift --version && uname -a
swift-driver version: 1.62.15 Apple Swift version 5.7.1 (swiftlang-5.7.1.135.3 clang-1400.0.29.51)
Target: arm64-apple-macosx13.0
Darwin bcd07458a91c 22.1.0 Darwin Kernel Version 22.1.0: Sun Oct  9 20:15:09 PDT 2022; root:xnu-8792.41.9~2/RELEASE_ARM64_T6000 arm64
sebsto commented 1 year ago

This PR proposes changes to make the archive plugin works with the examples. https://github.com/swift-server/swift-aws-lambda-runtime/pull/277

tomerd commented 1 year ago

made this PR to document the 1.x API. once merged we can tag a 1.0.0-alpha.1