Skip to content

Commit

Permalink
Fix dockerfile and linux/macos tar command args
Browse files Browse the repository at this point in the history
  • Loading branch information
alisinabh committed May 1, 2024
1 parent 808c30a commit 62af9be
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 10 deletions.
6 changes: 5 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,14 @@ RUN cargo build --release

FROM debian:$DEBIAN_RELEASE-slim

RUN apt-get update && apt-get install -y openssl && rm -rf /var/lib/apt/lists/*
RUN apt-get update && apt-get install -y openssl ca-certificates && rm -rf /var/lib/apt/lists/*

COPY --from=builder /app/target/release/atlas /usr/local/bin/

RUN mkdir -p /opt/atlas/db && chown nobody:root /opt/atlas/db

USER nobody

ENV DB_PATH=/opt/atlas/db

CMD ["atlas"]
25 changes: 16 additions & 9 deletions src/download_utils.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use core::fmt;
use futures_util::StreamExt;
use std::env;
use std::error::Error;
use std::path::PathBuf;
use tokio::fs::File;
Expand Down Expand Up @@ -82,14 +83,15 @@ pub async fn download_with_basic_auth(
pub async fn extract_db(path: &str, filename: &str) -> Result<String, Box<dyn Error>> {
let full_path = PathBuf::from(path).join(filename);

let output = Command::new("tar")
.arg("xvfz")
.arg(&full_path)
.arg("-C")
.arg(path)
.arg("*.mmdb")
.output()
.await?;
let mut command = Command::new("tar");

command.arg("xvfz").arg(&full_path).arg("-C").arg(path);

if env::consts::OS != "macos" {
command.arg("--wildcards");
}

let output = command.arg("*.mmdb").output().await?;

if !output.status.success() {
println!("{:?}", output);
Expand All @@ -98,7 +100,12 @@ pub async fn extract_db(path: &str, filename: &str) -> Result<String, Box<dyn Er

tokio::fs::remove_file(full_path).await?;

let extracted_filename = String::from_utf8(output.stderr)?.replace('\n', "")[2..].to_string();
let result = match env::consts::OS {
"macos" => output.stderr,
_ => output.stdout,
};

let extracted_filename = String::from_utf8(result)?.replace('\n', "")[2..].to_string();

Ok(extracted_filename)
}

0 comments on commit 62af9be

Please sign in to comment.