Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

General maintenance #143

Draft
wants to merge 19 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* @GAsplund
58 changes: 0 additions & 58 deletions .github/workflows/build_test.yml

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,45 +1,66 @@
name: Linting
name: Code validation

on:
push:
branches: [main]
tags:
- v[0-9]+.[0-9]+.[0-9]+*
pull_request:
branches: [main]

env:
WORKFLOW_NODE_VERSION: 20.x

jobs:
test:
name: Unit tests

runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4

- name: Use Node.js ${{ env.WORKFLOW_NODE_VERSION }}
uses: actions/setup-node@v4
with:
node-version: ${{ env.WORKFLOW_NODE_VERSION }}

- name: pnpm install
run: npm install -g pnpm

- run: pnpm install --frozen-lockfile

- run: pnpm test

run-linters:
name: Execute linters
runs-on: ubuntu-latest

steps:
-
uses: actions/checkout@v3
-
name: Use Node.js ${{ env.WORKFLOW_NODE_VERSION }}
uses: actions/setup-node@v3
- uses: actions/checkout@v4

- name: Use Node.js ${{ env.WORKFLOW_NODE_VERSION }}
uses: actions/setup-node@v4
with:
node-version: ${{ env.WORKFLOW_NODE_VERSION }}
-
name: pnpm install

- name: pnpm install
run: npm install -g pnpm
-
run: pnpm install prettier
-
run: pnpm install --frozen-lockfile
-
name: ESLint

- run: pnpm install prettier

- run: pnpm install --frozen-lockfile

- name: ESLint
uses: reviewdog/action-eslint@v1
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
reporter: github-pr-check
filter_mode: ${{ (github.event_name == 'pull_request') && 'file' || 'nofilter' }}
level: ${{ (github.event_name == 'pull_request') && 'error' || 'warning' }}
tool_name: ESLint
-
name: Prettier

- name: Prettier
uses: EPMatt/reviewdog-action-prettier@v1
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
Expand Down
51 changes: 51 additions & 0 deletions .github/workflows/docker.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
name: Docker

on:
push:
branches: [main]
tags:
- v[0-9]+.[0-9]+.[0-9]+*
pull_request:
branches: [main]

jobs:
build:
name: Build image

runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3

- name: Login to GitHub Container Registry
if: ${{ github.ref == 'refs/heads/main' }}
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@v5
with:
images: ghcr.io/${{ github.repository_owner }}/chalmers.it
tags: |
type=semver,pattern={{version}}
type=semver,pattern={{major}}.{{minor}}
type=semver,pattern={{major}}
type=sha
type=edge
type=ref,event=pr

- name: Build Docker image (and push on main)
uses: docker/build-push-action@v6
with:
push: ${{ github.ref == 'refs/heads/main' }}
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=gha
cache-to: type=gha,mode=max
40 changes: 23 additions & 17 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@ FROM node:20.8.0-alpine AS deps
LABEL maintainer="digIT <[email protected]>"

RUN apk add --no-cache libc6-compat
RUN yarn global add pnpm

WORKDIR /app
COPY package.json yarn.lock* package-lock.json* pnpm-lock.yaml* ./
RUN yarn global add pnpm && pnpm i --frozen-lockfile
RUN pnpm i --frozen-lockfile

##########################
# BUILD STAGE #
Expand All @@ -23,18 +25,22 @@ RUN yarn build
FROM node:20.8.0-alpine AS runner

WORKDIR /app
ENV NODE_ENV production
ENV HOSTNAME 0.0.0.0
ENV FORCE_COLOR 1
ENV MEDIA_PATH /app/media
ENV NODE_ENV=production
ENV HOSTNAME=0.0.0.0
ENV FORCE_COLOR=1
ENV MEDIA_PATH=/app/media

RUN addgroup --system --gid 1001 nodejs
RUN adduser --system --uid 1001 nextjs

# Copy built files
COPY --from=builder /app/public ./public
COPY --from=builder --chown=nextjs:nodejs /app/.next/standalone ./
COPY --from=builder --chown=nextjs:nodejs /app/.next/static ./.next/static
RUN yarn global add [email protected]

# Create media directory
RUN mkdir -p $MEDIA_PATH
RUN chown -R nextjs:nodejs $MEDIA_PATH

HEALTHCHECK --interval=5s --timeout=5s --retries=3 \
CMD wget 127.0.0.1:3000/api/heartbeat -q -O - > /dev/null 2>&1

# Copy logger configs
COPY --chown=nextjs:nodejs next-logger.config.js /app/
Expand All @@ -43,15 +49,15 @@ COPY --chown=nextjs:nodejs pino-pretty-transport.js /app/
# Copy database schema
COPY --chown=nextjs:nodejs prisma ./prisma

# Create media directory
RUN mkdir -p $MEDIA_PATH
RUN chown -R nextjs:nodejs $MEDIA_PATH
# Copy built files
COPY --from=builder /app/public ./public
COPY --from=builder --chown=nextjs:nodejs /app/.next/standalone ./
COPY --from=builder --chown=nextjs:nodejs /app/.next/static ./.next/static

USER nextjs

HEALTHCHECK --interval=5s --timeout=5s --retries=3 \
CMD wget 127.0.0.1:3000/api/heartbeat -q -O - > /dev/null 2>&1

EXPOSE 3000
ENV PORT 3000
CMD ["node", "server.js"]
ENV PORT=3000

SHELL ["/bin/sh", "-c"]
CMD npx prisma migrate deploy && node server.js
43 changes: 43 additions & 0 deletions docker-compose.gamma.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
services:
db:
image: postgres:16.0-alpine
environment:
POSTGRES_USER: postgres
POSTGRES_PASSWORD: postgres
POSTGRES_DB: postgres
ports:
- "5432:5432"

################## Gamma ##################
auth:
image: ghcr.io/cthit/gamma:latest
environment:
ADMIN_SETUP: true
COOKIE_DOMAIN: localhost:9090
BASE_URL: http://localhost:9090
DB_HOST: gamma-db
DB_NAME: auth
DB_PASSWORD: auth-password
DB_USER: auth
REDIS_HOST: gamma-redis
ROOT_DEBUG_LEVEL: INFO
SERVER_PORT: 9090
PRODUCTION: false
IS_MOCKING: true
PROFILE: production
UPLOAD_FOLDER: /uploads/
volumes:
- ./gamma-images:/uploads
ports:
- 9090:9090
restart: unless-stopped

gamma-redis:
image: redis:5.0

gamma-db:
image: postgres:16-alpine
environment:
POSTGRES_USER: user
POSTGRES_DB: auth
POSTGRES_PASSWORD: auth-password
40 changes: 20 additions & 20 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,42 +11,42 @@
"test": "jest"
},
"dependencies": {
"@prisma/client": "^5.9.1",
"ansis": "^1.5.6",
"@prisma/client": "5.21.1",
"ansis": "3.3.2",
"html-to-slack": "0.3.5",
"jest": "^29.7.0",
"marked": "^14.1.3",
"marked-base-url": "^1.1.5",
"next": "14.1.4",
"next": "14.2.16",
"next-auth": "^4.24.5",
"next-i18n-router": "^5.4.2",
"next-logger": "^3.0.2",
"next-i18n-router": "5.5.1",
"next-logger": "5.0.1",
"next-nprogress-bar": "^2.3.12",
"next-themes": "^0.2.1",
"next-themes": "0.4.3",
"node-schedule": "^2.1.1",
"pino": "^9.1.0",
"pino-pretty": "^11.1.0",
"pino": "9.5.0",
"pino-pretty": "11.3.0",
"react": "^18.2.0",
"react-calendar": "^5.0.0",
"react-calendar": "5.1.0",
"react-dom": "^18.2.0",
"react-icons": "^4.12.0",
"react-toastify": "^10.0.5",
"react-icons": "5.3.0",
"react-toastify": "10.0.6",
"reactjs-popup": "^2.0.6",
"sanitize-html": "^2.13.0"
"sanitize-html": "2.13.1"
},
"devDependencies": {
"@slack/types": "^2.13.0",
"@slack/types": "2.14.0",
"@types/node": "^20.11.16",
"@types/node-schedule": "^2.1.6",
"@types/react": "^18.2.55",
"@types/react": "^18.2.79",
"@types/react-dom": "^18.2.18",
"@types/sanitize-html": "^2.11.0",
"eslint": "^8.57.0",
"eslint-config-next": "14.1.4",
"prettier": "^3.2.5",
"prisma": "^5.9.1",
"sass": "^1.70.0",
"typescript": "^5.3.3",
"typescript-eslint": "^7.11.0"
"eslint-config-next": "14.2.16",
"prettier": "3.3.3",
"prisma": "5.21.1",
"sass": "1.80.6",
"typescript": "5.6.3",
"typescript-eslint": "7.18.0"
}
}
2 changes: 1 addition & 1 deletion pino-pretty-transport.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const ansis = require('ansis/colors');
const ansis = require('ansis');
const turquoise = ansis.hex('#09CDDA');

module.exports = (opts) =>
Expand Down
Loading