fix: frontend and backend now get variables at build time not runtime

This commit is contained in:
theoleuthardt 2025-02-28 11:29:44 +01:00
parent 607d496f2a
commit 776ed29bca
6 changed files with 17 additions and 11 deletions

View file

@ -39,6 +39,8 @@ jobs:
context: ./frontend context: ./frontend
push: true push: true
tags: ${{ secrets.DOCKERHUB_USERNAME }}/werkzeugkiste-frontend:latest tags: ${{ secrets.DOCKERHUB_USERNAME }}/werkzeugkiste-frontend:latest
build-args: |
NEXT_PUBLIC_BACKEND_URL=${{ secrets.NEXT_PUBLIC_BACKEND_URL }}
- name: Build and Push Backend - name: Build and Push Backend
uses: docker/build-push-action@v6 uses: docker/build-push-action@v6
@ -46,6 +48,8 @@ jobs:
context: ./backend context: ./backend
push: true push: true
tags: ${{ secrets.DOCKERHUB_USERNAME }}/werkzeugkiste-backend:latest tags: ${{ secrets.DOCKERHUB_USERNAME }}/werkzeugkiste-backend:latest
build-args: |
CORS_ALLOWED_ORIGIN=${{ secrets.CORS_ALLOWED_ORIGIN }}
deploy-on-server: deploy-on-server:
needs: docker-build-push needs: docker-build-push

View file

@ -61,7 +61,11 @@ USER fastify
EXPOSE 4000 EXPOSE 4000
ARG CORS_ALLOWED_ORIGIN
ENV CORS_ALLOWED_ORIGIN=$CORS_ALLOWED_ORIGIN
ENV PORT=4000 ENV PORT=4000
ENV HOSTNAME="0.0.0.0" ENV HOSTNAME="0.0.0.0"
CMD ["node", "dist/server.js"] CMD ["node", "dist/server.js"]

View file

@ -10,10 +10,6 @@ import { generateQRCode } from "./src/routes/generateqrcode.route";
import { wordCounter } from "./src/routes/wordcounter.route"; import { wordCounter } from "./src/routes/wordcounter.route";
import { videoToAudio } from "./src/routes/videotoaudio.route"; import { videoToAudio } from "./src/routes/videotoaudio.route";
import { removeBG } from "./src/routes/removebg.route"; import { removeBG } from "./src/routes/removebg.route";
import dotenv from "dotenv";
import path from "node:path";
dotenv.config({ path: path.resolve(__dirname, "../.env") });
const app = Fastify({ logger: true }); const app = Fastify({ logger: true });

View file

@ -1,30 +1,32 @@
services: services:
frontend: frontend:
env_file: .env
build: build:
context: ./frontend context: ./frontend
dockerfile: Dockerfile dockerfile: Dockerfile
args:
NEXT_PUBLIC_BACKEND_URL: ${NEXT_PUBLIC_BACKEND_URL}
container_name: werkzeugkiste-frontend container_name: werkzeugkiste-frontend
env_file: .env
environment: environment:
- NODE_ENV=${NODE_ENV} - NODE_ENV=${NODE_ENV}
- HOSTNAME=${HOSTNAME} - HOSTNAME=${HOSTNAME}
- PORT=${FRONTEND_PORT} - PORT=${FRONTEND_PORT}
- NEXT_PUBLIC_BACKEND_URL=${NEXT_PUBLIC_BACKEND_URL}
ports: ports:
- "${FRONTEND_PORT}:3000" - "${FRONTEND_PORT}:3000"
restart: unless-stopped restart: unless-stopped
backend: backend:
env_file: .env
build: build:
context: ./backend context: ./backend
dockerfile: Dockerfile dockerfile: Dockerfile
args:
CORS_ALLOWED_ORIGIN: ${CORS_ALLOWED_ORIGIN}
container_name: werkzeugkiste-backend container_name: werkzeugkiste-backend
env_file: .env
environment: environment:
- NODE_ENV=${NODE_ENV} - NODE_ENV=${NODE_ENV}
- HOSTNAME=${HOSTNAME} - HOSTNAME=${HOSTNAME}
- PORT=${BACKEND_PORT} - PORT=${BACKEND_PORT}
- CORS_ALLOWED_ORIGIN=${CORS_ALLOWED_ORIGIN}
ports: ports:
- "${BACKEND_PORT}:4000" - "${BACKEND_PORT}:4000"
restart: unless-stopped restart: unless-stopped

View file

@ -24,6 +24,9 @@ WORKDIR /app
COPY --from=deps /app/node_modules ./node_modules COPY --from=deps /app/node_modules ./node_modules
COPY . . COPY . .
ARG NEXT_PUBLIC_BACKEND_URL
ENV NEXT_PUBLIC_BACKEND_URL=$NEXT_PUBLIC_BACKEND_URL
# Next.js collects completely anonymous telemetry data about general usage. # Next.js collects completely anonymous telemetry data about general usage.
# Learn more here: https://nextjs.org/telemetry # Learn more here: https://nextjs.org/telemetry
# Uncomment the following line in case you want to disable telemetry during the build. # Uncomment the following line in case you want to disable telemetry during the build.

View file

@ -1,7 +1,4 @@
import type { NextConfig } from "next"; import type { NextConfig } from "next";
import dotenv from "dotenv";
dotenv.config({ path: "../.env" });
const nextConfig: NextConfig = { const nextConfig: NextConfig = {
output: "standalone", output: "standalone",