Skip to content

vsfedorenko/gradle-require-docker-plugin

Repository files navigation

Gradle RequireDocker plugin

Build Status codecov GitHub Release Gradle Plugins Release license Semantic Release

I am looking for help to develop this plugin. I have a lot of ideas, but I don't have enough time to implement them all. If you are interested, feel free to open an issue or a discussion to talk about it. Also, I will be happy to add you to the list of contributors. Thank you!

Integrate docker containers into your workflow. Require Docker containers to be running before executing a Gradle task and shutdown after.

With this plugin, you can require a Postgres container to be running before executing a Flyway migration and a JOOQ code generation or integration tests tasks. Plugin also maintains containers lifecycle, so you don't need to worry about stopping and removing containers after.

plugins {
    id("io.github.meiblorn.require-docker") version "x.y.z"
}

requireDocker {
    val jooq by requireDocker.specs.creating {
        val postgres by contaienrs.creating {
            image("postgres:latest")
            portBindings("5432:5432")
            envVars(
                "POSTGRES_PASSWORD" to "postgres",
                "POSTGRES_USER" to "postgres",
                "POSTGRES_DB" to "postgres",
            )
        }
    }
}

// Create Flyway migrations task
// This task creates schema and tables in the database
val jooqFlywayMigrate by tasks.creating {
    url = "jdbc:postgresql://localhost:5432/postgres"
    user = "postgres"
    password = "postgres"
}

val generateJooq by tasks.getting {
    // Declare a dependency on the jooqFlywayMigrate task
    // NOTE: JOOQ requires the database schema 
    //       to be created before generating the code
    dependsOn(jooqFlywayMigrate)
}

// Enforce containers to be running before 
// executing jooqFlywayMigrate and generateJooq tasks
requireDocker.spec("jooq") {
    requiredBy(jooqFlywayMigrate)
    requiredBy(generateJooq)
}

TODO:

  • Publish plugin to Gradle Plugin Portal
  • Add test coverage
  • Add GitHub Actions workflow
  • Add badges to README.md
  • Add more samples
  • Clean up code
    • Move Kotlin extensions to separate Gradle source set
    • Build internal task graph and then process it in a single place instead of iterating specs and containers in nested loops
    • Utilise dependency injection features of Gradle to simplify code
  • Cover with unit tests
  • Cover with integration tests
    • Check Docker client
    • Check Bmuschko's Gradle plugin conflicts
    • Check Spring Boot Gradle plugin conflicts
    • Check Micronaut Gradle plugin conflicts
  • Add java docs
  • Add docs (preferably using docusaurus)

License

RequireDocker plugin is licensed under the MIT License. See LICENSE for more information.

Project heavily relies on Bmuschko's Docker plugin.

Inspired by Avast's Docker Compose plugin and Monosoul's JOOQ plugin.

About

Integrate docker containers into your Gradle build lifecycle

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Contributors 3

  •  
  •  
  •  

Languages