Commit a17cc1e0 authored by Drew's avatar Drew

Initial commit

parents
FROM debian:latest
MAINTAINER Drew Crawford
ENV SWIFT_TAG="swift-2.2-SNAPSHOT-2015-12-22-a" RUNTIME_PACKAGES="libedit2 libpython2.7 libxml2 libicu52" BUILDTIME_PACKAGES="git ca-certificates python clang ninja-build cmake uuid-dev libbsd-dev libicu-dev pkg-config libedit-dev file libxml2-dev python-dev libncurses5-dev libsqlite3-dev libreadline6-dev rsync"
RUN \
# Create a directory to work in \
mkdir swift-dev && \
cd swift-dev && \
# Install the runtime and build-time dependencies \
apt-get update && \
apt-get install $RUNTIME_PACKAGES $BUILDTIME_PACKAGES -y --no-install-recommends && \
\
git clone https://github.com/apple/swift.git && \
cd swift && \
# submodules? Where we're going, we don't need submodules! \
./utils/update-checkout --clone && \
\
# The silly update-checkout script does not understand matching the swift checkout ref \
# In practice what you're supposed to do (I think! It's not documented!) is check out the same snapshot tag \
# Not all the folders have them (where do some of them come from??) but we'll just try them all \
find ../ -maxdepth 1 -type d -exec bash -c '(cd {} && echo checking out in `pwd` && git checkout $SWIFT_TAG)' \; && \
\
# And now we build, like a good little linuxen. \
# I believe this is what the linux build script does. In practice, this builds a system into /tmp/install and then tars it up. \
./utils/build-script --preset=buildbot_linux install_destdir="/tmp/install" installable_package="/tmp/swift.tar.gz" && \
\
# Install our tarball to /usr/local \
tar xf /tmp/swift.tar.gz -C /usr/local --strip-components 1 && \
\
# Clean up \
cd / && \
rm -rf /tmp/swift.tar.gz /swift-dev && \
apt-get remove --purge -y $BUILDTIME_PACKAGES && \
apt-get autoremove --purge -y && \
apt-get clean -y && \
apt-get autoclean -y && \
rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
ENTRYPOINT ["bash"]
# swift
This is the smallest Swift Docker image that I know how to make. I use this image as a production base for Swift language projects.
## Rationale
The "supported" Swift configuration is Ubuntu. However, I run Debian, and prefer more minimal Docker images in general. So, I set out to create a "proper" minimal Debian image.
## Use
Just pull from drewcrawford/swift. It's installed to `/usr/local`.
## Build
You can build with `docker build .`. You may want to up the number of cores if you're using VirtualBox, because it takes a long time single-threaded.
### Source
Here's a riddle: if sourcecode exists on GitHub, and nobody compiles it, is the project open-source?
Answer: We compile it. So I don't know.
The Swift build system is kind of convoluted, and building an installable package is not documented anywhere (that I can find anyway). I guess we'll give clattner a pass for being awesome otherwise, but it is hairy.
I dove into the build system, and worked out what (I think) they do to build a tarball, and here it is! This image should build, run, test, and validate Swift exactly as upstream does. Then we just turn around and install that tarball to `/usr/local`.
Since we build from source, you could modify this image to apply your own custom patches before building if you like. As such this Dockerfile may be useful as a reference for a workflow for developing Swift itself.
## FAQ
### Q: Can't you use Alpine?
A: [No.](https://lists.swift.org/pipermail/swift-users/Week-of-Mon-20151228/000653.html)
### Q: How large is this image?
A: 472.2 MB, at the time of this writing. 125.1 of that is Debian, so the delta of Swift itself is 347.1MB.
We uninstall all the build dependencies, so I don't know how to make it smaller.
### Q: Do I need this image to run Swift binaries?
A: Probably not. You really only need this image to build Swift programs. You should use a volume or a `docker cp` to move the built products into your own image, that does not have Swift installed, for distribution.
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment