diff --git a/.gitignore b/.gitignore index 4262603d..37db70b3 100644 --- a/.gitignore +++ b/.gitignore @@ -16,6 +16,7 @@ node_modules # local env files *.env* !example.env +!example.env.backend # local bugs log bugs.bug @@ -37,4 +38,6 @@ yarn-error.log* # Lock files # Вызвало сбой сборки докера # пока вернем до прихода DevOps -# package-lock.json* \ No newline at end of file +# package-lock.json* + +docker-compose.override.yaml diff --git a/Dockerfile.backend b/Dockerfile.backend new file mode 100644 index 00000000..a12108fa --- /dev/null +++ b/Dockerfile.backend @@ -0,0 +1,22 @@ +# syntax = docker/dockerfile:1.3 +ARG NODE_VERSION=16 + + + +FROM node:${NODE_VERSION}-alpine AS deps +WORKDIR /var/www +COPY package.json package-lock.json ./ +# RUN --mount=type=cache,target=/root/.npm npm install +RUN npm install + + + +FROM node:${NODE_VERSION}-alpine AS builder +WORKDIR /var/www +COPY --from=deps /var/www . +COPY . . +ENV NODE_ENV=production +# RUN --mount=type=cache,target=./node_modules/.cache npm run build +RUN npm run build +CMD ["node", "src/backend/main.mjs"] +EXPOSE 3030 diff --git a/README.md b/README.md index e0eb640e..af302a5e 100644 --- a/README.md +++ b/README.md @@ -140,6 +140,16 @@ docker-compose up --build ``` DocHub станет доступен по адресу [http://localhost:8080/main](http://localhost:8080/main) +### Локальное развертывание в режиме client-server + +Выполните команды: +``` +cp docker-compose.override.backend.yaml docker-compose.override.yaml +cp example.env.backend .env +docker-compose up --build +``` +DocHub станет доступен по адресу [http://localhost:8080/main](http://localhost:8080/main), api сервера [http://localhost:3030/](http://localhost:3030/) + ### Сборка из исходников для продакшен Проект является VueJS SPA приложением. В качестве backend пользуется GitLab. diff --git a/docker-compose.override.backend.yaml b/docker-compose.override.backend.yaml new file mode 100644 index 00000000..aa278b54 --- /dev/null +++ b/docker-compose.override.backend.yaml @@ -0,0 +1,20 @@ +version: "3.8" + +services: + nginx: + container_name: dochub-frontend + image: dochub-frontend + build: + context: . + dockerfile: Dockerfile + target: nginx + ports: + - "8080:8080" + backend: + container_name: dochub-backend + image: dochub-backend + build: + context: . + dockerfile: Dockerfile.backend + ports: + - "3030:3030" diff --git a/example.env.backend b/example.env.backend new file mode 100644 index 00000000..d36625c0 --- /dev/null +++ b/example.env.backend @@ -0,0 +1,3 @@ +VUE_APP_DOCHUB_MODE=backend +VUE_APP_PLANTUML_SERVER="localhost:8079/svg/" +VUE_APP_DOCHUB_BACKEND_URL="http://localhost:3030" \ No newline at end of file diff --git a/k8s_deploy_example.yaml b/k8s_deploy_example.yaml new file mode 100644 index 00000000..3a659369 --- /dev/null +++ b/k8s_deploy_example.yaml @@ -0,0 +1,163 @@ +--- +apiVersion: v1 +kind: Namespace +metadata: + name: dochub-portal +--- +apiVersion: apps/v1 +kind: Deployment +metadata: + labels: + app: dochub-web + name: dochub-web + namespace: dochub-portal +spec: + replicas: 2 + selector: + matchLabels: + app: dochub-web + template: + metadata: + labels: + app: dochub-web + spec: + containers: + - image: _IMG_TO_DEPLOY_ # replace with full registry path to builded DocHub image + imagePullPolicy: IfNotPresent + name: dochub-web + ports: + - containerPort: 8080 + name: http-port + protocol: TCP + livenessProbe: + httpGet: + path: / + port: 8080 + initialDelaySeconds: 5 + readinessProbe: + httpGet: + path: / + port: 8080 + initialDelaySeconds: 5 + resources: + limits: + cpu: 500m + memory: 500Mi + requests: + cpu: 250m + memory: 250Mi +--- +- apiVersion: v1 + kind: Service + metadata: + name: dochub-web + namespace: dochub-portal + spec: + ports: + - port: 8080 + protocol: TCP + targetPort: 8080 + selector: + app: dochub-web +--- +apiVersion: networking.k8s.io/v1 +kind: Ingress +metadata: + name: dochub-web +# uncomment below if you plan to use custom path in pathType.path field + # annotations: + # nginx.ingress.kubernetes.io/rewrite-target: / +spec: + ingressClassName: nginx-ingress # remove if you plan to use defaul ingress-controller or replace with right ingressClassName + rules: + - host: dochub.example.org # replace with right host name + http: + paths: + - pathType: Prefix + path: "/" + backend: + service: + name: dochub-web + port: + number: 8080 +--- + +# BACKEND +# Remove all lines below in case "Frontend only" + +apiVersion: apps/v1 +kind: Deployment +metadata: + labels: + app: dochub-api + name: dochub-api + namespace: dochub-portal +spec: + replicas: 2 + selector: + matchLabels: + app: dochub-api + template: + metadata: + labels: + app: dochub-api + spec: + containers: + - image: _IMG_TO_DEPLOY_ # replace with full registry path to builded DocHub backend image + imagePullPolicy: IfNotPresent + name: dochub-api + ports: + - containerPort: 3030 + name: api-port + protocol: TCP + livenessProbe: + httpGet: + path: / + port: 3030 + initialDelaySeconds: 15 + readinessProbe: + httpGet: + path: / + port: 3030 + initialDelaySeconds: 15 + resources: + limits: + cpu: 500m + memory: 500Mi + requests: + cpu: 250m + memory: 250Mi +--- +- apiVersion: v1 + kind: Service + metadata: + name: dochub-api + namespace: dochub-portal + spec: + ports: + - port: 8080 + protocol: TCP + targetPort: 3030 + selector: + app: dochub-api +--- +apiVersion: networking.k8s.io/v1 +kind: Ingress +metadata: + name: dochub-api +# uncomment below if you plan to use custom path in rules.host.http.paths.pathType.path field + # annotations: + # nginx.ingress.kubernetes.io/rewrite-target: / +spec: + ingressClassName: nginx-ingress # remove if you plan to use defaul ingress-controller or replace with right ingressClassName + rules: + - host: dochub-api.example.org # replace with right host name + http: + paths: + - pathType: Prefix + path: "/" + backend: + service: + name: dochub-api + port: + number: 8080