{"id":24616387,"url":"https://github.com/ranish-shrestha/book_api","last_synced_at":"2026-04-12T13:02:59.941Z","repository":{"id":261877820,"uuid":"885611560","full_name":"Ranish-Shrestha/Book_API","owner":"Ranish-Shrestha","description":null,"archived":false,"fork":false,"pushed_at":"2024-11-15T19:56:00.000Z","size":12854,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-01-24T22:47:33.047Z","etag":null,"topics":["docker-compose","jenkins","jenkinsfile","nexus3","nodejs","sonarqube"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Ranish-Shrestha.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-11-08T23:55:05.000Z","updated_at":"2024-11-15T23:46:58.000Z","dependencies_parsed_at":"2024-11-09T00:28:41.815Z","dependency_job_id":"49d9768c-adf7-49e8-881c-17a40d440eb1","html_url":"https://github.com/Ranish-Shrestha/Book_API","commit_stats":null,"previous_names":["ranish-shrestha/book_api"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Ranish-Shrestha%2FBook_API","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Ranish-Shrestha%2FBook_API/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Ranish-Shrestha%2FBook_API/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Ranish-Shrestha%2FBook_API/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Ranish-Shrestha","download_url":"https://codeload.github.com/Ranish-Shrestha/Book_API/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244300588,"owners_count":20430795,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["docker-compose","jenkins","jenkinsfile","nexus3","nodejs","sonarqube"],"created_at":"2025-01-24T22:47:41.748Z","updated_at":"2026-04-12T13:02:59.914Z","avatar_url":"https://github.com/Ranish-Shrestha.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Book API\n\n### Create database user and database\n\nOpen pgAdmin. Right Click on Login/Group Roles, click on Create and click on Login/Group Role.\n![Postgres_User](images/Postgres_User.png)\n\nEnter Name.\n![Postgres_Username](images/Postgres_Username.png)\n\nNavigate to Definition and enter Password.\n![Postgres_Password](images/Postgres_Password.png)\n\nNavigate to Privileges and give Superuser and Login privileges.\n![Postgres_Privileges](images/Postgres_Privileges.png)\n\n### Make `docker-compose.yml` file\n\n```sh\nversion: \"3\"\n\nservices:\n  jenkins:\n    image: jenkins/jenkins:lts\n    container_name: jenkins\n    ports:\n      - \"8080:8080\"\n      - \"50000:50000\"\n    volumes:\n      - jenkins_home:/var/jenkins_home\n    environment:\n      JENKINS_OPTS: --httpPort=8080\n\n  sonarqube:\n    image: sonarqube:latest\n    container_name: sonarqube\n    ports:\n      - \"9000:9000\"\n    environment:\n      SONARQUBE_JDBC_URL: jdbc:postgresql://db:5432/books #here 'books' is databasename\n      SONARQUBE_JDBC_USERNAME: sonaradmin\n      SONARQUBE_JDBC_PASSWORD: sonaradmin\n    depends_on:\n      - db\n\n  db:\n    image: postgres:latest\n    container_name: postgres\n    environment:\n      POSTGRES_USER: sonaradmin\n      POSTGRES_PASSWORD: sonaradmin\n      POSTGRES_DB: books\n    volumes:\n      - postgres_data:/var/lib/postgresql/data\n\n  nexus:\n    image: sonatype/nexus3:latest\n    container_name: nexus\n    ports:\n      - \"8081:8081\"\n    volumes:\n      - nexus-data:/nexus-data\n\nvolumes:\n  jenkins_home:\n  nexus-data:\n  postgres_data:\n\n```\n\n### Run commond in bash\n\nThis command will start all service in detached mode.\n\n```sh\ndocker-compose up -d\n```\n\n### Configure Jenkins\n\n- Go to http://localhost:8080 or http://your-localhost:8080.\n- Go to Manage Jenkins -\u003e Plugins -\u003e Install plugins like **NodeJs**, **SonarQube** and **Nexus Artifact Uploader**.\n- Go to Manage Jenkins -\u003e Tools -\u003e Select **NodeJs** and **SonarQube** versions and set _Name_ variable.\n\n### Configure SonarQube\n\n- Go to http://localhost:9000 or http://your-localhost:9000.\n- Go to Administration -\u003e Security -\u003e Users and Click on `Update Tokens`.\n  ![sonarqube](images/sonarqube.png)\n- Enter `Token Name`, choose `Expires in` and click `Generate` button. Copy New token.\n  ![sonarqube_token](images/sonarqube_token.png)\n- Go to Manage Jenkins -\u003e Credentials -\u003e Cick on global and Add New credentials for SonarQube.\n  ![sonarqube_creds](images/sonarqube_creds.png)\n- Go to Manage Jenkins -\u003e System. Configure Server URL and authentication token.\n  ![sonarqube_config](images/sonarqube_config.png)\n\n### Configure Nexus\n\n- Go to http://localhost:8081 or http://your-localhost:8081. Add Create three repositories. [Link](https://www.sonatype.com/blog/using-sonatype-nexus-repository-3-part-2-npm-packages)\n  ![Nexus](images/Nexus.png)\n- For group repository, add proxy and hosted repositories as members.\n  ![Nexus_group](images/Nexus_group.png)\n- Go to Security -\u003e Users. Add Create local user with `nx-admin` role.\n- Go to Security -\u003e Realms and transfer `npm Bearer Token Realm` to Active cards.\n  ![Nexus_Realm](images/Nexus_Realm.png)\n\n## To publish file using npm publish\n\n- Go to bash and execute the following code and enter Username and Password.\n\n```sh\nnpm login --registry=http://10.0.0.247:8081/repository/npm-book-group/\n```\n\n- Similarly, again execute the following code and enter the same Username and Password.\n\n```sh\nnpm login --registry=http://10.0.0.247:8081/repository/npm-book-repo/\n```\n\n- Finally, execute the following code.\n\n```sh\ncat ~/.npmrc\n```\n\nand Copy the lines generate and create a `my.npmrc` file in any directory.\n![Nexus_Creds_Generate](images/Nexus_Creds_Generate.png)\n\n- Go to Manage Jenkins -\u003e Credentials -\u003e Cick on global and Add New credentials for Nexus. Choose recently created `my.npmrc` file.\n  ![Nexus_Creds_Jenkins](images/Nexus_Creds_Jenkins.png)\n\n### Add publishConfig in `package.json` file\n\n```sh\n\"publishConfig\": {\n    \"registry\": \"http://10.0.0.247:8081/repository/npm-book-repo/\"\n  }\n```\n\n### Make Jenkins file\n\n```sh\npipeline {\n    agent any\n\n    tools {\n        nodejs('NodeJS')\n    }\n\n    environment {\n        SCANNER_HOME = tool 'SonarQubeScanner'\n        NEXUS_VERSION = \"nexus3\"\n        NEXUS_PROTOCOL = \"http\"\n        NODEJS_HOME = tool name: 'NodeJS' // Assumes NodeJS is configured in Jenkins tools\n        PATH = \"${NODEJS_HOME}/bin:${env.PATH}\"\n        SONARQUBE_SERVER = 'SonarQube'  // Name configured for SonarQube in Jenkins\n        NEXUS_URL = '10.0.0.247:8081' // Nexus URL\n        NEXUS_REPO = 'npm-book-repo'\n        NEXUS_CREDENTIALS_ID = 'npm-nexus-creds' // Jenkins credentials ID for Nexus\n    }\n\n\n    stages {\n        stage('Checkout') {\n            steps {\n                checkout scm\n            }\n        }\n\n        stage('Install Dependencies') {\n            steps {\n                sh 'npm install'\n            }\n        }\n\n        stage('Build') {\n            steps {\n                withCredentials([file(credentialsId: 'npm-nexus-creds', variable: 'mynpmrc')]) {\n                    echo 'Building...'\n                    sh 'npm install --userconfig $mynpmrc --registry http://10.0.0.247:8081/repository/npm-book-repo --loglevel verbose'\n                }\n            }\n        }\n\n        stage('SonarQube Analysis') {\n            steps {\n                script {\n                    withSonarQubeEnv('SonarQube') {\n                        sh \"\"\"${SCANNER_HOME}/bin/sonar-scanner -Dsonar.host.url=http://10.0.0.247:9000/ \\\n                        -Dsonar.token=squ_ee990db47a9bdffa732b9fea384c2782eb8e56e1 \\\n                        -Dsonar.projectName=\"Book_API\" \\\n                        -Dsonar.exclusions=**/node_modules/** \\\n                        -Dsonar.projectKey=Book_API\"\"\"\n                    }\n                }\n            }\n        }\n\n        stage('Quality Gate') {\n            steps {\n                script {\n                    sleep(time: 20, unit: 'SECONDS') // Sleep to wait for the status to update\n                    def qualityGate = waitForQualityGate()\n                    if (qualityGate.status == 'IN_PROGRESS') {\n                        sleep(time: 20, unit: 'SECONDS') // Sleep to wait for the status to update\n                        error \"Quality Gate is still in progress. Retrying...\"\n                    }\n\n                    if (qualityGate.status != 'OK') {\n                        error \"Quality Gate failed: ${qualityGate.status}\"\n                    }\n                    else {\n                        echo \"Quality Gate passed: ${qualityGate.status}\"\n                    }\n                }\n            }\n        }\n\n\n        stage('Publish to Nexus') {\n            steps {\n                withCredentials([file(credentialsId: 'npm-nexus-creds', variable: 'mynpmrc')]) {\n                    echo 'Publishing to Nexus...'\n                    sh 'npm publish --userconfig $mynpmrc --loglevel verbose'\n                }\n            }\n        }\n    }\n\n    post {\n        success {\n            echo 'Pipeline completed successfully!'\n        }\n        failure {\n            echo 'Pipeline failed.'\n        }\n    }\n}\n\n```\n\n### Create a Pipeline in Jenkins\n\n- Go to Dashboard -\u003e New Item -\u003e Create a pipeline.\n- Add description, GitHub link to project.\n  ![Job_General](images/Job_General.png)\n- In the Pipeline section, choose `Pipeline script from SCM` in Defination, choose `Git` as SCM and on repository URL enter GitHub project.\n  ![Job_Pipeline](images/Job_Pipeline.png)\n- Update specific branch and script path. And click save.\n  ![Job_Jenkins_Path](images/Job_Jenkins_Path.png)\n\n### Run the pipeline\n\n- Go to Dashboard and Click `Bulid` button.\n  ![Dashboard_build](images/Dashboard_build.png)\n- Message after executing the job.\n  ![Job_Completion](images/Job_Completion.png)\n\n### Check published file in Nexus\n\n- Go to Browser -\u003e click on your hosted repo.\n  ![Nexus_Publish](images/Nexus_Publish.png)\n\n## To publish project files using Artifact\n\n### Install Webpack\n\n```sh\n  npm install --save-dev webpack webpack-cli\n```\n\n### Add following lines in `package.json` file inside \"scripts\"\n\n```sh\n \"build\": \"webpack --config webpack.config.js\",\n  \"package\": \"rm -f publish/my-app.tgz \u0026\u0026 mkdir -p publish \u0026\u0026 cd dist \u0026\u0026 tar -czvf ../publish/my-app.tgz .\"\n```\n\n### Make a new Jenkins file\n\n```sh\npipeline {\n    agent any\n\n    tools {\n        nodejs('NodeJS')\n    }\n\n    environment {\n        NODEJS_HOME = tool name: 'NodeJS' // Assumes NodeJS is configured in Jenkins tools\n        PATH = \"${NODEJS_HOME}/bin:${env.PATH}\"\n\n        SCANNER_HOME = tool 'SonarQubeScanner'\n        SONARQUBE_SERVER = 'SonarQube'  // Name configured for SonarQube in Jenkins\n\n        NEXUS_VERSION = \"nexus3\"\n        NEXUS_PROTOCOL = \"http\"\n        NEXUS_URL = '10.0.0.247:8081' // Nexus URL\n        NEXUS_REPO = 'book-repo'\n        NEXUS_CREDENTIALS_ID = 'nexus-user-credentials' // Jenkins credentials ID for Nexus\n    }\n\n\n    stages {\n        stage('Checkout') {\n            steps {\n                checkout scm\n            }\n        }\n\n        stage('Build') {\n            steps {\n                echo 'Building...'\n                sh 'chmod +x node_modules/.bin/*'\n                sh 'npm install'\n                sh 'npm run build'\n            }\n        }\n\n        stage('Run Tests') {\n            steps {\n                echo 'Running Tests...'\n                sh 'npm test'\n            }\n        }\n\n        stage('SonarQube Analysis') {\n            steps {\n                script {\n                    withSonarQubeEnv('SonarQube') {\n                        sh \"\"\"${SCANNER_HOME}/bin/sonar-scanner -Dsonar.host.url=http://10.0.0.247:9000/ \\\n                        -Dsonar.token=squ_d216dda9f3c08bd2d5e093373b0ced7f2d09c050 \\\n                        -Dsonar.projectName=\"Book_API\" \\\n                        -Dsonar.exclusions=**/node_modules/**,**/coverage/**,**/__tests__/** \\\n                        -Dsonar.projectKey=Book_API \\\n                        -Dsonar.javascript.lcov.reportPaths=coverage/lcov.info -Dsonar.test.inclusions=tests/**/*.test.js\"\"\"\n                    }\n                }\n            }\n        }\n\n        stage('Quality Gate') {\n            steps {\n                script {\n                    echo \"Quality Gate is still in progress...\"\n\n                    sleep(time: 20, unit: 'SECONDS') // Sleep to wait for the status to update\n                    def qualityGate = waitForQualityGate()\n\n                    if (qualityGate.status != 'OK' || qualityGate.status != 'SUCCESS') {\n                        echo \"Quality Gate failed: ${qualityGate.status}\"\n                    }\n                    else {\n                        echo \"Quality Gate passed: ${qualityGate.status}\"\n                    }\n                }\n            }\n        }\n\n        stage('Package') {\n            steps {\n                echo 'Packing...'\n                sh 'npm run package'\n            }\n        }\n\n        stage('Publish to Nexus') {\n            steps {\n                echo \"Publishing to Nexus repository `${NEXUS_REPO}`...\"\n                nexusArtifactUploader artifacts: [\n                    [\n                        artifactId: 'BOOK_API',\n                        classifier: '',\n                        file: 'publish/my-app.tgz',\n                        type: 'tgz'\n                    ]\n                ],\n                credentialsId: \"${NEXUS_CREDENTIALS_ID}\",\n                groupId: 'np.book',\n                nexusUrl: \"${NEXUS_URL}\",\n                nexusVersion: \"${NEXUS_VERSION}\",\n                protocol: \"${NEXUS_PROTOCOL}\",\n                repository: \"${NEXUS_REPO}\",\n                version: '1.0.2'\n            }\n        }\n    }\n\n    post {\n        success {\n            echo 'Pipeline completed successfully!'\n        }\n        failure {\n            echo 'Pipeline failed.'\n        }\n    }\n}\n```\n\n### Create and Run Jenkins Pipeline as previous step\n\n- Job Success\n  ![Job_Success](images/Job_Success.png)\n\n### Check published file in Nexus\n\n- Go to Browser -\u003e click on your hosted repo.\n  ![Nexus_Publish_Artifact](images/Nexus_Publish_Artifact.png)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Franish-shrestha%2Fbook_api","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Franish-shrestha%2Fbook_api","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Franish-shrestha%2Fbook_api/lists"}