Skip to content

Commit

Permalink
scheduler: add prod docker configs
Browse files Browse the repository at this point in the history
  • Loading branch information
makinbacon21 committed Oct 31, 2024
1 parent 3af3e52 commit 56f0b0e
Show file tree
Hide file tree
Showing 5 changed files with 111 additions and 0 deletions.
17 changes: 17 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
FROM node:lts-bookworm
ARG DATABASE_URL
ENV NODE_ENV=production

RUN apt-get update
RUN apt-get install -y vim netcat-openbsd

WORKDIR /usr/src/app
COPY . .
EXPOSE 3000

RUN chown -R node /usr/src/app
USER node
RUN npm install --production
RUN npx prisma generate
RUN DATABASE_URL=$DATABASE_URL npm run build
CMD ["npm", "start"]
26 changes: 26 additions & 0 deletions Dockerfile.cron
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
FROM golang:1.23-bookworm

RUN useradd cronuser
RUN mkdir -p /app
RUN chown -R cronuser /app
WORKDIR /app

RUN apt update
RUN apt install -y cron rsyslog

COPY --chown=cronuser:cronuser ./crontab_file /etc/cron.d/cron-scraper
RUN crontab -u cronuser /etc/cron.d/cron-scraper
RUN chmod u+s /usr/sbin/cron
COPY --chown=cronuser:cronuser ./cron-startup.sh ./cron-startup.sh

USER cronuser

COPY ./swatscraper/go.mod ./swatscraper/go.sum ./
RUN go mod download

COPY --chown=cronuser:cronuser ./.env ./.env
COPY --chown=cronuser:cronuser ./swatscraper/*.go ./

RUN GOCACHE=/app/.cache CGO_ENABLED=0 GOOS=linux go build -o /app/swatscraper

ENTRYPOINT ["./cron-startup.sh"]
3 changes: 3 additions & 0 deletions cron-startup.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/bin/bash
echo "Start cron"
cron -f
1 change: 1 addition & 0 deletions crontab_file
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
0 * * * * /app/swatscraper
64 changes: 64 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
services:
scheduler:
image: registry.sccs.swarthmore.edu/sccs/scheduler/scheduler:latest
build:
context: .
dockerfile: ./Dockerfile
restart: unless-stopped
env_file:
- .env
environment:
NODE_ENV: production
DOMAIN: https://schedulerv2.sccs.swarthmore.edu
depends_on:
- scheduler-db
deploy:
labels:
- 'traefik.enable=true'
- 'traefik.docker.network=traefik'
- 'traefik.http.routers.scheduler.entrypoints=https'
- 'traefik.http.routers.scheduler.rule=Host(`schedulerv2.sccs.swarthmore.edu`)'
- 'traefik.http.routers.scheduler.tls=true'
- 'traefik.http.routers.scheduler.tls.certresolver=letsEncrypt'
- 'traefik.http.services.scheduler.loadbalancer.server.port=3000'
command: sh -c "sleep 5 && npx prisma migrate deploy && npm start "
networks:
- traefik
- internal

scheduler-db:
hostname: scheduler-db
image: postgres:16.4-bullseye
volumes:
- scheduler-dbdata:/var/lib/postgresql/data
env_file:
- .env
networks:
- internal

scheduler-cron:
image: registry.sccs.swarthmore.edu/sccs/scheduler/scheduler-cron:latest
build:
context: .
dockerfile: ./Dockerfile.cron
restart: unless-stopped
depends_on:
- scheduler-db
networks:
- internal

# (re)define traefik proxy network
networks:
internal:
driver: overlay
traefik:
# defined elsewhere
external: true

volumes:
scheduler-dbdata:
name: scheduler-dbdata
driver_opts:
type: nfs
o: "nfsvers=4,addr=130.58.218.26,rw,nolock,soft"
device: ":/volumes/scheduler-dbdata"

0 comments on commit 56f0b0e

Please sign in to comment.