diff --git a/Dockerfile b/Dockerfile index 0dd22e7..33ffcf1 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,14 +1,11 @@ # Create final image -FROM alpine:latest +FROM debian:latest ARG TARGETOS ARG TARGETARCH # Copy binary from builder -RUN apk update && apk add --no-cache curl bash wget gzip && rm -rf /var/cache/apk/* - - RUN mkdir -p /sos COPY --chmod=0755 exe/simple_object_storage-${TARGETOS}-${TARGETARCH} /sos/sos diff --git a/build.sh b/build.sh index 899d737..3dcd5ca 100755 --- a/build.sh +++ b/build.sh @@ -47,9 +47,16 @@ cp ${EXE_DIR}/simple_object_storage-linux-x86_64 ${EXE_DIR}/simple_object_storag echo "amd64 executable: ./simple_object_storage-linux-amd64" echo "arm64 executable: ./simple_object_storage-linux-arm64" -echo "Setting up Docker BuildX" -docker buildx create --name mybuilder --use || true - +echo "Setting up Docker BuildX builder 'sosbuilder'" +# Check if builder instance exists +if ! docker buildx inspect sosbuilder > /dev/null 2>&1; then + echo "Builder 'sosbuilder' not found, creating..." + docker buildx create --name sosbuilder +else + echo "Builder 'sosbuilder' already exists." +fi +# Ensure the builder is used +docker buildx use sosbuilder echo "Building multi-platform Docker image" docker buildx build --push -t gitea.jde.nz/j/simple-object-storage:latest --platform linux/amd64,linux/arm64 . diff --git a/src/config.cpp b/src/config.cpp index 88df257..df21b82 100644 --- a/src/config.cpp +++ b/src/config.cpp @@ -17,6 +17,11 @@ bool load_config(const std::string& config_path, ServerConfig& config) { nlohmann::json j; file >> j; + config.host = "0.0.0.0"; + config.port = 8123; + config.object_store_path = "/data/storage"; + config.write_tokens = {}; + // Parse write tokens if (j.contains("write_tokens")) { config.write_tokens = j["write_tokens"].get>(); diff --git a/src/config.hpp b/src/config.hpp index 9b54c75..ef20890 100644 --- a/src/config.hpp +++ b/src/config.hpp @@ -11,7 +11,7 @@ struct ServerConfig { std::vector write_tokens; std::filesystem::path object_store_path; std::string host = "0.0.0.0"; - uint16_t port = 80; + uint16_t port = 0; }; bool load_config(const std::string& config_path, ServerConfig& config); diff --git a/src/main.cpp b/src/main.cpp index b4ebef9..cbdce15 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -8,34 +8,20 @@ namespace simple_object_storage { int main(int argc, char* argv[]) { - std::filesystem::path config_path = "/data/sos_config.json"; - if (!std::filesystem::exists(config_path)) - config_path = std::filesystem::path(std::getenv("HOME")) / ".config/simple_object_storage/config.json"; - - if (!std::filesystem::exists(config_path)) - std::filesystem::create_directories(config_path.parent_path()); + std::filesystem::path system_config_path = "/data/sos_config.json"; + std::filesystem::path user_config_path = std::filesystem::path(std::getenv("HOME")) / ".config/simple_object_storage/config.json"; + + std::filesystem::path config_path; + if (std::filesystem::exists(system_config_path)) config_path = system_config_path; + else if (std::filesystem::exists(user_config_path)) config_path = user_config_path; + else { + std::cout << "No config file found. Checked " << system_config_path << " and " << user_config_path << std::endl; + return 1; + } ServerConfig config; if (!simple_object_storage::load_config(config_path, config)) { - // output default config using heredoc to config_path - std::ofstream config_file(config_path); - config_file << R"END( -{ - "write_tokens": [ - "fizzle1", - "fizzle2", - "fizzle3" - ], - "object_store_path": "/home/j/.simple_object_storage/", - "host": "0.0.0.0", - "port": 8123 -} -)END"; - config_file.close(); - } - - if (!simple_object_storage::load_config(config_path, config)) { - std::cerr << "Failed to load configuration at "<