Skip to content

Commit

Permalink
feat: update deployment workflows and improve Docker integration
Browse files Browse the repository at this point in the history
  • Loading branch information
nestorzamili committed Feb 22, 2025
1 parent 235aca9 commit 02bfa11
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 19 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: Deploy to VM

on:
workflow_run:
workflows: ["Build and Push Docker Image"]
workflows: ["Docker Build and Push"]
types: [completed]
workflow_dispatch:

Expand All @@ -12,8 +12,8 @@ jobs:
steps:
- name: Deploy to VM
run: |
ssh -i <(echo "${{ secrets.SSH_PRIVATE_KEY }}") ${{ secrets.VM_HOST }}@${{ secrets.VM_IP }} << 'EOF'
docker login -u "${{ secrets.DOCKER_USERNAME }}" --password-stdin <<< "${{ secrets.DOCKER_PASSWORD }}"
ssh -o StrictHostKeyChecking=no -i <(echo "${{ secrets.SSH_PRIVATE_KEY }}") ${{ secrets.VM_HOST }}@${{ secrets.VM_IP }} << 'EOF'
echo ${{ secrets.DOCKER_PASSWORD }} | docker login --username ${{ secrets.DOCKER_USERNAME }} --password-stdin
docker pull ${{ secrets.DOCKER_USERNAME }}/whatsapp-blast:latest
docker stop whatsapp-blast || true
Expand Down
16 changes: 12 additions & 4 deletions .github/workflows/docker-build.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Docker Build
name: Docker Build and Push

on:
workflow_run:
Expand All @@ -10,7 +10,9 @@ on:
jobs:
docker:
runs-on: ubuntu-latest
if: ${{ github.event.workflow_run.conclusion == 'success' }}
if: >
github.event.workflow_run.conclusion == 'success' &&
github.event.workflow_run.head_branch == 'main'
steps:
- name: Checkout Repository
uses: actions/checkout@v4
Expand All @@ -20,7 +22,11 @@ jobs:
- name: Get Latest Tag
id: get-latest-tag
run: |
echo "LATEST_TAG=$(git describe --tags --abbrev=0)" >> $GITHUB_ENV
if git describe --tags --abbrev=0 > /dev/null 2>&1; then
echo "LATEST_TAG=$(git describe --tags --abbrev=0)" >> $GITHUB_ENV
else
echo "LATEST_TAG=latest" >> $GITHUB_ENV
fi
- name: Login to Docker Hub
uses: docker/login-action@v3
Expand All @@ -35,4 +41,6 @@ jobs:
push: true
tags: |
${{ secrets.DOCKER_USERNAME }}/whatsapp-blast:latest
${{ secrets.DOCKER_USERNAME }}/whatsapp-blast:${{ env.LATEST_TAG }}
${{ secrets.DOCKER_USERNAME }}/whatsapp-blast:${{ env.LATEST_TAG }}
build-args: |
GIT_TAG=${{ env.LATEST_TAG }}
13 changes: 5 additions & 8 deletions DockerFile
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,20 @@ FROM node:22.0.0

WORKDIR /app

# Copy package files
ARG GIT_TAG=latest

COPY package*.json ./

# Install dependencies
RUN npm ci

# Copy rest of the application
COPY . .

# Build TypeScript
RUN npm run build

# Cleanup dev dependencies
RUN npm ci --only=production

# Expose port
EXPOSE 3000

# Start the application
CMD ["npm", "start"]
CMD ["npm", "start"]

LABEL git.tag=${GIT_TAG}
7 changes: 4 additions & 3 deletions src/services/quota.service.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import prisma from "../config/db";
import logger from "../config/logger";
import { Prisma } from "@prisma/client";

class QuotaService {
async getAvailableBalance(userId: string): Promise<number> {
Expand All @@ -22,7 +23,7 @@ class QuotaService {

async addQuota(userId: string, amount: number): Promise<void> {
try {
await prisma.$transaction(async (tx) => {
await prisma.$transaction(async (tx: Prisma.TransactionClient) => {
const quota = await tx.quota.findUnique({
where: { userId },
});
Expand Down Expand Up @@ -62,7 +63,7 @@ class QuotaService {

async reserveQuota(userId: string, amount: number): Promise<void> {
try {
await prisma.$transaction(async (tx) => {
await prisma.$transaction(async (tx: Prisma.TransactionClient) => {
const quota = await tx.quota.findUnique({
where: { userId },
select: { balance: true, lockedAmount: true },
Expand Down Expand Up @@ -103,7 +104,7 @@ class QuotaService {
successCount: number
): Promise<void> {
try {
await prisma.$transaction(async (tx) => {
await prisma.$transaction(async (tx: Prisma.TransactionClient) => {
const quota = await tx.quota.findUnique({
where: { userId },
select: { balance: true, lockedAmount: true },
Expand Down
2 changes: 1 addition & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"outDir": "./dist",
"typeRoots": ["./src/types", "./node_modules/@types"],
"skipLibCheck": true,
"forceConsistentCasingInFileNames": true,
"forceConsistentCasingInFileNames": true
},
"include": ["src/**/*"]
}

0 comments on commit 02bfa11

Please sign in to comment.