Optimize image create in Bluebox for use with Test Kitchen
How can I use Swift as a simple websever?
I received this question a few times recently. Below is a quick how to using Bluemix object storage.
Login into your BlueMix account here. After you login, select catalog from the top navigation. On the left navigation bar select the checkbox next to Storage to limit the display to IBM Cloud storage services only. Your screen should look like this:
After a few moments, the IBM Cloud Object Storage service should be created and added to your Bluemix space.
Click on service credentials on the left navigation bar to find your API key.
Note this API key, you will need it to access your object storage instance.
Your Bluemix space now has object storage enabled
Click on “Manage” on the left navigation bar. Then click “Add a container”
After clicking “Add a container” you will be prompted to give the container a name. Choose whatever name you want.
Click on “Add files” to upload new files to your container. This will open a file selector window. I uploaded the Openstack image you see above.
Once you select your file, your container information in Bluemix should update with storage space consumed and details on the uploaded file.
Follow the steps in the Bluemix Docs to setup and install the swift CLI.
Once the CLI is installed the first step will be to take the service credentials you noted earlier and export them into the appropriate environment variables for the swift tool. Below is an example.
Next execute the “swift auth” command. This will authenticate the swift session and output the storage path to the files that were added.
Note the OS_STORAGE_URL, this is the base URL for all unauthentacted public requests to object storage.
Use the swift command to enable unauthenticated read access to the container.
Noting the OS_STORAGE_URL above, the fully constructed URL for my object is:
Test accessing this with wget:
If the above command outputs exists, the file is now readable by all. Any additional files you add to the container will now also be readable from the web.
You can use use Bluemix object storage as a quick and dirty webserver. However, object storage does not give you the full control and customizations usually needed for a production web server. For simple things this is an easy way to get objects onto the web. In fact, I am serving the openstack logo at the top of this page out of Bluemix object storage.
Should you run into any issues consult the BlueMix Documentation or reach out to me on twitter