I've set up continuous deployment on Google Cloud Build since my application is deployed on Google Cloud, but I cannot seem to prevent ANSI characters from appearing on the Cloud Build logs.
I've tried setting the environment variable CARGO_TERM_COLOR=never in the Dockerfile, and adding --color never to the cargo build command, but my logs still seem to look like this.
FROM rust:1.67-bullseye AS builder
WORKDIR /app
COPY . .
ARG CARGO_TERM_COLOR=never
ARG CARGO_TARGET_DIR=./target
RUN cargo build --release --bin api --color never
FROM debian:bullseye-slim AS runtime
WORKDIR /app
COPY --from=builder /app/target/release/api /usr/local/bin
CMD ["/usr/local/bin/api"]
I guess the ANSI characters you see aren't the color but these little progress bars when you compile or download a dependency. You can turn the whole output of cargo build off with the --quiet flag. Other than that there's the configuration value term.progress.when, which can be set with the CARGO_TERM_PROGRESS_WHEN=never environment variable. Maybe try adding the environment variable and see if the ANSI characters vanish? I could be wrong about the source of the ANSI characters, but I think it's worth a shot .
Have you contacted Google? I ask because GitHub Actions and CircleCI work correctly. GitHub Actions strips the ANSI escapes and CircleCI shows the colors.
That might be the best thing to do. I've also noticed this issue doesn't appear on GitHub Actions.
I wonder if there's some configuration they've set behind the scenes to make sure cargo prints plain text, or they just remove any ANSI characters from the logs.
Google Cloud Build, GitHub Actions, CircleCI, etc. are examples of "build pipelines".
It can be argued that the term "build pipeline" refers to a specific configuration and that I'm over-generalizing the term.
The first part of the answer, the "nope", is what's important. Anything special is being done by GitHub Actions / CircleCI. There is nothing special happening when running Cargo; the ANSI escapes are present in the output.