Skip to content

Commit

Permalink
Use docker to build dashboard app. (as alternative) (eclipse-che#5848)
Browse files Browse the repository at this point in the history
* Use docker to build dashboard app.
By using layer for package.json and bower.json file, it saves extra time to get npm or bower dependencies

Also, if dashboard files are not modified, the build is faster.

it targets as well 5127

By default :
 "$ mvn clean install" --> use docker
 "$ mvn clean install -Pnative" --> use native tools

Change-Id: Ia65161b58e8ae70f7799500750a3d87687e34819
Signed-off-by: Florent BENOIT <fbenoit@redhat.com>
  • Loading branch information
benoitf authored Aug 7, 2017
1 parent 530aa44 commit 8fcd5dc
Show file tree
Hide file tree
Showing 5 changed files with 196 additions and 68 deletions.
27 changes: 27 additions & 0 deletions dashboard/.dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
Dockerfile
node_modules
bower_components
target
pom.xml
./typings
./tmp
./codeverage

# Eclipse #
###################

*.launch
.classpath
.project
.settings/
bin/
test-output/
maven-eclipse.xml

# Idea #
##################
*.iml
*.ipr
*.iws
.idea/

22 changes: 22 additions & 0 deletions dashboard/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Copyright (c) 2012-2017 Red Hat, Inc
# All rights reserved. This program and the accompanying materials
# are made available under the terms of the Eclipse Public License v1.0
# which accompanies this distribution, and is available at
# http://www.eclipse.org/legal/epl-v10.html

# This is a Dockerfile allowing to build dashboard by using a docker container.
# Build step: $ docker build -t eclipse-che-dashboard
# It builds an archive file that can be used by doing later
# $ docker run --rm eclipse-che-dashboard | tar -C target/ -zxf -
FROM mhart/alpine-node:6

RUN apk update && \
apk add --no-cache git
COPY package.json /dashboard/
RUN cd /dashboard && npm install
COPY bower.json /dashboard/
RUN cd /dashboard && ./node_modules/.bin/bower install --allow-root
COPY . /dashboard/
RUN cd /dashboard && npm run build && cd target/ && tar zcf /tmp/dashboard.tar.gz dist/

CMD zcat /tmp/dashboard.tar.gz
24 changes: 17 additions & 7 deletions dashboard/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,30 @@ Eclipse Che is a next generation Eclipse IDE and open source alternative to Inte
Che Dashboard
==============

#Requirements
- Python `v2.7.x`(`v3.x.x`currently not supported)
- Node.js `v4.x.x` (`v5.x.x` / `v6.x.x` are currently not supported)
- npm

Installation instructions for Node.js and npm can be found on the following [link](https://docs.npmjs.com/getting-started/installing-node).
## Requirements
- Docker

#Quick start
## Quick start

```sh
cd che/dashboard
mvn clean install
```

note: by default it will build dashboard using a docker image.
If all required tools are installed locally, the native profile can be used instead of the docker build by following command:

```sh
$ mvn -Pnative clean install
```

Required tools for native build:
- Python `v2.7.x`(`v3.x.x`currently not supported)
- Node.js `v4.x.x`, `v5.x.x` or `v6.x.x`
- npm

Installation instructions for Node.js and npm can be found on the following [link](https://docs.npmjs.com/getting-started/installing-node).

## Running
In order to run the project, the serve command is used
```sh
Expand Down
2 changes: 1 addition & 1 deletion dashboard/gulp/conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ var gutil = require('gulp-util');
*/
exports.paths = {
src: 'src',
dist: 'dist',
dist: 'target/dist',
tmp: '.tmp',
e2e: 'e2e'
};
Expand Down
189 changes: 129 additions & 60 deletions dashboard/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -35,72 +35,13 @@
<build>
<finalName>dashboard-war</finalName>
<plugins>
<plugin>
<artifactId>maven-clean-plugin</artifactId>
<configuration>
<filesets>
<fileset>
<directory>${basedir}/bower_components</directory>
<followSymlinks>false</followSymlinks>
</fileset>
<fileset>
<directory>${basedir}/node_modules</directory>
<followSymlinks>false</followSymlinks>
</fileset>
<fileset>
<directory>${basedir}/dist</directory>
<followSymlinks>false</followSymlinks>
</fileset>
</filesets>
</configuration>
</plugin>
<plugin>
<artifactId>maven-antrun-plugin</artifactId>
<executions>
<execution>
<id>compile</id>
<phase>compile</phase>
<goals>
<goal>run</goal>
</goals>
<configuration>
<target>
<!-- Download NPM dependencies -->
<exec dir="${basedir}" executable="npm" failonerror="true">
<arg value="install" />
</exec>
<!-- Change base HREF of the application that will be hosted on /dashboard -->
<replace file="${basedir}/dist/index.html">
<replacetoken><![CDATA[<base href="/">]]></replacetoken>
<replacevalue><![CDATA[<base href="/dashboard/">]]></replacevalue>
</replace>
</target>
</configuration>
</execution>
<execution>
<id>compilation</id>
<phase>test</phase>
<goals>
<goal>run</goal>
</goals>
<configuration>
<target unless="skipTests">
<!-- Run unit tests -->
<exec dir="${basedir}" executable="gulp" failonerror="true">
<arg value="test" />
</exec>
</target>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<configuration>
<webResources>
<resource>
<directory>dist</directory>
<directory>target/dist</directory>
</resource>
</webResources>
<webXml>${basedir}/src/webapp/WEB-INF/web.xml</webXml>
Expand Down Expand Up @@ -129,6 +70,134 @@
</plugins>
</build>
<profiles>
<profile>
<!-- Docker build used by default, to use native build, use -Pnative -->
<id>docker</id>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<build>
<plugins>
<plugin>
<artifactId>maven-antrun-plugin</artifactId>
<executions>
<execution>
<id>build-image</id>
<phase>generate-sources</phase>
<goals>
<goal>run</goal>
</goals>
<configuration>
<target>
<!-- build user dashboard with maven -->
<exec dir="${basedir}" executable="docker" failonerror="true">
<arg value="build" />
<arg value="-t" />
<arg value="eclipse-che-dashboard" />
<arg value="." />
</exec>
</target>
</configuration>
</execution>
<execution>
<id>unpack-docker-build</id>
<phase>generate-sources</phase>
<goals>
<goal>run</goal>
</goals>
<configuration>
<target>
<!-- build user dashboard with docker -->
<exec executable="bash">
<arg value="-c" />
<arg value="docker run --rm eclipse-che-dashboard | tar -C target/ -xf -" />
</exec>
</target>
</configuration>
</execution>
<execution>
<id>update-href</id>
<phase>prepare-package</phase>
<goals>
<goal>run</goal>
</goals>
<configuration>
<target>
<!-- Change base HREF of the application that will be hosted on /dashboard -->
<replace file="${basedir}/target/dist/index.html">
<replacetoken><![CDATA[<base href="/">]]></replacetoken>
<replacevalue><![CDATA[<base href="/dashboard/">]]></replacevalue>
</replace>
</target>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
<profile>
<id>native</id>
<build>
<plugins>
<plugin>
<artifactId>maven-clean-plugin</artifactId>
<configuration>
<filesets>
<fileset>
<directory>${basedir}/bower_components</directory>
<followSymlinks>false</followSymlinks>
</fileset>
<fileset>
<directory>${basedir}/node_modules</directory>
<followSymlinks>false</followSymlinks>
</fileset>
</filesets>
</configuration>
</plugin>
<plugin>
<artifactId>maven-antrun-plugin</artifactId>
<executions>
<execution>
<id>build-dashboard</id>
<phase>compile</phase>
<goals>
<goal>run</goal>
</goals>
<configuration>
<target>
<!-- build user dashboard -->
<exec dir="${basedir}" executable="npm" failonerror="true">
<arg value="install" />
</exec>
<!-- Change base HREF of the application that will be hosted on /dashboard -->
<replace file="${basedir}/target/dist/index.html">
<replacetoken><![CDATA[<base href="/">]]></replacetoken>
<replacevalue><![CDATA[<base href="/dashboard/">]]></replacevalue>
</replace>
</target>
</configuration>
</execution>
<execution>
<id>compilation</id>
<phase>test</phase>
<goals>
<goal>run</goal>
</goals>
<configuration>
<target unless="skipTests">
<!-- Run unit tests -->
<exec dir="${basedir}" executable="gulp" failonerror="true">
<arg value="test" />
</exec>
</target>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
<profile>
<id>qa</id>
<build>
Expand Down

0 comments on commit 8fcd5dc

Please sign in to comment.