New favicon and tag finger enhancement

- Updated the favicon to new LSIO logo
- Updated TagFinder so it checks against full digest parity rather than image size.
This commit is contained in:
Josh Stark 2020-06-27 11:24:49 +01:00
parent ac468df4a5
commit 994bcf8046
9 changed files with 146 additions and 7 deletions

View File

@ -18,8 +18,11 @@
package io.linuxserver.fleet.dockerhub.util;
import io.linuxserver.fleet.v2.types.docker.DockerTag;
import io.linuxserver.fleet.v2.types.docker.DockerTagManifestDigest;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Optional;
public class DockerTagFinder {
@ -32,11 +35,46 @@ public class DockerTagFinder {
DockerTag namedTagForBranch = tagBranchName.get();
Optional<DockerTag> versionedLatestTag = tags.stream()
.filter(tag -> !tag.equals(namedTagForBranch) && tag.getSize() == namedTagForBranch.getSize()).findFirst();
.filter(tag -> !tag.equals(namedTagForBranch) && allManifestsMatch(namedTagForBranch, tag)).findFirst();
return versionedLatestTag.orElse(namedTagForBranch);
}
return tags.isEmpty() ? null : tags.get(0);
}
private static boolean allManifestsMatch(final DockerTag namedTag, final DockerTag toCheck) {
final List<DockerTagManifestDigest> namedDigests = namedTag.getDigests();
final List<DockerTagManifestDigest> digestsToCheck = toCheck.getDigests();
boolean allMatch = true;
if (namedDigests.size() == digestsToCheck.size()) {
final Map<String, String> namedDigestsAsMap = toMapKeyedByArch(namedDigests);
for (DockerTagManifestDigest digestToCheck : digestsToCheck) {
final String archPlusVariant = digestToCheck.getArchitecture() + digestToCheck.getArchVariant();
final String foundDigest = namedDigestsAsMap.get(archPlusVariant);
allMatch = allMatch && (null != foundDigest) && foundDigest.equals(digestToCheck.getDigest());
}
} else {
allMatch = false;
}
return allMatch;
}
private static Map<String, String> toMapKeyedByArch(final List<DockerTagManifestDigest> initialList) {
final Map<String, String> map = new HashMap<>();
for (DockerTagManifestDigest digest : initialList) {
map.put(digest.getArchitecture() + digest.getArchVariant(), digest.getDigest());
}
return map;
}
}

View File

@ -17,6 +17,9 @@
package io.linuxserver.fleet.v2.types.docker;
import org.apache.commons.lang3.builder.ToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle;
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.List;
@ -55,4 +58,9 @@ public class DockerTag {
public LocalDateTime getBuildDate() {
return buildDate;
}
@Override
public final String toString() {
return ToStringBuilder.reflectionToString(this, ToStringStyle.SHORT_PREFIX_STYLE);
}
}

View File

@ -48,4 +48,8 @@ public class DockerTagManifestDigest {
return archVariant;
}
@Override
public final String toString() {
return architecture + "/" + archVariant + "[" + digest + "]";
}
}

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.3 KiB

After

Width:  |  Height:  |  Size: 2.2 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 15 KiB

After

Width:  |  Height:  |  Size: 15 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 23 KiB

After

Width:  |  Height:  |  Size: 19 KiB

View File

@ -1,5 +1,5 @@
#Sat May 09 13:48:27 BST 2020
app.build.date=2020-05-09T13\:48\:27
#Sat Jun 27 11:17:44 BST 2020
app.build.date=2020-06-27T11\:17\:44
app.build.os=Linux
app.build.user=josh
app.version=2.0.5

View File

@ -116,12 +116,19 @@
<tbody>
<@table.halfDisplayRow title="Docker Hub" value='<i class="fab fa-docker"></i> ${image.fullName}' link="https://hub.docker.com/r/${image.fullName}" />
<@table.halfDisplayRow title="Build Time" value=image.lastUpdatedAsString />
<#if image.metaData.baseImage?has_content>
<@table.halfDisplayRow title="Base Image" value=image.metaData.baseImage?html />
</#if>
<#if image.metaData.category?has_content>
<@table.halfDisplayRow title="Category" value=image.metaData.category?html />
</#if>
<@table.halfDisplayRow title="Synchronised" value=image.syncEnabled?string("Yes", "No") />
<@table.halfDisplayRow title="Stable" value=image.stable?string("Yes", "No") />
<@table.halfDisplayRow title="Deprecated" value=image.deprecated?string("Yes", "No") />
</tbody>
</@table.table>
@ -141,10 +148,6 @@
</thead>
<tbody>
<#if image.metaData.category?has_content>
<@table.halfDisplayRow title="Category" value=image.metaData.category />
</#if>
<#-- Any set external Urls -->
<#list image.metaData.externalUrls as url>

View File

@ -0,0 +1,86 @@
/*
* Copyright (c) 2020 LinuxServer.io
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package io.linuxserver.fleet.dockerhub.util;
import io.linuxserver.fleet.v2.types.docker.DockerTag;
import io.linuxserver.fleet.v2.types.docker.DockerTagManifestDigest;
import org.junit.Before;
import org.junit.Test;
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.List;
import static org.hamcrest.CoreMatchers.equalTo;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.MatcherAssert.assertThat;
public class DockerTagFinderTest {
@Test
public void shouldFindCorrectTagIfAllDigestsMatch() {
final DockerTag named = new DockerTag("latest", 1234L, LocalDateTime.now());
named.addDigest(new DockerTagManifestDigest(1234L, "digest1", "arch", "variant1"));
named.addDigest(new DockerTagManifestDigest(1234L, "digest2", "arch", "variant2"));
named.addDigest(new DockerTagManifestDigest(1234L, "digest3", "arch", "variant3"));
final DockerTag shouldMatch = new DockerTag("v1234", 1234L, LocalDateTime.now());
shouldMatch.addDigest(new DockerTagManifestDigest(1234L, "digest1", "arch", "variant1"));
shouldMatch.addDigest(new DockerTagManifestDigest(1234L, "digest2", "arch", "variant2"));
shouldMatch.addDigest(new DockerTagManifestDigest(1234L, "digest3", "arch", "variant3"));
final DockerTag shouldNotMatch = new DockerTag("v1234", 1234L, LocalDateTime.now());
shouldNotMatch.addDigest(new DockerTagManifestDigest(1234L, "digest1", "arch", "variant1"));
shouldNotMatch.addDigest(new DockerTagManifestDigest(1234L, "digest4", "arch", "variant2"));
shouldNotMatch.addDigest(new DockerTagManifestDigest(1234L, "digest3", "arch", "variant3"));
final List<DockerTag> tags = new ArrayList<>();
tags.add(named);
tags.add(shouldMatch);
tags.add(shouldNotMatch);
assertThat(DockerTagFinder.findVersionedTagMatchingBranch(tags, "latest"), is(equalTo(shouldMatch)));
}
@Test
public void shouldReturnFoundNamedTagIfNoOthersMatchFully() {
final DockerTag named = new DockerTag("latest", 1234L, LocalDateTime.now());
named.addDigest(new DockerTagManifestDigest(1234L, "digest1", "arch", "variant1"));
named.addDigest(new DockerTagManifestDigest(1234L, "digest2", "arch", "variant2"));
named.addDigest(new DockerTagManifestDigest(1234L, "digest3", "arch", "variant3"));
final DockerTag shouldMatch = new DockerTag("v1234", 1234L, LocalDateTime.now());
shouldMatch.addDigest(new DockerTagManifestDigest(1234L, "digest1", "arch", "variant1"));
shouldMatch.addDigest(new DockerTagManifestDigest(1234L, "digest5", "arch", "variant2"));
shouldMatch.addDigest(new DockerTagManifestDigest(1234L, "digest3", "arch", "variant3"));
final DockerTag shouldNotMatch = new DockerTag("v1234", 1234L, LocalDateTime.now());
shouldNotMatch.addDigest(new DockerTagManifestDigest(1234L, "digest1", "arch", "variant1"));
shouldNotMatch.addDigest(new DockerTagManifestDigest(1234L, "digest4", "arch", "variant2"));
shouldNotMatch.addDigest(new DockerTagManifestDigest(1234L, "digest3", "arch", "variant3"));
final List<DockerTag> tags = new ArrayList<>();
tags.add(named);
tags.add(shouldMatch);
tags.add(shouldNotMatch);
assertThat(DockerTagFinder.findVersionedTagMatchingBranch(tags, "latest"), is(equalTo(named)));
}
}