Skip to content

Commit f4642df

Browse files
authored
Separate business logic into Core library and console app into App project with .NET 9 support and improved structure (#2)
1 parent b2c5b5f commit f4642df

25 files changed

+633
-588
lines changed

.devcontainer/devcontainer.json

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
{
2-
"name": "SafariBooks Downloader",
3-
"image": "mcr.microsoft.com/dotnet/sdk:9.0",
4-
"workspaceFolder": "/workspaces/safaribooks",
1+
{
2+
"name": "SafariBooks Downloader",
3+
"image": "mcr.microsoft.com/dotnet/sdk:9.0",
4+
"workspaceFolder": "/workspaces/safaribooks",
55
"customizations": {
66
"vscode": {
77
"extensions": [
@@ -12,12 +12,12 @@
1212
"github.vscode-github-actions",
1313
"EditorConfig.EditorConfig",
1414
"ionutvmi.path-autocomplete"
15-
],
15+
],
1616
"settings": {
17-
"dotnet.defaultSolution": "src/SafariBooksDownloader.sln"
18-
}
19-
}
20-
},
21-
"forwardPorts": [],
22-
"postCreateCommand": "dotnet restore src/SafariBooksDownloader.sln"
17+
"dotnet.defaultSolution": "src/SafariBooksDownloader.slnx"
18+
}
19+
}
20+
},
21+
"forwardPorts": [],
22+
"postCreateCommand": "dotnet restore src/SafariBooksDownloader.slnx"
2323
}

.dockerignore

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
**/.classpath
2+
**/.dockerignore
3+
**/.env
4+
**/.git
5+
**/.gitignore
6+
**/.project
7+
**/.settings
8+
**/.toolstarget
9+
**/.vs
10+
**/.vscode
11+
**/*.*proj.user
12+
**/*.dbmdl
13+
**/*.jfm
14+
**/azds.yaml
15+
**/bin
16+
**/charts
17+
**/docker-compose*
18+
**/Dockerfile*
19+
**/node_modules
20+
**/npm-debug.log
21+
**/obj
22+
**/secrets.dev.yaml
23+
**/values.dev.yaml
24+
LICENSE
25+
README.md

.github/workflows/docker-publish.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ jobs:
5757
uses: docker/build-push-action@v5
5858
with:
5959
context: .
60-
platforms: linux/amd64,linux/arm64
60+
platforms: linux/amd64
6161
push: true
6262
tags: ${{ steps.meta.outputs.tags }}
6363
labels: ${{ steps.meta.outputs.labels }}

.github/workflows/docker-tests.yml

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
name: (PR) SafariBooks Validation
2+
3+
on:
4+
pull_request:
5+
branches: [ main ]
6+
7+
jobs:
8+
test:
9+
name: Test
10+
runs-on: ubuntu-latest
11+
12+
steps:
13+
- name: Checkout code
14+
uses: actions/checkout@v4
15+
16+
- name: Set up Docker Buildx
17+
uses: docker/setup-buildx-action@v3
18+
19+
- name: Build Docker image
20+
id: build
21+
uses: docker/build-push-action@v5
22+
with:
23+
context: .
24+
platforms: linux/amd64
25+
file: Dockerfile.test
26+
push: false
27+
cache-from: type=gha
28+
cache-to: type=gha,mode=max
29+
tags: safari-test:latest
30+
load: true
31+
32+
- name: Run tests in container
33+
run: |
34+
docker run --name safari-test-run safari-test || true
35+
docker cp safari-test-run:/src/SafariBooksDownloader.UnitTests/TestResults ./TestResults
36+
docker rm safari-test-run
37+
38+
- name: Find coverage file
39+
id: find_coverage
40+
run: |
41+
echo "file=$(find ./TestResults -name 'coverage.cobertura.xml' | head -n 1)" >> $GITHUB_OUTPUT
42+
43+
- name: Upload coverage reports
44+
uses: codecov/codecov-action@v3
45+
if: always()
46+
with:
47+
file: ${{ steps.find_coverage.outputs.file }}
48+
flags: unittests
49+
name: codecov-umbrella
50+
fail_ci_if_error: false
51+
token: ${{ secrets.CODECOV_TOKEN }}

.github/workflows/pr_validation.yml

Lines changed: 0 additions & 38 deletions
This file was deleted.

Dockerfile

Lines changed: 38 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,38 @@
1-
# Use the official .NET 9.0 runtime as the base image
2-
FROM mcr.microsoft.com/dotnet/runtime:9.0 AS base
3-
WORKDIR /app
4-
5-
# Use the official .NET 9.0 SDK for building
6-
FROM mcr.microsoft.com/dotnet/sdk:9.0 AS build
7-
ARG BUILD_CONFIGURATION=Release
8-
WORKDIR /src
9-
COPY ["src/SafariBooksDownloader/SafariBooksDownloader.csproj", "src/SafariBooksDownloader/"]
10-
RUN dotnet restore "src/SafariBooksDownloader/SafariBooksDownloader.csproj"
11-
COPY . .
12-
WORKDIR "/src/src/SafariBooksDownloader"
13-
RUN dotnet build "SafariBooksDownloader.csproj" -c $BUILD_CONFIGURATION -o /app/build
14-
15-
FROM build AS publish
16-
ARG BUILD_CONFIGURATION=Release
17-
RUN dotnet publish "SafariBooksDownloader.csproj" -c $BUILD_CONFIGURATION -o /app/publish /p:UseAppHost=false
18-
19-
FROM base AS final
20-
WORKDIR /app
21-
COPY --from=publish /app/publish .
22-
23-
# Create volumes for Books output and cookies
24-
VOLUME ["/app/Books", "/app/cookies.json"]
25-
26-
ENTRYPOINT ["dotnet", "SafariBooksDownloader.dll"]
1+
FROM mcr.microsoft.com/dotnet/sdk:9.0 AS build
2+
ARG BUILD_CONFIGURATION=Release
3+
4+
WORKDIR /src
5+
6+
COPY --link ./src/Directory.Build.props .
7+
8+
COPY src/SafariBooksDownloader.Core/SafariBooksDownloader.Core.csproj SafariBooksDownloader.Core/SafariBooksDownloader.Core.csproj
9+
COPY src/SafariBooksDownloader.App/SafariBooksDownloader.App.csproj SafariBooksDownloader.App/SafariBooksDownloader.App.csproj
10+
11+
RUN dotnet restore "SafariBooksDownloader.App/SafariBooksDownloader.App.csproj"
12+
13+
COPY src/SafariBooksDownloader.Core/ SafariBooksDownloader.Core/
14+
COPY src/SafariBooksDownloader.App/ SafariBooksDownloader.App/
15+
16+
RUN dotnet build "SafariBooksDownloader.App/SafariBooksDownloader.App.csproj" \
17+
--no-restore \
18+
--configuration $BUILD_CONFIGURATION
19+
20+
FROM build AS publish
21+
ARG BUILD_CONFIGURATION=Release
22+
23+
WORKDIR /src/SafariBooksDownloader.App
24+
25+
RUN dotnet publish "SafariBooksDownloader.App.csproj" \
26+
--configuration $BUILD_CONFIGURATION \
27+
--no-restore \
28+
--output /app/publish \
29+
/p:UseAppHost=false
30+
31+
FROM mcr.microsoft.com/dotnet/runtime:9.0 AS base
32+
WORKDIR /app
33+
34+
COPY --from=publish /app/publish .
35+
36+
VOLUME ["/Books", "/cookies.json"]
37+
38+
ENTRYPOINT ["dotnet", "SafariBooksDownloader.App.dll"]

Dockerfile.test

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
FROM mcr.microsoft.com/dotnet/sdk:9.0 AS test
2+
3+
WORKDIR /src
4+
5+
COPY --link ./src/Directory.Build.props .
6+
7+
COPY src/ ./
8+
9+
RUN dotnet restore SafariBooksDownloader.slnx
10+
11+
RUN dotnet build "SafariBooksDownloader.slnx" \
12+
--configuration Release \
13+
--no-restore
14+
15+
CMD ["dotnet", "test", "SafariBooksDownloader.slnx", "--configuration", "Release", "--no-build", "--verbosity", "normal", "--collect", "XPlat Code Coverage"]

0 commit comments

Comments
 (0)