wildfly / galleon

Galleon Provisioning Tool
https://docs.wildfly.org/galleon/
Apache License 2.0
26 stars 30 forks source link

Using Maven repository manager as a mirror does not seem to work #321

Closed rkrzewski closed 1 year ago

rkrzewski commented 1 year ago

I am running Galleon inside a Docker container to to build a customized Wildfly distribution.

Lately my builds of that container started to randomly fail with Could not transfer artifact <some artifact> from/to maven-central (https://repo1.maven.org/maven2/): Connect timed out. To counter that I've tried using my local Sonatype Nexus OSS instance as a mirror, but I have trouble getting it to work.

I've added settings.xml to the Docker image and loaded it using maven set-settings-file <path to settings xml file> command, following https://docs.wildfly.org/galleon/#_relying_on_maven_settings

The contents of the settings.xml file are:

<settings>
  <mirrors>
    <mirror>
      <id>nexus</id>
      <name>Nexus</name>
      <url>https://<my nexus instance>/nexus/repository/public/</url>
      <mirrorOf>*</mirrorOf>
    </mirror>
  </mirrors>
</settings>

But that had no effect. I've also tried using <mirrorOf>maven-central,jboss-public-repository-group,jboss-ga</mirrorOf> because that's what Galleon command maven get-info shows as the default repositories. Still no effect.

I've also tried adding my own repository maven add-repository --url=https://<my nexus instance>/nexus/repository/public/ --name=nexus but it had no effect. Galleon still hit Maven Central. maven get-info shows the repository I've added below the default ones, so maybe the default ones are contacted first. Then I've tried to delete the default repositories, but surprisingly I got the following error:

maven remove-repository maven-central
Error: Remove repository failed.
 * Repository maven-central doesn't exist

Then I thought that maybe I could replace the default repositories with custom ones, but it just created repositories with duplicate names. Adding a custom repository with same name a second time does not error out either, but overwrites previous definition.

Am I missing something? https://docs.wildfly.org/galleon/#_cli_tool_maven_configuration says that "Advanced mirroring (eg: external:*) is not supported." that seems to imply that basic mirroring is supposed to work?

jfdenise commented 1 year ago

@rkrzewski , could you try to set the settings.xml file you are using with: maven set-settings-file <path to your file>. Thank-you.

rkrzewski commented 1 year ago

@jfdenise I've did that. See 3rd paragraph of my issue description.

jfdenise commented 1 year ago

@rkrzewski , could you enable traces (--verbose) that would help track maven artifacts resolution

jfdenise commented 1 year ago

@rkrzewski , looking at Galleon in details, I can actually see a bug in the way mirroring is handled. The default repositories are not handled correctly. Would you mind log an issue in JIRA: https://issues.redhat.com/projects/GAL/issues/ I am working on a fix. Will ping you there with a branch for you to test.

rkrzewski commented 1 year ago

Sure. https://issues.redhat.com/browse/GAL-347

jfdenise commented 1 year ago

As a workaround, you can define a settings.xml with the following content, yoiur mirror should work for all repositories (let me know):

<settings xmlns="http://maven.apache.org/settings/1.0.0"    
          xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"    
          xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 http://maven.apache.org/xsd/settings-1.0.0.xsd"> 
    <mirrors>
        <mirror>
            <id>my-mirror</id>
            <name>My Mirror Repository</name>
            <url>https://other-mirror.repo.other-company.com/maven2</url>
            <mirrorOf>*</mirrorOf>
        </mirror>
    </mirrors>
    <profiles>
        <profile>
            <id>all-repos</id>
            <repositories>
                <repository>
                    <id>nexus</id>
                    <url>https://repository.jboss.org/nexus/content/groups/public/</url>
                </repository>
                <repository>
                    <id>central</id>
                    <url>https://repo1.maven.org/maven2/</url>
                </repository>
                <repository>
                    <id>rh</id>
                    <url>https://maven.repository.redhat.com/ga/</url>
                </repository>
            </repositories>
        </profile>
    </profiles>
    <activeProfiles>
        <activeProfile>all-repos</activeProfile>
    </activeProfiles>
</settings>
rkrzewski commented 1 year ago

Yes, it did work. I can see the following in the logs now:

[MAVEN] downloaded org.wildfly:wildfly-ee-galleon-pack:26.1.3.Final:zip from my-mirror
jfdenise commented 1 year ago

@rkrzewski , thank-you. The proper fix is in this branch: https://github.com/jfdenise/galleon

Would you be ok to rebuild galleon and gives it a try? Your settings should just contain the mirror, no need for the active profile. Thank-you.

rkrzewski commented 1 year ago

Sure no problem. I've built galleon locally, removed profiles and activeProfiles from settings.xml and rerun my test. I can see that galleon is still accessing my-mirror. To double check, I've removed mirrors section from settings.xml, restarted galleon and re-run the test. Now galleon is accessing maven-central as expected. Your fix worked perfectly.

Thanks for your quick reaction. I really appreciate it!

jfdenise commented 1 year ago

@rkrzewski , thank-you for your clear report. It really helped identify the problem. Thanks. Fixed in https://github.com/wildfly/galleon/pull/322