Skip to content

steklopod/gradle-docker-plugin

Repository files navigation

Docker - gradle plugin

Backend CI Build Status Quality Gate Status

Bugs Duplicated Lines (%) Maintainability Rating Reliability Rating Security Rating

πŸ›‘ This plugin gives helpful gradle tasks for working with docker containers for projects with any types and languages.

Quick start

  1. You only need to have docker-compose.yml file in root of your project

  2. In your build.gradle.kts file:

plugins {
     id("online.colaba.docker") version "1.4.1"
}

🎯 Run task

gradle deploy

this task is equivalent to docker-compose up --build --force-recreate --detach command.

Available tasks for docker plugin:

  • deploy - compose up project from docker-compose.yml file (default with recreate & rebuild)
  • deployDev - compose up docker container from docker-compose.dev.yml file
  • recompose, recomposeDev - compose up after removing current docker-service
  • stop, remove - stop/remove docker container
  • logs, docker - print current docker-services

Name of service for all tasks equals to ${project.name}. You can customize options of each task.

Customize it in your build.gradle.kts file

tasks{
    docker{
        exec = "rm -f ${project.name}"
    }
}

Another version of customization:

tasks{
    val remove by registering(Docker::class) { exec = "rm -f ${project.name}" }
    
    val deploy by existing(Docker::class){ 
                                            dependsOn(remove)
                                            recreate = false
                                            composeFile = "docker-compose.dev.yml"
                                         }
}

Run customized task

gradle deploy

🎫 Example

  • Structure:
[project]
     | - build.gradle.kts
     | - docker-compose.yml
     | - docker-compose.dev.yml (optional)

docker-compose.dev.yml, Dockerfile & Dockerfile.dev files are optionals


Optional

With docker plugin you have additional bonus task for executing a command line process on local PC [linux/windows]:

tasks{
       execute{
                command = "echo ${project.name}"
       }
}