Note: This approach to using Docker to build the application is perfect for instantly testing a new version of node.js without worrying about packages conflicts on your computer. No tricks, we perform npm install to download all node modules required by this project, and then you call the ng build to compile our project, like all standard node projects. In the second and third steps from the script, we effectively build the application using the Docker Image constructed before. And we will use them to build the application, and that approach doesn’t need to install those applications on our computer. The first step from the build.sh, we are building the Docker image that will contain the noje.js and npm. ĭocker run -rm -name node -v $PROJECT/:/tmp/angular -t /angular:v1 npm installĭocker run -rm -name node -v $PROJECT/:/tmp/angular -t /angular:v1 npm run build Then, later, we can give it to the Sonarqube to analyze for us. So, it means compile our Typescript and generate our Javascript code. We will build our Angular project on this script. Then, I recommend you to read our previous post, which has an outstanding level of detail about it. Suppose you need more details to configure the Docker Container for Sonarqube and how to configure the sonarqube. This project on Github does almost everything automatically. You can download the project from my GitHub repository: git clone Sonarqube Javascript Exampleįor our example, to learn using sonarqube with javascript, we have prepared a Hello Word built using Angular framework to make it easier to explain and go through all the steps that we need to learn. I will teach you how to start a Docker Container with Sonarqube, and then you can focus on the analysis. In our example below, we will show how to do it using an Angular project. How to use SonarQube with Node Jsįor a node js project, you need to compile the Typescript code and generate the Javascript code. You don’t need to include additional plugins from the Javascript side of your project for SonarQube Javascript integration. In our example, we are using all applications wrapped in a container. So, the only software that you need to install to get started is Docker and Git. You need to have already installed on your computer: However, to analyze Javascript code, we need to use the Sonarqube toolbox (Scanner), just a binary file (doesn’t require installation). However, Sonarqube already has many plugins and tools that speed up our hands-on analysis without any critical configuration. In the previous post about sonarqube with Docker, we focus on configuring and analyzing Maven’s Java projects. We can analyze an Angular project or Node.js, or any other Javascript technology. Without wasting, considerable time, installing a lot of software and dependencies. Summing up, the whole Dockerfile should look like this: FROM node:12-alpine3.Sonarqube with Docker and Javascript, it’s the perfect combination that you can use to improve the quality of your application. Line 7: Expose port 8081 to the outside once the container has launched: EXPOSE 8081 What we want to do is to run our application: CMD node index.js Line 6: This line describes what should be executed when the Node Docker image is launching. RUN npm ci -only=production & npm cache clean -force This results from the way the Docker image is being built (layers and cache), and this is what we should do: COPY package.json /app If you add the package.json first and run npm install later, Docker won't have to install the dependencies again if you change the package.json file. Lines 3-5: Copy the application to the /app directory and install dependencies. We shall use this directory to store files, run npm, and launch our application: WORKDIR /app Line 2: Set the working directory in the container to /app. In this example we'll use Docker Hub, the most popular one. You can share images using image registries.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |