Skip to content

Commit 34b3fd4

Browse files
authored
Merge pull request #293 from sixwaaaay/metadata
feat: container metadata
2 parents 8b1515e + 025d054 commit 34b3fd4

File tree

7 files changed

+57
-47
lines changed

7 files changed

+57
-47
lines changed

.github/workflows/comment.yaml

Lines changed: 8 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -82,36 +82,15 @@ jobs:
8282
username: ${{ secrets.DOCKERHUB_USERNAME }}
8383
password: ${{ secrets.DOCKERHUB_TOKEN }}
8484

85-
- uses: docker/build-push-action@v5
85+
- uses: docker/metadata-action@v5
86+
id: meta
8687
with:
87-
context: ./graal
88-
file: ./graal/Dockerfile
89-
push: true
90-
tags: ${{ secrets.DOCKERHUB_USERNAME }}/sharing-comment:prerelease
88+
images: ${{ secrets.DOCKERHUB_USERNAME }}/sharing-comment
9189

92-
release:
93-
runs-on: ubuntu-latest
94-
defaults:
95-
run:
96-
working-directory: ./graal
97-
if: github.ref == 'refs/heads/main'
98-
steps:
99-
- name: Checkout
100-
uses: actions/checkout@v4
101-
- uses: graalvm/setup-graalvm@v1
102-
with:
103-
java-version: '21'
104-
distribution: 'graalvm' # See 'Options' for all available distributions
105-
github-token: ${{ secrets.GITHUB_TOKEN }}
106-
- name: Native Image Build
107-
run: mvn -Pnative spring-boot:build-image -DskipTests
10890

109-
- uses: docker/login-action@v3
91+
- uses: docker/build-push-action@v5
11092
with:
111-
username: ${{ secrets.DOCKERHUB_USERNAME }}
112-
password: ${{ secrets.DOCKERHUB_TOKEN }}
113-
114-
- name: Push to Docker Hub
115-
run: |
116-
docker tag sharing-comment:0.0.1-SNAPSHOT ${{ secrets.DOCKERHUB_USERNAME }}/sharing-comment:latest
117-
docker push ${{ secrets.DOCKERHUB_USERNAME }}/sharing-comment:latest
93+
context: ./graal
94+
file: ./graal/Dockerfile
95+
push: ${{ github.event != 'pull_request' }}
96+
tags: ${{ steps.meta.outputs.tags}}

.github/workflows/release.yaml

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -35,13 +35,22 @@ jobs:
3535
with:
3636
username: ${{ secrets.DOCKERHUB_USERNAME }}
3737
password: ${{ secrets.DOCKERHUB_TOKEN }}
38+
39+
- name: Docker meta
40+
id: meta
41+
uses: docker/metadata-action@v5
42+
with:
43+
images: ${{ secrets.DOCKERHUB_USERNAME || 'app' }}/${{ matrix.tag }}
44+
3845
- name: Build and push
3946
uses: docker/build-push-action@v5
4047
with:
4148
context: ${{ matrix.context }}
4249
file: ${{ matrix.file }}
4350
push: true
44-
tags: ${{ secrets.DOCKERHUB_USERNAME || 'app' }}/${{ matrix.tag }}:${{ github.ref_name }}
51+
tags: ${{ steps.meta.outputs.tags }}
52+
labels: ${{ steps.meta.outputs.labels}}
53+
4554
graal:
4655
runs-on: ubuntu-latest
4756
defaults:
@@ -56,14 +65,23 @@ jobs:
5665
distribution: 'graalvm' # See 'Options' for all available distributions
5766
github-token: ${{ secrets.GITHUB_TOKEN }}
5867
- name: Native Image Build
59-
run: mvn -Pnative spring-boot:build-image -DskipTests
68+
run: mvn clean && mvn -Pnative -Pproduction native:compile -DskipTests -P!openapi
69+
70+
- uses: docker/metadata-action@v5
71+
id: meta
72+
with:
73+
images: ${{ secrets.DOCKERHUB_USERNAME }}/sharing-comment
6074

6175
- uses: docker/login-action@v3
6276
with:
6377
username: ${{ secrets.DOCKERHUB_USERNAME }}
6478
password: ${{ secrets.DOCKERHUB_TOKEN }}
6579

66-
- name: Push to Docker Hub
67-
run: |
68-
docker tag sharing-comment:0.0.1-SNAPSHOT ${{ secrets.DOCKERHUB_USERNAME }}/sharing-comment:${{ github.ref_name }}
69-
docker push ${{ secrets.DOCKERHUB_USERNAME }}/sharing-comment:${{ github.ref_name }}
80+
- name: Build and push
81+
uses: docker/build-push-action@v5
82+
with:
83+
context: ./graal
84+
file: ./graal/Dockerfile
85+
push: true
86+
tags: ${{ steps.meta.outputs.tags}}
87+
labels: ${{ steps.meta.outputs.labels }}

sharp/content.Tests/UnitTest.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ public async Task Test1()
7272
var (_, videos4) = await videoRepository.DailyPopularVideos(0, 10);
7373
Assert.NotNull(videos4);
7474
Assert.NotEmpty(videos4);
75+
await videoRepository.IncrementViewCount(1);
7576
}
7677

7778
[Fact(DisplayName = "Command")]

sharp/content.Tests/domainservice/Test.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
using content.repository;
33
using Moq;
44
using Qdrant.Client;
5-
using Qdrant.Client.Grpc;
65

76
public class HistoryServiceTests
87
{
@@ -13,14 +12,15 @@ public async Task GetHistory_ReturnsVideos()
1312
var mockHistoryRepo = new Mock<HistoryRepository>(null!);
1413
var mockClient = new Mock<QdrantClient>("localhost",default!,default!,default!,default!,default!);
1514
var mockDomainService = new Mock<IDomainService>();
15+
var mockIVideoRepository = new Mock<IVideoRepository>();
1616
var userId = 1L;
1717
var historyList = new List<long> { 1L, 2L };
1818
var videoDtos = new List<VideoDto> { new VideoDto(), new VideoDto() };
1919

2020
mockHistoryRepo.Setup(x => x.GetHistorys(userId, It.IsAny<long>(), It.IsAny<int>())).ReturnsAsync(historyList);
2121
mockDomainService.Setup(x => x.FindAllByIds(historyList)).ReturnsAsync(videoDtos);
2222

23-
var service = new HistoryService(mockHistoryRepo.Object, mockClient.Object, mockDomainService.Object);
23+
var service = new HistoryService(mockHistoryRepo.Object, mockClient.Object, mockDomainService.Object, mockIVideoRepository.Object);
2424

2525
// Act
2626
var result = await service.GetHistory(userId);
@@ -36,13 +36,13 @@ public async Task AddHistory_ReturnsTrue()
3636
var mockHistoryRepo = new Mock<HistoryRepository>(null!);
3737
var mockClient = new Mock<QdrantClient>("localhost",default!,default!,default!,default!,default!);
3838
var mockDomainService = new Mock<IDomainService>();
39-
39+
var mockIVideoRepository = new Mock<IVideoRepository>();
4040
var userId = 1L;
4141
var videoId = 2L;
4242

4343
mockHistoryRepo.Setup(x => x.AddHistory(userId, videoId)).Returns(Task.FromResult(1L));
44-
45-
var service = new HistoryService(mockHistoryRepo.Object, mockClient.Object, mockDomainService.Object);
44+
mockIVideoRepository.Setup(x => x.IncrementViewCount(videoId)).Returns(Task.CompletedTask);
45+
var service = new HistoryService(mockHistoryRepo.Object, mockClient.Object, mockDomainService.Object, mockIVideoRepository.Object);
4646

4747
// Act
4848
var result = await service.AddHistory(userId, videoId);

sharp/content/domainservice/HistoryService.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ namespace content.domainservice;
77

88
public record AddVideoHistory([property: JsonNumberHandling(JsonNumberHandling.AllowReadingFromString)] long VideoId);
99

10-
public class HistoryService(HistoryRepository history, QdrantClient client, IDomainService domain)
10+
public class HistoryService(HistoryRepository history, QdrantClient client, IDomainService domain,IVideoRepository video)
1111
{
1212

1313
public async Task<Pagination<VideoDto>> GetHistory(long userId, long page = 0, int size = 10)
@@ -19,6 +19,7 @@ public async Task<Pagination<VideoDto>> GetHistory(long userId, long page = 0, i
1919
public async Task<bool> AddHistory(long userId, long videoId)
2020
{
2121
await history.AddHistory(userId, videoId);
22+
await video.IncrementViewCount(videoId);
2223
return true;
2324
}
2425

sharp/content/repository/Client.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ public class UserRepository(HttpClient client) : IUserRepository
5454
{
5555
public string? Token { get; set; }
5656

57-
/// <summary> Find user information by id. </summary>
57+
/// <inheritdoc />
5858
public async Task<User> FindById(long id)
5959
{
6060
var req = new HttpRequestMessage(HttpMethod.Get, $"/users/{id}");
@@ -65,7 +65,7 @@ public async Task<User> FindById(long id)
6565
}
6666

6767

68-
/// <summary> Find user information by id list. </summary>
68+
/// <inheritdoc />
6969
public async Task<IReadOnlyList<User>> FindAllByIds(IEnumerable<long> ids)
7070
{
7171
var req = new HttpRequestMessage(HttpMethod.Get,
@@ -102,7 +102,7 @@ public class VoteRepository(HttpClient client) : IVoteRepository
102102
{
103103
public string? Token { get; set; }
104104

105-
/// <summary> Get voted status of videos. </summary>
105+
/// <inheritdoc />
106106
public async Task<IReadOnlyList<long>> VotedOfVideos(List<long> videoIds)
107107
{
108108
if (string.IsNullOrEmpty(Token) || videoIds.Count == 0)
@@ -126,7 +126,7 @@ public async Task<IReadOnlyList<long>> VotedOfVideos(List<long> videoIds)
126126
}
127127

128128

129-
/// <summary> Scan voted videos, which means paging through all voted videos. </summary>
129+
/// <inheritdoc />
130130
public async Task<(long?, IReadOnlyList<long>)> VotedVideos(long page, int size)
131131
{
132132
var url = $"/graph/videos?page={page}&size={size}";
@@ -233,10 +233,10 @@ public static IServiceCollection AddUserRepository(this IServiceCollection servi
233233
public static IApplicationBuilder UseToken(this IApplicationBuilder app) =>
234234
app.Use(async (context, next) =>
235235
{
236-
var userRepository = context.RequestServices.GetService<IUserRepository>();
237-
ArgumentNullException.ThrowIfNull(userRepository, nameof(userRepository));
238236
var authorization = context.Request.Headers.Authorization;
239237

238+
var userRepository = context.RequestServices.GetService<IUserRepository>();
239+
ArgumentNullException.ThrowIfNull(userRepository, nameof(userRepository));
240240
userRepository.Token = authorization;
241241

242242
var voteRepository = context.RequestServices.GetService<IVoteRepository>();

sharp/content/repository/Content.cs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ public interface IVideoRepository
5252
Task<IReadOnlyList<Video>> FindRecent(long page, int size);
5353
Task<(long, IReadOnlyList<Video>)> DailyPopularVideos(long page, int size);
5454
Task<Video> Save(Video video);
55+
Task IncrementViewCount(long id);
5556
}
5657

5758
public class VideoRepository(NpgsqlDataSource dataSource) : IVideoRepository
@@ -150,6 +151,16 @@ public async Task<Video> Save(Video video)
150151
);
151152
return result;
152153
}
154+
155+
public async Task IncrementViewCount(long id)
156+
{
157+
await using var connection = await dataSource.OpenConnectionAsync();
158+
await connection.ExecuteAsync(
159+
"UPDATE videos SET view_count = view_count + 1 WHERE id = @id",
160+
new { id }
161+
);
162+
}
163+
153164
}
154165

155166
/// <summary> The extensions for the video repository. </summary>

0 commit comments

Comments
 (0)