Multi-stack packaging with Docker multi-stage builds for Go, TypeScript/Vue, and PHP
Invoke after implementation and tests pass. Produces build artifacts, Docker images, and release bundles for Go, TypeScript/Vue, and PHP stacks.
# Go
go build -ldflags="-s -w" -o bin/ ./cmd/...
docker build -t myapp-api -f Dockerfile.go .
# TypeScript / Vue.js
npm run build
docker build -t myapp-frontend -f Dockerfile.vue .
# PHP
composer install --no-dev --optimize-autoloader
docker build -t myapp-php -f Dockerfile.php .
# Full stack
docker compose build
docker compose up -d
Go (multi-stage):
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 -ldflags="-s -w" -o /app/bin/server ./cmd/server
FROM alpine:3.19
COPY --from=builder /app/bin/server /usr/local/bin/server
EXPOSE 8080
ENTRYPOINT ["server"]
TypeScript/Vue (nginx SPA):
FROM node:20-alpine AS builder
WORKDIR /app
COPY package*.json ./
RUN npm ci
COPY . .
RUN npm run build
FROM nginx:alpine
COPY --from=builder /app/dist /usr/share/nginx/html
COPY nginx.conf /etc/nginx/conf.d/default.conf
EXPOSE 80
PHP (php-fpm):
FROM composer:2 AS deps
WORKDIR /app
COPY composer.json composer.lock ./
RUN composer install --no-dev --optimize-autoloader --no-scripts
FROM php:8.3-fpm-alpine
COPY --from=deps /app/vendor /var/www/vendor
COPY . /var/www
WORKDIR /var/www
EXPOSE 9000
docker build -t app:$(git rev-parse --short HEAD) .docker compose up -d and smoke test endpoints.-ldflags="-s -w" (stripped)dist/ directory generated with production modedocker compose.yml validated with docker compose config| Error | Cause | Fix |
|---|---|---|
| Build fails in Docker | Missing dependencies | Ensure go mod download / npm ci runs before COPY . . |
| Large image size | Dev deps included | Use multi-stage builds; --no-dev for composer |
| Port conflict | Container port already used | Check with docker ps and adjust compose ports |
| SPA routing 404 | Nginx not configured for SPA | Add try_files $uri $uri/ /index.html to nginx.conf |
go help build