From 86cd52a0813d034d3d5ab5fbc36e72a75d7fc4c0 Mon Sep 17 00:00:00 2001 From: Chewing_Bever Date: Sat, 5 Aug 2023 12:23:15 +0200 Subject: [PATCH] chore: add Dockerfile & ci for publishing dev images --- .dockerignore | 2 ++ .woodpecker/docker.yml | 20 ++++++++++++++++++++ Dockerfile | 33 ++++++++++++--------------------- docker-compose.yml | 17 +++++++++++++++++ server/src/cli.rs | 16 +++++++++++++--- 5 files changed, 64 insertions(+), 24 deletions(-) create mode 100644 .woodpecker/docker.yml create mode 100644 docker-compose.yml diff --git a/.dockerignore b/.dockerignore index e3f6cab..94ca2bf 100644 --- a/.dockerignore +++ b/.dockerignore @@ -2,3 +2,5 @@ target/ .git/ server/data/ server/test.db/ +Dockerfile +docker-compose.yml diff --git a/.woodpecker/docker.yml b/.woodpecker/docker.yml new file mode 100644 index 0000000..b26625b --- /dev/null +++ b/.woodpecker/docker.yml @@ -0,0 +1,20 @@ +branches: [dev] +platform: 'linux/amd64' +depends_on: + - build + +pipeline: + dev: + image: 'woodpeckerci/plugin-docker-buildx' + secrets: + - 'docker_username' + - 'docker_password' + settings: + registry: 'git.rustybever.be' + repo: 'git.rustybever.be/chewing_bever/rieter' + tags: + - 'dev' + platforms: [ 'linux/amd64' ] + when: + event: push + branch: dev diff --git a/Dockerfile b/Dockerfile index df91d82..88b51a8 100644 --- a/Dockerfile +++ b/Dockerfile @@ -4,21 +4,6 @@ ARG DI_VER=1.2.5 WORKDIR /app -# RUN apk add --no-cache \ -# build-base \ -# curl \ -# make \ -# unzip \ -# pkgconf \ -# openssl openssl-libs-static openssl-dev \ -# libarchive-static libarchive-dev \ -# zlib-static zlib-dev \ -# bzip2-static bzip2-dev \ -# xz-static xz-dev \ -# expat-static expat-dev \ -# zstd-static zstd-dev \ -# lz4-static lz4-dev \ -# acl-static acl-dev RUN apk add --no-cache \ build-base \ curl \ @@ -42,23 +27,29 @@ COPY . . # LIBARCHIVE_LDFLAGS='-lssl -lcrypto -L/lib -lz -lbz2 -llzma -lexpat -lzstd -llz4' # LIBARCHIVE_LDFLAGS='-L/usr/lib -lz -lbz2 -llzma -lexpat -lzstd -llz4 -lsqlite3' +# https://users.rust-lang.org/t/sigsegv-with-program-linked-against-openssl-in-an-alpine-container/52172 +ENV RUSTFLAGS='-C target-feature=-crt-static' + RUN cargo build --release && \ du -h target/release/rieterd && \ readelf -d target/release/rieterd && \ chmod +x target/release/rieterd - # [ "$(readelf -d target/debug/rieterd | grep NEEDED | wc -l)" = 0 ] && \ - # chmod +x target/debug/rieterd FROM alpine:3.18 -WORKDIR /app - RUN apk add --no-cache \ - libarchive + libgcc \ + libarchive \ + openssl COPY --from=builder /app/dumb-init /bin/dumb-init -COPY --from=builder /app/target/debug/rieterd /bin/rieterd +COPY --from=builder /app/target/release/rieterd /bin/rieterd + +ENV RIETER_PKG_DIR=/data/pkgs \ + RIETER_DATA_DIR=/data + +WORKDIR /data ENTRYPOINT ["/bin/dumb-init", "--"] CMD ["/bin/rieterd"] diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..d05d6d0 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,17 @@ +version: '3.4' + +services: + app: + image: 'rieterd:latest' + ports: + - '8000:8000' + environment: + - 'RIETER_API_KEY=test' + - 'RIETER_DATABASE_URL=postgres://rieter:rieter@db:5432/rieter' + + db: + image: 'postgres:15.3-alpine' + environment: + - 'POSTGRES_DB=rieter' + - 'POSTGRES_USER=rieter' + - 'POSTGRES_PASSWORD=rieter' diff --git a/server/src/cli.rs b/server/src/cli.rs index d1647dd..540f457 100644 --- a/server/src/cli.rs +++ b/server/src/cli.rs @@ -15,24 +15,34 @@ use tracing_subscriber::{layer::SubscriberExt, util::SubscriberInitExt}; #[command(author, version, about, long_about = None)] pub struct Cli { /// Directory where package archives will be stored + #[arg(env = "RIETER_PKG_DIR")] pub pkg_dir: PathBuf, /// Directory where repository metadata & SQLite database is stored + #[arg(env = "RIETER_DATA_DIR")] pub data_dir: PathBuf, /// API key to authenticate private routes with + #[arg(env = "RIETER_API_KEY")] pub api_key: String, /// Database connection URL; either sqlite:// or postgres://. Defaults to rieter.sqlite in the /// data directory - #[arg(short, long)] + #[arg(short, long, env = "RIETER_DATABASE_URL")] pub database_url: Option, /// Port the server will listen on - #[arg(short, long, value_name = "PORT", default_value_t = 8000)] + #[arg( + short, + long, + value_name = "PORT", + default_value_t = 8000, + env = "RIETER_PORT" + )] pub port: u16, /// Log levels for the tracing #[arg( long, value_name = "LOG_LEVEL", - default_value = "tower_http=debug,rieterd=debug" + default_value = "tower_http=debug,rieterd=debug", + env = "RIETER_LOG" )] pub log: String, }