Heroku buildpack: swift
For example a Dockerfile:
FROM docker.io/swift:5.5 as build WORKDIR /usr/src/app COPY Package.swift Package.resolved ./ COPY Sources Sources COPY Tests Tests RUN swift build --configuration release RUN swift test --configuration release FROM docker.io/swift:5.5-slim # Copy the build executable target (named in Package.swift) COPY --from=build /usr/src/app/.build/release/server . CMD ./server $PORT
Build and push the image to Heroku's registry:
$ heroku container:push web
Then release the image:
$ heroku container:release web
For historical purposes, below are the usage for the buildpack. Although its use is discouraged.
$ ls Procfile Package.swift Sources $ heroku create --buildpack kyle/swift $ git push heroku master remote: -----> Swift app detected remote: -----> Installing Swift 4.1 remote: -----> Installing clang-3.7.0 remote: -----> Building Package remote: -----> Copying binaries to 'bin'
You can also add it to upcoming builds of an existing application:
$ heroku buildpacks:set kyle/swift
The buildpack will detect your app as Swift if it has a
Package.swift file in
Using the Procfile, you can set the process to run for your web server. Any binaries built from your Swift source using swift package manager will be placed in your $PATH.
web: HelloWorld --workers 3 --bind 0.0.0.0:$PORT
Specify a Swift version
You can also customise the version of Swift used with a
in your repository:
$ cat .swift-version 4.1
.swift-version file is completely compatible with
NOTE: Since there are frequent Swift language changes, it's advised that you pin to your Swift version.
You can place custom scripts to be ran before and after compiling your Swift source code inside the following files in your repository:
This is useful if you would need to install any other dependencies.
Using the latest buildpack code
kyle/swift buildpack from the Heroku Registry represents the latest stable version of the buildpack. If you'd like to use the latest buildpack code from this Github repository, you can set your buildpack to the GitHub URL:
$ heroku buildpacks:set https://github.com/kylef/heroku-buildpack-swift