Skip to content

Commit 4225a5f

Browse files
[Milky] Dockerize (#90)
1 parent 604a1ed commit 4225a5f

5 files changed

Lines changed: 171 additions & 4 deletions

File tree

.dockerignore

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
*
2+
3+
!.git/
4+
!Lagrange.Codec/
5+
!Lagrange.Core/
6+
!Lagrange.Milky/
7+
!Lagrange.Milky.Implementation.Api.Generator/
8+
!Lagrange.Proto/
9+
!Lagrange.Proto.Generator/
10+
11+
*/bin/
12+
*/obj/

.github/workflows/milky-build.yaml

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,18 +7,20 @@ on:
77
- .github/workflows/milky-build.yaml
88
- Lagrange.Codec/**
99
- Lagrange.Core/**
10+
- Lagrange.Milky/**
11+
- Lagrange.Milky.Implementation.Api.Generator/**
1012
- Lagrange.Proto/**
1113
- Lagrange.Proto.Generator/**
12-
- Lagrange.Milky/**
1314
pull_request:
1415
branches: [ main ]
1516
paths:
1617
- .github/workflows/milky-build.yaml
1718
- Lagrange.Codec/**
1819
- Lagrange.Core/**
20+
- Lagrange.Milky/**
21+
- Lagrange.Milky.Implementation.Api.Generator/**
1922
- Lagrange.Proto/**
2023
- Lagrange.Proto.Generator/**
21-
- Lagrange.Milky/**
2224
workflow_dispatch:
2325

2426
jobs:
@@ -36,7 +38,7 @@ jobs:
3638
- os: ubuntu-latest
3739
rid: linux-x64
3840
binary-extension: ''
39-
41+
4042
env:
4143
RUNTIME_IDENTIFIER: ${{ matrix.rid }}
4244

Lines changed: 132 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,132 @@
1+
name: Build Lagrange.Milky image
2+
3+
on:
4+
push:
5+
branches: [ main ]
6+
paths:
7+
- .github/workflows/milky-docker.yaml
8+
- Lagrange.Codec/**
9+
- Lagrange.Core/**
10+
- Lagrange.Milky/**
11+
- Lagrange.Milky.Implementation.Api.Generator/**
12+
- Lagrange.Proto/**
13+
- Lagrange.Proto.Generator/**
14+
pull_request:
15+
branches: [ main ]
16+
paths:
17+
- .github/workflows/milky-docker.yaml
18+
- Lagrange.Codec/**
19+
- Lagrange.Core/**
20+
- Lagrange.Milky/**
21+
- Lagrange.Milky.Implementation.Api.Generator/**
22+
- Lagrange.Proto/**
23+
- Lagrange.Proto.Generator/**
24+
workflow_dispatch:
25+
26+
jobs:
27+
build:
28+
strategy:
29+
fail-fast: false
30+
matrix:
31+
include:
32+
- platform: linux/amd64
33+
runner: ubuntu-24.04
34+
- platform: linux/arm64
35+
runner: ubuntu-24.04-arm
36+
runs-on: ${{ matrix.runner }}
37+
steps:
38+
- uses: actions/checkout@v6
39+
40+
- name: Prepare
41+
run: |
42+
platform=${{ matrix.platform }}
43+
echo "PLATFORM_PAIR=${platform//\//-}" >> $GITHUB_ENV
44+
echo "REGISTRY_IMAGE=ghcr.io/${GITHUB_REPOSITORY_OWNER@L}/lagrange.milky" >> $GITHUB_ENV
45+
46+
- name: Docker meta
47+
id: meta
48+
uses: docker/metadata-action@v5
49+
with:
50+
images: ${{ env.REGISTRY_IMAGE }}
51+
52+
- name: Login to Docker Hub
53+
uses: docker/login-action@v3
54+
with:
55+
registry: ghcr.io
56+
username: ${{ github.repository_owner }}
57+
password: ${{ secrets.GITHUB_TOKEN }}
58+
59+
- name: Set up Docker Buildx
60+
uses: docker/setup-buildx-action@v3
61+
62+
- name: Build and push by digest
63+
id: build
64+
uses: docker/build-push-action@v6
65+
with:
66+
context: .
67+
file: Lagrange.Milky/Resources/Dockerfile
68+
platforms: ${{ matrix.platform }}
69+
labels: ${{ steps.meta.outputs.labels }}
70+
tags: ${{ env.REGISTRY_IMAGE }}
71+
outputs: type=image,push-by-digest=true,name-canonical=true,push=true
72+
73+
- name: Export digest
74+
run: |
75+
mkdir -p ${{ runner.temp }}/digests
76+
digest="${{ steps.build.outputs.digest }}"
77+
touch "${{ runner.temp }}/digests/${digest#sha256:}"
78+
79+
- name: Upload digest
80+
uses: actions/upload-artifact@v4
81+
with:
82+
name: digests-${{ env.PLATFORM_PAIR }}
83+
path: ${{ runner.temp }}/digests/*
84+
if-no-files-found: error
85+
retention-days: 1
86+
87+
merge:
88+
runs-on: ubuntu-latest
89+
needs:
90+
- build
91+
steps:
92+
- name: Prepare
93+
run: |
94+
echo "REGISTRY_IMAGE=ghcr.io/${GITHUB_REPOSITORY_OWNER@L}/lagrange.milky" >> $GITHUB_ENV
95+
96+
- name: Download digests
97+
uses: actions/download-artifact@v4
98+
with:
99+
path: ${{ runner.temp }}/digests
100+
pattern: digests-*
101+
merge-multiple: true
102+
103+
- name: Login to Docker Hub
104+
uses: docker/login-action@v3
105+
with:
106+
registry: ghcr.io
107+
username: ${{ github.repository_owner }}
108+
password: ${{ secrets.GITHUB_TOKEN }}
109+
110+
- name: Set up Docker Buildx
111+
uses: docker/setup-buildx-action@v3
112+
113+
- name: Docker meta
114+
id: meta
115+
uses: docker/metadata-action@v5
116+
with:
117+
images: ${{ env.REGISTRY_IMAGE }}
118+
tags: |
119+
type=ref,event=branch
120+
type=ref,event=pr
121+
type=semver,pattern={{version}}
122+
type=semver,pattern={{major}}.{{minor}}
123+
124+
- name: Create manifest list and push
125+
working-directory: ${{ runner.temp }}/digests
126+
run: |
127+
docker buildx imagetools create $(jq -cr '.tags | map("-t " + .) | join(" ")' <<< "$DOCKER_METADATA_OUTPUT_JSON") \
128+
$(printf '${{ env.REGISTRY_IMAGE }}@sha256:%s ' *)
129+
130+
- name: Inspect image
131+
run: |
132+
docker buildx imagetools inspect ${{ env.REGISTRY_IMAGE }}:${{ steps.meta.outputs.version }}

Lagrange.Milky/Lagrange.Milky.csproj

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
<ImplicitUsings>enable</ImplicitUsings>
66
<Nullable>enable</Nullable>
77
<PublishAot>true</PublishAot>
8+
<InvariantGlobalization>true</InvariantGlobalization>
89
</PropertyGroup>
910
<PropertyGroup Condition=" '$(Configuration)' == 'Debug'">
1011
<EmitCompilerGeneratedFiles>true</EmitCompilerGeneratedFiles>
@@ -33,4 +34,4 @@
3334
<ItemGroup>
3435
<EmbeddedResource Include="Resources\appsettings.jsonc" />
3536
</ItemGroup>
36-
</Project>
37+
</Project>
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
FROM mcr.microsoft.com/dotnet/sdk:10.0-alpine-aot AS build
2+
3+
WORKDIR /app/src
4+
5+
COPY --link Lagrange.Codec/*.csproj Lagrange.Codec/
6+
COPY --link Lagrange.Core/*.csproj Lagrange.Core/
7+
COPY --link Lagrange.Milky/*.csproj Lagrange.Milky/
8+
COPY --link Lagrange.Milky.Implementation.Api.Generator/*.csproj Lagrange.Milky.Implementation.Api.Generator/
9+
COPY --link Lagrange.Proto/*.csproj Lagrange.Proto/
10+
COPY --link Lagrange.Proto.Generator/*.csproj Lagrange.Proto.Generator/
11+
RUN dotnet restore Lagrange.Milky
12+
13+
COPY --link . .
14+
RUN dotnet publish Lagrange.Milky -c Release -p:DebugType=none -p:StaticExecutable=true -o /app/bin
15+
16+
17+
FROM scratch
18+
19+
COPY --from=build /app/bin/ .
20+
ENTRYPOINT ["./Lagrange.Milky"]

0 commit comments

Comments
 (0)