Skip to content

Commit b6d9599

Browse files
rdiaz82sciabarracom
authored andcommitted
Rdiaz82/test implementation (#7)
* modified the launcher to support a Hashmap as action result and some minor warnings removed * removed some compilation warnings * optimization in error path * test implementation * modified how to set env variables * minor changes * changes in tests * removed .travis.yml * fixed failing test
1 parent 7a75366 commit b6d9599

File tree

21 files changed

+1100
-2
lines changed

21 files changed

+1100
-2
lines changed

.gitattributes

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
# Auto detect text files and perform LF normalization.
2+
# Resources:
3+
# - https://www.kernel.org/pub/software/scm/git/docs/gitattributes.html
4+
# - http://davidlaing.com/2012/09/19/customise-your-gitattributes-to-become-a-git-ninja/
5+
# - https://help.github.com/articles/dealing-with-line-endings/
6+
* text=auto
7+
8+
*.go text eol=lf
9+
*.java text
10+
*.js text
11+
*.md text
12+
*.py text eol=lf
13+
*.scala text
14+
*.sh text eol=lf
15+
*.gradle text
16+
*.xml text
17+
*.bat text eol=crlf
18+
19+
*.jar binary
20+
*.png binary
21+
22+
# python files not having the .py extension
23+
tools/cli/wsk text eol=lf
24+
tools/cli/wskadmin text eol=lf
25+
26+
# bash files not having the .sh extension
27+
tools/vagrant/simple/wsk text eol=lf
28+
gradlew text eol=lf
29+
core/javaAction/proxy/gradlew text eol=lf
30+
tools/vagrant/hello text eol=lf
31+
sdk/docker/client/action text eol=lf

.gitignore

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
action/
2+
results/
3+
logs/
4+
out/
5+
build/
6+
*.retry
7+
8+
# Linux
9+
*~
10+
11+
# Mac
12+
.DS_Store
13+
14+
# Gradle
15+
.gradle
16+
build/
17+
!/tools/build/
18+
19+
# Python
20+
.ipynb_checkpoints/
21+
*.pyc
22+
23+
# NodeJS
24+
node_modules
25+
26+
# Vagrant
27+
.vagrant*
28+
29+
# IntelliJ
30+
.idea
31+
*.class
32+
*.iml
33+
out/
34+
35+
# .zip files must be explicited whitelisted
36+
*.zip

.scalafmt.conf

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# Licensed to the Apache Software Foundation (ASF) under one or more contributor
2+
# license agreements; and to You under the Apache License, Version 2.0.
3+
4+
style = intellij
5+
danglingParentheses = false
6+
maxColumn = 120
7+
docstrings = JavaDoc
8+
rewrite.rules = [SortImports]
9+
project.git = true

build.gradle

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one or more
3+
* contributor license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright ownership.
5+
* The ASF licenses this file to You under the Apache License, Version 2.0
6+
* (the "License"); you may not use this file except in compliance with
7+
* the License. You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
buildscript {
19+
repositories {
20+
jcenter()
21+
}
22+
dependencies {
23+
classpath "cz.alenkacz:gradle-scalafmt:${gradle.scalafmt.version}"
24+
}
25+
}
26+
27+
subprojects {
28+
apply plugin: 'scalafmt'
29+
scalafmt.configFilePath = gradle.scalafmt.config
30+
}
31+

gradle/README.md

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
<!--
2+
#
3+
# Licensed to the Apache Software Foundation (ASF) under one or more
4+
# contributor license agreements. See the NOTICE file distributed with
5+
# this work for additional information regarding copyright ownership.
6+
# The ASF licenses this file to You under the Apache License, Version 2.0
7+
# (the "License"); you may not use this file except in compliance with
8+
# the License. You may obtain a copy of the License at
9+
#
10+
# http://www.apache.org/licenses/LICENSE-2.0
11+
#
12+
# Unless required by applicable law or agreed to in writing, software
13+
# distributed under the License is distributed on an "AS IS" BASIS,
14+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
# See the License for the specific language governing permissions and
16+
# limitations under the License.
17+
#
18+
-->
19+
20+
# Gradle
21+
22+
Gradle is used to build OpenWhisk. It does not need to be pre-installed as it installs itself using the [Gradle Wrapper](https://docs.gradle.org/current/userguide/gradle_wrapper.html). To use it without installing, simply invoke the `gradlew` command at the root of the repository. You can also install `gradle` via [`apt`](http://linuxg.net/how-to-install-gradle-2-1-on-ubuntu-14-10-ubuntu-14-04-ubuntu-12-04-and-derivatives/) on Ubuntu or [`brew`](http://www.brewformulas.org/Gradle) on Mac. In the following we use `gradle` and `gradlew` as synonymous.
23+
24+
## Usage
25+
26+
In general, project level properties are set via `-P{propertyName}={propertyValue}`. A task is called via `gradle {taskName}` and a subproject task is called via `gradle :path:to:subproject:{taskName}`. To run tasks in parallel, use the `--parallel` flag (**Note:** It's an incubating feature and might break stuff).
27+
28+
### Build
29+
30+
To build all Docker images use `gradle distDocker` at the top level project, to build a specific component use `gradle :core:controller:distDocker`.
31+
32+
Project level options that can be used on `distDocker`:
33+
34+
- `dockerImageName` (*required*): The name of the image to build (e.g. whisk/controller)
35+
- `dockerHost` (*optional*): The docker host to run commands on, default behaviour is docker's own `DOCKER_HOST` environment variable
36+
- `dockerRegistry` (*optional*): The registry to push to
37+
- `dockerImageTag` (*optional*, default 'latest'): The tag for the image
38+
- `dockerTimeout` (*optional*, default 240): Timeout for docker operations in seconds
39+
- `dockerRetries` (*optional*, default 3): How many times to retry docker operations
40+
- `dockerBinary` (*optional*, default `docker`): The binary to execute docker commands
41+
42+
### Test
43+
44+
To run tests one uses the `test` task. OpenWhisk consolidates tests into a single `tests` project. Hence the command to run all tests is `gradle :tests:test`.
45+
46+
It is possible to run specific tests using [Gradle testfilters](https://docs.gradle.org/current/userguide/java_plugin.html#test_filtering). For example `gradle :tests:test --tests "your.package.name.TestClass.evenMethodName"`. Wildcard `*` may be used anywhere.
47+
48+
## Build your own `build.gradle`
49+
In Gradle, most of the tasks we use are default tasks provided by plugins in Gradle. The [`scala` Plugin](https://docs.gradle.org/current/userguide/scala_plugin.html) for example includes tasks, that are needed to build Scala projects. Moreover, Gradle is aware of *Applications*. The [`application` Plugin](https://docs.gradle.org/current/userguide/application_plugin.html) provides tasks that are required to distribute a self-contained application. When `application` and `scala` are used in conjunction, they hook into each other and provide the tasks needed to distribute a Scala application. `distTar` for example compiles the Scala code, creates a jar containing the compiled classes and resources and creates a Tarball including that jar and all of its dependencies (defined in the dependencies section of `build.gradle`). It also creates a start-script which correctly sets the classpath for all those dependencies and starts the app.
50+
51+
In OpenWhisk, we want to distribute our application via Docker images. Hence we wrote a "plugin" that creates the task `distDocker`. That task will build an image from the `Dockerfile` that is located next to the `build.gradle` it is called from, for example Controller's `Dockerfile` and `build.gradle` are both located at `core/controller`.
52+
53+
If you want to create a new `build.gradle` for your component, simply put the `Dockerfile` right next to it and include `docker.gradle` by using
54+
55+
```
56+
ext.dockerImageName = 'openwwhisk/{IMAGENAME}'
57+
apply from: 'path/to/docker.gradle'
58+
```
59+
60+
If your component needs to be build before you can build the image, make `distDocker` depend on any task needed to run before it, for example:
61+
62+
```
63+
distDocker.dependsOn ':common:scala:distDocker', 'distTar'
64+
```

gradle/docker.gradle

Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one or more
3+
* contributor license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright ownership.
5+
* The ASF licenses this file to You under the Apache License, Version 2.0
6+
* (the "License"); you may not use this file except in compliance with
7+
* the License. You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
import groovy.time.*
19+
20+
/**
21+
* Utility to build docker images based in gradle projects
22+
*
23+
* This extends gradle's 'application' plugin logic with a 'distDocker' task which builds
24+
* a docker image from the Dockerfile of the project that applies this file. The image
25+
* is automatically tagged and pushed if a tag and/or a registry is given.
26+
*
27+
* Parameters that can be set on project level:
28+
* - dockerImageName (required): The name of the image to build (e.g. controller)
29+
* - dockerRegistry (optional): The registry to push to
30+
* - dockerImageTag (optional, default 'latest'): The tag for the image
31+
* - dockerImagePrefix (optional, default 'whisk'): The prefix for the image,
32+
* 'controller' becomes 'whisk/controller' per default
33+
* - dockerTimeout (optional, default 840): Timeout for docker operations in seconds
34+
* - dockerRetries (optional, default 3): How many times to retry docker operations
35+
* - dockerBinary (optional, default 'docker'): The binary to execute docker commands
36+
* - dockerBuildArgs (options, default ''): Project specific custom docker build arguments
37+
* - dockerHost (optional): The docker host to run commands on, default behaviour is
38+
* docker's own DOCKER_HOST environment variable
39+
*/
40+
41+
ext {
42+
dockerRegistry = project.hasProperty('dockerRegistry') ? dockerRegistry + '/' : ''
43+
dockerImageTag = project.hasProperty('dockerImageTag') ? dockerImageTag : 'latest'
44+
dockerImagePrefix = project.hasProperty('dockerImagePrefix') ? dockerImagePrefix : 'whisk'
45+
dockerTimeout = project.hasProperty('dockerTimeout') ? dockerTimeout.toInteger() : 840
46+
dockerRetries = project.hasProperty('dockerRetries') ? dockerRetries.toInteger() : 3
47+
dockerBinary = project.hasProperty('dockerBinary') ? [dockerBinary] : ['docker']
48+
dockerBuildArg = ['build']
49+
}
50+
ext.dockerTaggedImageName = dockerRegistry + dockerImagePrefix + '/' + dockerImageName + ':' + dockerImageTag
51+
52+
if(project.hasProperty('dockerHost')) {
53+
dockerBinary += ['--host', project.dockerHost]
54+
}
55+
56+
if(project.hasProperty('dockerBuildArgs')) {
57+
dockerBuildArgs.each { arg ->
58+
dockerBuildArg += ['--build-arg', arg]
59+
}
60+
}
61+
62+
task distDocker {
63+
doLast {
64+
def start = new Date()
65+
def cmd = dockerBinary + dockerBuildArg + ['-t', dockerImageName, project.buildscript.sourceFile.getParentFile().getAbsolutePath()]
66+
retry(cmd, dockerRetries, dockerTimeout)
67+
println("Building '${dockerImageName}' took ${TimeCategory.minus(new Date(), start)}")
68+
}
69+
}
70+
task tagImage {
71+
doLast {
72+
def versionString = (dockerBinary + ['-v']).execute().text
73+
def matched = (versionString =~ /(\d+)\.(\d+)\.(\d+)/)
74+
75+
def major = matched[0][1] as int
76+
def minor = matched[0][2] as int
77+
78+
def dockerCmd = ['tag']
79+
if(major == 1 && minor < 12) {
80+
dockerCmd += ['-f']
81+
}
82+
retry(dockerBinary + dockerCmd + [dockerImageName, dockerTaggedImageName], dockerRetries, dockerTimeout)
83+
}
84+
}
85+
86+
task pushImage {
87+
doLast {
88+
def cmd = dockerBinary + ['push', dockerTaggedImageName]
89+
retry(cmd, dockerRetries, dockerTimeout)
90+
}
91+
}
92+
pushImage.dependsOn tagImage
93+
pushImage.onlyIf { dockerRegistry != '' }
94+
distDocker.finalizedBy pushImage
95+
96+
def retry(cmd, retries, timeout) {
97+
println("${new Date()}: Executing '${cmd.join(" ")}'")
98+
def proc = cmd.execute()
99+
proc.consumeProcessOutput(System.out, System.err)
100+
proc.waitForOrKill(timeout * 1000)
101+
if(proc.exitValue() != 0) {
102+
def message = "${new Date()}: Command '${cmd.join(" ")}' failed with exitCode ${proc.exitValue()}"
103+
if(proc.exitValue() == 143) { // 143 means the process was killed (SIGTERM signal)
104+
message = "${new Date()}: Command '${cmd.join(" ")}' was killed after ${timeout} seconds"
105+
}
106+
107+
if(retries > 1) {
108+
println("${message}, ${retries-1} retries left, retrying...")
109+
retry(cmd, retries-1, timeout)
110+
}
111+
else {
112+
println("${message}, no more retries left, aborting...")
113+
throw new GradleException(message)
114+
}
115+
}
116+
}

gradle/wrapper/gradle-wrapper.jar

53.4 KB
Binary file not shown.
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# Licensed to the Apache Software Foundation (ASF) under one or more contributor
2+
# license agreements; and to You under the Apache License, Version 2.0.
3+
4+
distributionBase=GRADLE_USER_HOME
5+
distributionPath=wrapper/dists
6+
zipStoreBase=GRADLE_USER_HOME
7+
zipStorePath=wrapper/dists
8+
distributionUrl=https\://services.gradle.org/distributions/gradle-4.1-bin.zip

0 commit comments

Comments
 (0)