DEV Community

Cover image for Hummingbird in the cloud
Szabolcs Toth
Szabolcs Toth

Posted on

Hummingbird in the cloud

Deploying your Server side Swift application using ARM-based server with Ubuntu in Oracle Cloud

The point, when you want to access your API server not only from localhost, comes very fast. When your application is in development phase, it is very difficult to commit yourself to any paid services, that's why I will show a way how to host your API server for free.

We will deploy our previously created parkAPI on Oracle Cloud Infrastructure (OCI). It offers you an "Always Free" Tier, you can find many tutorials on the web, how to register and start with it.

Although for the first sight it looks complicated, stay with me, you will see it is easy.

Step 1 - Create an ARM-based virtual machine with Ubuntu

Before creating the VM we need to configure the network.

Step 1.1 - Create a compartment

To easily separate the different workloads and setup user access properly, it is recommended to create a separate compartment.

  • Go to "Identity & Security", then from "Identity", choose "Compartments".

image 1

  • "Create Compartment" and fill "Name" and "Description".

image 2

Step 1.2 - Create Virtual Cloud Network (VCN)

  • Go to "Networking", then "Virtual cloud networks"

image 3

  • Set "Compartment" to "parkAPI"

image 4

  • "Create VCN" and fill "Name" and "PIv4 CIDR Blocks"

image 5

Step 1.3 - Create Subnets

  • Choose "Subnets" then "Create Subnet"

image 6

  • Fill "Name", "Create in Compartment", "IPv4 CIDR Block", choose "Public Subnet"

image 7

  • Add "Default Security List for VCN for parkAPI"

image 8

Step 1.4 - Create Internet Gateway (IG)

  • Choose "Internet Gateways", then "Create Internet Gateway"

image 9

  • Fill "Name" and "Create in Compartment"

image 10

Step 1.5 - Create Route rules

  • Choose "Route Tables" and click on "Default Route Table for VCN for parkAPI"

image 11

  • Click "Add Route Rules"

image 12

  • Set Internet Gateway

image 13

Step 1.6 - Create VM server

  • "Compute" and "Instances"

image 14

  • Set "Compartment" to "parkAPI" then "Create Instance"

image 15

  • Fill "Name", change "Image" to "Canonical Ubuntu 22.04 Minimal aarch64" and the "Shape" will automatically change to Ampere.

image 16

  • Assign the newly created VCN at "Networking" section

image 17

  • At "Add SSH keys" you either "Generate a key pair for me" or "Paste public keys", but you must have to set SSH key for administration purposes.

image 18

  • "Create"

Step 1.7 - Test our newly created server

Step 1.7.1 - Enable ping

By default OCI doesn't allow ping traffic, you need to allow it.

  • Go to "Security Lists" then click on "Default Security List for VCN for parkAPI"

image 19

  • Click on "Add Ingress Rules"
    image 20

  • Fill "Source CIDR| "IP Protocol" and "Type"

image 21

  • Go to "Instances" and set "Compartment" to "parkAPI" and you will see your public IP

image 22

  • Now you can try:
$ ping 144.24.166.181 -c 5
Enter fullscreen mode Exit fullscreen mode

Step 1.7.2 - Use ssh to login

$ ssh -i oci ubuntu@144.24.166.181` 
Enter fullscreen mode Exit fullscreen mode

where oci is your private SSH key.

Step 2. - Install Swift

  • Install developer tools
$ sudo apt install clang libpython2.7 libpython2.7-dev
Enter fullscreen mode Exit fullscreen mode
  • Download the Swift release for aarch64 platform
$ wget https://download.swift.org/swift-5.8.1-release/ubuntu2204-aarch64/swift-5.8.1-RELEASE/swift-5.8.1-RELEASE-ubuntu22.04-aarch64.tar.gz
Enter fullscreen mode Exit fullscreen mode
  • Unpack it
$ tar xzf swift-5.8.1-RELEASE-ubuntu22.04-aarch64.tar.gz
Enter fullscreen mode Exit fullscreen mode
  • Move the unpacked Swift folder under /usr
$ sudo mv swift-5.8.1-RELEASE-ubuntu22.04-aarch64 /usr/share/swift
Enter fullscreen mode Exit fullscreen mode
  • Add it to your PATH
$ echo "export PATH=/usr/share/swift/usr/bin:$PATH" >> ~/.bashrc
Enter fullscreen mode Exit fullscreen mode
  • Reload your SHELL with the updated PATH
$ source ~/.bashrc
Enter fullscreen mode Exit fullscreen mode
  • Test your Swift version
$ swift -v
Enter fullscreen mode Exit fullscreen mode

Step 3 - Install git

$ sudo apt install git
Enter fullscreen mode Exit fullscreen mode

Step 4 - Install and configure NGINX

  • Install NGINX server
$ sudo apt install nginx
Enter fullscreen mode Exit fullscreen mode
  • Start the service
$ sudo systemctl start nginx.service
Enter fullscreen mode Exit fullscreen mode
  • Add a rule at the top of the INPUT and OUTPUT chain to ACCEPT connexions to port 80. Try again after adding these rules:
$ sudo iptables -I INPUT -p tcp --dport 80 -m conntrack --ctstate NEW,ESTABLISHED -j ACCEPT

$ sudo iptables -I OUTPUT -p tcp --sport 80 -m conntrack --ctstate ESTABLISHED -j ACCEPT
Enter fullscreen mode Exit fullscreen mode
  • Before you can check your web server, you need to open the port: 80 on OCI side as well.

Under the Networking / Virtual cloud networks / Virtual Cloud / Network Details / Security Lists click on "Default Security List for VCN for parkAPI".

image 23

"Add Ingress Rules" and fill it.

image 24

Now, you will see your web server running.

Step 5 - Clone and run our API server

  • Clone our Hummingbird app from Github:
$ git clone https://github.com/kicsipixel/parkAPI
Enter fullscreen mode Exit fullscreen mode
  • Run your app
$ swift run parkAPI
Enter fullscreen mode Exit fullscreen mode
  • To be able to reach your API server you need to configure NGINX to serve as reverse proxy and connect localhost:8080 to www: 80.

Step 5 - NGINX as reverse proxy

  • Remove the default NGINX config
$ sudo unlink /etc/nginx/sites-enabled/default
Enter fullscreen mode Exit fullscreen mode
  • Create your own parkAPI.conf file under /etc/nginx/sites-available/
server {
    listen 80;
    listen [::]:80;    

    server_name 144.24.166.181 www.144.24.166.181;    

    location / {
        proxy_pass http://127.0.0.1:8080;
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection 'upgrade';
        proxy_set_header Host $host;
        proxy_cache_bypass $http_upgrade;
    }
}
Enter fullscreen mode Exit fullscreen mode
  • Create a symlink to sites-enabled
$ sudo ln -s /etc/nginx/sites-available/parkAPI.conf /etc/nginx/sites-enabled/parkAPI.conf
Enter fullscreen mode Exit fullscreen mode
  • Restart the server
$ sudo systemctl reload nginx
Enter fullscreen mode Exit fullscreen mode
  • Test your server in the browser.

image 25

Congratulations, your Hummingbird server is running in the cloud.

Top comments (0)