swift-server / swift-aws-lambda-runtime

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

Add `--disable-docker-image-update` plugin flag #311

Closed florentmorin closed 7 months ago

florentmorin commented 7 months ago

The --disable-docker-image-update plugin flag has be added to allow use of local docker images.

Motivation:

Sometimes, you need to use a customized local docker image (ie. you want to use AWS SDK for Swift and OpenSSL is required). In this case, docker pull mustn't to be called.

Until now, the plugin automatically called docker pull to update Docker image. With the new flag, Docker image update can be disabled.

Modifications:

Result:

I have a local docker image based on Swift 5.9.1 + Amazon Linux 2 and including OpenSSL.

FROM swift:5.9.1-amazonlinux2

# Install OpenSSL
RUN yum -y update && yum install -y \
    openssl \
    openssl-devel

I have build it with this command:

docker build -t swift-with-openssl .

Now, it's time to archive. Here are the results with or without the new flag.

Without flag:

😭 It fails with an error.


swift package archive --output-path /my/output/path --disable-sandbox --base-docker-image swift-with-openssl
# ...
-------------------------------------------------------------------------
building "my-awesome-lambda" in docker
-------------------------------------------------------------------------
updating "swift-with-openssl" docker image
  Using default tag: latest
  Error response from daemon: pull access denied for swift-with-openssl, repository does not exist or may require 'docker login': denied: requested access to the resource is denied
error: /usr/local/bin/docker pull swift-with-openssl failed with code 1

With flag:

😁 Everything works as expected.


swift package archive --output-path /my/output/path --disable-sandbox --base-docker-image swift-with-openssl --disable-docker-image-update
# ...
-------------------------------------------------------------------------
building "my-awesome-lambda" in docker
-------------------------------------------------------------------------
building "MyAwesomeLambda"
  [0/1] Planning build
  Building for production...
# ...
  Build complete! (145.13s)
-------------------------------------------------------------------------
archiving "MyAwesomeLambda"
-------------------------------------------------------------------------
1 archive created
  * MyAwesomeLambda at /my/output/path/MyAwesomeLambda/MyAwesomeLambda.zip
tomerd commented 7 months ago

@swift-server-bot test this please