redo docker

This commit is contained in:
linmeideli committed 2026-11-07 11:34:22 +08:00
1 parent 71bb200596
commit cb11feb327
5 files changed
+64 -67

No files matched your search

-40
View File
@@ -1,40 +0,0 @@
FROM --platform=$BUILDPLATFORM mcr.microsoft.com/dotnet/sdk:10.0 AS build
ARG TARGETARCH
ARG VERSION_SUFFIX=docker
WORKDIR /source
COPY src/ ./src/
RUN case "$TARGETARCH" in \
amd64) RID=linux-x64 ;; \
arm64) RID=linux-arm64 ;; \
arm) RID=linux-arm ;; \
*) echo "Unsupported target architecture: $TARGETARCH" >&2; exit 1 ;; \
esac && \
dotnet restore -r "$RID" ./src/Empostor.Server/Empostor.Server.csproj && \
dotnet publish ./src/Empostor.Server/Empostor.Server.csproj \
--configuration Release \
--runtime "$RID" \
--no-restore \
--self-contained false \
-p:PublishSingleFile=true \
-p:PublishTrimmed=false \
-p:VersionSuffix="$VERSION_SUFFIX" \
--output /app
FROM mcr.microsoft.com/dotnet/aspnet:10.0
WORKDIR /app
COPY --from=build /app/ ./
COPY marketplace/ ./marketplace/
RUN mkdir -p Data Log Pages Languages languages plugins libraries Update \
&& chown -R app:app Data Log Pages Languages languages plugins libraries Update \
&& chmod 0750 Data Log Pages Languages languages plugins libraries Update
ENV DOTNET_RUNNING_IN_CONTAINER=1
ENV DOTNET_SYSTEM_GLOBALIZATION_INVARIANT=1
USER app
ENTRYPOINT ["./Empostor.Server"]
+5 -2
View File
@@ -30,13 +30,16 @@ It is also recommended to [set up a Reverse Proxy](https://empostor.github.io/ge
### Docker
Docker Compose port mappings are generated from `config.json` before the container starts. Install Docker Engine with Compose v2 and Python 3.9 or newer. Copy `src/Empostor.Server/config.json` to `config.json` in the repository root and set `Server.PublicIp` to your public IP or domain, then run:
Docker Compose port mappings are generated from `config.json` on the host before the container starts. Install the .NET 10 SDK, Docker Engine with Compose v2, and Python 3.9 or newer. Generate the Linux x64 release, then set `Server.PublicIp` in its `config.json` to your public IP or domain:
```sh
dotnet tool restore
dotnet cake build.cake --target=Build
cd build/Empostor-Server_linux-x64
python3 docker-up.py
```
On Windows, use `python docker-up.py`. If `config.json` is missing, the script creates it from the repository defaults. The script builds the image and starts the service. Set `EMPOSTOR_CONFIG` to use a different configuration file; the launcher reads and mounts that same file read-only.
On Windows, use `Set-Location build/Empostor-Server_linux-x64` and `python docker-up.py`. The Linux x64 generated release folder contains the published server files, `config.json`, and the three Docker files. Cake adds these files to the release folder; it does not create a separate image context or deployment archive. The host-side launcher reads config, fills the port sections in `Dockerfile` and `compose.yml`, then invokes Compose using the same folder as the image build context. Rerun the Cake build after updating the server or marketplace. Set `EMPOSTOR_CONFIG` to use a different configuration file; the launcher reads and mounts that same file read-only.
| Configuration | Published ports |
| --- | --- |
+26 -1
View File
@@ -59,12 +59,37 @@ private void EmpostorPublish(string name, string project, string runtime, bool i
}
}
if (isServer && runtime == "linux-x64") {
CopyDirectory(Directory("./marketplace"), projBuildDir.Combine("marketplace"));
FileWriteText(projBuildDir.CombineWithFilePath("Dockerfile"), @"# syntax=docker/dockerfile:1
FROM mcr.microsoft.com/dotnet/aspnet:10.0
WORKDIR /app
COPY --exclude=docker-up.py --exclude=compose.yml --exclude=config.json . ./
RUN mkdir -p Data Log Pages Languages languages plugins libraries Update \
&& chown -R app:app Data Log Pages Languages languages plugins libraries Update \
&& chmod 0750 Data Log Pages Languages languages plugins libraries Update
ENV DOTNET_RUNNING_IN_CONTAINER=1
ENV DOTNET_SYSTEM_GLOBALIZATION_INVARIANT=1
# EMPPOSTOR_PORTS_START
# EMPPOSTOR_PORTS_END
USER app
ENTRYPOINT [""./Empostor.Server""]
");
CopyFile(File("./compose.yml"), projBuildDir.CombineWithFilePath("compose.yml"));
CopyFile(File("./docker-up.py"), projBuildDir.CombineWithFilePath("docker-up.py"));
}
if (runtime == "win-x64") {
Zip(projBuildDir, buildDir.CombineWithFilePath(projBuildName + ".zip"));
} else {
GZipCompress(projBuildDir, buildDir.CombineWithFilePath(projBuildName + ".tar.gz"));
}
if (BuildSystem.GitHubActions.IsRunningOnGitHubActions) {
BuildSystem.GitHubActions.Commands.UploadArtifact(projBuildDir, projBuildName);
}
+3 -2
View File
@@ -2,12 +2,13 @@ services:
empostor:
build:
context: .
dockerfile: Dockerfile
image: empostor-server:local
container_name: empostor-server
restart: unless-stopped
init: true
ports: []
ports:
# EMPPOSTOR_PORTS_START
# EMPPOSTOR_PORTS_END
volumes:
- type: bind
source: ${EMPOSTOR_DOCKER_CONFIG:-./config.json}
+30 -22
View File
@@ -6,7 +6,6 @@ import os
import pathlib
import subprocess
import sys
import tempfile
ROOT = pathlib.Path(__file__).resolve().parent
@@ -69,34 +68,43 @@ def port_mappings(config):
return sorted(mappings)
def replace_block(path, start_marker, end_marker, lines):
content = path.read_text(encoding="utf-8")
start = content.find(start_marker)
end = content.find(end_marker)
if start < 0 or end < start:
raise ValueError(f"{path.name} is missing its port markers")
start += len(start_marker)
replacement = "\n" + "".join(f"{line}\n" for line in lines)
path.write_text(content[:start] + replacement + content[end:], encoding="utf-8")
def write_port_mappings(mappings):
compose_lines = [f' - "{mapping}"' for mapping in mappings]
exposes = sorted({mapping.split(":", 1)[1] for mapping in mappings})
dockerfile_lines = [f"EXPOSE {port}" for port in exposes]
replace_block(COMPOSE, " # EMPPOSTOR_PORTS_START", " # EMPPOSTOR_PORTS_END", compose_lines)
replace_block(ROOT / "Dockerfile", "# EMPPOSTOR_PORTS_START", "# EMPPOSTOR_PORTS_END", dockerfile_lines)
def main():
if not CONFIG.is_file():
default_config = ROOT / "src" / "Empostor.Server" / "config.json"
CONFIG.parent.mkdir(parents=True, exist_ok=True)
CONFIG.write_bytes(default_config.read_bytes())
print(f"Created {CONFIG} from the repository default config.")
raise FileNotFoundError(f"config file not found: {CONFIG}")
with CONFIG.open(encoding="utf-8-sig") as stream:
config = json.load(stream)
mappings = port_mappings(config)
override = "services:\n empostor:\n ports:\n"
override += "".join(f' - "{item}"\n' for item in mappings)
with tempfile.NamedTemporaryFile("w", encoding="utf-8", suffix=".yml", delete=False) as stream:
stream.write(override)
override_path = pathlib.Path(stream.name)
try:
command = ["docker", "compose", "-f", str(COMPOSE), "-f", str(override_path)]
command.extend(sys.argv[1:] or ["up", "-d", "--build"])
environment = dict(os.environ, EMPOSTOR_DOCKER_CONFIG=str(CONFIG))
print("Publishing:")
for item in mappings:
print(f" {item}")
raise SystemExit(subprocess.call(command, cwd=ROOT, env=environment))
finally:
override_path.unlink(missing_ok=True)
write_port_mappings(mappings)
command = ["docker", "compose"]
command.extend(sys.argv[1:] or ["up", "-d", "--build"])
print("Publishing:")
for item in mappings:
print(f" {item}")
environment = dict(os.environ, EMPOSTOR_DOCKER_CONFIG=str(CONFIG))
raise SystemExit(subprocess.call(command, cwd=ROOT, env=environment))
if __name__ == "__main__":