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

@ -1,52 +1,54 @@
{ {
"name": "kdb-web", "name": "kdb-web",
"version": "0.3.dev70", "version": "0.3.dev70",
"scripts": { "scripts": {
"ng": "ng", "ng": "ng",
"update-version": "ts-node -O '{\"module\": \"commonjs\"}' update-version.ts", "update-version": "ts-node -O '{\"module\": \"commonjs\"}' update-version.ts",
"prestart": "npm run update-version", "prestart": "npm run update-version",
"start": "ng serve", "start": "ng serve",
"prebuild": "npm run update-version", "prebuild": "npm run update-version",
"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 .",
"private": true, "docker-build-stage": "export VERSION=$npm_package_version; ng build --configuration staging; docker build -t kdb-web/kdb-web:$VERSION ."
"dependencies": { },
"@angular/animations": "^14.0.0", "private": true,
"@angular/common": "^14.0.0", "dependencies": {
"@angular/compiler": "^14.0.0", "@angular/animations": "^14.0.0",
"@angular/core": "^14.0.0", "@angular/common": "^14.0.0",
"@angular/forms": "^14.0.0", "@angular/compiler": "^14.0.0",
"@angular/platform-browser": "^14.0.0", "@angular/core": "^14.0.0",
"@angular/platform-browser-dynamic": "^14.0.0", "@angular/forms": "^14.0.0",
"@angular/router": "^14.0.0", "@angular/platform-browser": "^14.0.0",
"@auth0/angular-jwt": "^5.1.0", "@angular/platform-browser-dynamic": "^14.0.0",
"@microsoft/signalr": "^6.0.9", "@angular/router": "^14.0.0",
"@ngx-translate/core": "^14.0.0", "@auth0/angular-jwt": "^5.1.0",
"@ngx-translate/http-loader": "^7.0.0", "@microsoft/signalr": "^6.0.9",
"@types/socket.io-client": "^3.0.0", "@ngx-translate/core": "^14.0.0",
"primeicons": "^6.0.1", "@ngx-translate/http-loader": "^7.0.0",
"primeng": "^14.1.2", "@types/socket.io-client": "^3.0.0",
"rxjs": "~7.5.0", "primeicons": "^6.0.1",
"socket.io-client": "^4.5.3", "primeng": "^14.1.2",
"tslib": "^2.3.0", "rxjs": "~7.5.0",
"zone.js": "~0.11.4" "socket.io-client": "^4.5.3",
}, "tslib": "^2.3.0",
"devDependencies": { "zone.js": "~0.11.4"
"@angular-devkit/build-angular": "^14.0.0", },
"@angular/cli": "~14.0.0", "devDependencies": {
"@angular/compiler-cli": "^14.0.0", "@angular-devkit/build-angular": "^14.0.0",
"@types/jasmine": "~4.0.0", "@angular/cli": "~14.0.0",
"@types/node": "^18.8.3", "@angular/compiler-cli": "^14.0.0",
"jasmine-core": "~4.1.0", "@types/jasmine": "~4.0.0",
"karma": "~6.3.0", "@types/node": "^18.8.3",
"karma-chrome-launcher": "~3.1.0", "jasmine-core": "~4.1.0",
"karma-coverage": "~2.2.0", "karma": "~6.3.0",
"karma-jasmine": "~5.0.0", "karma-chrome-launcher": "~3.1.0",
"karma-jasmine-html-reporter": "~1.7.0", "karma-coverage": "~2.2.0",
"ts-node": "~8.3.0", "karma-jasmine": "~5.0.0",
"typescript": "~4.7.2" "karma-jasmine-html-reporter": "~1.7.0",
} "ts-node": "~8.3.0",
"typescript": "~4.7.2"
}
} }

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",
}; };
/* /*