-
Notifications
You must be signed in to change notification settings - Fork 196
Conversation
Demo using Publish by John Sundell on Netlify: https://github.com/igor-makarov/PublishTest1 Most of the time is spent installing Swift and checking out and building deps. This PR would shave most of it off. |
I've added Swiftenv to this PR, which not makes installing Swift far easier on the Docker side, but also allows users to override Swift version via a |
Do you think it's a good idea to pre-install other versions as well? |
I love the idea of this! While my knowledge of Netlify is quite limited, let me know if I can help in any way 🙂 |
Sorry about the delay with this one @igor-makarov as I've been thinking long & hard about this one - it's an excellent point BTW! Long story short, I think that decision should rest with the devs at Netlify. The pain point with Swift is a new patch version of Swift is now released monthly on Linux. Looking at this quote from
Ideally therefore we would just install the latest Swift 5.1.x (or even 5.x, as per NodeJS) release via Docker by default and be done with it. However, I don't think this is possible via Swiftenv or via swift.org - "Swift 5.1" is really like a "Swift 5.1.0" as far as I'm aware. That said, I could be totally mistaken & I'm totally open to any suggestions with getting at the latest Swift 5.1.x release. If we just go for Swift 5.1.0, we miss out on the latest patches, plus the current release version of Xcode includes the Swift 5.1.3 compiler. The other thing worth pointing out is, with the exception of Python & PHP, no other language on Netlify has multiple versions installed (although I remember there used to be multiple Rubies too). So to conclude, the final decision I think should rest with the Netlify team, but ideally to be consistent with other languages, the Docker image would fetch the latest Swift 5.1.x patch release as & when the build takes place - I just don't know if there's a way of doing just that. |
Makes sense - after all, there's full caching support! 💪🏻 |
the swiftenv idea seems right. You could read an env var like |
Just to additionally address this point @mraerino - I've tried to mimic the behaviour of other languages (especially Ruby/RVM) by allowing you to pass in a |
In fact @igor-makarov the Swift version that's been fetched wasn't being cached - I have added the relevant shell script additions for this pending a fix for caching in general in #318. This works similarly to what's been set up for NodeJS/NVM & Ruby/RVM. So on a future date when said issue is fixed, if you have 5.1.2 specified, the build machine will only need to fetch it once for your project. |
Netlify devs: may I kindly ask if any of you can review this again? I have updated Swift in this PR to v5.2 by default now that it has been released & is readily available across both macOS & Linux. However, any other version of Swift can be used (& cached) provided it is specified in either a |
@SimonRice thank you for all the great work on this PR. it's in great shape. If anybody wants to beta test this as a special image config on their site, please comment here, so we can enable it for you. |
Would love to test this |
Ok, I've had the chance to test this and it appears to work great! I can get sites to build with both the preinstalled 5.2 version as well as a 5.1 version that was installed at runtime. The caching of swift versions also seems to work correctly. The one caveat I found is that trying to run versions of Swift @python-engineer we'll be in touch shortly so you can test this further before it is released publicly. Thanks for your willingness to help out with this! |
Great job @SimonRice ! Deploy log says the build image is still 3.3.7 - is there a process that needs to go through, or is this a propagation issue? |
we have not deployed latest master yet. and we will allow beta-testing before that. |
Thanks @mraerino. I would love to beta test this in my demo project as well! |
It looks like this is failing when it tries to install Swift while running in Netlify CI due to kylef/swiftenv#170. I'm testing a workaround where I unset |
@SimonRice, @python-engineer, and @igor-makarov, please feel free to visit https://build-image-beta.netlify.app/ to add your sites to the Swift beta! There's still some issues that I've mentioned above but the basics should work. Please let us know if anything is broken that I haven't already discovered. |
@Benaiah my project seems to work with the beta image, thank you! 👍🏻 |
Thank you so much for the build access @Benaiah - the one small production website I already migrated to Swift on Netlify is building well with this image without the workarounds I previously used. I also ran the deploy again to test the SPM cache & that has a positive impact on build times as well 🎉. |
Has this been released?
|
@alexito4 since I helped build this feature, I feel it's a slight duty to try to help you out here. I understand this feature has shipped. Can I ask:
If your answer to number 2 is "yes", you may wish to set your "Base Directory" setting to match that of your content & clear your "Output Directory" setting. One example of this is up at: Repo: https://github.com/SimonRice/NetlifyNoSwiftBuild Settings: Let me know if this helps at all. |
Thanks @SimonRice . That was exactly the situation. Thanks 👍 Now I just need to find some time to actually build on netlify ^^ |
are there any examples of swift apps on netlify, that use a db hosted externally,? |
a note here: Swift is supported at build time (in our CI system) to build static pages from your content. We do not (yet) support Swift for runtime workloads (in Netlify Functions) for the usecase of building static pages you should be able to use any database library you'd use in other contexts as long as it's integrated with the system that builds the pages. see https://github.com/JohnSundell/Publish for a popular swift static-site generator. |
This PR adds Apple's Swift Programming Language & Swift Package Manager support to the Netlify Build image. For those of you not aware, Swift is a programming language commonly used among developers on Apple's platforms (iOS, macOS, etc.) and has some server side traction via web frameworks such as Vapor.
On the Docker side, I've added a few steps to download & extract the Swift binary, along with a small sanity check. As with NVM on NodeJS & RVM on Ruby, I've used swiftenv so you don't need to hardcode Ubuntu version to the Docker file & so a user can override Swift version via a
.swift-version
file orSWIFT_VERSION
environment variable (the current readily available stable version, 5.2, is installed by default).On the
run-build-functions.sh
side, I've added aswift build
command if there's aPackage.swift
file, which does all the Swift Package Manager stuff. The.build
folder would be cached, except that as raised in #318 & #320, it seems likecache_artifacts
is no longer run fromrun-build.sh
at least when run locally.Finally, I've fixed a small bug around the "wapm packages" cache - a trailing comma is added to the directory name & so it isn't cached if
cache_artifacts
is run.You can find a small sample project at SimonRice/PlotSample, which has a build command of
swift run
that generates an HTML file in a directory (innovatively) namedhtml
- in addition, @JohnSundell (a prominent developer in the iOS & Swift community) has recently launched a very promising static site generator in Swift called Publish that can generate a bunch of HTML pages by runningswift run
- I know a lot of iOS developers would love to see this working on Netlify.