Add Docker support with Dockerfile and .dockerignore
This commit is contained in:
parent
a6ee5113c1
commit
bb2e6c31ed
16
.dockerignore
Normal file
16
.dockerignore
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
**/.DS_Store
|
||||||
|
**/.git
|
||||||
|
**/.gitignore
|
||||||
|
**/.vs
|
||||||
|
**/.vscode
|
||||||
|
**/bin
|
||||||
|
**/obj
|
||||||
|
**/TestResults
|
||||||
|
**/*.user
|
||||||
|
**/*.suo
|
||||||
|
**/*.cache
|
||||||
|
|
||||||
|
Dockerfile
|
||||||
|
docker-compose*.yml
|
||||||
|
README.md
|
||||||
|
docs
|
||||||
35
README.md
35
README.md
@ -153,6 +153,40 @@ MinIO 設定(`src/FileAccessAgent.Api/appsettings.json`):
|
|||||||
- `Minio:UseSsl`:`true|false`
|
- `Minio:UseSsl`:`true|false`
|
||||||
- `Minio:Region`:可空
|
- `Minio:Region`:可空
|
||||||
|
|
||||||
|
## Docker
|
||||||
|
|
||||||
|
API Dockerfile 位於 `src/FileAccessAgent.Api/Dockerfile`,建置時請使用 repo root 作為 build context,讓 Docker 可以存取 Api、Application、Domain、Infrastructure project references。
|
||||||
|
|
||||||
|
建置 image:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
docker build -f src/FileAccessAgent.Api/Dockerfile -t file-access-agent-api .
|
||||||
|
```
|
||||||
|
|
||||||
|
啟動 API(container 內 listen `8080`):
|
||||||
|
|
||||||
|
```bash
|
||||||
|
docker run --rm -p 8080:8080 \
|
||||||
|
-e Instance__TenantId=d8107508-e6b9-4630-b982-c7bbb0cb228f \
|
||||||
|
-e Auth__Issuer=http://host.docker.internal:7850/ \
|
||||||
|
-e Auth__Audience=file_access_api \
|
||||||
|
-e Auth__RequireHttpsMetadata=false \
|
||||||
|
-e MemberCenter__BaseUrl=http://host.docker.internal:7850/ \
|
||||||
|
file-access-agent-api
|
||||||
|
```
|
||||||
|
|
||||||
|
若使用 local storage,建議掛載 volume,避免 container 移除後檔案遺失:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
docker run --rm -p 8080:8080 \
|
||||||
|
-e Storage__Provider=local \
|
||||||
|
-e Instance__StorageRoot=/app/data/storage \
|
||||||
|
-v "$(pwd)/data/storage:/app/data/storage" \
|
||||||
|
file-access-agent-api
|
||||||
|
```
|
||||||
|
|
||||||
|
若使用 MinIO 且 MinIO 也在 Docker network 中,`Minio__Endpoint` 應使用 service/container DNS 名稱,例如 `minio:9000`;不要使用 container 內的 `localhost:9000`。
|
||||||
|
|
||||||
## 實作語言
|
## 實作語言
|
||||||
|
|
||||||
本專案已決定使用 C# / ASP.NET Core。
|
本專案已決定使用 C# / ASP.NET Core。
|
||||||
@ -226,4 +260,5 @@ MinIO 設定(`src/FileAccessAgent.Api/appsettings.json`):
|
|||||||
- 專案目標已依 `../member_center` 文件整理。
|
- 專案目標已依 `../member_center` 文件整理。
|
||||||
- 已確認使用 C# / ASP.NET Core。
|
- 已確認使用 C# / ASP.NET Core。
|
||||||
- `tenant_id` 與 delegated download token 分工已依最新版 `member_center` 文件校正。
|
- `tenant_id` 與 delegated download token 分工已依最新版 `member_center` 文件校正。
|
||||||
|
- API 已提供 Dockerfile,可用 .NET 8 多階段建置產生 container image。
|
||||||
- 目前目錄中的 .NET skeleton 可作為正式起點,但仍需依最新流程補上 Member Center validation 串接。
|
- 目前目錄中的 .NET skeleton 可作為正式起點,但仍需依最新流程補上 Member Center validation 串接。
|
||||||
|
|||||||
32
src/FileAccessAgent.Api/Dockerfile
Normal file
32
src/FileAccessAgent.Api/Dockerfile
Normal file
@ -0,0 +1,32 @@
|
|||||||
|
# syntax=docker/dockerfile:1
|
||||||
|
|
||||||
|
FROM mcr.microsoft.com/dotnet/sdk:8.0 AS build
|
||||||
|
ARG BUILD_CONFIGURATION=Release
|
||||||
|
WORKDIR /src
|
||||||
|
|
||||||
|
COPY ["FileAccessAgent.sln", "./"]
|
||||||
|
COPY ["src/FileAccessAgent.Api/FileAccessAgent.Api.csproj", "src/FileAccessAgent.Api/"]
|
||||||
|
COPY ["src/FileAccessAgent.Application/FileAccessAgent.Application.csproj", "src/FileAccessAgent.Application/"]
|
||||||
|
COPY ["src/FileAccessAgent.Domain/FileAccessAgent.Domain.csproj", "src/FileAccessAgent.Domain/"]
|
||||||
|
COPY ["src/FileAccessAgent.Infrastructure/FileAccessAgent.Infrastructure.csproj", "src/FileAccessAgent.Infrastructure/"]
|
||||||
|
RUN dotnet restore "src/FileAccessAgent.Api/FileAccessAgent.Api.csproj"
|
||||||
|
|
||||||
|
COPY . .
|
||||||
|
WORKDIR /src/src/FileAccessAgent.Api
|
||||||
|
RUN dotnet publish "FileAccessAgent.Api.csproj" \
|
||||||
|
-c "$BUILD_CONFIGURATION" \
|
||||||
|
-o /app/publish \
|
||||||
|
--no-restore \
|
||||||
|
/p:UseAppHost=false
|
||||||
|
|
||||||
|
FROM mcr.microsoft.com/dotnet/aspnet:8.0 AS final
|
||||||
|
WORKDIR /app
|
||||||
|
ENV ASPNETCORE_URLS=http://+:8080 \
|
||||||
|
DOTNET_RUNNING_IN_CONTAINER=true
|
||||||
|
EXPOSE 8080
|
||||||
|
|
||||||
|
RUN mkdir -p /app/data/storage && chown -R "$APP_UID:$APP_UID" /app/data
|
||||||
|
USER $APP_UID
|
||||||
|
|
||||||
|
COPY --from=build /app/publish .
|
||||||
|
ENTRYPOINT ["dotnet", "FileAccessAgent.Api.dll"]
|
||||||
Loading…
x
Reference in New Issue
Block a user