Closed mergesort closed 1 year ago
Hey @mergesort I'm pumped you're giving this a try! So here's whats happening - you are currently trying to run the build process on Vercel and that is not supported at the moment. Definitely not ideal as it doesn't allow for that true Vercel experience of connecting to the GitHub repo and just pushing code. With that said, I tried to mimic that experience with GitHub actions as best as possible.
Now that I'm re-reading my blog post it's pretty clear that I didn't do such a great job explaining this! All the swift commands in the blog post are meant to be run locally on your Mac OR on an amazon linux docker container. If you look at the starter repo I actually provide GitHub actions workflows that mimic the vercel experience: https://github.com/swift-cloud/vercel-starter-kit/blob/main/.github/workflows/deploy-prod.yml
The key is to create a new project on Vercel and NOT link it to the GitHub repository. This is counter intuitive and I clearly botched the explanation in my blog post. But the reason we are not linking to GitHub is because then you will encounter the build error when Vercel tries to build the swift application itself. Instead what we want to do is fill in the environment variables on the GitHub actions workflow and then let GitHub actions actually do the deploy.
Let me know if this makes any sense, I also plan on recording a video which will make this A LOT more clear.
Thanks for the super prompt response Andrew! You're right that it was a little bit unclear, but don't be too hard on yourself — this stuff is pretty bleeding edge and awesome. I was able to get a sample app deployed, and I have to say this is super cool. 😄
Only two days ago I was discussing with a friend how it makes me sad that there isn't an ecosystem for Swift that makes it as easy to deploy a serverless Swift function the way there is in the JavaScript ecosystem. Then I happened to stumble upon your library when googling "Swift Vercel" looking for something like Vercel, I wasn't actually expecting to get Swift running on Vercel! I'm traditionally a client engineer with some experience using Vapor and a bit of Node so this question will show how much of a novice I am in the space you're building upon.
This library is focused on being able to use Swift to write Vercel's edge functions, but it wouldn't allow me to interact with any other Vercel integrations out of the box, right? For example it would be nice to use Hasura or Supabase, which I assume I can do using their SDKs but wanted to make sure there was nothing built in here before looking into that.
Either way I wanted to say thank you, and I'm really rooting for this project to succeed!
Awesome! Glad to hear you got it deployed. And thanks for another great question that I need to do a better job explaining:
This package specifically builds your app to be deployed to Vercel's AWS Lambda infrastructure NOT their Edge runtime. This is partly confusing on my end but also pretty confusing in Vercel's marketing. Vercel has two pieces of compute infrastructure: Lambda and Cloudflare workers. Lambda is their traditional compute infrastructure and you actually can deploy to multiple lambda regions (I also support this in this package) but multi-region lambda is only for Vercel enterprise customers. Vercel's Edge Runtime (which is getting all the marketing hype right now) is a layer they built on-top of Cloudflare workers. We cannot deploy to their "edge" runtime right now. I actually just answered this for someone else here: https://forums.swift.org/t/swift-runtime-for-vercel-serverless-functions/62720/7
With all that said, you are deploying to AWS Lambda and this gives you access to the full swift runtime, and that means all packages like MongoDB, Alamofire, Hasura, Supabase etc. You can use anything you want. And truthfully, I think you can build extremely scalable backend applications using just Vercel and this package. There's a lot more I could say about this and I think it really goes to show that I need to make a video and really beef up my blog content.
Thanks for the very thoughtful reply to my slightly off-topic question, this actually gives me a much better understanding of what's happening here and how it's working so I really appreciate it!
I'm actually quite liking the Vercel experience so I think I'll stick with that, also having read your message to "not overthink it" in the Swift forum post. Last night I got a prototype of the Supabase SDK running on my Mac with your Vercel dev experience and it felt pretty darn magical so I'm definitely going to keep digging into the work you're doing. (I wasn't able to deploy it to Vercel because the Supabase Community Swift SDK doesn't appear to compile on Linux, but it's just some URLSession code I've seen not work correctly on Linux before so I'll tweak it myself to make it work.)
Thanks again for everything, and best of luck with swift.cloud!
@mergesort I just released support for cron jobs and also published a basic tutorial to YouTube: https://www.youtube.com/watch?v=zzBhcYbtArY
Hi there @AndrewBarba, I've been really enthusiastic about trying out Vercel using Swift since I saw your blog post, and finally had a chance to give it a shot. I've tried running it from scratch and also forking the Starter Kit repo but whenever I deploy a build to Vercel I run into this error.
I'd love to have a good serverless Swift solution that doesn't involve me using AWS so I'm very curious to see how this goes, and I'm very interested in all the work you're doing over at swift.cloud!