Skip to content

added install openssl-devel to amazonlinux2 Dockerfile #371

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Mar 27, 2024

Conversation

MarwaneKoutar
Copy link
Contributor

@MarwaneKoutar MarwaneKoutar commented Mar 1, 2024

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 
  1. 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"),
            ]
        )
    ]
)
  1. run the command
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
Copy link

sebsto commented Mar 1, 2024

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
Copy link

sebsto commented Mar 7, 2024

@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
Copy link
Member

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

@shahmishal
Copy link
Member

@swift-ci test

@shahmishal
Copy link
Member

Please also update the 5.10 Dockerfile. Thanks!

@MarwaneKoutar
Copy link
Contributor Author

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

@MaxDesiatov
Copy link
Contributor

@swift-ci test

@shahmishal
Copy link
Member

@swift-ci test

@MarwaneKoutar
Copy link
Contributor Author

@shahmishal could you please have a look at that?

@shahmishal
Copy link
Member

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

@MarwaneKoutar
Copy link
Contributor Author

@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
Copy link
Member

Yes buildx too, thanks!

@shahmishal
Copy link
Member

@swift-ci test

@shahmishal
Copy link
Member

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

@MarwaneKoutar
Copy link
Contributor Author

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

@MarwaneKoutar
Copy link
Contributor Author

@shahmishal Could you review it please?

@shahmishal
Copy link
Member

@swift-ci test

@shahmishal shahmishal merged commit d20a32d into swiftlang:main Mar 27, 2024
@sebsto
Copy link

sebsto commented Apr 18, 2024

@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
Copy link

sebsto commented Jul 8, 2024

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants