A minimal Go HTTP service with health checks, built with Docker and deployed via GitHub Actions.
- HTTP Server: Simple Go HTTP server with
/and/healthendpoints - Health Checks: Built-in health check endpoint for container orchestration
- Containerized: Built with Docker using Alpine Linux base image
- CI/CD: Automated build, test, and deployment pipeline
- Multi-platform: Supports Linux AMD64 and ARM64
- Security: Automated vulnerability scanning and linting
- Go 1.24+: For local development
- Docker: For container operations
- GitHub: For CI/CD pipeline
- Open in VS Code: Clone and open the repository
- DevContainer: VS Code will prompt to reopen in container
- Ready: All tools pre-installed in the container
# Clone the repository
git clone git@github.com:platformfuzz/go-hello-service.git
cd go-hello-service
# Install dependencies
go mod tidy
# Run locally
go run ./cmd/server
# Test
go test ./cmd/server# Build locally
docker build -t go-hello-service .
# Run locally
docker run -p 8080:8080 go-hello-service
# Build for multiple platforms
docker buildx build --platform linux/amd64,linux/arm64 -t go-hello-service .- Base Image:
alpine:latest - Binary:
/app/server - Port:
8080(configurable viaPORTenv var) - Health Check: Built-in Docker health check with curl
- User: Non-root user (
appuser)
The service provides a /health endpoint that returns:
{
"status": "healthy",
"timestamp": "2024-01-01T12:00:00Z",
"version": "1.0.0"
}The container includes a built-in health check:
HEALTHCHECK --interval=30s --timeout=5s --start-period=60s --retries=3 \
CMD curl -f http://localhost:8080/health || exit 1For ECS, Kubernetes, etc., use:
{
"healthCheck": {
"command": [
"CMD-SHELL",
"curl -f http://localhost:8080/health || exit 1"
],
"interval": 30,
"timeout": 5,
"retries": 3,
"startPeriod": 60
}
}Note: Uses curl (available in Alpine base image) for HTTP health checks.
The .github/workflows/ci.yml workflow provides:
- β
Go Module Check: Ensures
go.modis clean - β Binary Build: Validates Go compilation
- β Container Build: Tests Docker build process
- β Health Check Test: Validates container health check
- β Security Scan: Basic security checks
- β
Linting:
golangci-lintintegration - β
Vulnerability Check:
govulncheckintegration - β Tests: Automated test suite
- π Build & Push: Publishes to GitHub Container Registry
- π·οΈ Tagging: Automatic
latestand versioned tags - π¦ Multi-platform: AMD64 and ARM64 images
Images are published to: ghcr.io/platformfuzz/go-hello-service:latest
PORT: Server port (default:8080)
See Dockerfile for build configuration:
- Multi-stage build: Go builder + Alpine runtime
- Base Image: Alpine Linux with curl
- Security: Non-root user
- Health Check: Built-in curl-based health check
Returns a hello message with hostname and timestamp.
Response:
{
"message": "Hello, World!",
"timestamp": "2024-01-01T12:00:00Z",
"hostname": "container-hostname"
}Returns service health status.
Response:
{
"status": "healthy",
"timestamp": "2024-01-01T12:00:00Z",
"version": "1.0.0"
}.
βββ cmd/
β βββ server/
β βββ main.go # Main server implementation
β βββ main_test.go # Unit tests
βββ .github/
β βββ workflows/
β βββ ci.yml # CI/CD pipeline
βββ .devcontainer/
β βββ devcontainer.json # VS Code DevContainer
βββ .vscode/
β βββ extensions.json # Recommended extensions
β βββ settings.json # Go development settings
βββ Dockerfile # Docker build configuration
βββ go.mod # Go module definition
βββ README.md # This file
# Add a new dependency
go get github.com/example/package
# Update go.mod
go mod tidy# Run all tests
go test ./...
# Run with coverage
go test -cover ./...
# Run specific test
go test ./cmd/server# Build image
docker build -t go-hello-service .
# Run container
docker run -p 8080:8080 go-hello-service
# Check health
docker inspect go-hello-service --format='{{.State.Health.Status}}'
# Build multi-platform
docker buildx build --platform linux/amd64,linux/arm64 -t go-hello-service .{
"family": "go-hello-service",
"containerDefinitions": [
{
"name": "server",
"image": "ghcr.io/platformfuzz/go-hello-service:latest",
"portMappings": [
{
"containerPort": 8080,
"protocol": "tcp"
}
],
"healthCheck": {
"command": [
"CMD-SHELL",
"curl -f http://localhost:8080/health || exit 1"
],
"interval": 30,
"timeout": 5,
"retries": 3,
"startPeriod": 60
}
}
]
}version: '3.8'
services:
server:
image: ghcr.io/platformfuzz/go-hello-service:latest
ports:
- "8080:8080"
environment:
- PORT=8080
healthcheck:
test: ["CMD-SHELL", "curl -f http://localhost:8080/health || exit 1"]
interval: 30s
timeout: 5s
retries: 3
start_period: 60s- Vulnerability Scanning: Automated
govulncheckintegration - Code Quality:
golangci-lintenforcement - Minimal Base Image: Alpine Linux for reduced attack surface
- Non-root User: Container runs as non-root user
- Graceful Shutdown: Proper signal handling
- Error Handling: Comprehensive error management
MIT License - see LICENSE file for details.
- Fork the repository
- Create a feature branch
- Make your changes
- Ensure all tests pass
- Submit a pull request
The CI/CD pipeline will automatically validate your changes before merging.