Streamline Deployment with App Platform, Container Registry, and GitHub/GitLab. Configure Docker, set up workflows, and automate with DigitalOcean.
1# Dockerfile Nest.js Application2# Production stage3FROM node:lts45# Set working directory6WORKDIR /app78# Copy package files9COPY package*.json ./1011# Install only production dependencies12RUN npm ci --only=production1314# Copy built application from builder stage15COPY --from=builder /app/dist ./dist1617# Expose the application port18EXPOSE 30001920# Start the application21CMD ["npm", "run", "start:prod"]
1name: Build and Deploy NestJS23on:4 push:5 branches: [ "main" ]6 pull_request:7 branches: [ "main" ]89env:10 REGISTRY: "registry.digitalocean.com/your-registry-name"11 IMAGE_NAME: "your-app-name"1213jobs:14 build-and-push:15 runs-on: ubuntu-latest1617 steps:18 - name: Checkout code19 uses: actions/checkout@v32021 - name: Install Node.js22 uses: actions/setup-node@v323 with:24 node-version: '18'25 cache: 'npm'2627 - name: Install dependencies28 run: npm ci2930 - name: Run tests31 run: npm test3233 - name: Build application34 run: npm run build3536 - name: Install doctl37 uses: digitalocean/action-doctl@v238 with:39 token: ${{ secrets.DIGITALOCEAN_ACCESS_TOKEN }}4041 - name: Log in to DigitalOcean Container Registry42 run: doctl registry login --expiry-seconds 6004344 - name: Build container image45 run: docker build -t $(echo $REGISTRY)/$(echo $IMAGE_NAME):$(echo $GITHUB_SHA | head -c7) -t $(echo $REGISTRY)/$(echo $IMAGE_NAME):latest .4647 - name: Push image to DigitalOcean Container Registry48 run: |49 docker push $(echo $REGISTRY)/$(echo $IMAGE_NAME):$(echo $GITHUB_SHA | head -c7)50 docker push $(echo $REGISTRY)/$(echo $IMAGE_NAME):latest