Skip to content

Commit 8b81bc4

Browse files
committed
docs: update and improve README
1 parent 1332623 commit 8b81bc4

File tree

1 file changed

+74
-26
lines changed

1 file changed

+74
-26
lines changed

README.md

Lines changed: 74 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -11,19 +11,19 @@ The plugins are published to a private repository that you need to add to the pl
1111
> }
1212
> ```
1313
14-
### Docker Run Gradle Plugin
15-
Inspired by docker-run module in [palantir/gradle-docker](https://github.com/palantir/gradle-docker),
16-
but with a slightly different behaviour.
17-
It allows you to create custom independent tasks with different configurations instead of just having a single configuration available.
18-
One extension that can be used to specify default values for all custom tasks.
14+
# Docker Run Gradle Plugin
15+
Inspired by docker-run module in [palantir/gradle-docker](https://github.com/palantir/gradle-docker), but with a slightly different behaviour.
1916
2017
Add the plugin dependency to the `build.gradle.kts`
2118
```kotlin
2219
plugins {
23-
id("com.wolfyscript.devtools.docker.run") version ("a2.0.0.2")
20+
id("com.wolfyscript.devtools.docker.run") version ("a2.1.0.0")
2421
}
2522
```
2623
24+
## Default Behaviour
25+
The plugin provides an extension `dockerRun` and 3 tasks (`dockerRun`, `dockerStatus`, and `dockerStop`).
26+
2727
Use the extension to configure the container to run, or specify defaults for custom tasks
2828
```kotlin
2929
dockerRun {
@@ -39,30 +39,37 @@ dockerRun {
3939
arguments.set(setOf("-it")) // Allow for console interactivity with 'docker attach'
4040
}
4141
```
42+
The tasks can then be used to either run, stop, or get the status of the associated container.
43+
44+
## Custom Behaviour
45+
This plugin allows you to create custom independent tasks and configure them independently of each other.
46+
You can also create custom extensions that can be used to specify default values for your custom tasks.
47+
This makes it possible to run multiple different containers.
4248
43-
#### Creating custom tasks
44-
Simply create a new task of the given type.
45-
Then apply the defaults if necessary, or not to create an independent task.
49+
### Creating custom tasks
50+
Create custom run, stop, or status tasks.
51+
The `applyExtension` allows to easily apply defaults that are specified in the given `DockerRunExtension`.
52+
If not used, the task is completely independent.
4653
```kotlin
4754
target.task<DockerStopTask>("container_stop") {
48-
applyExtension(extensions.getByName<DockerRunExtension>("dockerRun")) // Apply defaults
55+
applyExtension(extensions.getByName<DockerRunExtension>("dockerRun")) // Apply defaults as conventions
4956
name.set("${name.get()}_$serverName") // overrides default
5057
}
5158
5259
target.task<DockerRunTask>("container_run") {
53-
applyExtension(extensions.getByName<DockerRunExtension>("dockerRun")) // Apply defaults
60+
applyExtension(extensions.getByName<DockerRunExtension>("dockerRun")) // Apply defaults as conventions
5461
name.set("${name.get()}_$serverName") // overrides default
5562
}
5663
```
5764
58-
#### Use custom extensions
65+
### Use custom extensions
5966
```kotlin
6067
val defaultCustomExt = target.extensions.create<DockerRunExtension>("customDockerRun").apply {
6168
// Configuration
6269
}
6370
6471
target.task<DockerStopTask>("container_stop") {
65-
applyExtension(defaultCustomExt) // Apply defaults
72+
applyExtension(defaultCustomExt) // Apply defaults as conventions
6673
}
6774
6875
target.task<DockerRunTask>("container_run") {
@@ -71,8 +78,8 @@ target.task<DockerRunTask>("container_run") {
7178
7279
```
7380
74-
### Minecraft Servers Gradle Plugin
75-
This plugin uses the docker run plugin to run minecraft servers via gradle tasks inside of docker containers.
81+
# Minecraft Servers Gradle Plugin
82+
This plugin uses the docker run plugin to simplify running minecraft servers via Gradle tasks inside docker containers.
7683
It uses the [itzg/minecraft-server](https://github.com/itzg/docker-minecraft-server) image, and can be freely configured for different server types.
7784
7885
Add the plugin dependency to the `build.gradle.kts`
@@ -81,26 +88,67 @@ plugins {
8188
id("com.wolfyscript.devtools.docker.minecraft_servers") version ("2.0-SNAPSHOT")
8289
}
8390
```
84-
The plugin can then be configured using the `minecraftServers` extension.
91+
## Configuring Servers
92+
The servers can then be configured using the `minecraftServers` extension.
8593
Some properties like the `serversDir`, `libName`, `libDir` are used as defaults for the specified servers in `servers`.
8694
87-
Each server entry in `servers` needs a unique name, that is used for the directory, container, and task.
88-
A custom directory can be specified via `serverDir`, that will be used instead of the default one.
89-
The same applies to `libName` and `libDir`, which also override the defaults.
90-
`version` = the minecraft version of the server (See [image docs](https://docker-minecraft-server.readthedocs.io/en/latest/versions/minecraft/))
91-
`type` = the type of the server (See [image docs](https://docker-minecraft-server.readthedocs.io/en/latest/types-and-platforms/))
92-
`ports` = a list of ports to publish and map from container to host
95+
All server data is stored within the specified host `serversDir` directory. The default directory is the project directory.
96+
97+
Each server entry in `servers` needs to be registered under a unique name, and is then stored within a subdirectory of the same name.
98+
The property defaults from the `minecraftServers` extension may be overridden by each server seperately.
99+
100+
`version`: the minecraft version of the server (See [image docs](https://docker-minecraft-server.readthedocs.io/en/latest/versions/minecraft/))
101+
`type`: the type of the server (See [image docs](https://docker-minecraft-server.readthedocs.io/en/latest/types-and-platforms/))
102+
`ports`: a list of ports to publish and map from container to host
93103
94104
```kotlin
95105
minecraftServers {
96106
serversDir.set(file("./test_servers"))
97107
libName.set("${project.name}-${version}.jar")
98108
servers {
99-
register("spigot_1_17") {
100-
version.set("1.17.1")
109+
register("spigot") {
110+
version.set("1.21.6")
101111
type.set("SPIGOT")
102-
ports.set(setOf("25565"))
112+
ports.add("25565")
113+
destFileName.set("scafall.jar") // set a name for the copied app
114+
imageVersion.set("java21") // Use a different version of the docker image
103115
}
104116
}
105117
}
106-
```
118+
```
119+
120+
## Configuring Minecraft Docker
121+
The plugin also provides the `minecraftDockerRun` that allows configuring the docker containers itself.
122+
123+
Here is an example from scafall:
124+
The main purpose here is to have the duplicated code in a buildSrc plugin. Including a debugger connection, resource limits, and other defaults.
125+
```kotlin
126+
val debugPort: String = System.getenv("debugPort") ?: "5006"
127+
val debugPortMapping = "${debugPort}:${debugPort}"
128+
129+
minecraftDockerRun {
130+
// By default, the container is removed when stopped.
131+
// That makes it impossible to know why a container may fail to start.
132+
// In that case disable it to debug and delete the container manually.
133+
// clean.set(false)
134+
env.putAll(
135+
mapOf(
136+
// Limit each container memory
137+
"MEMORY" to "2G",
138+
// Allows attaching the IntelliJ Debugger
139+
"JVM_OPTS" to "-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=*:${debugPort}",
140+
"FORCE_REDOWNLOAD" to "false"
141+
)
142+
)
143+
arguments(
144+
// Constrain to only use 2 cpus to better align with real production servers
145+
"--cpus",
146+
"2",
147+
// allow console interactivity (docker attach)
148+
"-it"
149+
)
150+
ports.set(listOf(debugPortMapping))
151+
}
152+
```
153+
154+

0 commit comments

Comments
 (0)