From 558ffe1d871987e509d4a0940169aee047299e28 Mon Sep 17 00:00:00 2001 From: emeric Date: Fri, 27 May 2022 23:33:43 +0200 Subject: [PATCH 1/3] Rollback to alpine 3.14 as 3.15+ seems to clash with the system timer used for the scanner. fixes #228 --- Dockerfile-release | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Dockerfile-release b/Dockerfile-release index 6bb7d3bc..e94ceeb3 100644 --- a/Dockerfile-release +++ b/Dockerfile-release @@ -1,4 +1,4 @@ -FROM alpine:3.16 AS build +FROM alpine:3.14 AS build WORKDIR /tmp/workdir @@ -132,7 +132,7 @@ RUN \ rm -rf /tmp/fakeroot/share/Wt/resources/themes ## Release Stage -FROM alpine:3.16 AS release +FROM alpine:3.14 AS release LABEL maintainer="Emeric Poupon " ARG RUNTIME_PACKAGES=" \ From 657b35d5415e52571bbcc07cbfd319416b41fc05 Mon Sep 17 00:00:00 2001 From: emeric Date: Sat, 28 May 2022 14:57:39 +0200 Subject: [PATCH 2/3] Fixed arch build --- .../workflows/{build.yml => build-alpine.yml} | 6 ++-- .github/workflows/build-arch.yml | 34 +++++++++++++++++++ Dockerfile-build => Dockerfile-build-alpine | 0 Dockerfile-build-arch | 26 ++++++++++++++ .../services/database/impl/ScanSettings.cpp | 7 +++- .../services/scanner/impl/ScannerService.cpp | 8 ++--- .../services/scanner/impl/ScannerService.hpp | 4 +-- src/libs/utils/include/utils/Path.hpp | 8 ----- 8 files changed, 75 insertions(+), 18 deletions(-) rename .github/workflows/{build.yml => build-alpine.yml} (90%) create mode 100644 .github/workflows/build-arch.yml rename Dockerfile-build => Dockerfile-build-alpine (100%) create mode 100644 Dockerfile-build-arch diff --git a/.github/workflows/build.yml b/.github/workflows/build-alpine.yml similarity index 90% rename from .github/workflows/build.yml rename to .github/workflows/build-alpine.yml index bc06035c..a6d4874b 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build-alpine.yml @@ -1,4 +1,4 @@ -name: Build +name: Build (alpine) on: [push, pull_request] jobs: Build: @@ -22,11 +22,11 @@ jobs: id: buildx uses: docker/setup-buildx-action@v1 - - name: Build + - name: Build (alpine) uses: docker/build-push-action@v2 with: context: ./ - file: ./Dockerfile-build + file: ./Dockerfile-build-alpine builder: ${{ steps.buildx.outputs.name }} build-args: LMS_BUILD_TYPE=${{ matrix.BUILD_TYPE }} push: false diff --git a/.github/workflows/build-arch.yml b/.github/workflows/build-arch.yml new file mode 100644 index 00000000..ea06617c --- /dev/null +++ b/.github/workflows/build-arch.yml @@ -0,0 +1,34 @@ +name: Build (arch) +on: [push, pull_request] +jobs: + Build: + strategy: + matrix: + BUILD_TYPE: [Release, Debug] + runs-on: ubuntu-latest + steps: + - name: Check Out Repo + uses: actions/checkout@v2 + + - name: Cache Docker layers + uses: actions/cache@v2 + with: + path: /tmp/.buildx-cache + key: ${{ runner.os }}-buildx-${{ github.sha }} + restore-keys: | + ${{ runner.os }}-buildx- + + - name: Set up Docker Buildx + id: buildx + uses: docker/setup-buildx-action@v1 + + - name: Build + uses: docker/build-push-action@v2 + with: + context: ./ + file: ./Dockerfile-build-arch + builder: ${{ steps.buildx.outputs.name }} + build-args: LMS_BUILD_TYPE=${{ matrix.BUILD_TYPE }} + push: false + cache-from: type=local,src=/tmp/.buildx-cache + cache-to: type=local,dest=/tmp/.buildx-cache diff --git a/Dockerfile-build b/Dockerfile-build-alpine similarity index 100% rename from Dockerfile-build rename to Dockerfile-build-alpine diff --git a/Dockerfile-build-arch b/Dockerfile-build-arch new file mode 100644 index 00000000..eaecaaef --- /dev/null +++ b/Dockerfile-build-arch @@ -0,0 +1,26 @@ +FROM archlinux:latest + +ARG BUILD_PACKAGES="\ + clang \ + cmake \ + boost \ + ffmpeg \ + gtest \ + graphicsmagick \ + libconfig \ + make \ + pkgconfig \ + taglib \ + wt" + +RUN pacman -Syy +RUN pacman -S --noconfirm ${BUILD_PACKAGES} + +# LMS +COPY . /tmp/lms/ +ARG LMS_BUILD_TYPE="Release" +RUN \ + DIR=/tmp/lms/build && mkdir -p ${DIR} && cd ${DIR} && \ + cmake /tmp/lms/ -DCMAKE_BUILD_TYPE=${LMS_BUILD_TYPE} -DCMAKE_INSTALL_PREFIX=/usr && \ + VERBOSE=1 make -j$(nproc) && \ + make test diff --git a/src/libs/services/database/impl/ScanSettings.cpp b/src/libs/services/database/impl/ScanSettings.cpp index 70f08b72..13005720 100644 --- a/src/libs/services/database/impl/ScanSettings.cpp +++ b/src/libs/services/database/impl/ScanSettings.cpp @@ -67,7 +67,12 @@ std::vector ScanSettings::getAudioFileExtensions() const { const auto extensions {StringUtils::splitString(_audioFileExtensions, " ")}; - return std::vector(std::cbegin(extensions), std::cend(extensions)); + + std::vector res (std::cbegin(extensions), std::cend(extensions)); + std::sort(std::begin(res), std::end(res)); + res.erase(std::unique( std::begin(res), std::end(res)), std::end(res)); + + return res; } void diff --git a/src/libs/services/scanner/impl/ScannerService.cpp b/src/libs/services/scanner/impl/ScannerService.cpp index de5c94ae..fc712c13 100644 --- a/src/libs/services/scanner/impl/ScannerService.cpp +++ b/src/libs/services/scanner/impl/ScannerService.cpp @@ -69,11 +69,11 @@ getNextFirstOfMonth(Wt::WDate current) } bool -isFileSupported(const std::filesystem::path& file, const std::unordered_set& extensions) +isFileSupported(const std::filesystem::path& file, const std::vector& extensions) { const std::filesystem::path extension {StringUtils::stringToLower(file.extension().string())}; - return (extensions.find(extension) != extensions.end()); + return (std::find(std::cbegin(extensions), std::cend(extensions), extension) != std::cend(extensions)); } bool @@ -642,7 +642,7 @@ ScannerService::refreshScanSettings() { const auto fileExtensions {scanSettings->getAudioFileExtensions()}; _fileExtensions.clear(); - std::transform(std::cbegin(fileExtensions), std::end(fileExtensions), std::inserter(_fileExtensions, std::begin(_fileExtensions)), + std::transform(std::cbegin(fileExtensions), std::end(fileExtensions), std::back_inserter(_fileExtensions), [](const std::filesystem::path& extension) { return std::filesystem::path{ StringUtils::stringToLower(extension.string()) }; }); } _mediaDirectory = scanSettings->getMediaDirectory(); @@ -896,7 +896,7 @@ ScannerService::scanMediaDirectory(const std::filesystem::path& mediaDirectory, // Check if a file exists and is still in a media directory static bool -checkFile(const std::filesystem::path& p, const std::filesystem::path& mediaDirectory, const std::unordered_set& extensions) +checkFile(const std::filesystem::path& p, const std::filesystem::path& mediaDirectory, const std::vector& extensions) { try { diff --git a/src/libs/services/scanner/impl/ScannerService.hpp b/src/libs/services/scanner/impl/ScannerService.hpp index 0d8ecf91..9614bcb9 100644 --- a/src/libs/services/scanner/impl/ScannerService.hpp +++ b/src/libs/services/scanner/impl/ScannerService.hpp @@ -22,7 +22,7 @@ #include #include #include -#include +#include #include #include @@ -114,7 +114,7 @@ namespace Scanner std::size_t _scanVersion {}; Wt::WTime _startTime; Database::ScanSettings::UpdatePeriod _updatePeriod {Database::ScanSettings::UpdatePeriod::Never}; - std::unordered_set _fileExtensions; + std::vector _fileExtensions; std::filesystem::path _mediaDirectory; Database::ScanSettings::RecommendationEngineType _recommendationServiceType; }; diff --git a/src/libs/utils/include/utils/Path.hpp b/src/libs/utils/include/utils/Path.hpp index b72e9cb4..e6361a5f 100644 --- a/src/libs/utils/include/utils/Path.hpp +++ b/src/libs/utils/include/utils/Path.hpp @@ -38,11 +38,3 @@ Wt::WDateTime getLastWriteTime(const std::filesystem::path& dir); // returns false if aborted by user bool exploreFilesRecursive(const std::filesystem::path& directory, std::function cb, const std::filesystem::path& excludeDirFileName = {}); -namespace std -{ - template <> - struct hash - { - inline std::size_t operator()(const std::filesystem::path &path) const { return hash_value(path); } - }; -} From 8d0bbd080725624ecece8c8187c87df45c08f763 Mon Sep 17 00:00:00 2001 From: emeric Date: Sat, 28 May 2022 18:52:30 +0200 Subject: [PATCH 3/3] Fixed lgtm alert --- .../recommendation/impl/features/FeaturesEngine.cpp | 6 +++--- .../recommendation/impl/features/FeaturesEngine.hpp | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/libs/services/recommendation/impl/features/FeaturesEngine.cpp b/src/libs/services/recommendation/impl/features/FeaturesEngine.cpp index daee3d4b..fddb0324 100644 --- a/src/libs/services/recommendation/impl/features/FeaturesEngine.cpp +++ b/src/libs/services/recommendation/impl/features/FeaturesEngine.cpp @@ -213,7 +213,7 @@ FeaturesEngine::loadFromTraining(const TrainSettings& trainSettings, const Progr } void -FeaturesEngine::loadFromCache(FeaturesEngineCache cache) +FeaturesEngine::loadFromCache(FeaturesEngineCache&& cache) { LMS_LOG(RECOMMENDATION, INFO) << "Constructing features classifier from cache..."; @@ -341,9 +341,9 @@ FeaturesEngine::load(bool forceReload, const ProgressCallback& progressCallback) { FeaturesEngineCache::invalidate(); } - else if (const std::optional cache {FeaturesEngineCache::read()}) + else if (std::optional cache {FeaturesEngineCache::read()}) { - loadFromCache(*cache); + loadFromCache(std::move(*cache)); return; } diff --git a/src/libs/services/recommendation/impl/features/FeaturesEngine.hpp b/src/libs/services/recommendation/impl/features/FeaturesEngine.hpp index 706d7f72..d6839f16 100644 --- a/src/libs/services/recommendation/impl/features/FeaturesEngine.hpp +++ b/src/libs/services/recommendation/impl/features/FeaturesEngine.hpp @@ -63,7 +63,7 @@ class FeaturesEngine : public IEngine ReleaseContainer getSimilarReleases(Database::ReleaseId releaseId, std::size_t maxCount) const override; ArtistContainer getSimilarArtists(Database::ArtistId artistId, EnumSet linkTypes, std::size_t maxCount) const override; - void loadFromCache(FeaturesEngineCache cache); + void loadFromCache(FeaturesEngineCache&& cache); // Use training (may be very slow) struct TrainSettings