Skip to content

Commit

Permalink
refactor: separate cron
Browse files Browse the repository at this point in the history
  • Loading branch information
rharkor committed Sep 26, 2023
1 parent 95e902c commit 3650873
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .github/workflows/deploy-template.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,14 @@ jobs:

- name: Build the docker image
run: |
# Main application
docker build -t rg.fr-par.scw.cloud/namespace-main/main-application-image:latest .
docker push rg.fr-par.scw.cloud/namespace-main/main-application-image:latest
# Cron
docker build -t rg.fr-par.scw.cloud/namespace-main/cron-image:latest -f cron/Dockerfile .
docker push rg.fr-par.scw.cloud/namespace-main/cron-image:latest
- name: Push docker compose
run: |
eval $(ssh-agent -s)
Expand Down
19 changes: 19 additions & 0 deletions crons/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
FROM node:18-alpine

RUN mkdir -p /usr/src/app

WORKDIR /usr/src/app

ENV PORT 3000
ENV NEXT_TELEMETRY_DISABLED 1
ENV NODE_ENV production

COPY package.json .
COPY package-lock.json .
COPY prisma/schema.prisma ./prisma/schema.prisma

RUN npm ci --only=production

COPY . .

CMD [ "npm", "run", "cron" ]
10 changes: 10 additions & 0 deletions docker/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,16 @@ services:
ports:
- "3000:3000"

crons:
image: #{DOCKER_DEPLOY_CRONS_IMAGE}#
restart: unless-stopped
logging:
driver: "json-file"
options:
max-size: "50m"
volumes:
- ./uploads:/app/uploads

db:
image: postgres:latest
restart: unless-stopped
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
"init": "cd scripts && npm i && npm run init && cd .. && npx -y prisma migrate dev && npm run seed",
"dev": "npm run is-initialized && npx -y prisma migrate dev && cross-env FORCE_COLOR=1 next dev",
"build": "npm run is-initialized && npm run full-sub-package-setup && next build",
"start": "npm run is-initialized && npm run deploy-db:prod && npm run seed && concurrently \"next start\" \"npm run cron\"",
"start": "npm run is-initialized && npm run deploy-db:prod && npm run seed && next start",
"start:with-cron": "npm run is-initialized && npm run deploy-db:prod && npm run seed && concurrently \"next start\" \"npm run cron\"",
"deploy-db:prod": "npx -y prisma migrate deploy",
"cron": "npx -y tsx ./crons/index.ts",
"lint": "next lint",
Expand Down

0 comments on commit 3650873

Please sign in to comment.