Skip to content

Commit

Permalink
♻️ improve docker compose deployment + made controlpanel production i…
Browse files Browse the repository at this point in the history
…mages
  • Loading branch information
TarradeMarc committed Feb 7, 2025
1 parent a5c8a5b commit 57c34e3
Show file tree
Hide file tree
Showing 13 changed files with 142 additions and 31 deletions.
2 changes: 1 addition & 1 deletion configmanager/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ const fs = require('fs');
const hsts = require('hsts')
const path = require('path')

const API_URL = "http://controlpanel-api:8050";
const API_URL = process.env.CONTROLPANEL_API_URL;

app.use(hsts({
maxAge: 31536000,
Expand Down
12 changes: 6 additions & 6 deletions controlpanel/api/.env
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
DB_USER=<POSTGRES_USER>
DB_PASSWORD=<POSTGRES_PASSWORD>
DB_HOST=<POSTGRES_HOST>
DB_PORT=<POSTGRES_PORT>
DB_USER=postgres
DB_PASSWORD=postgres
DB_HOST=controlpanel-db
DB_PORT=5432

# Number of minutes
CRON_CONFIGMANAGER=60

CONTROLPANEL_FRONTEND_URL=<FRONT_END_URL> #http://localhost:4200
CONFIGMANAGER_URL=<CONFIGMANAGER_URL> #http://localhost:3000
CONTROLPANEL_FRONTEND_URL=http://localhost:4200
CONFIGMANAGER_URL=http://configmanager:3000
3 changes: 1 addition & 2 deletions controlpanel/api/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,10 @@ WORKDIR /app

COPY package*.json ./

RUN npm install -g nodemon
RUN npm install

COPY . .

EXPOSE 8050

CMD ["nodemon", "--watch", ".", "--legacy-watch", "server.js"]
CMD ["node", "server.js"]
14 changes: 14 additions & 0 deletions controlpanel/api/Dockerfile-dev
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
FROM node:21

WORKDIR /app

COPY package*.json ./

RUN npm install -g nodemon
RUN npm install

COPY . .

EXPOSE 8050

CMD ["nodemon", "--watch", ".", "--legacy-watch", "server.js"]
21 changes: 16 additions & 5 deletions controlpanel/cad/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,14 +1,25 @@
FROM node:21
FROM node:21 AS build

WORKDIR /app

COPY package*.json ./

RUN npm install -g @angular/cli
RUN npm install
RUN npm ci

COPY . .

EXPOSE 4200
RUN npm run build --prod

CMD [ "ng", "serve", "--host", "0.0.0.0", "--port", "4200", "--poll", "1000"]
FROM nginx:alpine

RUN rm /etc/nginx/conf.d/default.conf

COPY nginx.conf /etc/nginx/conf.d/default.conf
COPY --from=build /app/dist/cad/browser /usr/share/nginx/html
COPY replace-env.sh /docker-entrypoint.d/99-replace-env.sh

RUN chmod +x /docker-entrypoint.d/99-replace-env.sh

EXPOSE 80

CMD ["nginx", "-g", "daemon off;"]
14 changes: 14 additions & 0 deletions controlpanel/cad/Dockerfile-dev
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
FROM node:21

WORKDIR /app

COPY package*.json ./

RUN npm install -g @angular/cli
RUN npm install

COPY . .

EXPOSE 4200

CMD [ "ng", "serve", "--host", "0.0.0.0", "--port", "4200", "--poll", "1000"]
4 changes: 2 additions & 2 deletions controlpanel/cad/angular.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@
},
{
"type": "anyComponentStyle",
"maximumWarning": "2kB",
"maximumError": "4kB"
"maximumWarning": "8kB",
"maximumError": "10kB"
}
],
"outputHashing": "all"
Expand Down
16 changes: 16 additions & 0 deletions controlpanel/cad/nginx.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
server {
listen 80;

server_name localhost;

location / {
root /usr/share/nginx/html;
index index.html;
try_files $uri $uri/ /index.html;
}

error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
}
8 changes: 8 additions & 0 deletions controlpanel/cad/replace-env.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/bin/sh

for file in /usr/share/nginx/html/*.js; do
echo "Processing $file ...";
sed -i 's|<REPLACE_CONTROLPANEL_API_URL>|'${CONTROLPANEL_API_URL}'|g' $file
done

exec "$@"
3 changes: 2 additions & 1 deletion controlpanel/cad/src/app/services/global-state.service.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { Injectable } from '@angular/core';
import { ProtectedApp } from '../models/protected-app';
import { BehaviorSubject } from 'rxjs';
import { environment } from '../../environments/environment';

@Injectable({
providedIn: 'root'
Expand All @@ -9,7 +10,7 @@ export class GlobalStateService {

private selectedAppSubject = new BehaviorSubject<ProtectedApp>(this.selectedApp);
selectedApp$ = this.selectedAppSubject.asObservable();
readonly API_URL = 'http://localhost:8050'; // http://controlpanel-api:8050
readonly API_URL = environment.CONTROLPANEL_API_URL;

get selectedApp(): ProtectedApp {
const local = localStorage.getItem('protectedApp');
Expand Down
3 changes: 3 additions & 0 deletions controlpanel/cad/src/environments/environment.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export const environment = {
CONTROLPANEL_API_URL: '<REPLACE_CONTROLPANEL_API_URL>',
}
71 changes: 58 additions & 13 deletions docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ services:
- configvolume:/data/blocklist
ports:
- "3000:3000"
environment:
- CONTROLPANEL_API_URL=http://controlpanel-api:8050

proxy:
container_name: proxy
Expand All @@ -39,6 +41,8 @@ services:
ports:
- "24224:24224"
- "24224:24224/udp"
environment:
- CONTROLPANEL_API_URL=controlpanel-api

clone:
container_name: clone
Expand All @@ -58,10 +62,47 @@ services:
logging:
driver: fluentd

# controlpanel-api-dev:
# container_name: controlpanel-api-dev
# build:
# context: controlpanel/api
# dockerfile: Dockerfile-dev
# image: api-dev
# ports:
# - 8050:8050
# depends_on:
# config:
# condition: service_started
# controlpanel-db:
# condition: service_healthy
# fluent:
# condition: service_started
# volumes:
# - ./controlpanel/api:/app:cached
# - /app/node_modules

# controlpanel-dev:
# container_name: controlpanel-dev
# build:
# context: controlpanel/cad
# dockerfile: Dockerfile-dev
# image: controlpanel-dev
# ports:
# - 4200:4200
# depends_on:
# - controlpanel-api-dev
# volumes:
# - ./controlpanel/cad:/app
# - /app/node_modules
# environment:
# - CHOKIDAR_USEPOLLING=true

controlpanel-api:
container_name: controlpanel-api
build: controlpanel/api
image: api
build:
context: controlpanel/api
dockerfile: Dockerfile
# image: ghcr.io/sap/controlpanel-api:latest
ports:
- 8050:8050
depends_on:
Expand All @@ -71,23 +112,27 @@ services:
condition: service_healthy
fluent:
condition: service_started
volumes:
- ./controlpanel/api:/app:cached
- /app/node_modules
environment:
- DB_USER=postgres
- DB_PASSWORD=postgres
- DB_HOST=controlpanel-db
- DB_PORT=5432
- CRON_CONFIGMANAGER=60
- CONTROLPANEL_FRONTEND_URL=http://localhost
- CONFIGMANAGER_URL=http://configmanager:3000

controlpanel:
container_name: controlpanel
build: controlpanel/cad
image: controlpanel
build:
context: controlpanel/cad
dockerfile: Dockerfile
# image: ghcr.io/sap/controlpanel-frontend:latest
ports:
- 4200:4200
- 80:80
depends_on:
- controlpanel-api
volumes:
- ./controlpanel/cad:/app
- /app/node_modules
environment:
- CHOKIDAR_USEPOLLING=true
- CONTROLPANEL_API_URL=http://localhost:8050

controlpanel-db:
image: postgres
Expand All @@ -102,7 +147,7 @@ services:
volumes:
- postgres_data:/var/lib/postgresql/data
healthcheck:
test: ["CMD-SHELL", "pg_isready -U postgres"]
test: ["CMD-SHELL", "pg_isready"]
interval: 10s
timeout: 5s
retries: 5
Expand Down
2 changes: 1 addition & 1 deletion fluentbit/fluent-bit.conf
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
[OUTPUT]
Name http
Match **
Host controlpanel-api
Host ${CONTROLPANEL_API_URL}
Port 8050
URI /logs
Format json
Expand Down

0 comments on commit 57c34e3

Please sign in to comment.