Skip to content

Commit 5411c61

Browse files
committed
ci: Dockerized
1 parent 6361c7b commit 5411c61

5 files changed

Lines changed: 106 additions & 7 deletions

File tree

.dockerignore

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
node_modules
2+
dist
3+
.git
4+
.env
5+
*.log
6+
npm-debug.log*
7+
test
8+
*spec.ts
9+
*.md

.github/workflows/deploy.yml

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
name: Deploy to VPS
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
8+
jobs:
9+
build:
10+
runs-on: ubuntu-latest
11+
steps:
12+
- name: Checkout repository
13+
uses: actions/checkout@v3
14+
15+
- name: Log in to Docker Hub
16+
uses: docker/login-action@v2
17+
with:
18+
username: ${{ secrets.DOCKER_USERNAME }}
19+
password: ${{ secrets.DOCKER_PASSWORD }}
20+
21+
- name: Build and push Docker image
22+
uses: docker/build-push-action@v4
23+
with:
24+
context: .
25+
push: true
26+
tags: ${{ secrets.DOCKER_USERNAME }}/${{github.event.repository.name}}:latest
27+
28+
deploy:
29+
runs-on: ubuntu-latest
30+
needs: build
31+
steps:
32+
- name: Checkout repository
33+
uses: actions/checkout@v3
34+
35+
- name: Deploy on VPS
36+
uses: appleboy/ssh-action@v0.1.10
37+
with:
38+
host: ${{ secrets.VPS_1_HOST_IP }}
39+
username: ${{ secrets.VPS_1_HOST_USERNAME }}
40+
password: ${{ secrets.VPS_1_HOST_PASSWORD }}
41+
port: ${{ secrets.VPS_1_HOST_PORT }}
42+
script: |
43+
cd /media/${{github.event.repository.name}}
44+
docker compose pull
45+
docker compose up -d

Dockerfile

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# Stage 1: Builder
2+
FROM node:22-alpine AS builder
3+
4+
WORKDIR /app
5+
6+
# Copy package files and install dependencies (including devDependencies for build)
7+
COPY package*.json ./
8+
RUN npm ci
9+
10+
# Copy application source code
11+
COPY . .
12+
13+
# Build the NestJS application
14+
RUN npm run build
15+
16+
# Stage 2: Production
17+
FROM node:22-alpine AS production
18+
19+
WORKDIR /app
20+
21+
# Set NODE_ENV to production
22+
ENV NODE_ENV production
23+
24+
# Copy only production package files and install production dependencies
25+
COPY package*.json ./
26+
RUN npm ci --omit=dev
27+
28+
# Copy built application from the builder stage
29+
COPY --from=builder /app/dist ./dist
30+
31+
# Expose the application port (default for NestJS is 3000)
32+
EXPOSE 3000
33+
34+
# Command to run the application
35+
CMD ["node", "dist/main.js"]

src/main.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ async function bootstrap() {
2323

2424
// Serve Swagger UI
2525
const swaggerDocument = JSON.parse(
26-
fs.readFileSync(path.join(process.cwd(), 'src', 'swagger.json'), 'utf8'),
26+
fs.readFileSync(path.join(__dirname, 'swagger.json'), 'utf8'),
2727
);
2828
app.use('/docs', swaggerUi.serve, swaggerUi.setup(swaggerDocument));
2929

tsconfig.json

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,21 @@
1515
"outDir": "./dist",
1616
"baseUrl": "./",
1717
"paths": {
18-
"@modules/*": ["src/modules/*"],
19-
"@common/*": ["src/common/*"],
20-
"@config/*": ["src/config/*"],
21-
"@database/*": ["src/database/*"],
22-
"@helpers/*": ["src/helpers/*"]
18+
"@modules/*": [
19+
"src/modules/*"
20+
],
21+
"@common/*": [
22+
"src/common/*"
23+
],
24+
"@config/*": [
25+
"src/config/*"
26+
],
27+
"@database/*": [
28+
"src/database/*"
29+
],
30+
"@helpers/*": [
31+
"src/helpers/*"
32+
]
2333
},
2434
"incremental": true,
2535
"skipLibCheck": true,
@@ -29,4 +39,4 @@
2939
"strictBindCallApply": false,
3040
"noFallthroughCasesInSwitch": false
3141
}
32-
}
42+
}

0 commit comments

Comments
 (0)