Skip to content

Commit

Permalink
fix: docker update
Browse files Browse the repository at this point in the history
  • Loading branch information
ralfaron committed Sep 15, 2024
1 parent 2538426 commit e13288e
Show file tree
Hide file tree
Showing 23 changed files with 218 additions and 146 deletions.
16 changes: 16 additions & 0 deletions .env
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
MYSQL_ROOT_PASSWORD=db>D6~M$4§Y:sChh
MYSQL_USER=aas-server
MYSQL_PASSWORD=60PYRe6Vd8C99u4n

MONGO_INITDB_ROOT_USERNAME=aas-server
MONGO_INITDB_ROOT_PASSWORD=bObXJWW6e8Nh78YF

NEXTCLOUD_MYSQL_ROOT_PASSWORD=H68rJ7h4wJ75PgUY
NEXTCLOUD_MYSQL_PASSWORD=VgpnIrk8jJRj435b
NEXTCLOUD_ADMIN_USER=aas-server
NEXTCLOUD_ADMIN_PASSWORD=5w0vmrkzrwDIDyZs
NEXTCLOUD_TRUSTED_DOMAINS=localhost

AAS_INDEX=mysql://aas-server:60PYRe6Vd8C99u4n@aasportal-index:3306
USER_STORAGE=mongodb://aas-server:bObXJWW6e8Nh78YF@aasportal-users:27017/aasportal-users
TEMPLATE_STORAGE=http://aas-server:5w0vmrkzrwDIDyZs@aasportal-cloud:8080/templates
4 changes: 2 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ temp
*-audit.json
swagger.json
swagger.yaml
projects/aas-server/src/app/routes
./projects/ass-server/src/assets/app-info.json
/projects/aas-server/src/app/routes
/projects/ass-server/src/assets/app-info.json

# System files
.DS_Store
Expand Down
6 changes: 3 additions & 3 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@
"CONTENT_ROOT": "projects/aas-server/build",
"WEB_ROOT": "projects/aas-portal/dist",
"ASSETS": "projects/aas-server/src/assets",
// "USER_STORAGE": "mongodb://172.16.160.177:27017/aasportal-users",
// "TEMPLATE_STORAGE": "http://172.16.160.177:8080/templates",
// "AAS_INDEX": "mysql://172.16.160.177:3306",
"USER_STORAGE": "mongodb://aas-server:bObXJWW6e8Nh78YF@localhost:27017/aasportal-users",
"TEMPLATE_STORAGE": "http://aas-server:5w0vmrkzrwDIDyZs@localhost:8080/templates",
"AAS_INDEX": "mysql://aas-server:60PYRe6Vd8C99u4n@localhost:3306",
"ENDPOINTS": "[\"file:///endpoints/samples?name=Samples\"]",
}
},
Expand Down
15 changes: 7 additions & 8 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,22 +1,21 @@
# Dockerfile to build server and client parts
# Creates an all-in-one Docker image
FROM node:20.11.1-alpine AS build
WORKDIR /usr/src/app
COPY . .
# RUN apk add g++ make py3-pip
RUN npm install
RUN node --no-warnings --loader ts-node/esm create-app-info.ts
RUN npm run build

FROM node:20.11.1-alpine AS aasportal
RUN apk upgrade --update-cache --available && apk add openssl && rm -rf /var/cache/apk/*
WORKDIR /usr/src/app
COPY projects/aas-server/package.json package.json
COPY projects/aas-server/src/assets assets/
COPY --from=build /usr/src/app/projects/aas-server/package.json package.json
RUN npm install --omit=dev
COPY --from=build /usr/src/app/projects/aas-server/dist/ /usr/src/app/
COPY --from=build /usr/src/app/projects/aas-core/dist/ /usr/src/app/node_modules/aas-core/dist/
COPY --from=build /usr/src/app/projects/aas-core/package.json /usr/src/app/node_modules/aas-core/package.json
COPY --from=build /usr/src/app/projects/aas-portal/dist/browser/ /usr/src/app/wwwroot/
COPY --from=build /usr/src/app/projects/aas-server/src/assets assets/
COPY --from=build /usr/src/app/projects/aas-server/dist/ .
COPY --from=build /usr/src/app/projects/aas-core/dist/ node_modules/aas-core/dist/
COPY --from=build /usr/src/app/projects/aas-core/package.json node_modules/aas-core/package.json
COPY --from=build /usr/src/app/projects/aas-portal/dist/browser/ wwwroot/
ENV NODE_LOG=./log/debug.log
ENV NODE_SERVER_PORT=80
ENV ENDPOINTS=["\"file:///endpoints/samples?name=Samples\""]
Expand Down
3 changes: 2 additions & 1 deletion Dockerfile.aas-portal
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
# Dockerfile to build server and client parts
# Dockerfile to build client app
FROM node:20.11.1-alpine AS build
WORKDIR /usr/src/app
COPY . .
RUN npm install
RUN npm run aas-portal:build

FROM nginx:latest AS aas-portal
#possibility to check host & port availability of other containers via netcat
RUN apt-get update -y && apt-get install -y netcat-openbsd
Expand Down
19 changes: 8 additions & 11 deletions Dockerfile.aas-server
Original file line number Diff line number Diff line change
@@ -1,28 +1,25 @@
# Dockerfile to build server and client parts
FROM node:20.11.1-alpine as build
# Dockerfile to build server app
FROM node:20.11.1-alpine AS build
WORKDIR /usr/src/app
COPY . .
# RUN apk add g++ make py3-pip
RUN npm install
RUN node --no-warnings --loader ts-node/esm create-app-info.ts
RUN npm run aas-server:build

FROM node:20.11.1-alpine AS aas-server
RUN apk upgrade --update-cache --available && apk add openssl && rm -rf /var/cache/apk/*
WORKDIR /usr/src/app
COPY projects/aas-server/package.json package.json
COPY projects/aas-server/src/assets assets/
COPY --from=build /usr/src/app/projects/aas-server/package.json package.json
RUN npm install --omit=dev
COPY --from=build /usr/src/app/projects/aas-server/dist/ /usr/src/app/
COPY --from=build /usr/src/app/projects/aas-core/dist/ /usr/src/app/node_modules/aas-core/dist/
COPY --from=build /usr/src/app/projects/aas-core/package.json /usr/src/app/node_modules/aas-core/package.json
COPY --from=build /usr/src/app/projects/aas-server/src/assets assets/
COPY --from=build /usr/src/app/projects/aas-server/dist/ .
COPY --from=build /usr/src/app/projects/aas-core/dist/ node_modules/aas-core/dist/
COPY --from=build /usr/src/app/projects/aas-core/package.json node_modules/aas-core/package.json
ENV NODE_LOG=./log/debug.log
ENV NODE_SERVER_PORT=1337
ENV USER_STORAGE=mongodb://172.16.160.177:27017/aasportal-users
ENV AAS_INDEX=mysql://172.16.160.177:3306
ENV TEMPLATE_STORAGE: http://172.16.160.177:8080/templates
ENV ENDPOINTS=["\"file:///endpoints/samples?name=Samples\""]
ENV NODE_ENV=production

EXPOSE 1337
CMD ["node", "aas-server.js" ]

30 changes: 18 additions & 12 deletions create-app-info.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import { readFile, writeFile, readdir } from 'fs/promises';
import path from 'path';
import { existsSync } from 'fs';
import { dirname, resolve, join } from 'path';
import { dirname, join } from 'path';
import { fileURLToPath } from 'url';

interface Package {
Expand Down Expand Up @@ -65,7 +65,16 @@ const exclude = new Set(['aas-core', 'aas-lib', 'aas-portal', 'aas-server', 'fhg
await main();

async function main(): Promise<void> {
const project: Package = await read(resolve(__dirname, 'package.json'));
const packageFile = join(__dirname, 'package.json');
let project: Package;
try {
project = await JSON.parse((await readFile(packageFile)).toString());
console.info(`File ${packageFile} read.`);
} catch (error) {
console.error(error);
return;
}

const appInfo: ApplicationInfo = {
name: project.name,
version: project.version,
Expand All @@ -76,16 +85,13 @@ async function main(): Promise<void> {
libraries: await readLibrariesAsync(project),
};

const file = resolve(__dirname, 'projects/aas-server/src/assets/app-info.json');
await write(file, appInfo);
}

async function read<T>(file: string): Promise<T> {
return JSON.parse((await readFile(file)).toString());
}

function write(file: string, data: object): Promise<void> {
return writeFile(file, JSON.stringify(data, undefined, 2));
const file = join(__dirname, 'projects/aas-server/src/assets/app-info.json');
try {
await writeFile(file, JSON.stringify(appInfo, undefined, 2));
console.info(`File ${file} read.`);
} catch (error) {
console.error(error);
}
}

async function readLibrariesAsync(project: Package): Promise<Library[]> {
Expand Down
56 changes: 47 additions & 9 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,14 @@ services:
ports:
- 27017:27017
volumes:
#persist db data (users remain after restart)
- mongodata:/data/db
environment:
- MONGO_INITDB_ROOT_USERNAME=aas-server
- MONGO_INITDB_ROOT_PASSWORD=aas-server
- MONGO_INITDB_ROOT_USERNAME=${MONGO_INITDB_ROOT_USERNAME}
- MONGO_INITDB_ROOT_PASSWORD=${MONGO_INITDB_ROOT_PASSWORD}
- MONGO_INITDB_DATABASE=aasportal-users

aasportal-index:
image: mariadb:latest
image: mariadb
container_name: aasportal-index
command: --default-authentication-plugin=mysql_native_password
healthcheck:
Expand All @@ -34,20 +33,56 @@ services:
- sqldata:/var/lib/mysql
restart: always
environment:
MYSQL_ROOT_PASSWORD: db>D6~M$4§Y:sChh
MYSQL_ROOT_PASSWORD: ${MYSQL_ROOT_PASSWORD}
MYSQL_DATABASE: aas-index
MYSQL_USER: aas-server
MYSQL_PASSWORD: aas-server
MYSQL_USER: ${MYSQL_USER}
MYSQL_PASSWORD: ${MYSQL_PASSWORD}
ports:
- 3306:3306

aasportal-cloud-db:
image: mariadb
container_name: aasportal-cloud-db
restart: always
command: --transaction-isolation=READ-COMMITTED --log-bin=binlog --binlog-format=ROW
volumes:
- nextcloud_db:/var/lib/mysql
environment:
- MYSQL_ROOT_PASSWORD=${NEXTCLOUD_MYSQL_ROOT_PASSWORD}
- MYSQL_PASSWORD=${NEXTCLOUD_PASSWORD}
- MYSQL_DATABASE=nextcloud
- MYSQL_USER=nextcloud

aasportal-cloud:
image: nextcloud
container_name: aasportal-cloud
restart: always
ports:
- 8080:80
links:
- aasportal-cloud-db
volumes:
- nextcloud:/var/www/html
environment:
- MYSQL_PASSWORD=${NEXTCLOUD_MYSQL_PASSWORD}
- MYSQL_DATABASE=nextcloud
- MYSQL_USER=nextcloud
- MYSQL_HOST=aasportal-cloud-db
- NEXTCLOUD_ADMIN_USER=${NEXTCLOUD_ADMIN_USER}
- NEXTCLOUD_ADMIN_PASSWORD=${NEXTCLOUD_ADMIN_PASSWORD}
- NEXTCLOUD_TRUSTED_DOMAINS=${NEXTCLOUD_TRUSTED_DOMAINS}

aas-server:
container_name: aas-server
build:
context: .
dockerfile: ./Dockerfile.aas-server
environment:
- USER_STORAGE=mongodb://aasportal-users:27017/aasportal-users
- USER_STORAGE=${USER_STORAGE}
- AAS_INDEX=${AAS_INDEX}
- TEMPLATE_STORAGE=${TEMPLATE_STORAGE}
ports:
- 1337:1337

aas-portal:
container_name: aas-portal
Expand All @@ -57,6 +92,9 @@ services:
restart: always
ports:
- 80:80

volumes:
mongodata:
sqldata:
sqldata:
nextcloud_db:
nextcloud:
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "aas-portal-project",
"version": "3.0.0-development.94",
"description": "Web-based visualization and control of aaset administration shells.",
"description": "Web-based visualization and control of asset administration shells.",
"type": "module",
"scripts": {
"create-app-info": "node --no-warnings --loader ts-node/esm create-app-info.ts",
Expand Down
2 changes: 1 addition & 1 deletion projects/aas-lib/src/test/aas-tree/aas-tree-search.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { TranslateFakeLoader, TranslateLoader, TranslateModule, TranslateService
import { AASTreeSearch } from '../../lib/aas-tree/aas-tree-search';
import { sampleDocument } from '../assets/sample-document';
import { AASTreeService } from '../../lib/aas-tree/aas-tree.service';
import { NotifyService } from 'projects/aas-lib/dist';
import { NotifyService } from '../../lib/notify/notify.service';

describe('AASTreeSearch', function () {
let search: AASTreeSearch;
Expand Down
23 changes: 17 additions & 6 deletions projects/aas-server/src/app/aas-index/aas-index-factory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,23 +15,34 @@ import { LowDbIndex } from './lowdb/lowdb-index.js';
import { Variable } from '../variable.js';
import { LowDbData } from './lowdb/lowdb-types.js';
import { MySqlIndex } from './mysql/mysql-index.js';
import { Logger } from '../logging/logger.js';
import { urlToString } from '../convert.js';

export class AASIndexFactory {
public constructor(private readonly container: DependencyContainer) {}

public create(): AASIndex {
const variable = this.container.resolve(Variable);
const logger = this.container.resolve<Logger>('Logger');
if (variable.AAS_INDEX) {
const url = new URL(variable.AAS_INDEX);
if (url.protocol === 'mysql:') {
return new MySqlIndex(variable);
}
try {
const url = new URL(variable.AAS_INDEX);
if (url.protocol === 'mysql:') {
const index = new MySqlIndex(variable);
logger.info(`AAS index connected to ${urlToString(url)}.`);
return index;
}

throw new Error('Not implemented.');
throw new Error(`${urlToString(url)} is a not supported AAS index.`);
} catch (error) {
logger.error(error);
}
}

const dbFile = path.join(variable.CONTENT_ROOT, 'db.json');
const db = new Low<LowDbData>(new JSONFile(dbFile), { documents: [], endpoints: [], elements: [] });
return new LowDbIndex(db, variable);
const index = new LowDbIndex(db, variable);
logger.info('Using internal AAS index.');
return index;
}
}
Loading

0 comments on commit e13288e

Please sign in to comment.