Skip to content

Commit

Permalink
Merge branch 'dev' into 'main'
Browse files Browse the repository at this point in the history
  • Loading branch information
mthalman committed Dec 22, 2024
2 parents 75cf442 + 8c26091 commit da07705
Show file tree
Hide file tree
Showing 13 changed files with 133 additions and 8 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ jobs:

- name: Publish
working-directory: src/Valleysoft.Dredge
run: dotnet publish -f net8.0 -c Release --no-restore -o ${{ github.workspace }}/publish --runtime ${{ matrix.rid }} --no-self-contained
run: dotnet publish -f net9.0 -c Release --no-restore -o ${{ github.workspace }}/publish --runtime ${{ matrix.rid }} --no-self-contained

- name: Rename output
run: |
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ The main documentation is in the [docs](docs) directory.
Download the desired executable from the [release page](https://github.com/mthalman/dredge/releases).

Prerequisites:
* [.NET 8 runtime](https://dotnet.microsoft.com/download/dotnet/8.0)
* [.NET 9 runtime](https://dotnet.microsoft.com/download/dotnet/9.0)

### Running as a container

Expand Down
31 changes: 31 additions & 0 deletions docs/commands/referrers.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# Referrers

Sub-commands:

* [`list`](#query-referrers) - Lists the referrers to a manifest

## Query Referrers

Returns the referrers to the specified manifest.

```console
> dredge referrer list mcr.microsoft.com/dotnet/core/sdk:latest
{
"manifests": [
{
"mediaType": "application/vnd.oci.image.manifest.v1+json",
"digest": "sha256:551e9aa2046071e51b1611a7e85f85af3d2cc6841935cc176a931de4194ecdc1",
"size": 788,
"urls": [],
"annotations": {
"org.opencontainers.image.created": "2024-08-13T14:20:19Z",
"vnd.microsoft.artifact.lifecycle.end-of-life.date": "2022-12-13"
},
"artifactType": "application/vnd.microsoft.artifact.lifecycle"
}
],
"annotations": {},
"schemaVersion": 2,
"mediaType": "application/vnd.oci.image.index.v1+json"
}
```
6 changes: 3 additions & 3 deletions src/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM --platform=$BUILDPLATFORM mcr.microsoft.com/dotnet/sdk:8.0-jammy@sha256:4d0de0f52f1252139b2709c9fc2f7bb23155fd8e33936a44a6ebfb02df0ec45c AS build
FROM --platform=$BUILDPLATFORM mcr.microsoft.com/dotnet/sdk:9.0-noble@sha256:991fd7c9c41fc12b47313bd2e1fb292c39e50fb50453ac11287b2877d3623d55 AS build

ARG TARGETARCH
ARG PACKAGE_VERSION
Expand All @@ -11,10 +11,10 @@ RUN dotnet restore -a $TARGETARCH Valleysoft.Dredge/*.csproj

COPY Valleysoft.Dredge/ Valleysoft.Dredge/
COPY Valleysoft.Dredge.Analyzers/ Valleysoft.Dredge.Analyzers/
RUN dotnet publish Valleysoft.Dredge/*.csproj -f net8.0 -o /app -a $TARGETARCH --no-self-contained /p:Version=$PACKAGE_VERSION --no-restore
RUN dotnet publish Valleysoft.Dredge/*.csproj -f net9.0 -o /app -a $TARGETARCH --no-self-contained /p:Version=$PACKAGE_VERSION --no-restore


FROM mcr.microsoft.com/dotnet/runtime:8.0-jammy-chiseled@sha256:f50b13c931ecef4538f75f98b417947085ec03c697a4df167306ff30ff81e43f
FROM mcr.microsoft.com/dotnet/runtime:9.0-noble-chiseled@sha256:d5c0e8bfef9e0b506a0129af076af2677c51d02f73c5995e54cd33e8ce3cc6e0
WORKDIR /app
COPY --from=build /app .
ENTRYPOINT ["./dredge"]
2 changes: 1 addition & 1 deletion src/Valleysoft.Dredge.Tests/Valleysoft.Dredge.Tests.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<TargetFramework>net9.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>

Expand Down
5 changes: 4 additions & 1 deletion src/Valleysoft.Dredge/Commands/Image/OsCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using Newtonsoft.Json;
using System.IO.Compression;
using System.Text;
using System.Text.RegularExpressions;
using Valleysoft.DockerRegistryClient;
using Valleysoft.DockerRegistryClient.Models.Manifests;
using ImageConfig = Valleysoft.DockerRegistryClient.Models.Images.Image;
Expand All @@ -10,6 +11,8 @@ namespace Valleysoft.Dredge.Commands.Image;

public class OsCommand : RegistryCommandBase<OsOptions>
{
private static readonly Regex osReleaseRegex = new(@"(\./)?(etc|usr/lib)/os-release");

public OsCommand(IDockerRegistryClientFactory dockerRegistryClientFactory)
: base("os", "Gets OS info about the container image", dockerRegistryClientFactory)
{
Expand Down Expand Up @@ -75,7 +78,7 @@ protected override Task ExecuteAsync()
// Look for the os-release file (skip symlinks)
if (entry is not null &&
entry.Size > 0 &&
(entry.Name == "etc/os-release" || entry.Name == "usr/lib/os-release"))
(osReleaseRegex.IsMatch(entry.Name)))
{
using MemoryStream memStream = new();
tarStream.CopyEntryContents(memStream);
Expand Down
50 changes: 50 additions & 0 deletions src/Valleysoft.Dredge/Commands/Referrer/ListCommand.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
using Newtonsoft.Json;
using Valleysoft.DockerRegistryClient;
using Valleysoft.DockerRegistryClient.Models.Manifests;
using Valleysoft.DockerRegistryClient.Models.Manifests.Oci;

namespace Valleysoft.Dredge.Commands.Referrer;

public class ListCommand : RegistryCommandBase<ListOptions>
{
public ListCommand(IDockerRegistryClientFactory dockerRegistryClientFactory)
: base("list", "Lists the referrers to a manifest", dockerRegistryClientFactory)
{
}

protected override Task ExecuteAsync()
{
ImageName imageName = ImageName.Parse(Options.Image);
return CommandHelper.ExecuteCommandAsync(imageName.Registry, async () =>
{
using IDockerRegistryClient client = await DockerRegistryClientFactory.GetClientAsync(imageName.Registry);

OciImageIndex initialIndex;

string digest;
if (!string.IsNullOrEmpty(imageName.Digest))
{
digest = imageName.Digest;
}
else
{
ManifestInfo manifestInfo = await client.Manifests.GetAsync(imageName.Repo, imageName.Tag!);
digest = manifestInfo.DockerContentDigest;
}

Page<OciImageIndex> indexPage = await client.Referrers.GetAsync(imageName.Repo, digest, Options.ArtifactType);
initialIndex = indexPage.Value;
while (indexPage.NextPageLink is not null)
{
Page<OciImageIndex> nextPage = await client.Referrers.GetAsync(imageName.Repo, digest, Options.ArtifactType);
initialIndex.Manifests = initialIndex.Manifests
.Concat(nextPage.Value.Manifests)
.ToArray();
}

string output = JsonConvert.SerializeObject(initialIndex, JsonHelper.Settings);

Console.Out.WriteLine(output);
});
}
}
24 changes: 24 additions & 0 deletions src/Valleysoft.Dredge/Commands/Referrer/ListOptions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
using System.CommandLine;

namespace Valleysoft.Dredge.Commands.Referrer;

public class ListOptions : OptionsBase
{
private readonly Argument<string> imageArg;
private readonly Option<string> artifactTypeArg;

public string Image { get; set; } = string.Empty;
public string? ArtifactType { get; set; }

public ListOptions()
{
imageArg = Add(new Argument<string>("name", "Name of the manifest (<name>, <name>:<tag>, or <name>@<digest>)"));
artifactTypeArg = Add(new Option<string>("--artifact-type", "Artifact media type to filter by"));
}

protected override void GetValues()
{
Image = GetValue(imageArg);
ArtifactType = GetValue(artifactTypeArg);
}
}
12 changes: 12 additions & 0 deletions src/Valleysoft.Dredge/Commands/Referrer/ReferrerCommand.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
using System.CommandLine;

namespace Valleysoft.Dredge.Commands.Referrer;

public class ReferrerCommand : Command
{
public ReferrerCommand(IDockerRegistryClientFactory dockerRegistryClientFactory)
: base("referrer", "Commands related to referrers")
{
AddCommand(new ListCommand(dockerRegistryClientFactory));
}
}
2 changes: 2 additions & 0 deletions src/Valleysoft.Dredge/DockerRegistryClientWrapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,7 @@ public DockerRegistryClientWrapper(RegistryClient dockerRegistryClient)

public ITagOperations Tags => dockerRegistryClient.Tags;

public IReferrerOperations Referrers => dockerRegistryClient.Referrers;

public void Dispose() => dockerRegistryClient.Dispose();
}
1 change: 1 addition & 0 deletions src/Valleysoft.Dredge/IDockerRegistryClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,6 @@ public interface IDockerRegistryClient : IDisposable
IBlobOperations Blobs { get; }
ICatalogOperations Catalog { get; }
IManifestOperations Manifests { get; }
IReferrerOperations Referrers { get; }
ITagOperations Tags { get; }
}
2 changes: 2 additions & 0 deletions src/Valleysoft.Dredge/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using Valleysoft.Dredge;
using Valleysoft.Dredge.Commands.Image;
using Valleysoft.Dredge.Commands.Manifest;
using Valleysoft.Dredge.Commands.Referrer;
using Valleysoft.Dredge.Commands.Repo;
using Valleysoft.Dredge.Commands.Settings;
using Valleysoft.Dredge.Commands.Tag;
Expand All @@ -11,6 +12,7 @@
{
new ImageCommand(clientFactory),
new ManifestCommand(clientFactory),
new ReferrerCommand(clientFactory),
new RepoCommand(clientFactory),
new TagCommand(clientFactory),
new SettingsCommand(clientFactory),
Expand Down
2 changes: 1 addition & 1 deletion src/Valleysoft.Dredge/Valleysoft.Dredge.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFrameworks>net6.0;net7.0;net8.0</TargetFrameworks>
<TargetFrameworks>net8.0;net9.0</TargetFrameworks>
<Nullable>enable</Nullable>
<AssemblyName>dredge</AssemblyName>
<LangVersion>11.0</LangVersion>
Expand Down

0 comments on commit da07705

Please sign in to comment.