Nasser Setti

Streamline Your Deployment Process with App Platform, Container Registry, and GitHub/GitLab Workflow

Published 30-12-2024
4 min read
Streamline Your Deployment Process with App Platform, Container Registry, and GitHub/GitLab Workflow
#DigitalOcean
#Docker
#Github

Streamline Deployment with App Platform, Container Registry, and GitHub/GitLab. Configure Docker, set up workflows, and automate with DigitalOcean.

Whenever I attempted to deploy an application, I encountered two primary challenges:
  • How could I accomplish the task in a straightforward manner?
  • How could I automate the process?
This combination, which is commonly used in DigitalOcean resources, addresses these concerns.
By employing this combination, your workflow will undoubtedly become more efficient.
I will provide you with the simplest method to implement this process:
Configure your Docker image:
Ensure that your Docker image is properly configured.
dockerfile
1# Dockerfile Nest.js Application
2# Production stage
3FROM node:lts
4
5# Set working directory
6WORKDIR /app
7
8# Copy package files
9COPY package*.json ./
10
11# Install only production dependencies
12RUN npm ci --only=production
13
14# Copy built application from builder stage
15COPY --from=builder /app/dist ./dist
16
17# Expose the application port
18EXPOSE 3000
19
20# Start the application
21CMD ["npm", "run", "start:prod"]
Set up your workflow to include an option to upload the image to the DO container registry:
Configure your workflow to include an option to upload the image to the DigitalOcean container registry.
yaml
1name: Build and Deploy NestJS
2
3on:
4 push:
5 branches: [ "main" ]
6 pull_request:
7 branches: [ "main" ]
8
9env:
10 REGISTRY: "registry.digitalocean.com/your-registry-name"
11 IMAGE_NAME: "your-app-name"
12
13jobs:
14 build-and-push:
15 runs-on: ubuntu-latest
16
17 steps:
18 - name: Checkout code
19 uses: actions/checkout@v3
20
21 - name: Install Node.js
22 uses: actions/setup-node@v3
23 with:
24 node-version: '18'
25 cache: 'npm'
26
27 - name: Install dependencies
28 run: npm ci
29
30 - name: Run tests
31 run: npm test
32
33 - name: Build application
34 run: npm run build
35
36 - name: Install doctl
37 uses: digitalocean/action-doctl@v2
38 with:
39 token: ${{ secrets.DIGITALOCEAN_ACCESS_TOKEN }}
40
41 - name: Log in to DigitalOcean Container Registry
42 run: doctl registry login --expiry-seconds 600
43
44 - name: Build container image
45 run: docker build -t $(echo $REGISTRY)/$(echo $IMAGE_NAME):$(echo $GITHUB_SHA | head -c7) -t $(echo $REGISTRY)/$(echo $IMAGE_NAME):latest .
46
47 - name: Push image to DigitalOcean Container Registry
48 run: |
49 docker push $(echo $REGISTRY)/$(echo $IMAGE_NAME):$(echo $GITHUB_SHA | head -c7)
50 docker push $(echo $REGISTRY)/$(echo $IMAGE_NAME):latest
Create your application and specify the DO container registry as its source:
Create your application and provide it with the DigitalOcean container registry as its source. You will be prompted to select the desired container and images for your application.More informations can be found [https://docs.digitalocean.com/products/app-platform/](https://docs.digitalocean.com/products/app-platform/)
Enable the “Upload new image” trigger:
Activate the “Upload new image” trigger.
Congratulations! You have successfully deployed your application and automated your workflow simultaneously.

Article Details

Published:30-12-2024
Updated:31-12-2024
Reading Time:4 min

Share This Article