rustic-rs / rustic_server

A REST server built in rust for use with rustic/restic
https://rustic.cli.rs/ecosystem/rustic-server/
GNU Affero General Public License v3.0
18 stars 2 forks source link

Build & publish docker images #62

Closed simonsan closed 1 week ago

simonsan commented 1 week ago

We can check here: https://github.com/rustic-rs/rustic/blob/main/.github/workflows/release-image.yml and https://github.com/restic/rest-server/issues/258

simonsan commented 1 week ago

Because you both, @mueckinger (https://github.com/rustic-rs/rustic/pull/1297) @timtorChen (https://github.com/rustic-rs/rustic/pull/1351), were contributing to the Docker ecosystem in rustic, I'm tagging you here. Does someone of you want to tackle this issue and create a Dockerfile? It would be really helpful! 🫂 🚀

timtorChen commented 1 week ago

I can take this issue. Is there any preference for buid process?

  1. After Gtihub relase, copy the binary file into the Docker image. (https://github.com/rustic-rs/rustic/blob/main/Dockerfile)
  2. Build binary in the Docker build time (https://github.com/timtorChen/rustic-exporter/blob/main/Dockerfile)

If there is no preference, I will create a PR with method 1.

simonsan commented 1 week ago

Super! 👍🏽 yeah, 1. is preferred, I would say.

FROM alpine AS builder
ARG RUSTIC_SERVER_VERSION
ARG TARGETARCH
RUN if [ "$TARGETARCH" = "amd64" ]; then \
        ASSET="rustic_server-x86_64-unknown-linux-musl.tar.xz";\
    fi; \
    wget https://github.com/rustic-rs/rustic_server/releases/download/${RUSTIC_SERVER_VERSION}/${ASSET} && \
    tar -xf ${ASSET} && \
    mkdir /etc_files && \
    touch /etc_files/passwd && \
    touch /etc_files/group

FROM scratch
COPY --from=builder /rustic_server-x86_64-unknown-linux-musl /
COPY --from=builder /etc_files/ /etc/
ENTRYPOINT ["/rustic-server"]

This is 1. adopted to this repo, but we would still need to expose setting ports for example and other settings. I also pushed a /health endpoint in 32dc6e12fb9418c2181c0ed11667eeb42a3ca719 that returns a 200 OK http status code when running, the uptime, and a timestamp when the response was sent (for logging). it's reachable under /health/live.

simonsan commented 1 week ago

Current help for serve options:

Start a server with the specified configuration

Usage: rustic-server.exe serve [OPTIONS]

Options:
      --listen <LISTEN>                IP address and port to bind to [env: RUSTIC_SERVER_LISTEN=]
      --path <DATA_DIR>                Path to the data directory [env: RUSTIC_SERVER_DATA_DIR=]
      --max-size <QUOTA>               Optional maximum size (quota) of a repository in bytes [env:
                                       RUSTIC_SERVER_QUOTA=]
  -v, --verbose                        Enable verbose logging [env: RUSTIC_SERVER_VERBOSE=]
  -c, --config <CONFIG>                Use the specified config file [env:
                                       RUSTIC_SERVER_CONFIG_PATH=]
      --no-auth                        Disable .htpasswd authentication [env:
                                       RUSTIC_SERVER_DISABLE_AUTH=]
      --htpasswd-file <HTPASSWD_FILE>  Optional location of .htpasswd file (default: "<data
                                       directory>/.htpasswd") [env: RUSTIC_SERVER_HTPASSWD_FILE=]
      --private-repos                  Users can only access their private repositories [env:
                                       RUSTIC_SERVER_PRIVATE_REPOS=]
      --append-only                    Enable append only mode [env: RUSTIC_SERVER_APPEND_ONLY=]
      --acl-path <ACL_PATH>            Full path including file name to read from. Governs per-repo
                                       ACLs. (default: "<data directory>/acl.toml") [env:
                                       RUSTIC_SERVER_ACL_PATH=]
      --tls                            Enable TLS support [env: RUSTIC_SERVER_DISABLE_TLS=]
      --tls-key <TLS_KEY>              Optional path to the TLS key file [env:
                                       RUSTIC_SERVER_TLS_KEY=]
      --tls-cert <TLS_CERT>            Optional path to the TLS certificate file [env:
                                       RUSTIC_SERVER_TLS_CERT=]
      --log <LOG_FILE>                 Write HTTP requests in the combined log format to the
                                       specified filename [env: RUSTIC_SERVER_LOG_FILE=]
  -h, --help                           Print help (see more with '--help')

Looking at it, the easiest would probably expose the env vars, so I added them to all the possible options now, will be in the next release.

timtorChen commented 1 week ago

Setting HEALTHCHECK would need some extra work for stratch image. Is compiling musl curl or wget in docker image a good idea?