refactor(docker): run all containers as root, add compact log format support

- Docker: remove appuser creation and USER directive in all 7 Dockerfiles
- observability: recognize APP_LOG_FORMAT=compact as non-JSON pretty output
This commit is contained in:
ZhenYi 2026-05-12 23:59:31 +08:00
parent 066bb4e83d
commit 1c55cb8559
8 changed files with 8 additions and 22 deletions

View File

@ -2,9 +2,7 @@ FROM ubuntu:24.04
RUN apt-get update && apt-get install -y --no-install-recommends \ RUN apt-get update && apt-get install -y --no-install-recommends \
ca-certificates libssl3 openssh-client procps git \ ca-certificates libssl3 openssh-client procps git \
&& rm -rf /var/lib/apt/lists/* && rm -rf /var/lib/apt/lists/*
RUN useradd --system --create-home appuser WORKDIR /app
WORKDIR /home/appuser
COPY ./target/release/app /bin COPY ./target/release/app /bin
USER appuser
EXPOSE 3000 EXPOSE 3000
CMD ["app"] CMD ["app"]

View File

@ -2,9 +2,7 @@ FROM ubuntu:24.04
RUN apt-get update && apt-get install -y --no-install-recommends \ RUN apt-get update && apt-get install -y --no-install-recommends \
ca-certificates libssl3 \ ca-certificates libssl3 \
&& rm -rf /var/lib/apt/lists/* && rm -rf /var/lib/apt/lists/*
RUN useradd --system --create-home appuser WORKDIR /app
WORKDIR /home/appuser
COPY ./target/release/email-worker /bin COPY ./target/release/email-worker /bin
USER appuser
EXPOSE 8084 EXPOSE 8084
CMD ["email-worker"] CMD ["email-worker"]

View File

@ -2,9 +2,7 @@ FROM ubuntu:24.04
RUN apt-get update && apt-get install -y --no-install-recommends \ RUN apt-get update && apt-get install -y --no-install-recommends \
ca-certificates libssl3 \ ca-certificates libssl3 \
&& rm -rf /var/lib/apt/lists/* && rm -rf /var/lib/apt/lists/*
RUN useradd --system --create-home appuser WORKDIR /app
WORKDIR /home/appuser
COPY ./target/release/gingress /bin COPY ./target/release/gingress /bin
USER appuser
EXPOSE 80 443 8080 EXPOSE 80 443 8080
ENTRYPOINT ["gingress"] ENTRYPOINT ["gingress"]

View File

@ -2,9 +2,7 @@ FROM ubuntu:24.04
RUN apt-get update && apt-get install -y --no-install-recommends \ RUN apt-get update && apt-get install -y --no-install-recommends \
ca-certificates libssl3 git \ ca-certificates libssl3 git \
&& rm -rf /var/lib/apt/lists/* && rm -rf /var/lib/apt/lists/*
RUN useradd --system --create-home appuser WORKDIR /app
WORKDIR /home/appuser
COPY ./target/release/git-hook /bin COPY ./target/release/git-hook /bin
USER appuser
EXPOSE 8083 EXPOSE 8083
CMD ["git-hook"] CMD ["git-hook"]

View File

@ -2,9 +2,7 @@ FROM ubuntu:24.04
RUN apt-get update && apt-get install -y --no-install-recommends \ RUN apt-get update && apt-get install -y --no-install-recommends \
ca-certificates libssl3 git openssh-client \ ca-certificates libssl3 git openssh-client \
&& rm -rf /var/lib/apt/lists/* && rm -rf /var/lib/apt/lists/*
RUN useradd --system --create-home appuser WORKDIR /app
WORKDIR /home/appuser
COPY ./target/release/gitserver /bin COPY ./target/release/gitserver /bin
USER appuser
EXPOSE 8021 2222 EXPOSE 8021 2222
CMD ["gitserver"] CMD ["gitserver"]

View File

@ -2,9 +2,7 @@ FROM ubuntu:24.04
RUN apt-get update && apt-get install -y --no-install-recommends \ RUN apt-get update && apt-get install -y --no-install-recommends \
ca-certificates libssl3 \ ca-certificates libssl3 \
&& rm -rf /var/lib/apt/lists/* && rm -rf /var/lib/apt/lists/*
RUN useradd --system --create-home appuser WORKDIR /app
WORKDIR /home/appuser
COPY ./target/release/metrics-aggregator /bin COPY ./target/release/metrics-aggregator /bin
USER appuser
EXPOSE 9090 EXPOSE 9090
CMD ["metrics-aggregator"] CMD ["metrics-aggregator"]

View File

@ -2,9 +2,7 @@ FROM ubuntu:24.04
RUN apt-get update && apt-get install -y --no-install-recommends \ RUN apt-get update && apt-get install -y --no-install-recommends \
ca-certificates libssl3 \ ca-certificates libssl3 \
&& rm -rf /var/lib/apt/lists/* && rm -rf /var/lib/apt/lists/*
RUN useradd --system --create-home appuser WORKDIR /app
WORKDIR /home/appuser
COPY ./target/release/static-server /bin COPY ./target/release/static-server /bin
USER appuser
EXPOSE 8081 EXPOSE 8081
CMD ["static-server"] CMD ["static-server"]

View File

@ -41,7 +41,7 @@ pub fn instance_id() -> String {
fn use_json() -> bool { fn use_json() -> bool {
match std::env::var("APP_LOG_FORMAT").as_deref() { match std::env::var("APP_LOG_FORMAT").as_deref() {
Ok("json") => true, Ok("json") => true,
Ok("pretty") => false, Ok("pretty") | Ok("compact") => false,
_ => !std::io::stdout().is_terminal(), // TTY → pretty, non-TTY → json _ => !std::io::stdout().is_terminal(), // TTY → pretty, non-TTY → json
} }
} }