Skip to content
This repository was archived by the owner on Jul 18, 2025. It is now read-only.

Commit ff7fb5e

Browse files
author
Matthieu Nottale
committed
gradle plugin with a 'render' task, and example usage.
Signed-off-by: Matthieu Nottale <[email protected]>
1 parent 85420c7 commit ff7fb5e

File tree

10 files changed

+158
-0
lines changed

10 files changed

+158
-0
lines changed

gradle/build.gradle

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
plugins {
2+
id 'java'
3+
}
4+
5+
plugins {
6+
id 'java-gradle-plugin'
7+
}
8+
apply plugin: 'java-gradle-plugin'
9+
group 'docker'
10+
version '1.0-SNAPSHOT'
11+
12+
sourceCompatibility = 1.8
13+
14+
repositories {
15+
mavenCentral()
16+
}
17+
18+
dependencies {
19+
testCompile group: 'junit', name: 'junit', version: '4.12'
20+
}
21+
22+
23+
gradlePlugin {
24+
plugins {
25+
dockerapp {
26+
id = 'com.docker.gradle.dockerapp'
27+
implementationClass = 'com.docker.gradle.dockerapp.DockerAppPlugin'
28+
}
29+
}
30+
}

gradle/example/build.gradle

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
buildscript{
2+
dependencies{
3+
classpath files('../build/libs/dockerapp-plugin-1.0-SNAPSHOT.jar')
4+
}
5+
}
6+
7+
apply plugin: com.docker.gradle.dockerapp.DockerAppPlugin
8+
9+
import com.docker.gradle.dockerapp.*
10+
11+
task renderIt(type: DockerAppRender) {
12+
appPath = 'simple'
13+
target = 'rendered.yml'
14+
}
218 KB
Loading

gradle/example/settings.gradle

Whitespace-only changes.
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
version: "3.6"
2+
services:
3+
mysql:
4+
image: mysql:${mysql.image.version}
5+
environment:
6+
MYSQL_ROOT_PASSWORD: ${mysql.rootpass}
7+
MYSQL_DATABASE: ${mysql.database}
8+
MYSQL_USER: ${mysql.user.name}
9+
MYSQL_PASSWORD: ${mysql.user.password}
10+
volumes:
11+
- source: db_data
12+
target: /var/lib/mysql
13+
type: volume
14+
deploy:
15+
mode: replicated
16+
replicas: 1
17+
wordpress:
18+
image: wordpress
19+
environment:
20+
WORDPRESS_DB_USER: ${mysql.user.name}
21+
WORDPRESS_DB_PASSWORD: ${mysql.user.password}
22+
WORDPRESS_DB_NAME: ${mysql.database}
23+
WORDPRESS_DB_HOST: mysql
24+
WORDPRESS_DEBUG: ${debug}
25+
deploy:
26+
mode: ${wordpress.scale.mode}
27+
replicas: ${wordpress.scale.replicas}
28+
29+
volumes:
30+
db_data:
31+
name: ${volumes.db_data.name}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
version: 0.1.0
2+
name: simple
3+
description: ""
4+
maintainers:
5+
- name: sakuya.izayoi
6+
7+
targets:
8+
swarm: true
9+
kubernetes: true
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
debug: true
2+
mysql:
3+
image:
4+
version: 8
5+
rootpass: axx[<^cz3d.fPb
6+
database: wordpressdata
7+
user:
8+
name: wordpress
9+
password: wordpress
10+
wordpress:
11+
scale:
12+
mode: global
13+
replicas: 0
14+
volumes:
15+
db_data:
16+
name: db_data

gradle/settings.gradle

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
rootProject.name = 'dockerapp-plugin'
2+
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
package com.docker.gradle.dockerapp;
2+
3+
import org.gradle.api.*;
4+
5+
public class DockerAppPlugin implements Plugin<Project> {
6+
static final String TASK_NAME = "yourTask";
7+
8+
@Override
9+
public void apply(Project target) {
10+
}
11+
}
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
package com.docker.gradle.dockerapp;
2+
3+
import org.gradle.api.DefaultTask;
4+
import org.gradle.api.tasks.Input;
5+
import org.gradle.api.tasks.OutputFile;
6+
import org.gradle.api.tasks.TaskAction;
7+
8+
import java.io.BufferedReader;
9+
import java.io.InputStreamReader;
10+
11+
public class DockerAppRender extends DefaultTask {
12+
private String appPath;
13+
private String target;
14+
@OutputFile
15+
public String GetTarget() {
16+
return target;
17+
}
18+
public void setTarget(String t) {
19+
target = t;
20+
}
21+
@Input
22+
public String GetAppPath() {
23+
return appPath;
24+
}
25+
26+
public void setAppPath(String ap) {
27+
appPath = ap;
28+
}
29+
@TaskAction
30+
public void process() {
31+
try {
32+
Process p = Runtime.getRuntime().exec("docker-app " + "render " + appPath + " -o " + target);
33+
BufferedReader input =
34+
new BufferedReader
35+
(new InputStreamReader(p.getInputStream()));
36+
String line;
37+
while ((line = input.readLine()) != null) {
38+
System.out.println(line);
39+
}
40+
input.close();
41+
} catch (Exception e) {
42+
e.printStackTrace();
43+
}
44+
}
45+
}

0 commit comments

Comments
 (0)