From fdefd8204408ff53338d0236c9f2ba21ecf559e9 Mon Sep 17 00:00:00 2001 From: Damian Rene <37555910+DCRepublic@users.noreply.github.com> Date: Mon, 28 Oct 2024 10:58:18 -0400 Subject: [PATCH 1/3] Update node.js.yml --- .github/workflows/node.js.yml | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/.github/workflows/node.js.yml b/.github/workflows/node.js.yml index 4732fd9..942805b 100644 --- a/.github/workflows/node.js.yml +++ b/.github/workflows/node.js.yml @@ -6,8 +6,6 @@ name: Node.js CI on: push: branches: [ "main", "dcrepublic-dev", "v6ctor-dev"] - pull_request: - branches: [ "main" ] jobs: build: @@ -16,7 +14,7 @@ jobs: strategy: matrix: - node-version: [18.x, 20.x, 22.x] + node-version: [20.x, 22.x] # See supported Node.js release schedule at https://nodejs.org/en/about/releases/ steps: From 56f0b0e9065a68c4088037fb454751fe6db41944 Mon Sep 17 00:00:00 2001 From: Thomas Makin Date: Thu, 31 Oct 2024 14:15:09 -0400 Subject: [PATCH 2/3] scheduler: add prod docker configs --- Dockerfile | 17 ++++++++++++ Dockerfile.cron | 26 +++++++++++++++++++ cron-startup.sh | 3 +++ crontab_file | 1 + docker-compose.yml | 64 ++++++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 111 insertions(+) create mode 100644 Dockerfile create mode 100644 Dockerfile.cron create mode 100755 cron-startup.sh create mode 100644 crontab_file create mode 100644 docker-compose.yml diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..74d52ec --- /dev/null +++ b/Dockerfile @@ -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"] diff --git a/Dockerfile.cron b/Dockerfile.cron new file mode 100644 index 0000000..fd61193 --- /dev/null +++ b/Dockerfile.cron @@ -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"] diff --git a/cron-startup.sh b/cron-startup.sh new file mode 100755 index 0000000..2336a34 --- /dev/null +++ b/cron-startup.sh @@ -0,0 +1,3 @@ +#!/bin/bash +echo "Start cron" +cron -f diff --git a/crontab_file b/crontab_file new file mode 100644 index 0000000..e36df19 --- /dev/null +++ b/crontab_file @@ -0,0 +1 @@ +0 * * * * /app/swatscraper diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..99ecda8 --- /dev/null +++ b/docker-compose.yml @@ -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" From 0094e6e7d0e763ec173f6315b351777155ea069f Mon Sep 17 00:00:00 2001 From: Thomas Makin Date: Thu, 31 Oct 2024 14:17:07 -0400 Subject: [PATCH 3/3] v2: bump swatscraper --- swatscraper | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/swatscraper b/swatscraper index 32a5d97..26f1d82 160000 --- a/swatscraper +++ b/swatscraper @@ -1 +1 @@ -Subproject commit 32a5d975a8cbe906764c553846d220de1f0ed4ab +Subproject commit 26f1d82850014294d64734ae2f9c5b3429bd0eb7