Out Plane LogoOut Plane

Go

Step-by-step guide to deploy a Go application on Out Plane

This guide walks you through deploying a Go application on Out Plane using Git-driven deployment with a Dockerfile.

Prerequisites

  • An Out Plane account
  • A GitHub account
  • Go 1.21+ installed on your machine
  • Git installed on your machine

Create the Go App

Create a new directory for your project:

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

Initialize a Go module:

go mod init github.com/YOUR_USERNAME/my-go-app

Replace YOUR_USERNAME with your GitHub username.

Create a file called main.go:

package main

import (
    "encoding/json"
    "log"
    "net/http"
    "os"
)

type Response struct {
    Message string `json:"message"`
}

func main() {
    port := os.Getenv("PORT")
    if port == "" {
        port = "8080"
    }

    http.HandleFunc("/", homeHandler)
    http.HandleFunc("/health", healthHandler)

    log.Printf("Server starting on port %s", port)
    log.Fatal(http.ListenAndServe(":"+port, nil))
}

func homeHandler(w http.ResponseWriter, r *http.Request) {
    w.Header().Set("Content-Type", "application/json")
    json.NewEncoder(w).Encode(Response{Message: "Hello from Out Plane"})
}

func healthHandler(w http.ResponseWriter, r *http.Request) {
    w.WriteHeader(http.StatusOK)
    w.Write([]byte("OK"))
}

Create the Dockerfile

Create a file called Dockerfile in your project root:

FROM golang:1.22-alpine AS builder

WORKDIR /app

COPY go.mod go.sum ./
RUN go mod download

COPY . .

RUN CGO_ENABLED=0 GOOS=linux go build -ldflags="-w -s" -o server .

FROM alpine:3.19

RUN apk --no-cache add ca-certificates

WORKDIR /app

COPY --from=builder /app/server .

EXPOSE 8080

CMD ["./server"]

Create a .dockerignore file:

.git
*.exe
*.test
.DS_Store

Test Locally

Run the application:

go run main.go

Open http://localhost:8080 in your browser. You should see the JSON response.

Push to GitHub

Initialize a Git repository and push to GitHub:

git init
git add .
git commit -m "Initial commit"
git remote add origin [email protected]:YOUR_USERNAME/my-go-app.git
git branch -M main
git push -u origin main

Replace YOUR_USERNAME with your GitHub username.

Deploy on Out Plane

Step 1: Install GitHub App

  1. Go to console.outplane.com
  2. Navigate to Applications from the sidebar
  3. Click Deploy Application
  4. If prompted, click Install GitHub App
  5. Select which repositories Out Plane can access
  6. Click Install and you'll be redirected back

Step 2: Select Repository

  1. Find your repository in the list
  2. Click to select it
  3. Choose the branch to deploy (default: main)
  4. Set Root Directory to /

Step 3: Configure Build

SettingValue
Build MethodSelect Dockerfile
Application NameEnter a unique name (e.g., my-go-app)
Port8080

Step 4: Select Resources

Go applications are lightweight and efficient:

InstancevCPURAMRecommended For
op-200.5512 MBMost Go apps
op-4611 GBHigher traffic
op-8222 GBHeavy workloads

Step 5: Configure Scaling

  • Min Scale: Set to 1 for always-on, or 0 for scale-to-zero
  • Max Scale: Set based on expected traffic

Step 6: Environment Variables (Optional)

Click Add Variable to add any required environment variables:

KeyValue
DATABASE_URLYour database connection string

Step 7: Deploy

  1. Review your configuration
  2. Click Create Application
  3. Wait for the build to complete (typically 1-2 minutes for Go)

Step 8: Access Your App

Once the deployment status shows Ready:

  1. Go to the application Overview tab
  2. Find your domain: my-go-app.outplane.app
  3. Click to open your live application

Using a Web Framework

Gin Example

Install Gin:

go get -u github.com/gin-gonic/gin

Update main.go:

package main

import (
    "os"
    "github.com/gin-gonic/gin"
)

func main() {
    port := os.Getenv("PORT")
    if port == "" {
        port = "8080"
    }

    gin.SetMode(gin.ReleaseMode)
    r := gin.Default()

    r.GET("/", func(c *gin.Context) {
        c.JSON(200, gin.H{"message": "Hello from Out Plane"})
    })

    r.GET("/health", func(c *gin.Context) {
        c.String(200, "OK")
    })

    r.Run(":" + port)
}

Run go mod tidy to update dependencies, then commit and push.

Automatic Deployments

Push to your branch to trigger automatic deployments:

git add .
git commit -m "Add new endpoint"
git push origin main

Database Connection

To connect to PostgreSQL, use a driver like pgx:

go get github.com/jackc/pgx/v5
import (
    "context"
    "os"
    "github.com/jackc/pgx/v5/pgxpool"
)

func initDB() (*pgxpool.Pool, error) {
    dbURL := os.Getenv("DATABASE_URL")
    return pgxpool.New(context.Background(), dbURL)
}

Next Steps

Buildpack alternative: Instead of Dockerfile, you can select Buildpack. Out Plane will auto-detect Go from your go.mod file and build automatically.