Published 30-12-2024
Last Modified 6 days ago
# Dockerfile Nest.js Application# Production stageFROM node:lts# Set working directoryWORKDIR /app# Copy package filesCOPY package*.json ./# Install only production dependenciesRUN npm ci --only=production# Copy built application from builder stageCOPY --from=builder /app/dist ./dist# Expose the application portEXPOSE 3000# Start the applicationCMD ["npm", "run", "start:prod"]
name: Build and Deploy NestJSon:push:branches: [ "main" ]pull_request:branches: [ "main" ]env:REGISTRY: "registry.digitalocean.com/your-registry-name"IMAGE_NAME: "your-app-name"jobs:build-and-push:runs-on: ubuntu-lateststeps:- name: Checkout codeuses: actions/checkout@v3- name: Install Node.jsuses: actions/setup-node@v3with:node-version: '18'cache: 'npm'- name: Install dependenciesrun: npm ci- name: Run testsrun: npm test- name: Build applicationrun: npm run build- name: Install doctluses: digitalocean/action-doctl@v2with:token: ${{ secrets.DIGITALOCEAN_ACCESS_TOKEN }}- name: Log in to DigitalOcean Container Registryrun: doctl registry login --expiry-seconds 600- name: Build container imagerun: docker build -t $(echo $REGISTRY)/$(echo $IMAGE_NAME):$(echo $GITHUB_SHA | head -c7) -t $(echo $REGISTRY)/$(echo $IMAGE_NAME):latest .- name: Push image to DigitalOcean Container Registryrun: |docker push $(echo $REGISTRY)/$(echo $IMAGE_NAME):$(echo $GITHUB_SHA | head -c7)docker push $(echo $REGISTRY)/$(echo $IMAGE_NAME):latest