Skip to content
This repository was archived by the owner on May 27, 2026. It is now read-only.

Commit 3ee7d3c

Browse files
committed
build: dockerize
1 parent e2ca787 commit 3ee7d3c

5 files changed

Lines changed: 146 additions & 1 deletion

File tree

.github/workflows/milky-build.yaml

Lines changed: 45 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ jobs:
3434
- os: ubuntu-latest
3535
rid: linux-x64
3636
binary-extension: ''
37-
37+
3838
env:
3939
RUNTIME_IDENTIFIER: ${{ matrix.rid }}
4040

@@ -60,3 +60,47 @@ jobs:
6060
with:
6161
name: Lagrange.Milky-${{ matrix.rid }}
6262
path: Lagrange.Milky/bin/Release/net9.0/${{ matrix.rid }}/publish/Lagrange.Milky${{ matrix.binary-extension }}
63+
64+
docker:
65+
needs: build
66+
runs-on: ubuntu-latest
67+
if: github.event_name != 'pull_request'
68+
69+
steps:
70+
- uses: actions/checkout@v4
71+
72+
- name: Download build artifact
73+
uses: actions/download-artifact@v4
74+
with:
75+
name: Lagrange.Milky-linux-x64
76+
path: Lagrange.Milky/bin/Release/net9.0/linux-x64/publish
77+
78+
- name: Set up Docker Buildx
79+
uses: docker/setup-buildx-action@v3
80+
81+
- name: Login to Github Registry
82+
uses: docker/login-action@v3
83+
with:
84+
registry: ghcr.io
85+
username: ${{ github.repository_owner }}
86+
password: ${{ secrets.GITHUB_TOKEN }}
87+
88+
- name: Extract metadata (tags, labels) for Docker
89+
id: meta
90+
uses: docker/metadata-action@v5
91+
with:
92+
images: |
93+
ghcr.io/${{ github.repository_owner }}/lagrange.milky
94+
tags: |
95+
type=edge
96+
type=sha,event=branch
97+
type=ref,event=tag
98+
99+
- name: Build and push
100+
uses: docker/build-push-action@v5
101+
with:
102+
context: .
103+
file: Lagrange.Milky/Resources/Dockerfile
104+
push: true
105+
tags: ${{ steps.meta.outputs.tags }}
106+
labels: ${{ steps.meta.outputs.labels }}
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
name: Build Lagrange.Milky Docker
2+
3+
on:
4+
push:
5+
branches: [ main ]
6+
paths:
7+
- Lagrange.Codec/**
8+
- Lagrange.Core/**
9+
- Lagrange.Proto/**
10+
- Lagrange.Proto.Generator/**
11+
- Lagrange.Milky/**
12+
pull_request:
13+
branches: [ main ]
14+
paths:
15+
- Lagrange.Codec/**
16+
- Lagrange.Core/**
17+
- Lagrange.Proto/**
18+
- Lagrange.Proto.Generator/**
19+
- Lagrange.Milky/**
20+
workflow_dispatch:
21+
22+
jobs:
23+
build:
24+
runs-on: ubuntu-latest
25+
26+
steps:
27+
- uses: actions/checkout@v4
28+
29+
- name: Set up QEMU
30+
uses: docker/setup-qemu-action@v3
31+
32+
- name: Set up Docker Buildx
33+
uses: docker/setup-buildx-action@v3
34+
35+
- name: Login to Github Registry
36+
uses: docker/login-action@v3
37+
if: github.event_name != 'pull_request'
38+
with:
39+
registry: ghcr.io
40+
username: ${{ github.repository_owner }}
41+
password: ${{ secrets.GITHUB_TOKEN }}
42+
43+
- name: Extract metadata (tags, labels) for Docker
44+
id: meta
45+
uses: docker/metadata-action@v5
46+
with:
47+
images: |
48+
ghcr.io/${{ github.repository_owner }}/lagrange.milky
49+
tags: |
50+
type=edge
51+
type=sha,event=branch
52+
type=ref,event=tag
53+
54+
- name: Build and push
55+
uses: docker/build-push-action@v5
56+
with:
57+
context: .
58+
file: Lagrange.Milky/Resources/Dockerfile
59+
push: ${{ github.event_name != 'pull_request' }}
60+
tags: ${{ steps.meta.outputs.tags }}
61+
labels: ${{ steps.meta.outputs.labels }}
62+
platforms: linux/amd64

Lagrange.Milky/Lagrange.Milky.csproj

Lines changed: 1 addition & 0 deletions
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>
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
FROM --platform=$BUILDPLATFORM mcr.microsoft.com/dotnet/sdk:9.0-alpine AS build
2+
3+
WORKDIR /root/build
4+
ARG TARGETARCH
5+
6+
RUN apk add --upgrade --no-cache \
7+
build-base \
8+
clang \
9+
zlib-dev
10+
COPY --link . /root/build
11+
12+
RUN dotnet publish Lagrange.Milky -p:DebugType="none" -c Release -a $TARGETARCH -o /root/out
13+
14+
# ===
15+
16+
FROM alpine
17+
18+
WORKDIR /app/data
19+
20+
COPY --link --from=tianon/gosu /gosu /usr/local/bin/
21+
COPY --link Lagrange.Milky/Resources/docker-entrypoint.sh /app/bin/docker-entrypoint.sh
22+
23+
COPY --link --from=build /root/out /app/bin
24+
25+
ENTRYPOINT ["/app/bin/docker-entrypoint.sh"]
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#!/bin/sh
2+
3+
USER_ID=${UID:-0}
4+
5+
if [ "$USER_ID" -ne 0 ]; then
6+
chown -R $USER_ID /app/data
7+
useradd --shell /bin/sh -u $USER_ID -o -c "" -m user
8+
usermod -a -G root user
9+
export HOME=/home/user
10+
exec /usr/sbin/gosu user /app/bin/Lagrange.Milky "$@"
11+
else
12+
exec /app/bin/Lagrange.Milky "$@"
13+
fi

0 commit comments

Comments
 (0)