Skip to content

Commit

Permalink
Merge pull request #3 from Syriiin/optimise-docker-images
Browse files Browse the repository at this point in the history
Optimise docker images
  • Loading branch information
Syriiin authored Apr 25, 2024
2 parents d2714a2 + e17b42b commit bb8e57a
Show file tree
Hide file tree
Showing 7 changed files with 63 additions and 124 deletions.
29 changes: 0 additions & 29 deletions Difficalcy.Catch/Dockerfile

This file was deleted.

29 changes: 0 additions & 29 deletions Difficalcy.Mania/Dockerfile

This file was deleted.

29 changes: 0 additions & 29 deletions Difficalcy.Osu/Dockerfile

This file was deleted.

29 changes: 0 additions & 29 deletions Difficalcy.Taiko/Dockerfile

This file was deleted.

9 changes: 5 additions & 4 deletions Difficalcy/Services/WebBeatmapProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,18 @@ namespace Difficalcy.Services
{
public class WebBeatmapProvider : IBeatmapProvider
{
private IConfiguration _configuration;
private string _beatmapDirectory;
private readonly HttpClient _httpClient = new HttpClient();

public WebBeatmapProvider(IConfiguration configuration)
{
_configuration = configuration;
_beatmapDirectory = configuration["BEATMAP_DIRECTORY"];
Directory.CreateDirectory(_beatmapDirectory);
}

public async Task<bool> EnsureBeatmap(string beatmapId)
{
var beatmapPath = Path.Combine(_configuration["BEATMAP_DIRECTORY"], beatmapId);
var beatmapPath = Path.Combine(_beatmapDirectory, beatmapId);
if (!File.Exists(beatmapPath))
{
using var response = await _httpClient.GetAsync($"https://osu.ppy.sh/osu/{beatmapId}");
Expand All @@ -34,7 +35,7 @@ public async Task<bool> EnsureBeatmap(string beatmapId)

public Stream GetBeatmapStream(string beatmapId)
{
var beatmapPath = Path.Combine(_configuration["BEATMAP_DIRECTORY"], beatmapId);
var beatmapPath = Path.Combine(_beatmapDirectory, beatmapId);
return File.OpenRead(beatmapPath);
}
}
Expand Down
54 changes: 54 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
FROM mcr.microsoft.com/dotnet/aspnet:8.0-jammy-chiseled AS base

LABEL org.opencontainers.image.source https://github.com/Syriiin/difficalcy

WORKDIR /app
EXPOSE 80
ENV ASPNETCORE_URLS=http://+:80
ENV ASPNETCORE_ENVIRONMENT=Production
ENV BEATMAP_DIRECTORY=/app/beatmaps

FROM mcr.microsoft.com/dotnet/sdk:8.0-jammy AS build
WORKDIR /src

COPY ./Difficalcy/Difficalcy.csproj ./Difficalcy/
COPY ./Difficalcy.Catch/Difficalcy.Catch.csproj ./Difficalcy.Catch/
COPY ./Difficalcy.Mania/Difficalcy.Mania.csproj ./Difficalcy.Mania/
COPY ./Difficalcy.Osu/Difficalcy.Osu.csproj ./Difficalcy.Osu/
COPY ./Difficalcy.Taiko/Difficalcy.Taiko.csproj ./Difficalcy.Taiko/

RUN dotnet restore ./Difficalcy.Catch/Difficalcy.Catch.csproj
RUN dotnet restore ./Difficalcy.Mania/Difficalcy.Mania.csproj
RUN dotnet restore ./Difficalcy.Osu/Difficalcy.Osu.csproj
RUN dotnet restore ./Difficalcy.Taiko/Difficalcy.Taiko.csproj

COPY ./Difficalcy/ ./Difficalcy/
COPY ./Difficalcy.Catch/ ./Difficalcy.Catch/
COPY ./Difficalcy.Mania/ ./Difficalcy.Mania/
COPY ./Difficalcy.Osu/ ./Difficalcy.Osu/
COPY ./Difficalcy.Taiko/ ./Difficalcy.Taiko/

RUN dotnet publish ./Difficalcy.Catch/Difficalcy.Catch.csproj -o /app/difficalcy-catch --runtime linux-x64 --self-contained false
RUN dotnet publish ./Difficalcy.Mania/Difficalcy.Mania.csproj -o /app/difficalcy-mania --runtime linux-x64 --self-contained false
RUN dotnet publish ./Difficalcy.Osu/Difficalcy.Osu.csproj -o /app/difficalcy-osu --runtime linux-x64 --self-contained false
RUN dotnet publish ./Difficalcy.Taiko/Difficalcy.Taiko.csproj -o /app/difficalcy-taiko --runtime linux-x64 --self-contained false

FROM base AS difficalcy-catch
LABEL org.opencontainers.image.description "Lazer powered osu!catch difficulty calculator API"
COPY --from=build /app/difficalcy-catch .
ENTRYPOINT ["./Difficalcy.Catch"]

FROM base AS difficalcy-mania
LABEL org.opencontainers.image.description "Lazer powered osu!mania difficulty calculator API"
COPY --from=build /app/difficalcy-mania .
ENTRYPOINT ["./Difficalcy.Mania"]

FROM base AS difficalcy-osu
LABEL org.opencontainers.image.description "Lazer powered osu! difficulty calculator API"
COPY --from=build /app/difficalcy-osu .
ENTRYPOINT ["./Difficalcy.Osu"]

FROM base AS difficalcy-taiko
LABEL org.opencontainers.image.description "Lazer powered osu!taiko difficulty calculator API"
COPY --from=build /app/difficalcy-taiko .
ENTRYPOINT ["./Difficalcy.Taiko"]
8 changes: 4 additions & 4 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ services:
difficalcy-osu:
build:
context: .
dockerfile: ./Difficalcy.Osu/Dockerfile
target: difficalcy-osu
environment:
- REDIS_CONFIGURATION=cache:6379
volumes:
Expand All @@ -13,7 +13,7 @@ services:
difficalcy-taiko:
build:
context: .
dockerfile: ./Difficalcy.Taiko/Dockerfile
target: difficalcy-taiko
environment:
- REDIS_CONFIGURATION=cache:6379
volumes:
Expand All @@ -24,7 +24,7 @@ services:
difficalcy-catch:
build:
context: .
dockerfile: ./Difficalcy.Catch/Dockerfile
target: difficalcy-catch
environment:
- REDIS_CONFIGURATION=cache:6379
volumes:
Expand All @@ -35,7 +35,7 @@ services:
difficalcy-mania:
build:
context: .
dockerfile: ./Difficalcy.Mania/Dockerfile
target: difficalcy-mania
environment:
- REDIS_CONFIGURATION=cache:6379
volumes:
Expand Down

0 comments on commit bb8e57a

Please sign in to comment.