Create Docker image with Maven build

There are lots of maven Docker plugin available to integrate the docker with maven.

In this example, I am going to show how to build the Docker image while building a maven project.

Copy the below snippet and put into your pom.xml file and then create a maven property “docker.image.name” with the appropriate docker image name and also make sure that the Dockerfile available in the correct location.

Then run the ‘mvn install’ and once its done, run ‘docker images’ and check that the docker image is available in the list of images.

pom.xml:


  <plugin>
	<groupId>org.codehaus.mojo</groupId>		
	<artifactId>exec-maven-plugin</artifactId>		
	<version>1.4.0</version>		
	<executions>		
		<execution>		
			<goals>		
				<goal>java</goal>		
			</goals>		
		</execution>		
		<execution>		
			<id>build-image</id>		
			<phase>install</phase>		
			<goals>		
				<goal>exec</goal>		
			</goals>		
			<configuration>		
				<executable>docker</executable>		
				<arguments>		
					<argument>build</argument>		
					<argument>-t=${docker.image.name}</argument>		
					<argument>.</argument>		
				</arguments>		
			</configuration>		
		</execution>		
	</executions>			
 </plugin>		
<plugin>
      
Advertisements

Create private function in AngularJs controller

If we want to create a private function inside an AngualrJS controller file, then we should prefix the function with _ symbol. Refer the below example.


class customerController {    
	// when landing on the page, get all customes and show them
	constructor($scope, $http) {
		 this.$http = $http;
		 this.customers = this._formatCustomers(this.getCustomers());
	}
	
    getCustomers() {
         this.$http({
              method: 'GET',
              url: `/api/customers`
          }).then(response => response.data);				
    }
	
    _formatCustomers(data) {
       //You can put some logic here to format the customer data.           
    }
}

angular.module('myApp').controller('customerController', customerController);


In the above example, customerController has two functions. They are getCustomers and _formatCustomers. Note that the first one is public and the later is private which can be accessed only within the controller js file.