mirror of
https://github.com/OHTU-German-learning-website/OHTU-German-learning-website.git
synced 2026-10-12 19:13:51 +03:00
Committed changes suggested by technical assistant.
This commit is contained in:
+35
-24
@@ -1,22 +1,19 @@
|
|||||||
FROM node:18-alpine
|
FROM node:18-alpine
|
||||||
|
|
||||||
WORKDIR /app/gradesa
|
|
||||||
# Disable Husky during install
|
# Disable Husky during install
|
||||||
ENV HUSKY=0
|
ENV HUSKY=0
|
||||||
|
|
||||||
# Set default environment variables for build
|
# Can be overriden by setting build-args when building image
|
||||||
|
ARG DB_HOST="localhost"
|
||||||
ENV SESSION_SECRET=secret \
|
ARG DB_PORT="5432"
|
||||||
|
ARG DB_USER="postgres"
|
||||||
DB_HOST=localhost \
|
ARG DB_PASSWORD="password"
|
||||||
|
ARG DB_NAME="postgres"
|
||||||
DB_PORT=5432 \
|
ARG SESSION_SECRET="secret"
|
||||||
|
ARG NODE_ENV="production"
|
||||||
DB_USER=postgres \
|
# NOTE: The above args and the following ENVs are overridden
|
||||||
|
# by .env and .env.$NODE_ENV file contents if they exist
|
||||||
DB_PASSWORD=password \
|
# so these apply ONLY when ./init-env.sh has not been run
|
||||||
|
|
||||||
DB_NAME=postgres
|
|
||||||
|
|
||||||
RUN apk update && \
|
RUN apk update && \
|
||||||
apk add --no-cache wget && \
|
apk add --no-cache wget && \
|
||||||
@@ -25,14 +22,29 @@ RUN apk update && \
|
|||||||
|
|
||||||
RUN apk add --no-cache postgresql-client
|
RUN apk add --no-cache postgresql-client
|
||||||
|
|
||||||
|
# OpenShift requires non-root user
|
||||||
|
RUN adduser -D nonroot
|
||||||
|
USER nonroot
|
||||||
|
|
||||||
|
WORKDIR /app/gradesa
|
||||||
|
|
||||||
# Copy package files from gradesa
|
# Copy package files from gradesa
|
||||||
COPY gradesa/package*.json ./
|
COPY --chown=nonroot:nonroot gradesa/package*.json ./
|
||||||
|
|
||||||
|
# Set default environment variables for build
|
||||||
|
ENV SESSION_SECRET=$SESSION_SECRET \
|
||||||
|
DB_HOST=$DB_HOST \
|
||||||
|
DB_PORT=$DB_PORT \
|
||||||
|
DB_USER=$DB_USER \
|
||||||
|
DB_PASSWORD=$DB_PASSWORD \
|
||||||
|
DB_NAME=$DB_NAME \
|
||||||
|
NODE_ENV=$NODE_ENV
|
||||||
|
|
||||||
# Install ALL dependencies (including dev) for build
|
# Install ALL dependencies (including dev) for build
|
||||||
RUN npm i
|
RUN npm ci
|
||||||
|
|
||||||
# Copy app files including .env.production
|
# Copy app files including .env.production
|
||||||
COPY gradesa/ .
|
COPY --chown=nonroot:nonroot gradesa/ .
|
||||||
|
|
||||||
#This is for memory optimizing
|
#This is for memory optimizing
|
||||||
ENV NODE_OPTIONS="--max-old-space-size=8192"
|
ENV NODE_OPTIONS="--max-old-space-size=8192"
|
||||||
@@ -41,16 +53,15 @@ ENV NODE_OPTIONS="--max-old-space-size=8192"
|
|||||||
RUN npm run build
|
RUN npm run build
|
||||||
|
|
||||||
# Remove dev dependencies
|
# Remove dev dependencies
|
||||||
RUN npm prune --production
|
RUN npm prune --omit=dev
|
||||||
|
|
||||||
|
# Copy static files to .next/standalone, this is not done automatically
|
||||||
|
RUN cp -r .next/static .next/standalone/.next
|
||||||
|
RUN cp -r public .next/standalone/
|
||||||
|
|
||||||
# OpenShift requires non-root user
|
|
||||||
RUN adduser -D nonroot && chown -R nonroot:nonroot /app/gradesa
|
|
||||||
USER nonroot
|
|
||||||
|
|
||||||
# Next.js needs to listen on 8080
|
# Next.js needs to listen on 8080
|
||||||
ENV PORT=8080
|
ENV PORT=8080
|
||||||
EXPOSE 8080
|
EXPOSE 8080
|
||||||
|
|
||||||
|
CMD ["npm", "run", "start:standalone"]
|
||||||
|
|
||||||
CMD ["npm", "start"]
|
|
||||||
|
|||||||
@@ -0,0 +1,30 @@
|
|||||||
|
services:
|
||||||
|
db:
|
||||||
|
image: docker.io/library/postgres:15
|
||||||
|
container_name: gradesa-db
|
||||||
|
environment:
|
||||||
|
POSTGRES_PASSWORD: password
|
||||||
|
volumes:
|
||||||
|
- pg-data:/var/lib/postgresql/data/
|
||||||
|
restart: unless-stopped
|
||||||
|
healthcheck:
|
||||||
|
test: ["CMD", "pg_isready", "-U", "postgres"]
|
||||||
|
interval: 10s
|
||||||
|
retries: 20
|
||||||
|
command: -p 7742
|
||||||
|
|
||||||
|
gradesa:
|
||||||
|
build:
|
||||||
|
context: .
|
||||||
|
dockerfile: Dockerfile
|
||||||
|
args:
|
||||||
|
NODE_ENV: production
|
||||||
|
DB_HOST: db
|
||||||
|
DB_PORT: 7742
|
||||||
|
ports:
|
||||||
|
- 8080:8080
|
||||||
|
depends_on:
|
||||||
|
- db
|
||||||
|
|
||||||
|
volumes:
|
||||||
|
pg-data:
|
||||||
@@ -7,6 +7,7 @@
|
|||||||
"dev": "next dev --turbopack",
|
"dev": "next dev --turbopack",
|
||||||
"build": "next build",
|
"build": "next build",
|
||||||
"start": "sh ./data/migrate.sh --skip-schema-gen && next start",
|
"start": "sh ./data/migrate.sh --skip-schema-gen && next start",
|
||||||
|
"start:standalone": "sh ./data/migrate.sh --skip-schema-gen && node .next/standalone/server.js",
|
||||||
"lint": "next lint",
|
"lint": "next lint",
|
||||||
"test": "vitest --disable-console-intercept",
|
"test": "vitest --disable-console-intercept",
|
||||||
"test:coverage": "vitest --disable-console-intercept --coverage.enabled=true",
|
"test:coverage": "vitest --disable-console-intercept --coverage.enabled=true",
|
||||||
|
|||||||
@@ -2,17 +2,18 @@
|
|||||||
|
|
||||||
import { checkUseIsAdmin } from "@/context/user.context";
|
import { checkUseIsAdmin } from "@/context/user.context";
|
||||||
import { Button } from "@/components/ui/button";
|
import { Button } from "@/components/ui/button";
|
||||||
import router from "next/navigation";
|
import { useRouter } from "next/navigation";
|
||||||
import { useUser } from "@/context/user.context";
|
import { useUser } from "@/context/user.context";
|
||||||
|
|
||||||
export default function EditButton({ url }) {
|
export default function EditButton({ url }) {
|
||||||
const { setActAs } = useUser();
|
const { setActAs } = useUser();
|
||||||
|
const router = useRouter();
|
||||||
if (checkUseIsAdmin()) {
|
if (checkUseIsAdmin()) {
|
||||||
return (
|
return (
|
||||||
<Button
|
<Button
|
||||||
onClick={() => {
|
onClick={() => {
|
||||||
setActAs({ label: "Lehrer", value: "admin" });
|
setActAs({ label: "Lehrer", value: "admin" });
|
||||||
router.redirect(url);
|
router.push(url);
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
Edit Page
|
Edit Page
|
||||||
|
|||||||
Reference in New Issue
Block a user