Go Web Server¶
A minimal web server written in Go using the standard library. Demonstrates deploying a compiled language application on AppMecca with multi-stage Docker builds for small, efficient images.
Overview¶
| Repository | git@gitlab.com:appmecca-sample-apps/go-web-server.git |
| Tech Stack | Go 1.22 / stdlib net/http |
| Services | web (port 8080) |
| Database | None |
| Cache | None |
| URL Pattern | https://go-web-server-web.{env}.appmecca.net |
What This App Demonstrates¶
- Deploying a compiled Go binary on AppMecca
- Multi-stage Docker builds (compile in one stage, run in another)
- Minimal container images (around 15 MB vs 300+ MB)
- Using Go's standard library for HTTP serving
appmecca.yaml¶
containers:
- name: web
dockerfile: Dockerfile
context: .
deploy:
- name: web
container: web
port: 8080
health_check:
path: /health
The configuration is identical in structure to any other single-container app. The only difference is the port -- Go's net/http is configured to listen on 8080 by convention.
Step-by-Step Deployment¶
1. Register the app¶
2. Build the container¶
Expected output
Go builds tend to be fast because the compiler produces a single static binary with no runtime dependencies.
3. Deploy¶
Expected output
4. Verify¶
mecca queue status takes the action ID printed when you deployed. To look up the app
itself — including the exact URL for your group — use mecca app show:
Test the endpoint:
Key Concepts¶
Multi-stage Docker builds¶
Go applications benefit significantly from multi-stage builds. The first stage uses the full Go toolchain to compile the binary. The second stage copies only the compiled binary into a minimal base image.
# Stage 1: Compile
FROM golang:1.22-alpine AS builder
WORKDIR /app
COPY main.go .
RUN go build -o server main.go
# Stage 2: Run
FROM alpine:3.19
COPY --from=builder /app/server /server
EXPOSE 8080
CMD ["/server"]
Image size comparison
| Stage | Image size |
|---|---|
golang:1.22-alpine (build stage) |
~300 MB |
| Final image (Alpine + binary) | ~15 MB |
The final image contains only Alpine Linux and your compiled binary. No Go toolchain, no source code, no build artifacts.
Static binaries¶
Go compiles to a static binary by default, which means the resulting executable has no external dependencies. This lets you use extremely small base images like alpine or even scratch (an empty image).
Port conventions¶
Go applications commonly listen on port 8080, but you can use any port. The port value in appmecca.yaml must match whatever your application listens on inside the container. AppMecca handles the external routing -- users always access your app over HTTPS on port 443.
Any language, same workflow
AppMecca does not care what language your application is written in. As long as your container listens on the declared port and responds to health checks, the deployment workflow is identical for Go, Python, Node.js, Rust, Java, or anything else.
What's Next?¶
- Hello Flask -- see the same pattern in Python
- Node Express API -- see the same pattern in Node.js
- Multi-Container App -- deploy multiple services from one repository
- Triggering Builds -- build options, branch builds, and log streaming