Server Side Swift - Vapor, local packages

Hi,
I am new to Server Side Swift, and Swift Package Manager as well.
I am building a new vapor app, using local package dependencies.

"docker-compose build" step (for Docker deployment of Vapor app) fails at step:
"RUN swift package resolve".

error: Error Domain=NSCocoaErrorDomain Code=260 "The file doesn’t exist."
ERROR: Service 'app' failed to build : The command '/bin/sh -c swift package resolve' returned a non-zero code: 1

It looks like this step does not resolve dependencies for my local swift package.
Can you let me know how to include local dependencies for a vapor app, for deployment in docker? Should we use only remote repos?
Thanks in advance for your help.

2 Likes

When you say local package dependencies do you mean defined with a path: "../"?

1 Like

Yes. you are right.
I realized that this step works only for remote repositories. Is there a workaround for this? Thanks!

Well if you copy in your local dependencies to your container it should work as well

Hi Tim,
Can you point me to a resource online on how this is done (using local repos) ?.
In Vapor 4, I am using the built in docker-compose.yml/Dockerfile to do it for me. I am still learning to use Docker commands.
I tried to pushing my code to a private repo for my custom package dependency, after resolving ssh related authentication issues, docker build fails at a point, where it is not able to find module "Accelerate" (which is an Apple f/w) used in my custom dependency. Hence it looks like it is better to do this locally in a container. but I don't know exactly how.
Thank you!

You can't use Accelerate or any Apple framework other than Foundation, XCTest and Dispatch in Docker or Linux. So if you want to use those you'll need to stick to macOS (including for deployment)

1 Like

Oh Ok. Did not know this. I am trying to use my front-end code as a swift package dependency in Server-Side using vapor. Vapor build and vapor run works fine, but it is only Docker build which is failing currently at "RUN swift build --enable-test-discovery -c release" command, as it is unable to find Accelerate module. Can you point me to this limitation in Docker docs if possible? I would like to try as much as possible before giving up on this approach. Thanks!

By default, Docker on macOS is a Linux virtual machine, so the limitation is the same: there is no Accelerate. You'll either have to find a way to dockerize a macOS container (I think it's possible but not easy) or run directly on macOS.

Ok, thank you. I will look into this option.
Due to change in architecture, had to move the code from front-end to backend.

Was thinking of using Vapor to use the front-end code as swift package dependency, rather than develop the API from scratch.

Since I have a monorepo, I also have plenty of local deps at relative paths.

To build in docker, I run docker build -f path/to/vapor/app/Dockerfile $GIT_ROOT

And my Dockerfiles look like

FROM swift:5.5-focal
WORKDIR /src
COPY ./lib1 ./lib1
COPY ./lib2 ./lib2
COPY ./path/to/vapor/app/ ./path/to/vapor/app/
RUN swift build --package-path ./path/to/vapor/app/ -c release
1 Like