Search code examples
c++azuredockerazure-sdk

Installing Azure SDK for C++ in a docker container


I would like to know how I may install azure c++ sdk in a docker container. I need it for a C++ services that downloads and processes files in Azure blob storage. Personally, I feel like the container will become too large and also the installation is kind of complex compare to the popular:

...
// Docker file
        
RUN git clone https://github.com/blah/bla.git \
    && cd blah && mkdir -p build \
    && cd build \
    && cmake .. \
    && cmake --build . --target install 
...

I have read the installation guide here and here but after following the whole installation procedure in my development environment (Centos 8), cmake fails to find the azure-storage-blobs-cpp even after adding the -DCMAKE_TOOLCHAIN_FILE=[path to vcpkg repo]/scripts/buildsystems/vcpkg.cmake flag correctly.

Is there an alternative or straight forward way like in the above snippet for installing the SDK in my development environment and then in a Linux based container for deployment?


Solution

  • While researching, I came across this issue. Here, janbernloehr references to a library called azure-storage-cpplite which I searched and tried. Yes, it solves my problem!

    First, it's easy to install locally or in a docker container. Dependencies: OpenSSL, libuuid and libcurl.

    RUN git clone https://github.com/azure/azure-storage-cpplite.git \
        && cd azure-storage-cpplite && mkdir -p build && cd build \ 
        && cmake .. -DCMAKE_BUILD_TYPE=Release \
        && cmake --build . \ 
        && cmake --build . --target install
    

    Secondly, it's simple to include the library in your CMake project.

    set(Headers
      include/your-file.h
    )
    
    set(Sources
      src/your-file.cpp
      )
    
    set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -lm -Wl,-R/usr/local/lib")
    
    set(CURL_LIBRARY "-lcurl") 
    find_package(CURL REQUIRED) 
    
    add_library(appname STATIC ${Sources} ${Headers})
    
    target_compile_features(appname PUBLIC cxx_std_17)
    
    target_include_directories(appname PUBLIC ${CURL_INCLUDE_DIR})
    target_link_libraries(appname ${CURL_LIBRARIES} azure-storage-lite -lcrypto -luuid)
    

    Thirdly, it is lightweight, with close to 30MB in download size which is OK for a docker container.

    If it wasn't for this issue I wouldn't have found the cpplite SDK. I don't know why it's a hidden gem. If you know anything let us know.