Pragmatism in the real world

Using CircleCI for a PHP project

For a new client project, I've decided to use CircleCI to run my tests every time I push to GitHub. This turned out to be quite easy; this is how I did it. I started by creating a config file, .circleci/config.yml containing the following: version: 2 jobs: build: working_directory: /var/www/html docker: – image: php:7.1-apache environment: APP_ENV: test steps: – run: name: Install system packages command: apt-get update && apt-get -y install git – run: name:… continue reading.

Automatically converting PDF to Keynote

I use rst2pdf to create presentations which provides me with a PDF file. When it comes to presenting on stage, on Linux there are tools such as pdfpc and on Mac there's Keynote. Keynote doesn't read PDF files by default, so we have to convert them and the tool I use for this is Melissa O'Neill's PDF to Keynote. This is a GUI tool, so I manually create the Keynote file when I need it… continue reading.

Detecting OpenWhisk web actions

I've already written about OpenWhisk web actions and how they allow you to send a status code and HTTP headers to the client by returning a dictionary with the keys status, headers and body from your main() method: func main(args: [String:Any]) -> [String:Any] { return [ "body": "Hello world", "statusCode": 200, "headers": [ "Content-Type": "text/xml", ], ] } If this test action is in the default namespace, then we create it with wsk action update… continue reading.

Calling an OpenWhisk action in Swift

As OpenWhisk is a Functions as a Service system, it makes sense to create actions that do one thing and call other actions when they want other work done. As an example, in DrinksChooser, the choose action calls the incrementDrinkCount action which increments the count of the recommended drink in Redis. This way, choose doesn't have to know anything about Redis as that's not its job. In OpenWhisk's Swift environment, there's the Whisk.invoke() method to… continue reading.

Passing secrets to your OpenWhisk action

There is only one way to pass data into your OpenWhisk action: parameters. Your function receives a dictionary of parameters and returns one. Let's explore how you can set these parameters. Parameters passed to the action You can see this by creating this action: test.swift func main(args: [String:Any]) -> [String:Any] { return args } Add the action to OpenWhisk with: wsk action update params params.swift -a web-export true and test: $ wsk action invoke -b… continue reading.

Quick tip: OpenWhisk autocompletion

I've just discovered how to enable Bash autocompletion for the wsk command line tool! $ cd /usr/local/bin $ wsk sdk install bashauto This will create a file called wsk_cli_bash_completion.sh in your /usr/local/bin directory. Now, source this file within your .bash_profile or equivalent: $ echo -e "\n# OpenWhisk autocompletion\nsource ~/bin/wsk_cli_bash_completion.sh" >> ~/.bash_profile Start a new terminal window, (or source ~/.bash_profile in your current one) and you can now press the tab key after typing wsk to… continue reading.

Error handling in OpenWhisk actions

With a standard OpenWhisk action, we return a dictionary of the data and let OpenWhisk deal with converting it to JSON etc. OpenWhisk will also set the correct 200 status code. How do we handle an error though? It turns out that if there is a key called "error" in our returned dictionary, then all the other data is ignored and an error is sent back. To show this, consider this action: func main(args: [String:Any])… continue reading.

Using ngrok to test on a mobile

To test a website that you're developing on your local computer on a mobile device such as a phone or tablet use ngrok. This is the way to do it: Start up ngrok: $ ngrok http my-dev-site.local:80 This will start up ngrok and give you a "Forwarding" URL such as http://24f55bf5.ngrok.io. In this case, it will direct all traffic to that URL to http://my-dev-site.local. If you run your website on a different port, such as… continue reading.

OpenWhisk web actions

The first way that you learn to call your OpenWhisk action over HTTP is a POST request that is authenticated using your API key. This key allows all sorts of write access to your account, so you never release it. If you want to access the action over HTTP without the API key, you have two choices: Web Actions or API Gateway. This article discusses how to use Web Actions as they are very useful… continue reading.

Serverless Swift on OpenWhisk

I'm interested in serverless computing and as I write Swift, the OpenWhisk platform comes up high when you Google. This turns out to be a really good choice as OpenWhisk is Open Source so I can read the source code (and have done!). In principle, I can also run my own instance of it if I need to to for regulatory reasons, or just to avoid vendor lock-in. Commercially, the whole point of Serverless (aka… continue reading.