Giter VIP home page Giter VIP logo

swift-ubuntu-docker's Introduction

Build Status - Master

Swift 5 - Ubuntu Docker

This repo contains the code for generating two Docker images for Swift:

  • The ibmcom/swift-ubuntu image contains the Swift 5.0.2 RELEASE toolchain as well as the dependencies for running Kitura-based applications. Our development team uses this image for development and testing of Swift 5 applications on the Linux Ubuntu (v14.04) operating system.

  • The ibmcom/swift-ubuntu-runtime image contains only those libraries (.so files) provided by the Swift 5.0.2 RELEASE toolchain that are required to run Swift applications. Note that this image does not contain SwiftPM or any of the build tools used when compiling and linking Swift applications. Hence, the size for the ibmcom/swift-ubuntu-runtime image (~300 MB) is much smaller than that of the ibmcom/swift-ubuntu image. The ibmcom/swift-ubuntu-runtime image is ideal for provisioning your Swift application as an IBM Container on the IBM Cloud.

  • The ibmcom/swift-ubuntu-xenial and ibmcom/swift-ubuntu-xenial-runtime images follow a similar convention, but for Linux Ubuntu 16.04. These images are multi-arch so will pull down the appropriate image for your architecture. We currently offer support for amd64 and s390x architectures.

Recent updates

  1. Upgraded to the Swift 5.0.2 RELEASE binaries.
  2. Changed location of Swift binaries and libraries so they are available system wide (not just for the root user).
  3. Reduced number of layers in images.
  4. Removed system packages no longer needed.
  5. Aligned version of Ubuntu with version found in Cloud Foundry environments (v14.04).
  6. Reduced size of the Docker image.
  7. Updated Dockerfiles per guidelines in Best practices for writing Dockerfiles.
  8. Added Support for amd64 and s390x architectures of Xenial Linux Ubuntu 16.04.

Quick Start

The easiest way to get started is by using the Kitura command line tools to generate the docker files needed, and copy them over to your project. If you just want to explore our supported base images, see the next sections.

To get started with kitura init:

  1. Create a new directory, change into it and run kitura init. This will generate a project which will include two files named Dockerfile and Dockerfile-tools.
  2. Copy the Dockerfile and Dockerfile-tools files into your project's root directory (this is the directory that contains your Package.swift file and the Sources and Tests folders).
  3. Edit the Dockerfile in a text editor and replace references to your kitura init folder with the name of your project. Dockerfile-Tools has preconfigured behavior to download and compile Swift binaries and copy the executable into your application. It doesn't need editing.
  4. Run the following commands, replacing YOUR_PROJECT with the name of your project. Note: Use all lower case letters for your projects name and replace spaces with dashes.
    1. docker build -t YOUR_PROJECT-build -f Dockerfile-tools .
    2. docker run -v $PWD:/root/project -w /root/project YOUR_PROJECT-build /swift-utils/tools-utils.sh build release
    3. docker run -it -p 8090:8080 -v $PWD:/root/project -w /root/project YOUR_PROJECT-run sh -c ".build-ubuntu/release/YOUR_PROJECT"

Dockerfile-tools is responsible for downloading the Swift binaries and builds the exectuables.

The Dockerfile then copies the applications source code, and then compiled executable into the runtime image of the application. This means the large Swift binary file isn't copied into your application, and reduces the overall size of your app, meaning faster uploads and a smaller storage quota impact.

The final command runs your Docker image locally.

This was the quickest way to get started, but if you just want see explore our base images then see the following sections for detailed instructions.

ibmcom/swift-ubuntu

Pulling ibmcom/swift-ubuntu from Docker Hub

Run the following command to download the latest version of the ibmcom/swift-ubuntu image from Docker Hub:

docker pull ibmcom/swift-ubuntu:latest

Use a specific version of ibmcom/swift-ubuntu

Docker images are tagged with Swift version number. To use the Swift 5.0.2 image from Docker Hub, issue the following command:

docker pull ibmcom/swift-ubuntu:5.0.2

Using ibmcom/swift-ubuntu for development

Mount a folder on your host to your Docker container using the following command:

docker run -i -t -v <absolute path to the swift package>:/<swift package name> ibmcom/swift-ubuntu:5.0.2

After executing the above command, you will have terminal access to the Docker container (the default command for the image is /bin/bash). This will allow you to build, test, and run your Swift application in a Linux environment (Ubuntu v14.04).

Privileged mode

If you attempt to run the Swift REPL and you get the error failed to launch REPL process: process launch failed: 'A' packet returned an error: 8, then you should run your Docker container in privileged mode:

docker run --privileged -i -t ibmcom/swift-ubuntu:5.0.2

This issue is described at https://bugs.swift.org/browse/SR-54.

ibmcom/swift-ubuntu-xenial

Pulling ibmcom/swift-ubuntu-xenial from Docker Hub

Run the following command to download the latest version of the ibmcom/swift-ubuntu-xenial image from Docker Hub:

docker pull ibmcom/swift-ubuntu-xenial:latest

This image supports both amd64 and s390x architectures and will pull down the correct image based on the architecture you are using i.e. ibmcom/swift-ubuntu-xenial-amd64 or ibmcom/swift-ubuntu-xenial-s390x.

Using ibmcom/swift-ubuntu-xenial for development

Mount a folder on your host to your Docker container using the following command:

docker run -i -t -v <absolute path to the swift package>:/<swift package name> ibmcom/swift-ubuntu-xenial:latest

After executing the above command, you will have terminal access to the Docker container (the default command for the image is /bin/bash). This will allow you to build, test, and run your Swift application in a Linux environment (Ubuntu v16.04, amd64 or s390x), depending on your architecture.

Privileged mode

If you attempt to run the Swift REPL and you get the error failed to launch REPL process: process launch failed: 'A' packet returned an error: 8, then you should run your Docker container in privileged mode:

docker run --privileged -i -t ibmcom/swift-ubuntu-xenial:latest

This issue is described at https://bugs.swift.org/browse/SR-54.

ibmcom/swift-ubuntu-runtime

Pulling ibmcom/swift-ubuntu-runtime from Docker Hub

Run the following command to download the latest version of the ibmcom/swift-ubuntu-runtime image from Docker Hub:

docker pull ibmcom/swift-ubuntu-runtime:latest

Use a specific version of ibmcom/swift-ubuntu-runtime

Docker images are now tagged with Swift version number. To use the Swift 5.0.2 image from Docker Hub, issue the following command:

docker pull ibmcom/swift-ubuntu-runtime:5.0.2

Using ibmcom/swift-ubuntu-runtime

You can extend the ibmcom/swift-ubuntu-runtime image in your own Dockerfile to add your Swift application binaries (and any other dependencies you may need). For instance, the next sample Dockerfile simply adds the binaries for the Kitura-Starter application and specifies the command to start the server (total image size after adding the Kitura-Starter binaries is ~300MB):

# Builds a Docker image for running the Kitura-Starter sample application.

...

FROM ibmcom/swift-ubuntu-runtime:5.0.2
LABEL Description="Docker image for running the Kitura-Starter sample application."

USER root

# Expose default port for Kitura
EXPOSE 8080

# Binaries should have been compiled against the correct platform (i.e. Ubuntu 14.04).
RUN mkdir /Kitura-Starter
ADD .build/debug/Kitura-Starter /Kitura-Starter
ADD .build/debug/*.so /Kitura-Starter
ADD .build/debug/*.so.* /Kitura-Starter
CMD [ "sh", "-c", "/Kitura-Starter/Kitura-Starter" ]

For details on how to create an IBM Container to execute a Swift application, please see 10 Steps To Running a Swift App in an IBM Container and Running Kitura in an IBM Container.

Exposing ports in your Docker container

Exposing your server's port running in a Docker container to the host system (e.g. macOS) is quite easy using the latest version of Docker:

docker run -p <host port>:<container port> [additional options] <image name>

For example, if your Swift server is running on port 8080, and you want to make it accessible via port 9080 on the host system, run the following command:

docker run -p 9080:8080 [additional options] <image name>

Port 8080 in the container will then be mapped to port 9080 on the host system. For further details on the -p option, see the official Docker documentation.

Contributing

Improvements are very welcome! You can find more info on contributing in our contributing guidelines.

swift-ubuntu-docker's People

Contributors

akimacho avatar bdhernand avatar csjones avatar dgrove-oss avatar dingwilson avatar djones6 avatar graemer957 avatar ianpartridge avatar jpkessle avatar kyemaloy97 avatar rolivieri avatar sandmman avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

swift-ubuntu-docker's Issues

Update to Ubuntu 16.04 LTS?

Want to run perfect.org, but for ubuntu 14 I have to patch openssl to 1.0.2 (manually without apt-get) to get things working. It's not necessary when ubuntu 16 base image is used.

clone_build_kitura.sh doesn't exist where expected in last image

I'm following the steps here:
http://www.kitura.io/en/starter/deploying.html

According to this line:

From within the Docker container, execute the clone_build_kitura.sh script to build the Kitura-Starter sample project:

There should be a clone_build_kitura.sh file in /root/ of the container.

$ docker image ls
ibmcom/kitura-ubuntu   latest              2ce2120d8fe2        12 days ago         1.24 GB
$ docker run -ti -p 8090:8090 ibmcom/kitura-ubuntu:latest /bin/bash
# ls root/
Kitura-Starter  swift-3.0.2-RELEASE-ubuntu14.04

Thanks!

Thanks for supporting Kitura Ubuntu Swift Docker images. I just switched over to using them. It did take me a bit of searching to find them. Is this repo linked to the main Kitura repos? (I didn't see such links).

Cannot open shared object file in 16.04

Hi,

I tested the https://github.com/IBM-Swift/Kitura-Sample with the 16.04-runtime image, but it doesn't work, the 14.04-runtime image is working.
The error happens when I want to run the docker-image, I get the following error:

error while loading shared libraries: libicuuc.so.52: cannot open shared object file: No such file or directory

I used the following dockerfile within the kitura-sample project:

# ===== builder =====
FROM ibmcom/swift-ubuntu-xenial-amd64:4.1 as builder

RUN mkdir -p /appcode
COPY Sources /appcode/Sources
COPY Tests /appcode/Tests
COPY Package.swift /appcode/
RUN cd /appcode && swift build --configuration release

# ===== runtime =====
FROM ibmcom/swift-ubuntu-xenial-runtime-amd64:4.1

USER root

# Expose default port for Kitura
EXPOSE 8080

COPY --from=builder /appcode/.build/release /apps/kitura/.build/release/
COPY public /apps/kitura/public
COPY chat /apps/kitura/chat
COPY Views /apps/kitura/Views

ENTRYPOINT [ "sh", "-c", "cd /apps/kitura && .build/release/Kitura-Sample" ]

When I use FROM ibmcom/swift-ubuntu:4.1 as builder and FROM ibmcom/swift-ubuntu-runtime:4.1 everything is working.

I tried to debug it a little bit. It looks like the problem is, that the runtime-image is deleting the files in the following directory:

swift-4.1-RELEASE-ubuntu16.04/usr/lib/swift/linux/*

(I tried to extract them back from the swift-tar, than it worked. But I don't know if this would be the right solution, because the 14.04 image is doing the same)

Tagged Docker Images

Thanks for providing a Docker image for Kitura-based apps. I was wondering if you could tag your Docker images so that developers can update their environment independently of Kitura releases.

For example, I used Kitura with swift-DEVELOPMENT-SNAPSHOT-2016-07-25-a for a while before I was able to upgrade to more recent versions of Swift. Meanwhile, the Docker image started using a newer version of Swift, which broke my Docker build referencing ibmcom/swift-ubuntu:latest.

My suggestion would be to tag the Docker images with the Swift version they are based on.

Volume Mount

I was wondering if it would be interesting to add VOLUME key within the docker file to allow user to mount a local volume.
It would be interesting eg. to allow a mac user to edit locally his file and use only the docker env to compile and test like a sandbox.

Dunno like it happens in other docks mount a volume like

/data/swift

swift-slim ?

Hi,

Is there any interest in building a docker container with the swift dependencies built into a statically compiled binary? 1.2GB from ubuntu guts and the full gcc buildchain is kind of rough.

Cannot open shared object file in 18.04 (libFoundation.so)

Hello,
I have similar problem with #56 . Maybe I made something wrong.
I try to launch a binary release swift file.

My Dockerfile:
FROM ibmcom/swift-ubuntu-runtime:latest COPY . /app CMD ["/app/server"]

I have error:
/app/server: error while loading shared libraries: libFoundation.so: cannot open shared object file: No such file or directory

Can you help with it?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.