-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add distroless Dockerfile and implement internal health check (#3366)
- rslib(http_server): add `is_running()` method - rslib(sync): introduce `--healthcheck` argument for health probe in distroless - doc(syncserver): add table comparing Dockerfile and Dockerfile.distroless - Expand cross-platform support with distroless - add `Dockerfile.distroless` - Dockerfile: bump rust `1.79` to `1.80.1` - Dockerfile: bump alpine `3.20` to `3.20.2` Note: Implemented an internal health check because distroless images do not include curl, which is used to reduce image size and attack surface. For more details, see https://blog.sixeyed.com/docker-healthchecks-why-not-to-use-curl-or-iwr/ https://github.com/GoogleContainerTools/distroless fix: failed: check:format:rust typo remove extra space fix failed:check:format:rust update doc fetch `host` and `port` using envy fix: failed: check:format:rust Update doc + add dockerignore - dockerignore: This helps avoid sending unwanted files and directories to the builder - add new line - I am still experimenting cross platform compilation, I am getting 4.337 From https://github.com/ankitects/rust-url 4.337 * [new ref] bb930b8d089f4d30d7d19c12e54e66191de47b88 -> refs/commit/bb930b8d089f4d30d7d19c12e54e66191de47b88 4.397 error: failed to get `percent-encoding-iri` as a dependency of package `anki v0.0.0 (/app/rslib)` still checking what could be the issue fix: failed: check:format:dprint
- Loading branch information
1 parent
be2f013
commit 83fe301
Showing
6 changed files
with
71 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
node_modules/ | ||
target/ | ||
out/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
FROM rust:1.80.1 AS builder | ||
|
||
ARG ANKI_VERSION | ||
|
||
RUN apt-get update && apt-get install -y build-essential protobuf-compiler && apt-get clean && rm -rf /var/lib/apt/lists/* | ||
|
||
RUN cargo install --git https://github.com/ankitects/anki.git \ | ||
--tag ${ANKI_VERSION} \ | ||
--root /anki-server \ | ||
anki-sync-server | ||
|
||
FROM gcr.io/distroless/cc-debian12 | ||
|
||
COPY --from=builder /anki-server/bin/anki-sync-server /usr/bin/anki-sync-server | ||
|
||
ENV SYNC_PORT=${SYNC_PORT:-"8080"} | ||
|
||
EXPOSE ${SYNC_PORT} | ||
|
||
CMD ["anki-sync-server"] | ||
|
||
# This health check will work for Anki versions 24.08.x and newer. | ||
# For older versions, it may incorrectly report an unhealthy status, which should not be the case. | ||
HEALTHCHECK --interval=30s --timeout=10s --start-period=5s --retries=3 \ | ||
CMD ["anki-sync-server", "--healthcheck"] | ||
|
||
LABEL maintainer="Jean Khawand <[email protected]>" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,29 @@ | ||
// Copyright: Ankitects Pty Ltd and contributors | ||
// License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html | ||
use std::env; | ||
use std::process; | ||
|
||
use anki::log::set_global_logger; | ||
use anki::sync::http_server::SimpleServer; | ||
|
||
fn main() { | ||
if let Some(arg) = env::args().nth(1) { | ||
if arg == "--healthcheck" { | ||
run_health_check(); | ||
return; | ||
} | ||
} | ||
if env::var("RUST_LOG").is_err() { | ||
env::set_var("RUST_LOG", "anki=info") | ||
} | ||
set_global_logger(None).unwrap(); | ||
println!("{}", SimpleServer::run()); | ||
} | ||
|
||
fn run_health_check() { | ||
if SimpleServer::is_running() { | ||
process::exit(0); | ||
} else { | ||
process::exit(1); | ||
} | ||
} |