micro--go-micro
c09695d4e2
Run Tests / Unit Tests (push) Has been cancelled
Run Tests / Etcd Integration Tests (push) Has been cancelled
micro build: - Generates Dockerfiles for services (if not present) - Builds container images for all services in micro.mu - Supports --tag, --registry, --push flags - --compose flag generates docker-compose.yml micro deploy: - Default: deploys with docker-compose - --ssh user@host: deploys via SSH (rsync + build on remote) - --build: rebuild images before deploying Complete workflow: micro run # Develop locally micro build # Build images micro deploy # Deploy Or for simple SSH deploys: micro deploy --ssh user@host Co-authored-by: Shelley <shelley@exe.dev>
3.2 KiB
3.2 KiB
layout
| layout |
|---|
| default |
Deployment
The micro build and micro deploy commands help you go from development to production.
Quick Start
# Build container images
micro build
# Deploy with docker-compose
micro deploy
Building Images
Basic Build
micro build
This:
- Reads
micro.mu(if present) to find services - Generates a
Dockerfilefor each service (if not present) - Runs
docker buildfor each service
Build Options
micro build --tag v1.0.0 # Specific tag (default: latest)
micro build --registry docker.io/myuser # Push to registry
micro build --push # Build and push
Generated Dockerfile
If no Dockerfile exists, one is generated:
FROM golang:1.22-alpine AS builder
WORKDIR /app
COPY go.mod go.sum ./
RUN go mod download
COPY . .
RUN CGO_ENABLED=0 go build -o /service .
FROM alpine:latest
RUN apk --no-cache add ca-certificates
WORKDIR /app
COPY --from=builder /service /app/service
EXPOSE 8080
CMD ["/app/service"]
Customize by creating your own Dockerfile.
Generating docker-compose.yml
micro build --compose
Generates a docker-compose.yml from your micro.mu config:
version: '3.8'
services:
users:
image: users:latest
ports:
- "8081:8081"
environment:
- MICRO_REGISTRY=mdns
posts:
image: posts:latest
ports:
- "8082:8082"
depends_on:
- users
environment:
- MICRO_REGISTRY=mdns
Deploying
Docker Compose
micro deploy
Runs docker compose up -d using the generated docker-compose.yml.
micro deploy --build # Rebuild images first
SSH Deploy
For simple deployments to a single server:
micro deploy --ssh user@host
This:
- Creates
~/microon the remote host - Syncs your code using rsync
- Builds each service on the remote host
- Starts services in the background
micro deploy --ssh user@host --path /opt/myapp # Custom remote path
View Logs
After deploying:
# Docker Compose
docker compose logs -f
# SSH deploy
ssh user@host 'tail -f ~/micro/*.log'
Complete Workflow
# 1. Develop locally
micro run
# 2. Build images
micro build --tag v1.0.0
# 3. Generate compose file
micro build --compose
# 4. Deploy
micro deploy
Or for SSH:
# 1. Develop locally
micro run
# 2. Deploy to server
micro deploy --ssh user@host
Configuration
The micro.mu file drives both build and deploy:
service users
path ./users
port 8081
service posts
path ./posts
port 8082
depends users
service web
path ./web
port 8089
depends users posts
path- Where to find the service codeport- Exposed port (used in Dockerfile and compose)depends- Service dependencies (used in compose depends_on)
Tips
- Version your images - Use
--tag v1.0.0not justlatest - Use a registry - Push images with
--registryfor team sharing - Custom Dockerfiles - Override the generated one for complex builds
- SSH for simple deploys - Great for single-server setups
- Compose for local prod - Test production config locally