Search code examples
wildflymaven-cargokeycloak

Use Maven Cargo to install Wildfly with Keycloak


I'm trying to use Maven Cargo to produce a Wildfly container and get Keycloak running on it. I've been at this for a while now and the way I see it there are two ways to go about it. I could either use an artifact installer for Wildfly and then try to deploy Keycloak to it, or I could use a zip installer and have it install Keycloak's appliance build. I have the basics of both solutions working although neither of them work all the way.
They both seem to have downsides. If you use the artifact installer you have a more stable installer, but deploying the war takes quite a bit of lower level configuration for Wildfly. (Deployment Instructions). On the other hand, the zip installer requires finding a place to download a distribution from and then manipulating it a bit before Cargo will recognize it, because the zip structure is not what Cargo seems to be expecting.

I'm getting the zip from here: https://repository.jboss.org/nexus/content/repositories/releases/org/keycloak/keycloak-appliance-dist-all/1.0.2.Final/keycloak-appliance-dist-all-1.0.2.Final.zip)

Thanks in advance guys.


Solution

  • I figured out a way to do this and attached the relevant pom snippet. The only oddball piece here ends up being the files section. It's being used to deploy a database file that has a couple test users, realms, apps, etc.

    <plugin>
        <groupId>org.codehaus.cargo</groupId>
        <artifactId>cargo-maven2-plugin</artifactId>
        <version>1.4.6</version>
        <configuration>
            <container>
                <containerId>wildfly8x</containerId>
                <!-- <log>${basedir}/target/cargo.log</log> -->
                <!-- <output>${basedir}/target/wildfly.log</output> -->
                <home>${project.basedir}/target/cargo/installs/keycloak-appliance-dist-all-1.0.4.Final/keycloak-appliance-dist-all-1.0.4.Final/keycloak</home>
                <artifactInstaller>
                    <groupId>org.keycloak</groupId>
                    <artifactId>keycloak-appliance-dist-all</artifactId>
                    <version>1.0.4.Final</version>
                </artifactInstaller>
            </container>
            <configuration>
                <properties>
                    <cargo.servlet.port>8080</cargo.servlet.port>
                    <cargo.servlet.users>root:root:ManagementRealm</cargo.servlet.users>
                    <cargo.jboss.configuration>standalone</cargo.jboss.configuration>
                </properties>
                <files>
                    <file>
                        <file>${project.basedir}/WildflyKeycoakConfigs/keycloak.h2.db</file>
                        <todir>/data</todir>
                    </file>
                </files>
            </configuration>
        </configuration>
    </plugin>