Skip to main content

09 - Deploy and DevOps with Claude

Prepare deployment: multi-stage Dockerfile, Docker Compose, CI/CD with GitHub Actions, health check, logging and production monitoring.

What do you think about this article?

At a Glance

Prepare deployment: multi-stage Dockerfile, Docker Compose, CI/CD with GitHub Actions, health check, logging and production monitoring.

Deploy and DevOps with Claude

Deployment is often the most neglected phase in personal projects, but it's essential for turning code into a working product. Claude can help you configure containerization, CI/CD, monitoring, and logging professionally.

In this article, we'll see how to use Claude to prepare the project for production, create automated deployment pipelines, and configure infrastructure.

What You'll Learn

  • Containerization with Docker (multi-stage builds)
  • Docker Compose for local development
  • CI/CD with GitHub Actions
  • Cloud deployment (AWS, Railway, Fly.io)
  • Basic logging and monitoring

Containerization with Docker

Multi-Stage Build for Spring Boot

Dockerfile - Optimized Spring Boot
# Stage 1: Build
FROM eclipse-temurin:21-jdk-alpine AS builder
WORKDIR /app

COPY pom.xml mvnw ./
COPY .mvn .mvn
RUN ./mvnw dependency:go-offline -B

COPY src src
RUN ./mvnw package -DskipTests -B
RUN java -Djarmode=layertools -jar target/*.jar extract

# Stage 2: Runtime
FROM eclipse-temurin:21-jre-alpine
WORKDIR /app

RUN addgroup -g 1001 appgroup && \
    adduser -u 1001 -G appgroup -D appuser
USER appuser

COPY --from=builder /app/dependencies/ ./
COPY --from=builder /app/spring-boot-loader/ ./
COPY --from=builder /app/application/ ./

HEALTHCHECK --interval=30s --timeout=3s --start-period=30s \
    CMD wget -q --spider http://localhost:8080/actuator/health || exit 1

EXPOSE 8080
ENTRYPOINT ["java", "org.springframework.boot.loader.launch.JarLauncher"]

Multi-Stage Build for Angular

Dockerfile - Angular with Nginx
# Stage 1: Build
FROM node:20-alpine AS builder
WORKDIR /app

COPY package*.json ./
RUN npm ci

COPY . .
RUN npm run build -- --configuration=production

# Stage 2: Serve
FROM nginx:alpine
COPY --from=builder /app/dist/*/browser /usr/share/nginx/html
COPY nginx.conf /etc/nginx/conf.d/default.conf

EXPOSE 80
CMD ["nginx", "-g", "daemon off;"]

Docker Compose for Development

docker-compose.yml
version: '3.8'

services:
  backend:
    build: ./backend
    ports:
      - "8080:8080"
    environment:
      - SPRING_PROFILES_ACTIVE=docker
      - DATABASE_URL=jdbc:postgresql://postgres:5432/orders
    depends_on:
      postgres:
        condition: service_healthy

  frontend:
    build: ./frontend
    ports:
      - "4200:80"
    depends_on:
      - backend

  postgres:
    image: postgres:16-alpine
    environment:
      - POSTGRES_DB=orders
      - POSTGRES_PASSWORD=postgres
    volumes:
      - postgres_data:/var/lib/postgresql/data
    healthcheck:
      test: ["CMD-SHELL", "pg_isready"]
      interval: 10s

volumes:
  postgres_data:

CI/CD with GitHub Actions

.github/workflows/ci.yml
name: CI/CD Pipeline

on:
  push:
    branches: [main]
  pull_request:
    branches: [main]

jobs:
  test:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - uses: actions/setup-java@v4
        with:
          java-version: '21'
          distribution: 'temurin'
          cache: maven
      - run: ./mvnw verify
        working-directory: ./backend

  build:
    needs: test
    runs-on: ubuntu-latest
    if: github.event_name == 'push'
    steps:
      - uses: actions/checkout@v4
      - uses: docker/setup-buildx-action@v3
      - uses: docker/login-action@v3
        with:
          registry: ghcr.io
          username: ${{ '{{' }} github.actor {{ '}}' }}
          password: ${{ '{{' }} secrets.GITHUB_TOKEN {{ '}}' }}
      - uses: docker/build-push-action@v5
        with:
          context: ./backend
          push: true
          tags: ghcr.io/${{ '{{' }} github.repository {{ '}}' }}-backend:${{ '{{' }} github.sha {{ '}}' }}

Logging and Monitoring

application.yml - Logging Configuration
logging:
  level:
    root: INFO
    com.company.orders: DEBUG

management:
  endpoints:
    web:
      exposure:
        include: health,info,metrics,prometheus
  endpoint:
    health:
      show-details: when_authorized

Deploy Checklist

Pre-Deploy Checklist

  • Optimized multi-stage Dockerfile
  • Docker Compose for local development
  • Health check configured
  • CI/CD pipeline working
  • Secrets properly managed (not in git)
  • Structured logging for production
  • Metrics exposed (Prometheus/Actuator)

Conclusion

In this article, we've seen how to prepare the project for production deployment. In the next and final article, we'll explore project evolution: scalability, maintenance, and adding new features.

Key Takeaways

  • Multi-stage builds: Small and secure images
  • Docker Compose: Reproducible local environment
  • Automated CI/CD: Consistent and reliable deployment
  • Health checks: Essential for orchestrators
  • Structured logging: Easier production debugging

Try These Tools

Free developer tools related to this topic.

Commenti

Caricamento commenti...

Sign in to comment

Discuss this article in the community

Join the Telegram group to discuss with other developers, ask questions and share your experiences.

Did you like this article?

Explore other content on the blog or discover my projects