swiftlang / swift-docker

Docker Official Image packaging for Swift
https://swift.org
Apache License 2.0
1.35k stars 182 forks source link

added install openssl-devel to amazonlinux2 Dockerfile #371

Closed MarwaneKoutar closed 4 months ago

MarwaneKoutar commented 5 months ago

Swift build for AWS Lambda failing

When using the command "swift package --disable-sandbox plugin archive" to build a Swift Lambda function that has aws-sdk-swift as a dependency, the build of it will fail because of a missing package in the image it uses. This is why I added openssl-devel in the install section.

Reproducing the Bug

  1. Initialize a Swift project for AWS Lambda
    swift package init --type executable 
  2. edit overall project to conform to a Lambda function

for example

// Import the packages required by our function
import AWSLambdaRuntime

// Define the request structure
struct Request: Codable {
    let rawPath: String
}

// Define the response structure
struct Response: Codable {
    let body: String
}

// Entry point for the Lambda function
@main
struct HelloWorld: SimpleLambdaHandler {

    // Lambda Function handler
    func handle(_ event: Request, context: LambdaContext) async throws -> Response {

        return Response(body: "Hello, world!")
    }
}

make sure to put this into Sources/HelloWorld/LambdaHandler.swift

  1. add aws-sdk-swift as a package and as a product dependency
    
    // swift-tools-version: 5.9.0
    // The swift-tools-version declares the minimum version of Swift required to build this package.

import PackageDescription

let package = Package( name: "aws-swift-app", platforms: [.macOS(.v12)], products: [ .executable(name: "HelloWorld", targets: ["HelloWorld"]) ], dependencies: [ .package(url: "https://github.com/swift-server/swift-aws-lambda-runtime", branch: "main"), .package(url: "https://github.com/awslabs/aws-sdk-swift", from: "0.37.0") ], targets: [ .executableTarget( name: "HelloWorld", dependencies: [ .product(name: "AWSLambdaRuntime",package: "swift-aws-lambda-runtime"), .product(name: "AWSDynamoDB",package: "aws-sdk-swift"), ] ) ] )

5. run the command
```bash
swift package --disable-sandbox plugin archive

The Error

The project would start compiling until it prints this:

Capture d’écran 2024-03-01 à 17 37 44

Which basically says that it is missing some files

The Fix

Adding openssl-devel to the installed packages in the amazonlinux2 image which is the image that swift package uses.

sebsto commented 5 months ago

Looks good to me @MarwaneKoutar, thanks. @shahmishal can you have a look and merge if OK ? Do you think we need to update the SLIM version as well ? (I don't think so, as the objectives of the SLIM version is to be as small as possible)

sebsto commented 5 months ago

@shahmishal

I understand your concern to not open the door to vendor requests and to keep the image as small as possible. However, I would like you to consider these three points:

1/ this is Amazon Linux and AWS SDK for Swift. This image is used by AWS customers using Swift, the vast majority will need to install the AWS SDK on it. I'm not asking to add this package on all Linux images, just the Amazon one.

2/ The slim images exist and they are minimal, a customer that wants the smallest possible image will use the slim version

3/ both Apple and Amazon are focus on customer experience. Given the fact that this is an Amazon Linux image, to be deployed on AWS, we want to give the best possible DX to our common customers.

Let me know what the team decision is. Thanks

shahmishal commented 5 months ago

@sebsto Thanks for the explanation! This does make sense because Amazon Linux 2 docker images are mostly used on AWS platforms.

shahmishal commented 5 months ago

@swift-ci test

shahmishal commented 5 months ago

Please also update the 5.10 Dockerfile. Thanks!

MarwaneKoutar commented 5 months ago

Hey @shahmishal, I've just updated it. Thank you!

MaxDesiatov commented 5 months ago

@swift-ci test

shahmishal commented 5 months ago

@swift-ci test

MarwaneKoutar commented 5 months ago

@shahmishal could you please have a look at that?

shahmishal commented 5 months ago

This looks good, I just noticed we would also want this updated on the nightly Dockerfiles too.

MarwaneKoutar commented 5 months ago

@shahmishal would you like to also have this update on the buildx Dockerfiles? I've added it on the nightly-main too, is that good?

shahmishal commented 5 months ago

Yes buildx too, thanks!

shahmishal commented 5 months ago

@swift-ci test

shahmishal commented 5 months ago

@MarwaneKoutar Please let me know once you have buildx updated. Thanks

MarwaneKoutar commented 5 months ago

@shahmishal Sorry I've missed your last message. I just updated the buildx ones.

MarwaneKoutar commented 5 months ago

@shahmishal Could you review it please?

shahmishal commented 4 months ago

@swift-ci test

sebsto commented 4 months ago

@shahmishal Hello Mishal,

I noticed the builds at Docker Hub are based on a 4 months commit.
Do you know when this pull request will land into Docker hub ? We're block on another project with this dependency

Thank you !

sebsto commented 1 month ago

I just test the image swift:5.10-amazonlinux2 today https://hub.docker.com/layers/library/swift/5.10-amazonlinux2/images/sha256-12e5f88e33b3c997ad16502fea3c1287c4a00757d63a04fc669e3cac3a9795ce?context=explore

and I confirm this change landed well.

Thank you !

@MarwaneKoutar Time to update the build script of the SAM tLambda templates at https://github.com/swift-server-community/aws-lambda-swift-sam-template