diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index c2357d1d912e0221f91b3c7f7d6cbddf693756b8..6e611ba2382f78dc800c042ef9025ca46cac99d7 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -5,7 +5,6 @@ include: stages: - lint - - test - build - release - docker @@ -13,45 +12,11 @@ stages: - helm - deploy-test - deploy-prod -# Lint microservices - -lint-agent: - extends: .lint-agent - stage: lint - -lint-hin-agent: - extends: .lint-hin-agent - stage: lint - -# lint-dashboard: -# extends: .lint-dashboard -# stage: lint - -# Test microservices - -test-agent: - extends: .test-agent - stage: test - -test-hin-agent: - extends: .test-hin-agent - stage: test -# test-dashboard: -# extends: .test-dashboard -# stage: test # Bare microservice build -build-agent: - extends: .build-agent - stage: build - -build-hin-agent: - extends: .build-hin-agent - stage: build - -build-dashboard: - extends: .build-dashboard +build-all: + extends: .build-all stage: build # Docker build microservices diff --git a/README.md b/README.md index 2019f1723479c1cbe56e8f01d0f2f29e4e807620..0bceb2a287659c03e6b984d375fa65490c1a02a8 100644 --- a/README.md +++ b/README.md @@ -1,13 +1,17 @@ # OCM Engine -- [Introduction](#introduction) -- [Requirements](#requirements) -- [Architecture](#architecture) -- [Setup](#setup) -- [Local env](#local) -- [Docker env](#docker) -- [Usage](#usage-via-postman) -- [Example](#send-didcomm-messages-between-two-ocms) +- [OCM Engine](#ocm-engine) + - [Introduction](#introduction) + - [Apps list:](#apps-list) + - [Library list:](#library-list) + - [Requirements](#requirements) + - [Architecture](#architecture) + - [Setup](#setup) + - [Local](#local) + - [Docker](#docker) + - [Usage via Postman](#usage-via-postman) + - [Send Didcomm messages between two OCMs](#send-didcomm-messages-between-two-ocms) + - [License](#license) ## Introduction @@ -136,4 +140,3 @@ Example: ## License This project is licensed under the AGPL License - see the [LICENSE](LICENSE) file for details. - diff --git a/apps/agent/deployment/ci-cd/Dockerfile b/apps/agent/deployment/ci-cd/Dockerfile index 42e977d4978d05b84fce8d2f684d1df1c391cb34..50fd4edb5b18cfd12ab88d824e2b1d7de5c2fd22 100644 --- a/apps/agent/deployment/ci-cd/Dockerfile +++ b/apps/agent/deployment/ci-cd/Dockerfile @@ -1,38 +1,24 @@ -FROM node:18.16.0-buster-slim +FROM node:18.19.1-buster-slim as production -# Argument handler -ARG API_TOKEN -ARG JOB_ID +ENV NODE_ENV production # Instal required software -RUN apt update -y && apt install python3 git make build-essential wget unzip -y +RUN apt update -y && apt install yarn python3 make build-essential -y -# Set the working directory -WORKDIR app +WORKDIR /app -# Set the ENV variables -ENV GITLAB_BASE_URL=https://code.vereign.com/api/v4 -ENV GITLAB_PROJECT_ID=662 -ENV TOKEN=$API_TOKEN -ENV ID=$JOB_ID - -# Download the artifacts from the GitLab API -RUN wget --header "PRIVATE-TOKEN: $TOKEN" -O artifacts.zip "${GITLAB_BASE_URL}/projects/${GITLAB_PROJECT_ID}/jobs/${ID}/artifacts" - -# Unzip the artifacts (if needed) - adjust this command based on your artifact type -RUN unzip -q artifacts.zip && rm artifacts.zip - -# Fix locations -RUN cp ./dist/apps/agent/main.js . -RUN cp ./dist/apps/agent/main.js.map . -RUN cp -r ./dist/libs/askar . -#RUN cp -r ./dist/libs/clients . # no need by backend -RUN cp -r ./dist/libs/config . -RUN cp -r ./dist/libs/dtos . -RUN cp -r ./dist/libs/ledgers . +# Copy the build artifacts from the previous stage +COPY build /app/build +# Install only required dependencies, see nx.json generatePackageJson +COPY build/apps/agent/package.json . +COPY build/apps/agent/yarn.lock . RUN yarn install +COPY build/apps/agent . +COPY build/libs . +RUN rm -rf /app/build/* + # Expose required ports EXPOSE 8080 EXPOSE 8001 diff --git a/apps/agent/deployment/local/Dockerfile b/apps/agent/deployment/local/Dockerfile index bb1da9010cbabdc0c66fadc10fd7abb79b1732e7..c90849bba44195e876d46e4e9bd5a3863ac74422 100644 --- a/apps/agent/deployment/local/Dockerfile +++ b/apps/agent/deployment/local/Dockerfile @@ -1,6 +1,6 @@ -FROM node:18.16.0-buster-slim +FROM node:18.19.1-buster-slim -RUN apt update -y && apt install python3 git make build-essential -y +RUN apt update -y && apt install yarn python3 make build-essential -y WORKDIR app diff --git a/apps/dashboard/deployment/ci-cd/Dockerfile b/apps/dashboard/deployment/ci-cd/Dockerfile index e39ecce758f7bf1044a65f8dabf531f1fcd1ff93..4c9259ef7211997d2c5efad4200482c8c48bdbe5 100644 --- a/apps/dashboard/deployment/ci-cd/Dockerfile +++ b/apps/dashboard/deployment/ci-cd/Dockerfile @@ -1,38 +1,37 @@ -FROM nginx:1.25.3-bookworm -RUN apt update -y && apt install npm nodejs python3 git make build-essential wget unzip -y +FROM nginx:1-alpine as production -RUN npm i -g yarn +ENV NODE_ENV production -# Copy the built React app files into the NGINX web server directory -ARG API_TOKEN -ARG JOB_ID +# Install yarn +RUN apk add --no-cache yarn -# Set the ENV variables -ENV GITLAB_BASE_URL=https://code.vereign.com/api/v4 -ENV GITLAB_PROJECT_ID=662 -ENV TOKEN=$API_TOKEN -ENV ID=$JOB_ID +WORKDIR /app -# Download the artifacts from the GitLab API -RUN wget --header "PRIVATE-TOKEN: $TOKEN" -O artifacts.zip "${GITLAB_BASE_URL}/projects/${GITLAB_PROJECT_ID}/jobs/${ID}/artifacts" - -# Unzip the artifacts (if needed) - adjust this command based on your artifact type -RUN unzip -q artifacts.zip && rm artifacts.zip +# Copy the build artifacts from the previous stage +COPY build /app/build +# Install only required dependencies, see nx.json generatePackageJson +COPY build/apps/dashboard/package.json . +COPY build/apps/dashboard/yarn.lock . RUN yarn install -RUN mkdir -p /usr/share/nginx/html/ocm-test/dashboard -RUN mkdir -p /usr/share/nginx/html/ocm/dashboard +# Create required directories +RUN mkdir -p /usr/share/nginx/html/ocm-test/dashboard /usr/share/nginx/html/ocm/dashboard + +# Move the projects +RUN mv build/apps/ocm-test-dashboard/* /usr/share/nginx/html/ocm-test/dashboard && \ + mv build/apps/dashboard/* /usr/share/nginx/html/ocm/dashboard -RUN cp -r dist/apps/ocm-test-dashboard/* /usr/share/nginx/html/ocm-test/dashboard -RUN cp -r dist/apps/dashboard/* /usr/share/nginx/html/ocm/dashboard +# Copy shared resources +RUN cp -r build/libs/clients /usr/share/nginx/html/ocm-test/dashboard/clients && \ + cp -r build/libs/clients /usr/share/nginx/html/ocm/dashboard/clients -RUN cp -r dist/libs /usr/share/nginx/html/ocm-test/dashboard -RUN cp -r dist/libs /usr/share/nginx/html/ocm/dashboard +# Create symlink for node_modules +RUN ln -s /app/node_modules /usr/share/nginx/html/ocm-test/dashboard/node_modules && \ + ln -s /app/node_modules /usr/share/nginx/html/ocm/dashboard/node_modules -RUN cp -r node_modules /usr/share/nginx/html/ocm-test/dashboard -RUN cp -r node_modules /usr/share/nginx/html/ocm/dashboard +RUN rm -rf /app/build/* # Expose the port that NGINX will run on EXPOSE 8080 diff --git a/apps/dashboard/deployment/local/Dockerfile b/apps/dashboard/deployment/local/Dockerfile index f097b257ba97b3a8dd7b738a83eb8c7979d2684f..5159d0b78e0cdbc92a083a884af43d04e5cd70a4 100644 --- a/apps/dashboard/deployment/local/Dockerfile +++ b/apps/dashboard/deployment/local/Dockerfile @@ -1,6 +1,6 @@ -FROM node:18.16.0-buster-slim +FROM node:18.19.1-alpine -RUN apt update -y && apt install python3 git make build-essential -y +RUN apk add --no-cache yarn WORKDIR /app diff --git a/apps/dashboard/src/components/App/index.tsx b/apps/dashboard/src/components/App/index.tsx index f539f1e742a51280916669cee85507eb4201b31b..edcaac2bfb4a7d33e727cd1a32e3c1fad305ca05 100644 --- a/apps/dashboard/src/components/App/index.tsx +++ b/apps/dashboard/src/components/App/index.tsx @@ -20,7 +20,8 @@ const App = observer(() => { }, wsUrl: config.OCMENGINE_WS_URL, httpUrl: config.OCMENGINE_HTTP_URL, - getAuthorization: async () => config.OCMENGINE_AUTHORIZATION || `Bearer ${auth.getToken()}` || "", + getAuthorization: async () => + config.OCMENGINE_AUTHORIZATION || `Bearer ${auth.getToken()}` || "", }); setAppLoading(false); }, [auth]); diff --git a/apps/dashboard/src/utils/getConfig.ts b/apps/dashboard/src/utils/getConfig.ts index 467aac0613bfce8734661d5d4ad0353eb97d9661..96b5af62e01edbd9d52d7a00f57a6a046bf21997 100644 --- a/apps/dashboard/src/utils/getConfig.ts +++ b/apps/dashboard/src/utils/getConfig.ts @@ -16,7 +16,7 @@ export const getConfig = (): Config => { OCMENGINE_WS_URL: lsWs || window.OCMENGINE_WS_URL, TSA_URL: tsaHttp || window.TSA_URL, BASE_PATH: window.BASE_PATH, - OCMENGINE_AUTHORIZATION: authorization + OCMENGINE_AUTHORIZATION: authorization, }; }; diff --git a/apps/hin-agent/deployment/ci-cd/Dockerfile b/apps/hin-agent/deployment/ci-cd/Dockerfile index d141cf84a710988c2bf536098650ec97adeea004..24523c9addff5dd78353efe95c96aab731cc373e 100644 --- a/apps/hin-agent/deployment/ci-cd/Dockerfile +++ b/apps/hin-agent/deployment/ci-cd/Dockerfile @@ -1,38 +1,24 @@ -FROM node:18.16.0-buster-slim +FROM node:18.19.1-buster-slim as production -# Argument handler -ARG API_TOKEN -ARG JOB_ID +ENV NODE_ENV production # Instal required software -RUN apt update -y && apt install python3 git make build-essential wget unzip -y +RUN apt update -y && apt install yarn python3 make build-essential -y -# Set the working directory -WORKDIR app +WORKDIR /app -# Set the ENV variables -ENV GITLAB_BASE_URL=https://code.vereign.com/api/v4 -ENV GITLAB_PROJECT_ID=662 -ENV TOKEN=$API_TOKEN -ENV ID=$JOB_ID - -# Download the artifacts from the GitLab API -RUN wget --header "PRIVATE-TOKEN: $TOKEN" -O artifacts.zip "${GITLAB_BASE_URL}/projects/${GITLAB_PROJECT_ID}/jobs/${ID}/artifacts" - -# Unzip the artifacts (if needed) - adjust this command based on your artifact type -RUN unzip -q artifacts.zip && rm artifacts.zip - -# Fix locations -RUN cp ./dist/apps/hin-agent/main.js . -RUN cp ./dist/apps/hin-agent/main.js.map . -RUN cp -r ./dist/libs/askar . -#RUN cp -r ./dist/libs/clients . # no need by backend -RUN cp -r ./dist/libs/config . -RUN cp -r ./dist/libs/dtos . -RUN cp -r ./dist/libs/ledgers . +# Copy the build artifacts from the previous stage +COPY build /app/build +# Install only required dependencies, see nx.json generatePackageJson +COPY build/apps/hin-agent/package.json . +COPY build/apps/hin-agent/yarn.lock . RUN yarn install +COPY build/apps/hin-agent . +COPY build/libs . +RUN rm -rf /app/build/* + # Expose required ports EXPOSE 8080 EXPOSE 8001 diff --git a/apps/hin-agent/deployment/local/Dockerfile b/apps/hin-agent/deployment/local/Dockerfile index e8c3e323c1b00cc0f357616db31077a66b819ae2..072b47c6eb670470472d30a395c0bff80378573e 100644 --- a/apps/hin-agent/deployment/local/Dockerfile +++ b/apps/hin-agent/deployment/local/Dockerfile @@ -1,6 +1,6 @@ -FROM node:18.16.0-buster-slim +FROM node:18.19.1-buster-slim -RUN apt update -y && apt install python3 git make build-essential -y +RUN apt update -y && apt install yarn python3 make build-essential -y WORKDIR app diff --git a/deployment/ci-cd/build.Dockerfile b/deployment/ci-cd/build.Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..248d4d068622ab27a77f3f65f049d1a47b170415 --- /dev/null +++ b/deployment/ci-cd/build.Dockerfile @@ -0,0 +1,27 @@ +################### +# Linter, Test, Build +################### + +FROM node:18.19.1 as build + +ARG JOB_ID + +WORKDIR app + +COPY ./package.json . +COPY ./yarn.lock . + +# Install dependencies +RUN yarn install --frozen-lockfile + +COPY . . + +# Linter & test +RUN yarn nx run-many --target=lint --projects=agent,hin-agent,dashboard --configuration=production +RUN yarn nx run-many --target=test --configuration=production + +# Build all +RUN yarn nx run-many --target=build --configuration=production --parallel=3 +RUN yarn nx run dashboard:build:production --output-path ./dist/apps/dashboard --base-href /ocm/dashboard/ --skip-nx-cache +RUN yarn nx run dashboard:build:production --output-path ./dist/apps/ocm-test-dashboard --base-href /ocm-test/dashboard/ --skip-nx-cache +RUN yarn nx run dashboard:build:production --output-path ./dist/apps/swissrun-dashboard --base-href /swissrun/dashboard/ --skip-nx-cache diff --git a/deployment/ci-cd/lint.Dockerfile b/deployment/ci-cd/lint.Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..5b312a615ec8176222c97badc15e11a6d55b3362 --- /dev/null +++ b/deployment/ci-cd/lint.Dockerfile @@ -0,0 +1,21 @@ +################### +# Linter, Test +################### + +FROM node:18.19.1 as build + +ARG JOB_ID + +WORKDIR app + +COPY ./package.json . +COPY ./yarn.lock . + +# Install dependencies +RUN yarn install --frozen-lockfile + +COPY . . + +# Linter & test +RUN yarn nx run-many --target=lint --projects=agent,hin-agent,dashboard --configuration=production +RUN yarn nx run-many --target=test --configuration=production diff --git a/nx.json b/nx.json index 9450bdea7fc9946171ba594f5199e55d47b88ffd..3cec24b6832fe17cc0abba2dd87951cf89b08db9 100644 --- a/nx.json +++ b/nx.json @@ -14,6 +14,9 @@ "dependsOn": ["^build"] }, "build": { + "options": { + "generatePackageJson": true + }, "dependsOn": ["^build"], "inputs": ["production", "^production"] }, diff --git a/package.json b/package.json index 7f3dc4381a1cab52a41e4a873eca088a6b2f406a..9b51e811bb0bdecee43b52f65ff43f5537d8d668 100644 --- a/package.json +++ b/package.json @@ -46,6 +46,7 @@ "@nestjs/passport": "^10.0.1", "@nestjs/platform-express": "^9.0.0", "@nestjs/platform-ws": "^10.1.3", + "@nestjs/swagger": "^6.3.0", "@nestjs/websockets": "^9.4.2", "@swc/helpers": "~0.5.2", "antd": "^5.10.1", @@ -76,7 +77,6 @@ "@babel/preset-react": "^7.14.5", "@commitlint/config-conventional": "^17.6.1", "@nestjs/schematics": "^9.0.0", - "@nestjs/swagger": "^6.3.0", "@nestjs/testing": "^9.0.0", "@nx/eslint-plugin": "16.10.0", "@nx/jest": "16.10.0",