This repository contains the source for building Swift applications as reproducible Docker images using source-to-image.
For more information about using these images with OpenShift, please see the official OpenShift Documentation.
For more information about the open source Swift programming language goto the Swift website.
Below you can read how to build and how to use. FYI, you don't have to build this repo, you can use a prebuilt image - I'll try to keep updated versions of it available on docker hub.
Swift versions available
- Swift 3.0
OS versions available
- ubuntu14 = Ubuntu 14.04
- centos7 = CentOS 7 (IN WORK)
- rhel7 = RHEL 7 (IN WORK)
You'll need to have the s2i tool.
$ docker search dudash/swift
$ docker pull dudash/swift-VER-PLATFORM
Use the s2i
tool to build the final image that contains your application code - in this case the test app provided in this repo:
$ git clone https://github.com/dudash/s2i-swift.git
$ s2i build ./3.0/test/test-app/ dudash/swift-30-ubuntu14 swift-test-app
./3.0/test/test-app/
is the top directory of the source code (replace test path with your code's path).openshift/swift-30-ubuntu14
is the name of the s2i builder image created bymake build
above (including the repo).swift-test-app
is the name of the new application image that contains your app built from source code.
Finally, run your application in a container to see that it worked (swift-test-app is the image you created using s2i):
$ docker run swift-test-app
Use the s2i
tool to build the final image that contains your application code
- Hello swift from github example
$ s2i build https://github.com/dudash/openshiftexamples-simpleswift.git dudash/swift-30-ubuntu14 hello-swift
$ docker run hello-swift
- Apple's swift example package-dealer on github (with logging set to 5):
$ s2i build --loglevel 5 https://github.com/apple/example-package-dealer.git dudash/swift-30-ubuntu14 package-dealer
$ docker run package-dealer
Package Manager Builds
You can build swift apps for linux that leverage Swift Package Manager. The build process assumes you will have a Package.swift at the top level describing your app and it's dependencies. Your app's Swift code should be located in a "Sources" directory. Local package dependencies should be placed in a directory called "LocalPackages" (see the test app as an example).
Straight Source Builds
You can just point s2i to a folder of swift files and it will compile them into an executable. Note you will need a main.swift file for Swift to execute.
You can install the S2I Swift images from with templates:
$ oc create -n openshift -f https://raw.githubusercontent.com/dudash/s2i-swift/master/openshift-resources/swift-all-ubuntu14-imagestreamlist.json
Note: Drop the -n openshift
if you don't have admin rights... or ask your admin to create it.
To prepare the s2i builder image (for building on Ubuntu 14.04 & Swift 3.0):
$ git clone https://github.com/dudash/s2i-swift.git
$ cd s2i-swift
$ make build VERSION=3.0 TARGET=ubuntu14
**[swift-version]**: Dockerfile to build container images from **[swift-version]/test/test-app**: Sample application used for tests **hack/**: Folder containing scripts which are responsible for the build and test actions performed by the Makefile **s2i/**: Build scripts which will be injected into the builder image and executed during application source code builds