/IBM_SWIFT

https://github.com/IBM-Bluemix/swift-helloworld

Primary LanguageSwiftApache License 2.0Apache-2.0

Build Status - Master macOS Linux Dependency Status

BLAH BLAH BBLAH

#Swift HelloWorld App Overview This project contains a simple Swift hello world application that can be deployed to Bluemix or run locally on your OS X or Ubuntu Linux system. This sample application creates a basic server that returns an HTML greeting to the client. Please note that this is not a production-ready application. Instead, it is for educational purposes to learn about the types of applications you can develop using the Swift programming language.

Application Requirements

To compile and run this sample application on your system, you need to install the Swift compiler for your platform. Please note that the Swift language is evolving and changing rapidly. The latest version of this Swift application works with the DEVELOPMENT-SNAPSHOT-2016-06-06-a version of the Swift binaries. You can download this version of the Swift binaries by following this link.

If you are interested in manually deploying the application to Bluemix, you'd need to install the Cloud Foundry command line on your system. Once it is installed, you can use it to authenticate and access your Bluemix organization(s) and spaces. You can find further details on how to deploy this sample application to Bluemix in the following sections.

Run the app locally

Once you have installed the Swift compiler and cloned this Git repo, you can now compile and run the application. Go to the root folder of this repo on your system and issue the following command:

$ swift build

You should see an output similar to the following:

Compile Swift Module 'SwiftyJSON' (2 sources)
Compile Swift Module 'CloudFoundryEnv' (7 sources)
Compile Swift Module 'Utils' (6 sources)
Compile Swift Module 'Server' (1 sources)
Linking .build/debug/Server

Once the application is successfully compiled, you can run the executable that was generated by the Swift compiler:

$ .build/debug/Server

You should see an output similar to the following:

Server is listening on port: 8090

To connect to the server, you can use the browser of your preference (e.g. Firefox, Chrome, etc.) to point to the following URL: http://<hostname>:8090/, where <hostname> is the hostname or the IP address of the system where you are running the sample app. If the browser is running on the same system, you can use localhost as the value for the hostname. After you access the server, the browser should render an HTML page with the following message:

Hello from Swift on Linux!

Below the greeting message, you should also see an HTML table that displays the environment variables for the app.

Running the app on Bluemix

Using the magical button

Click the magical button below to automatically deploy this sample application to Bluemix.

Deploy to Bluemix

When automatically deploying to Bluemix, the manifest.yml file [included in the repo] is parsed to obtain the name of the application. For further details on the structure of the manifest.yml file, see the Cloud Foundry documentation.

Using the Cloud Foundry command line

You can also manually deploy the app to Bluemix. Though not as magical as using the Bluemix button above, manually deploying the app gives you some insights about what is happening behind the scenes. Remember that you'd need the Cloud Foundry command line installed on your system to deploy the app to Bluemix.

Using the Cloud Foundry command line you can get a list of the buildpacks (along with their versions) that are installed on Bluemix.

cf buildpacks

Executing the above command should result in output similar to the following:

Getting buildpacks...

buildpack                                 position   enabled   locked   filename   
liberty-for-java                          1          true      false    buildpack_liberty-for-java_v2.9-20160519-1249.zip   
sdk-for-nodejs                            2          true      false    buildpack_sdk-for-nodejs_v3.4-20160518-1653.zip   
noop-buildpack                            3          true      false    noop-buildpack-20140311-1519.zip   
java_buildpack                            4          true      false    java-buildpack-v3.5.1.zip   
ruby_buildpack                            5          true      false    ruby_buildpack-cached-v1.6.9.zip   
nodejs_buildpack                          6          true      false    nodejs_buildpack-cached-v1.5.3.zip   
go_buildpack                              7          true      false    go_buildpack-cached-v1.7.0.zip   
python_buildpack                          8          true      false    python_buildpack-cached-v1.5.2.zip   
php_buildpack                             9          true      false    php_buildpack-cached-v4.3.0.zip   
swift_buildpack                           10         true      false    swift_buildpack-cached-v1.1.1.zip   
aspnet5-experimental                      11         true      false    buildpack_aspnet5-experimental_v0.7-20151022-1257.zip   
xpages_buildpack                          12         true      false    xpages_buildpack_v1.1.1-20160518-0936.zip   
aspnet5-experimental_v0_6-20150916-1220   13         true      false    buildpack_aspnet5-experimental_v0.6-20150916-1220.zip   
liberty-for-java_v2_3-20151208-1311       14         true      false    liberty-for-java_v2.3-20151208-1311.zip   
sdk-for-nodejs_v3_3-20160428-1409         15         true      false    buildpack_sdk-for-nodejs_v3.3-20160428-1409.zip   
liberty_for_java_v2_8-20160430-1011       16         true      false    buildpack_liberty-for-java_v2.8-20160430-1011.zip   
xpages_buildpack_v1_0_0-20160310-1442     17         true      false    xpages_buildpack_v1.0.0-20160310-1442.zip   
swift_buildpack-cached-v1_0_3             18         true      false    swift_buildpack-cached-v1.0.3.zip

Looking at the output above, we can see that the Swift buildpack (v1.1.1) is installed on Bluemix. This will allow a seamless deployment of the starter application to Bluemix. After you have cloned this Git repo, go to its root folder on your system and issue the following command Cloud Foundry command:

cf push

Executing the Cloud Foundry push command will parse the contents of the manifest.yml file and upload the application to Bluemix. This action should generate an output similar to the following:

Using manifest file /Users/olivieri/git/swift-helloworld/manifest.yml

Updating app swift-helloworld in org roliv@us.ibm.com / space dev as roliv@us.ibm.com...
OK

Uploading swift-helloworld...
Uploading app files from: /Users/olivieri/git/swift-helloworld
Uploading 34.8K, 14 files
Done uploading               
OK

Stopping app swift-helloworld in org roliv@us.ibm.com / space dev as roliv@us.ibm.com...
OK

Starting app swift-helloworld in org roliv@us.ibm.com / space dev as roliv@us.ibm.com...
-----> Downloaded app package (16K)
Cloning into '/tmp/buildpacks/swift-buildpack'...
-----> Installing system level dependencies...
-----> Installing libblocksruntime0_0.1-1_amd64.deb
-----> Installing libblocksruntime-dev_0.1-1_amd64.deb
-----> Installing libcurl3_7.35.0-1ubuntu2.6_amd64.deb
-----> Installing libkqueue0_1.0.4-2ubuntu1_amd64.deb
-----> Installing libssl-dev_1.0.1f-1ubuntu2.19_amd64.deb
-----> Installing openssl_1.0.1f-1ubuntu2.19_amd64.deb
-----> Writing profile script...
-----> Buildpack version 1.1.4
-----> Installing Swift DEVELOPMENT-SNAPSHOT-2016-06-06-a
       Downloaded Swift
-----> Installing Clang 3.7.0
       Downloaded Clang
-----> Adding libdispatch binaries...
-----> Building Package...
       Cloning https://github.com/IBM-Swift/Swift-cfenv.git
       HEAD is now at eefdf83 Migrating code to swift 06-06.
       Resolved version: 1.3.0
       Cloning https://github.com/IBM-Swift/SwiftyJSON.git
       HEAD is now at 3dc35da IBM-Swift/Kitura#504 updates to work on linux os for 31-05 migration (#5)
       Resolved version: 9.0.0
       Cloning https://github.com/IBM-Swift/BlueSocket.git
       HEAD is now at 6e8915c Added blurb about BlueSSLService add-on.
       Resolved version: 0.5.20
       Compile Swift Module 'SwiftyJSON' (2 sources)
       Compile Swift Module 'Socket' (3 sources)
       Compile Swift Module 'CloudFoundryEnv' (7 sources)
       Compile Swift Module 'Utils' (3 sources)
       Compile Swift Module 'Server' (1 sources)
       Linking .build/release/Server
-----> Copying dynamic libraries
-----> Copying binaries to 'bin'
-----> Cleaning up build files
-----> Cleaning up cache folder

0 of 1 instances running, 1 starting
1 of 1 instances running

App started


OK

App swift-helloworld was started using this command `Server`

Showing health and status for app swift-helloworld in org roliv@us.ibm.com / space dev as roliv@us.ibm.com...
OK

requested state: started
instances: 1/1
usage: 128M x 1 instances
urls: swift-helloworld-leptophyllous-redbone.mybluemix.net
last uploaded: Wed Jul 13 15:38:05 UTC 2016
stack: unknown
buildpack: Swift

     state     since                    cpu    memory          disk          details   
#0   running   2016-07-13 10:41:00 AM   0.0%   12.2M of 128M   30.7M of 1G      
Ricardos-MacBook-Pro:swift-helloworld olivieri$

Once the sample application is pushed to Bluemix, you can access it using its route. You can log on to your Bluemix account to find the route of your application or you can inspect the output from the execution of the cf push command. The string value (e.g. swift-helloworld.mybluemix.net) shown next to the urls should contain the route. Use that route as the URL to access the sample server using the browser of your choice. The browser should render an HTML page with the following message at the top:

Hello from Swift on Linux!

Using a different version of Swift on Bluemix for your application

If you look closely at the output above returned by the cf push command, you will notice that DEVELOPMENT-SNAPSHOT-2016-06-06-a was the Swift version used for compiling and running the sample app on Bluemix. If you have a Swift application that compiles with a different version of the Swift binaries, say DEVELOPMENT-SNAPSHOT-2016-04-25-a, you'd need to update the contents of the .swift-version file to:

DEVELOPMENT-SNAPSHOT-2016-04-25-a

After updating the .swift-version file, you can run the cf push -b https://github.com/IBM-Swift/swift-buildpack command. Note that if using a version of the Swift binaries other than DEVELOPMENT-SNAPSHOT-2016-06-06-a, you'd need to add the -b https://github.com/IBM-Swift/swift-buildpack parameter for the execution of the push command. This action should upload your application to Bluemix and use the DEVELOPMENT-SNAPSHOT-2016-04-25-a version of the Swift binaries for compiling and running your application as shown.

For a complete list of the Swift versions currently supported by the Swift buildpack for Bluemix, see the buildpack's manifest file. If you cannot find the version of the Swift binaries you are looking for in this file, then that version is not currently supported.

What's next?

As new releases of the Swift binaries are made available at (Swift.org)[https://swift.org/], our team will update the (Swift buildpack)[https://github.com/IBM-Swift/swift-buildpack] for Bluemix and this sample app. Stay tuned for updates!