Improved docker support for deployment #70

This commit is contained in:
Sven Heidemann 2022-10-23 14:11:15 +02:00
parent ffe7b5e109
commit f891587ce3
13 changed files with 135 additions and 77 deletions

View File

@ -8,7 +8,7 @@ volumes:
services: services:
kdb_bot_staging_1: kdb_bot_staging_1:
image: kdb-bot/kdb-bot:0.3 image: kdb-bot/kdb-bot:0.3
container_name: kdb_staging_1 container_name: kdb_bot_staging_1
depends_on: depends_on:
- kdb_db_staging_1 - kdb_db_staging_1
volumes: volumes:
@ -19,7 +19,8 @@ services:
KDB_PREFIX: "!kt " KDB_PREFIX: "!kt "
restart: 'no' restart: 'no'
ports: ports:
- '8043:80' - '8044:80'
command: bash /app/bot/bot -stage
kdb_web_staging_1: kdb_web_staging_1:
image: kdb-web/kdb-web:0.3 image: kdb-web/kdb-web:0.3
@ -30,7 +31,7 @@ services:
- kdb_web_staging_1:/app - kdb_web_staging_1:/app
restart: 'no' restart: 'no'
ports: ports:
- '8044:80' - '8043:80'
kdb_db_staging_1: kdb_db_staging_1:
image: mysql:latest image: mysql:latest

View File

@ -13,5 +13,6 @@ RUN apk add bash
RUN apk add nano RUN apk add nano
RUN pip install -r requirements.txt --extra-index-url https://pip.sh-edraft.de RUN pip install -r requirements.txt --extra-index-url https://pip.sh-edraft.de
RUN pip install flask[async]
CMD [ "bash", "/app/bot/bot"] CMD [ "bash", "/app/bot/bot"]

View File

@ -51,7 +51,7 @@ class Api(Flask):
self.error_handler_spec[None][code][exc_class] = self.handle_exception self.error_handler_spec[None][code][exc_class] = self.handle_exception
# websockets # websockets
self._socketio = SocketIO(self, cors_allowed_origins='*') self._socketio = SocketIO(self, cors_allowed_origins='*', path='/api/socket.io')
self._socketio.on_event('connect', self.on_connect) self._socketio.on_event('connect', self.on_connect)
self._socketio.on_event('disconnect', self.on_disconnect) self._socketio.on_event('disconnect', self.on_disconnect)

View File

@ -57,6 +57,14 @@
], ],
"outputHashing": "all" "outputHashing": "all"
}, },
"staging": {
"fileReplacements": [
{
"replace": "src/environments/environment.ts",
"with": "src/environments/environment.staging.ts"
}
]
},
"development": { "development": {
"buildOptimizer": false, "buildOptimizer": false,
"optimization": false, "optimization": false,

View File

@ -1,2 +1,4 @@
FROM nginx:alpine FROM nginx:alpine
COPY nginx.conf /etc/nginx/nginx.conf
RUN rm -rf /usr/share/nginx/html/*
COPY ./dist/kdb-web/ /usr/share/nginx/html COPY ./dist/kdb-web/ /usr/share/nginx/html

36
kdb-web/nginx.conf Normal file
View File

@ -0,0 +1,36 @@
events{}
http {
include /etc/nginx/mime.types;
server {
listen 80;
sendfile on;
default_type application/octet-stream;
gzip on;
gzip_http_version 1.1;
gzip_disable “MSIE [16]\.”;
gzip_min_length 256;
gzip_vary on;
gzip_proxied expired no-cache no-store private auth;
gzip_types text/plain text/css application/json application/javascript application/x-javascript text/xml application/xml application/xml+rss text/javascript;
gzip_comp_level 9;
root /usr/share/nginx/html;
index index.html;
location / {
try_files $uri $uri/ /index.html =404;
}
location /api {
proxy_pass http://kdb_bot_staging_1;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
proxy_set_header Host $host;
proxy_cache_bypass $http_upgrade;
proxy_redirect off;
}
}
}

View File

@ -10,7 +10,9 @@
"build": "ng build", "build": "ng build",
"watch": "ng build --watch --configuration development", "watch": "ng build --watch --configuration development",
"test": "ng test", "test": "ng test",
"docker-build": "export VERSION=$npm_package_version; ng build; docker build -t kdb-web/kdb-web:$VERSION ." "docker-build": "export VERSION=$npm_package_version; ng build; docker build -t kdb-web/kdb-web:$VERSION .",
"docker-build-dev": "export VERSION=$npm_package_version; ng build --configuration development; docker build -t kdb-web/kdb-web:$VERSION .",
"docker-build-stage": "export VERSION=$npm_package_version; ng build --configuration staging; docker build -t kdb-web/kdb-web:$VERSION ."
}, },
"private": true, "private": true,
"dependencies": { "dependencies": {

View File

@ -1,11 +1,11 @@
import { HttpClient } from '@angular/common/http'; import { HttpClient } from "@angular/common/http";
import { Injectable } from '@angular/core'; import { Injectable } from "@angular/core";
import { throwError } from 'rxjs'; import { throwError } from "rxjs";
import { catchError } from 'rxjs/operators'; import { catchError } from "rxjs/operators";
import { Appsettings } from 'src/app/models/config/appsettings'; import { Appsettings } from "src/app/models/config/appsettings";
import { SoftwareVersion } from 'src/app/models/config/software-version'; import { SoftwareVersion } from "src/app/models/config/software-version";
import { Theme } from 'src/app/models/view/theme'; import { Theme } from "src/app/models/view/theme";
import { Themes } from 'src/app/models/view/themes.enum'; import { environment } from "../../../environments/environment";
@Injectable({ @Injectable({
providedIn: 'root' providedIn: 'root'
@ -31,11 +31,11 @@ export class SettingsService {
} }
public getApiURL(): string { public getApiURL(): string {
if (!this.appsettings || !this.appsettings.ApiURL) { if (!environment || !environment.apiURL) {
console.error('ApiURL is not set!'); console.error('ApiURL is not set!');
return ''; return '';
} }
return this.appsettings.ApiURL; return environment.apiURL;
} }
public getWebVersion(): SoftwareVersion | null { public getWebVersion(): SoftwareVersion | null {
@ -43,12 +43,11 @@ export class SettingsService {
console.error('WebVersion is not set!'); console.error('WebVersion is not set!');
return null; return null;
} }
const webVersion = new SoftwareVersion( return new SoftwareVersion(
this.appsettings.WebVersion.Major, this.appsettings.WebVersion.Major,
this.appsettings.WebVersion.Minor, this.appsettings.WebVersion.Minor,
this.appsettings.WebVersion.Micro this.appsettings.WebVersion.Micro
); );
return webVersion;
} }
public getThemes(): Theme[] | null { public getThemes(): Theme[] | null {

View File

@ -1,11 +1,10 @@
import { HttpClient } from '@angular/common/http'; import { Injectable } from "@angular/core";
import { Injectable } from '@angular/core'; import { ToastOptions } from "src/app/models/utils/toast-options";
import { ToastOptions } from 'src/app/models/utils/toast-options'; import { SettingsService } from "../settings/settings.service";
import { SettingsService } from '../settings/settings.service'; import { SpinnerService } from "../spinner/spinner.service";
import { SpinnerService } from '../spinner/spinner.service'; import { ToastService } from "../toast/toast.service";
import { ToastService } from '../toast/toast.service';
import io from "socket.io-client"; import io from "socket.io-client";
import { MessageService } from 'primeng/api'; import { MessageService } from "primeng/api";
@Injectable({ @Injectable({
providedIn: 'root' providedIn: 'root'
@ -23,7 +22,7 @@ export class SocketService {
} }
startSocket() { startSocket() {
this.socket = io(`${this.settingsService.getApiURL()}`) this.socket = io(`${this.settingsService.getApiURL()}`, {path: '/api/socket.io'})
this.socket.on('connect', () => { this.socket.on('connect', () => {
if (this.disconnected) { if (this.disconnected) {
if (this.spinnerService.showSpinnerState) { if (this.spinnerService.showSpinnerState) {

View File

@ -0,0 +1,4 @@
export const environment = {
production: true,
apiURL: "http://localhost:5000",
};

View File

@ -1,3 +1,4 @@
export const environment = { export const environment = {
production: true production: true,
apiURL: "https://kdb.keksdose-gaming.de/",
}; };

View File

@ -0,0 +1,4 @@
export const environment = {
production: true,
apiURL: "https://kdb-test.keksdose-gaming.de/",
};

View File

@ -3,7 +3,8 @@
// The list of file replacements can be found in `angular.json`. // The list of file replacements can be found in `angular.json`.
export const environment = { export const environment = {
production: false production: false,
apiURL: "https://kdb_web_prod_1",
}; };
/* /*