From d70bc1584bfbacebf0fa8b62f8409cb315d6174f Mon Sep 17 00:00:00 2001 From: ProgramRipper Date: Sat, 20 Dec 2025 00:17:11 +0800 Subject: [PATCH 1/2] [Milky] Dockerize --- .dockerignore | 12 +++ .github/workflows/milky-build.yaml | 2 +- .github/workflows/milky-docker.yaml | 130 +++++++++++++++++++++++++++ Lagrange.Milky/Lagrange.Milky.csproj | 3 +- Lagrange.Milky/Resources/Dockerfile | 20 +++++ 5 files changed, 165 insertions(+), 2 deletions(-) create mode 100644 .dockerignore create mode 100644 .github/workflows/milky-docker.yaml create mode 100644 Lagrange.Milky/Resources/Dockerfile diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 00000000..5e6c6f35 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,12 @@ +* + +!.git/ +!Lagrange.Codec/ +!Lagrange.Core/ +!Lagrange.Milky/ +!Lagrange.Milky.Implementation.Api.Generator/ +!Lagrange.Proto/ +!Lagrange.Proto.Generator/ + +*/bin/ +*/obj/ diff --git a/.github/workflows/milky-build.yaml b/.github/workflows/milky-build.yaml index 5610c0e1..2f1912b9 100644 --- a/.github/workflows/milky-build.yaml +++ b/.github/workflows/milky-build.yaml @@ -36,7 +36,7 @@ jobs: - os: ubuntu-latest rid: linux-x64 binary-extension: '' - + env: RUNTIME_IDENTIFIER: ${{ matrix.rid }} diff --git a/.github/workflows/milky-docker.yaml b/.github/workflows/milky-docker.yaml new file mode 100644 index 00000000..7040e729 --- /dev/null +++ b/.github/workflows/milky-docker.yaml @@ -0,0 +1,130 @@ +name: Build Lagrange.Milky image + +on: + push: + branches: [ main ] + paths: + - .github/workflows/milky-docker.yaml + - Lagrange.Codec/** + - Lagrange.Core/** + - Lagrange.Proto/** + - Lagrange.Proto.Generator/** + - Lagrange.Milky/** + pull_request: + branches: [ main ] + paths: + - .github/workflows/milky-docker.yaml + - Lagrange.Codec/** + - Lagrange.Core/** + - Lagrange.Proto/** + - Lagrange.Proto.Generator/** + - Lagrange.Milky/** + workflow_dispatch: + +jobs: + build: + strategy: + fail-fast: false + matrix: + include: + - platform: linux/amd64 + runner: ubuntu-24.04 + - platform: linux/arm64 + runner: ubuntu-24.04-arm + runs-on: ${{ matrix.runner }} + steps: + - uses: actions/checkout@v6 + + - name: Prepare + run: | + platform=${{ matrix.platform }} + echo "PLATFORM_PAIR=${platform//\//-}" >> $GITHUB_ENV + echo "REGISTRY_IMAGE=ghcr.io/${GITHUB_REPOSITORY_OWNER@L}/lagrange.milky" >> $GITHUB_ENV + + - name: Docker meta + id: meta + uses: docker/metadata-action@v5 + with: + images: ${{ env.REGISTRY_IMAGE }} + + - name: Login to Docker Hub + uses: docker/login-action@v3 + with: + registry: ghcr.io + username: ${{ github.repository_owner }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + + - name: Build and push by digest + id: build + uses: docker/build-push-action@v6 + with: + context: . + file: Lagrange.Milky/Resources/Dockerfile + platforms: ${{ matrix.platform }} + labels: ${{ steps.meta.outputs.labels }} + tags: ${{ env.REGISTRY_IMAGE }} + outputs: type=image,push-by-digest=true,name-canonical=true,push=true + + - name: Export digest + run: | + mkdir -p ${{ runner.temp }}/digests + digest="${{ steps.build.outputs.digest }}" + touch "${{ runner.temp }}/digests/${digest#sha256:}" + + - name: Upload digest + uses: actions/upload-artifact@v4 + with: + name: digests-${{ env.PLATFORM_PAIR }} + path: ${{ runner.temp }}/digests/* + if-no-files-found: error + retention-days: 1 + + merge: + runs-on: ubuntu-latest + needs: + - build + steps: + - name: Prepare + run: | + echo "REGISTRY_IMAGE=ghcr.io/${GITHUB_REPOSITORY_OWNER@L}/lagrange.milky" >> $GITHUB_ENV + + - name: Download digests + uses: actions/download-artifact@v4 + with: + path: ${{ runner.temp }}/digests + pattern: digests-* + merge-multiple: true + + - name: Login to Docker Hub + uses: docker/login-action@v3 + with: + registry: ghcr.io + username: ${{ github.repository_owner }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + + - name: Docker meta + id: meta + uses: docker/metadata-action@v5 + with: + images: ${{ env.REGISTRY_IMAGE }} + tags: | + type=ref,event=branch + type=ref,event=pr + type=semver,pattern={{version}} + type=semver,pattern={{major}}.{{minor}} + + - name: Create manifest list and push + working-directory: ${{ runner.temp }}/digests + run: | + docker buildx imagetools create $(jq -cr '.tags | map("-t " + .) | join(" ")' <<< "$DOCKER_METADATA_OUTPUT_JSON") \ + $(printf '${{ env.REGISTRY_IMAGE }}@sha256:%s ' *) + + - name: Inspect image + run: | + docker buildx imagetools inspect ${{ env.REGISTRY_IMAGE }}:${{ steps.meta.outputs.version }} diff --git a/Lagrange.Milky/Lagrange.Milky.csproj b/Lagrange.Milky/Lagrange.Milky.csproj index c9f5038a..fbcc58eb 100644 --- a/Lagrange.Milky/Lagrange.Milky.csproj +++ b/Lagrange.Milky/Lagrange.Milky.csproj @@ -5,6 +5,7 @@ enable enable true + true true @@ -33,4 +34,4 @@ - \ No newline at end of file + diff --git a/Lagrange.Milky/Resources/Dockerfile b/Lagrange.Milky/Resources/Dockerfile new file mode 100644 index 00000000..f1797b11 --- /dev/null +++ b/Lagrange.Milky/Resources/Dockerfile @@ -0,0 +1,20 @@ +FROM mcr.microsoft.com/dotnet/sdk:10.0-alpine-aot AS build + +WORKDIR /app/src + +COPY --link Lagrange.Codec/*.csproj Lagrange.Codec/ +COPY --link Lagrange.Core/*.csproj Lagrange.Core/ +COPY --link Lagrange.Milky/*.csproj Lagrange.Milky/ +COPY --link Lagrange.Milky.Implementation.Api.Generator/*.csproj Lagrange.Milky.Implementation.Api.Generator/ +COPY --link Lagrange.Proto/*.csproj Lagrange.Proto/ +COPY --link Lagrange.Proto.Generator/*.csproj Lagrange.Proto.Generator/ +RUN dotnet restore Lagrange.Milky + +COPY --link . . +RUN dotnet publish Lagrange.Milky -c Release -p:DebugType=none -p:StaticExecutable=true -o /app/bin + + +FROM scratch + +COPY --from=build /app/bin/ . +ENTRYPOINT ["./Lagrange.Milky"] From 6942952b0270d7aa69a8f90631461fff5ffcb75f Mon Sep 17 00:00:00 2001 From: ProgramRipper Date: Thu, 1 Jan 2026 11:02:53 +0800 Subject: [PATCH 2/2] ci: add Lagrange.Milky.Implementation.Api.Generator to workflow paths --- .github/workflows/milky-build.yaml | 6 ++++-- .github/workflows/milky-docker.yaml | 6 ++++-- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/.github/workflows/milky-build.yaml b/.github/workflows/milky-build.yaml index 2f1912b9..b375e46f 100644 --- a/.github/workflows/milky-build.yaml +++ b/.github/workflows/milky-build.yaml @@ -7,18 +7,20 @@ on: - .github/workflows/milky-build.yaml - Lagrange.Codec/** - Lagrange.Core/** + - Lagrange.Milky/** + - Lagrange.Milky.Implementation.Api.Generator/** - Lagrange.Proto/** - Lagrange.Proto.Generator/** - - Lagrange.Milky/** pull_request: branches: [ main ] paths: - .github/workflows/milky-build.yaml - Lagrange.Codec/** - Lagrange.Core/** + - Lagrange.Milky/** + - Lagrange.Milky.Implementation.Api.Generator/** - Lagrange.Proto/** - Lagrange.Proto.Generator/** - - Lagrange.Milky/** workflow_dispatch: jobs: diff --git a/.github/workflows/milky-docker.yaml b/.github/workflows/milky-docker.yaml index 7040e729..5a13cdc7 100644 --- a/.github/workflows/milky-docker.yaml +++ b/.github/workflows/milky-docker.yaml @@ -7,18 +7,20 @@ on: - .github/workflows/milky-docker.yaml - Lagrange.Codec/** - Lagrange.Core/** + - Lagrange.Milky/** + - Lagrange.Milky.Implementation.Api.Generator/** - Lagrange.Proto/** - Lagrange.Proto.Generator/** - - Lagrange.Milky/** pull_request: branches: [ main ] paths: - .github/workflows/milky-docker.yaml - Lagrange.Codec/** - Lagrange.Core/** + - Lagrange.Milky/** + - Lagrange.Milky.Implementation.Api.Generator/** - Lagrange.Proto/** - Lagrange.Proto.Generator/** - - Lagrange.Milky/** workflow_dispatch: jobs: