Skip to main content

Go App on CloudFlow

Learn how to run a "Hello World" Go app at the edge for low latency and high availability. You can use our repo as a template, or perform the steps yourself using the Kubernetes dashboard or kubectl commands.

Option 1 - Copy Our GitHub Repo

workflow status

Make a new repo from our template: in your browser visit https://github.com/section/go-template and select Use this template (don't clone, don't fork, but use the template). Choose yourself as an owner, give it a name of your choice, and make it be Public (not Private).

  1. In your new GitHub repo, under Settings > Secrets > Actions, use New repository secret to add these two:
  2. Make any change to ./helloworld.py and watch your changes go live.

Option 2 - Step by Step

Following are step-by-step instructions to deploy a Go "Hello World" application to the edge on CloudFlow. We'll Dockerize it, and deploy it on CloudFlow.

Prerequisites

  • You need Docker installed so that you can build a docker image.

Create the Go App

Create a new directory for your app.

mkdir my-go-app
cd my-go-app

Create helloworld.go with the following code.

helloworld.go
package main

import (
"fmt"
"net/http"
)

func main() {
http.HandleFunc("/", HelloServer)
http.ListenAndServe(":8080", nil)
}

func HelloServer(w http.ResponseWriter, r *http.Request) {
fmt.Fprintf(w, "Hello World from Go on CloudFlow!")
}

Dockerize It

Let's build the container image that we'll deploy to CloudFlow. First make a Dockerfile in your directory with the following content.

Dockerfile
FROM golang:1.19
WORKDIR /usr/src/my-go-app
RUN go mod init my-go-app
RUN go mod download && go mod verify
COPY . .
RUN go build -v -o /usr/local/bin/my-go-app ./...
CMD ["my-go-app"]
EXPOSE 8080

Build and tag it.

docker build . -t ghcr.io/YOUR_GITHUB_USERNAME/my-go-app:prod

Launch it locally to test it.

docker run -p 8080:8080 ghcr.io/YOUR_GITHUB_USERNAME/my-go-app:prod
curl http://localhost:8080

Push It

Push it to GitHub Packages. This makes it available to CloudFlow.

docker push ghcr.io/YOUR_GITHUB_USERNAME/my-go-app:prod

Be sure to make it public. To see your packages and make this change, visit https://github.com/YOUR_GITHUB_USERNAME?tab=packages

Deploy It

Next, use the Create Project command in the CloudFlow Console in order to deploy your new container. Use the image name ghcr.io/YOUR_GITHUB_USERNAME/my-go-app:prod with port 8080.

Apply this service resource to your Project with either the Kubernetes dashboard or kubectl apply -f ingress-upstream.yaml.

See the pods running on CloudFlow's network with either the Kubernetes dashboard or kubectl get pods -o wide. The -o wide switch shows where your app is running according to the default AEE location optimization strategy. Your app will be optimally deployed according to traffic. In lieu of significant traffic, your deployment will be made to default locations.

Finally, follow the instructions that configure DNS and TLS.

See What You've Built

See the "Hello World!" app you've built by visiting the https://YOUR.DOMAIN.COM, substituting YOUR.DOMAIN.COM according to your DNS and HTTPS configuration.