From 309ea7cf6117d05f080188dea2f18500b9b18bb6 Mon Sep 17 00:00:00 2001 From: alagishev Date: Wed, 22 Jan 2025 19:49:37 +0300 Subject: [PATCH] Setup docker build with download npm from the registry + CI workflow --- .github/workflows/ci-workflow.yml | 32 ++++++++++++++++++++++++++++++ .github/workflows/frontend-ci.yaml | 17 ---------------- Dockerfile | 15 ++++++++------ Dockerfile.local | 12 +++++++++++ README.md | 14 +++++++++++++ package-lock.json | 7 +++---- package.json | 2 +- 7 files changed, 71 insertions(+), 28 deletions(-) create mode 100644 .github/workflows/ci-workflow.yml delete mode 100644 .github/workflows/frontend-ci.yaml create mode 100644 Dockerfile.local diff --git a/.github/workflows/ci-workflow.yml b/.github/workflows/ci-workflow.yml new file mode 100644 index 0000000..19a9fd3 --- /dev/null +++ b/.github/workflows/ci-workflow.yml @@ -0,0 +1,32 @@ +name: Frontend & Docker CI Workflow + +on: + release: + types: [created] + push: + branches: + - main + - release + - develop + - feature/* + delete: + branches: + - release + - feature/* + +jobs: + call-frontend-ci-workflow: + uses: netcracker/qubership-apihub-ci/.github/workflows/frontend-ci.yaml@main + call-docker-ci-workflow: + needs: call-frontend-ci-workflow + uses: netcracker/qubership-apihub-ci/.github/workflows/docker-ci.yml@main + with: + name: qubership-apihub-build-task-consumer + file: Dockerfile + context: "" + platforms: linux/amd64,linux/arm64 + labels: | + maintainer=qubership + qubership-apihub-build-task-consumer-package-version=${{ needs.jobs.call-frontend-ci-workflow.outputs.package_version }} + secrets: + NPMRC: ${{ secrets.NPMRC }} diff --git a/.github/workflows/frontend-ci.yaml b/.github/workflows/frontend-ci.yaml deleted file mode 100644 index 66ae11f..0000000 --- a/.github/workflows/frontend-ci.yaml +++ /dev/null @@ -1,17 +0,0 @@ -name: Frontend CI Workflow - -on: - push: - branches: - - main - - release - - develop - - feature/* - delete: - branches: - - release - - feature/* - -jobs: - call-frontend-ci-workflow: - uses: netcracker/qubership-apihub-ci/.github/workflows/frontend-ci.yaml@main diff --git a/Dockerfile b/Dockerfile index 14974c2..72e08c5 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,13 +1,16 @@ -FROM node:20 +FROM docker.io/node:20 + +ARG TAG=dev WORKDIR /usr/src/app -ADD .npmrc .npmrc -COPY package*.json ./ -RUN npm ci +RUN apt-get update && apt-get install -y jq && rm -rf /var/lib/apt/lists/* + -ADD dist dist +RUN --mount=type=secret,id=npmrc,target=.npmrc mv $(npm pack @netcracker/qubership-apihub-build-task-consumer@"$TAG") qubership-apihub-build-task-consumer.tgz +RUN tar zxvf ./qubership-apihub-build-task-consumer.tgz && mv ./package/dist dist +RUN --mount=type=secret,id=npmrc,target=.npmrc mv ./package/package.json package.json && npm install --production USER 10001 -CMD [ "node", "--max-old-space-size=3100", "--max-semi-space-size=32", "dist/main" ] \ No newline at end of file +CMD [ "node", "--max-old-space-size=3100", "--max-semi-space-size=32", "dist/main" ] diff --git a/Dockerfile.local b/Dockerfile.local new file mode 100644 index 0000000..b5148fa --- /dev/null +++ b/Dockerfile.local @@ -0,0 +1,12 @@ +FROM docker.io/node:20 + +WORKDIR /usr/src/app + +ADD .npmrc .npmrc +COPY package*.json ./ +RUN npm ci +ADD dist dist + +USER 10001 + +CMD [ "node", "--max-old-space-size=3100", "--max-semi-space-size=32", "dist/main" ] \ No newline at end of file diff --git a/README.md b/README.md index a0d85b5..65e8269 100644 --- a/README.md +++ b/README.md @@ -8,6 +8,20 @@ NodeJS microservice for APIHUB Package versions builds. $ npm ``` +## Building the app locally + +```bash +npm install +npm run build +``` + +For build docker image rename file `Dockerfile.local` -> `Dockerfile` and execute + +```bash +podman build . +``` + + ## Running the app ```bash diff --git a/package-lock.json b/package-lock.json index cd92204..a5618db 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,11 +1,11 @@ { - "name": "qubership-apihub-build-task-consumer", + "name": "@netcracker/qubership-apihub-build-task-consumer", "version": "2.0.3-dev.7", "lockfileVersion": 3, "requires": true, "packages": { "": { - "name": "qubership-apihub-build-task-consumer", + "name": "@netcracker/qubership-apihub-build-task-consumer", "version": "2.0.3-dev.7", "license": "Apache-2.0", "dependencies": { @@ -22,6 +22,7 @@ "form-data": "^4.0.0", "js-yaml": "4.1.0", "jszip": "^3.10.1", + "openapi-types": "^12.1.0", "reflect-metadata": "^0.1.13", "rxjs": "7.8.1", "swagger-ui-express": "^4.3.0" @@ -44,7 +45,6 @@ "eslint-config-prettier": "8.5.0", "eslint-plugin-prettier": "4.0.0", "jest": "29.5.0", - "openapi-types": "^12.1.0", "parse-multipart-data": "^1.5.0", "prettier": "2.6.0", "rimraf": "3.0.2", @@ -7810,7 +7810,6 @@ "version": "12.1.3", "resolved": "https://registry.npmjs.org/openapi-types/-/openapi-types-12.1.3.tgz", "integrity": "sha512-N4YtSYJqghVu4iek2ZUvcN/0aqH1kRDuNqzcycDxhOUpg7GdvLa2F3DgS6yBNhInhv2r/6I0Flkn7CqL8+nIcw==", - "dev": true, "license": "MIT" }, "node_modules/optional": { diff --git a/package.json b/package.json index 74e64b2..fc765ca 100644 --- a/package.json +++ b/package.json @@ -34,6 +34,7 @@ "adm-zip": "^0.5.10", "dotenv": "^16.0.3", "form-data": "^4.0.0", + "openapi-types": "^12.1.0", "js-yaml": "4.1.0", "jszip": "^3.10.1", "reflect-metadata": "^0.1.13", @@ -58,7 +59,6 @@ "eslint-config-prettier": "8.5.0", "eslint-plugin-prettier": "4.0.0", "jest": "29.5.0", - "openapi-types": "^12.1.0", "parse-multipart-data": "^1.5.0", "prettier": "2.6.0", "rimraf": "3.0.2",