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-appInitialize a Go module:
go mod init github.com/YOUR_USERNAME/my-go-appReplace 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_StoreTest Locally
Run the application:
go run main.goOpen 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 mainReplace YOUR_USERNAME with your GitHub username.
Deploy on Out Plane
Step 1: Install GitHub App
- Go to console.outplane.com
- Navigate to Applications from the sidebar
- Click Deploy Application
- If prompted, click Install GitHub App
- Select which repositories Out Plane can access
- Click Install and you'll be redirected back
Step 2: Select Repository
- Find your repository in the list
- Click to select it
- Choose the branch to deploy (default:
main) - Set Root Directory to
/
Step 3: Configure Build
| Setting | Value |
|---|---|
| Build Method | Select Dockerfile |
| Application Name | Enter a unique name (e.g., my-go-app) |
| Port | 8080 |
Step 4: Select Resources
Go applications are lightweight and efficient:
| Instance | vCPU | RAM | Recommended For |
|---|---|---|---|
| op-20 | 0.5 | 512 MB | Most Go apps |
| op-46 | 1 | 1 GB | Higher traffic |
| op-82 | 2 | 2 GB | Heavy workloads |
Step 5: Configure Scaling
- Min Scale: Set to
1for always-on, or0for scale-to-zero - Max Scale: Set based on expected traffic
Step 6: Environment Variables (Optional)
Click Add Variable to add any required environment variables:
| Key | Value |
|---|---|
DATABASE_URL | Your database connection string |
Step 7: Deploy
- Review your configuration
- Click Create Application
- Wait for the build to complete (typically 1-2 minutes for Go)
Step 8: Access Your App
Once the deployment status shows Ready:
- Go to the application Overview tab
- Find your domain:
my-go-app.outplane.app - Click to open your live application
Using a Web Framework
Gin Example
Install Gin:
go get -u github.com/gin-gonic/ginUpdate 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 mainDatabase Connection
To connect to PostgreSQL, use a driver like pgx:
go get github.com/jackc/pgx/v5import (
"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.