fix dockerfile

This commit is contained in:
dumbasPL 2023-08-01 00:26:16 +02:00
parent 31e5ff5bda
commit cdbd0e72e3
5 changed files with 28 additions and 35 deletions

View file

@ -1,6 +1,6 @@
*.MD
.editorconfig
Dockerfile
Dockerfile*
docker-compose.yml
config.yaml
config/

4
.gitignore vendored
View file

@ -1,2 +1,4 @@
/target
/config.yaml
/config.yaml
/config
!/config/example.yaml

View file

@ -1,19 +1,21 @@
FROM rust:1-bookworm as builder
FROM rust:1-bookworm as chef
RUN cargo install cargo-chef
WORKDIR /app
FROM chef as planner
COPY . .
RUN cargo chef prepare --recipe-path recipe.json
FROM chef as builder
COPY --from=planner /app/recipe.json recipe.json
RUN cargo chef cook --release --recipe-path recipe.json
COPY . .
RUN cargo build --release --bin windscribe-ephemeral-port
FROM debian:bookworm-slim AS runtime
RUN groupadd --gid 1000 wind && useradd --uid 1000 --gid wind --shell /bin/bash --create-home wind
WORKDIR /app
RUN apt-get update && apt-get install -y libssl3 ca-certificates && rm -rf /var/lib/apt/lists/*
WORKDIR /config
RUN groupadd --gid 1000 wind && useradd --uid 1000 --gid wind --shell /bin/bash wind && chown wind:wind /config
COPY --from=builder /app/target/release/windscribe-ephemeral-port /usr/local/bin
USER wind
ENTRYPOINT ["/usr/local/bin/windscribe-ephemeral-port"]
ENTRYPOINT ["/usr/local/bin/windscribe-ephemeral-port", "--cache-dir", "/config", "--config", "/config/config.yaml"]

View file

@ -1,21 +0,0 @@
FROM rust:1-alpine as builder
RUN apk add --no-cache musl-dev openssl-dev
WORKDIR /app
COPY . .
RUN cargo build --release --bin windscribe-ephemeral-port
FROM alpine AS runtime
RUN addgroup -g 1000 wind && adduser -u 1000 -G wind -s /bin/sh -D wind
WORKDIR /app
COPY --from=builder /app/target/release/windscribe-ephemeral-port /usr/local/bin
USER wind
ENTRYPOINT ["/usr/local/bin/windscribe-ephemeral-port"]

View file

@ -7,7 +7,7 @@ use std::{
path::PathBuf,
};
use tokio::fs;
use tracing::warn;
use tracing::{debug, warn};
#[derive(Debug, Serialize, Deserialize)]
pub struct Config {
@ -90,11 +90,15 @@ pub async fn load_config(config_path: Option<PathBuf>) -> Result<Config> {
None => get_config_paths("config.yaml"),
};
debug!("Config paths: {:?}", config_paths);
let config_path = config_paths
.iter()
.find(|path| path.exists())
.ok_or_else(|| anyhow!("No config file found, tried: {:?}", config_paths))?;
debug!("Using config path: {:?}", config_path);
let config = fs::read_to_string(config_path).await?;
let config: Config =
serde_path_to_error::deserialize(serde_yaml::Deserializer::from_str(&config))?;
@ -104,21 +108,27 @@ pub async fn load_config(config_path: Option<PathBuf>) -> Result<Config> {
pub async fn get_cache(cache_path: Option<PathBuf>, name: &str) -> Result<SimpleCache> {
let cache_dir = match cache_path {
Some(path) => vec![path],
Some(path) => vec![path.join(format!("{}.json", name))],
None => get_config_paths(format!("{}.json", name).as_str()),
};
debug!("Cache paths: {:?}", cache_dir);
let existing_cache_path = cache_dir.iter().find(|path| path.exists());
let cache_path = match existing_cache_path {
Some(path) => Some(path),
None => cache_dir.first(),
};
debug!("Using cache path: {:?}", cache_path);
// create cache directory if it doesn't exist
if let Some(directory) = cache_path.and_then(|path| path.parent()) {
fs::create_dir_all(directory).await?;
};
debug!("Loading cache from: {:?}", cache_path);
match cache_path {
Some(path) => SimpleCache::load(path.to_owned()).await,
None => {