Skip to content

Commit

Permalink
Azure Blob Storage Providers (#49)
Browse files Browse the repository at this point in the history
* Use centralized ruleset and add Azure project

* Add implementations.

* Update names

* Update Azure resolver  to latest API

* Fix DI

* Cleanup

* Update AzureBlobStorageImageProvider.cs

* Update Azure deps

* Fix build

* Drop IImageProvider settings

* Drop IImageCache Settings

* Simplify configuration.

* Add Azure Provider integration tests.

* Update appveyor.yml

* Attempt to use Azurite for Azure tests

* Update .travis.yml

* Use expanded commands

* Use build root

* Run in background.

* Skip test for now.

* Push both artifacts

* Fix artifact path

* Update ImageSharp
  • Loading branch information
JimBobSquarePants authored May 25, 2019
1 parent 0ad58bb commit 75fd113
Show file tree
Hide file tree
Showing 44 changed files with 701 additions and 453 deletions.
16 changes: 0 additions & 16 deletions .editorconfig

This file was deleted.

3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[submodule "standards"]
path = standards
url = https://github.com/SixLabors/Standards
11 changes: 7 additions & 4 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ language: csharp

matrix:
include:
- os: linux # Ubuntu 14.04
dist: trusty
- os: linux # Ubuntu 16.04
dist: xenial
sudo: required
dotnet: 2.1.300
dotnet: 2.1.603
mono: latest
# - os: osx # OSX 10.11
# osx_image: xcode7.3.1
Expand All @@ -18,6 +18,9 @@ branches:
- coverity_scan

script:
- git submodule -q update --init
- npm install -g azurite
- azurite --silent --location /home/travis/build/SixLabors/ --debug /home/travis/build/SixLabors/debug.log &
- dotnet restore
- dotnet test tests/ImageSharp.Web.Tests/ImageSharp.Web.Tests.csproj -c Release -f "netcoreapp2.1"
- dotnet test tests/ImageSharp.Web.Tests/ImageSharp.Web.Tests.csproj -c Release -f "netcoreapp1.1"
Expand All @@ -43,7 +46,7 @@ addons:
apt:
# Install framework 1.1.2 in order to run tests on netcoreapp1.1, see https://codeblog.jonskeet.uk/2017/08/15/using-net-core-2-0-sdk-on-travis/
sources:
- sourceline: 'deb [arch=amd64] https://packages.microsoft.com/repos/microsoft-ubuntu-trusty-prod trusty main'
- sourceline: 'deb [arch=amd64] https://packages.microsoft.com/repos/microsoft-ubuntu-xenial-prod xenial main'
key_url: 'https://packages.microsoft.com/keys/microsoft.asc'
packages:
- dotnet-sharedframework-microsoft.netcore.app-1.1.2
29 changes: 23 additions & 6 deletions ImageSharp.Web.sln
Original file line number Diff line number Diff line change
@@ -1,20 +1,22 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 15
VisualStudioVersion = 15.0.26730.12
# Visual Studio Version 16
VisualStudioVersion = 16.0.28803.452
MinimumVisualStudioVersion = 10.0.40219.1
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "SolutionItems", "SolutionItems", "{C317F1B1-D75E-4C6D-83EB-80367343E0D7}"
ProjectSection(SolutionItems) = preProject
.editorconfig = .editorconfig
standards\.editorconfig = standards\.editorconfig
.travis.yml = .travis.yml
appveyor.yml = appveyor.yml
build.cmd = build.cmd
build.ps1 = build.ps1
codecov.yml = codecov.yml
CodeCoverage.runsettings = CodeCoverage.runsettings
.github\CONTRIBUTING.md = .github\CONTRIBUTING.md
features.md = features.md
ImageSharp.ruleset = ImageSharp.ruleset
NuGet.config = NuGet.config
README.md = README.md
standards\SixLabors.ruleset = standards\SixLabors.ruleset
standards\stylecop.json = standards\stylecop.json
EndProjectSection
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Source", "Source", "{815C0625-CD3D-440F-9F80-2D83856AB7AE}"
Expand All @@ -34,7 +36,9 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Samples", "Samples", "{EA41
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ImageSharp.Web.Sample", "samples\ImageSharp.Web.Sample\ImageSharp.Web.Sample.csproj", "{BD73DBBD-6859-44C2-99FC-84148A6239A5}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ImageSharp.Web.Benchmarks", "tests\ImageSharp.Web.Benchmarks\ImageSharp.Web.Benchmarks.csproj", "{0B15E490-7821-42DF-86A5-4DEAE921DE59}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ImageSharp.Web.Benchmarks", "tests\ImageSharp.Web.Benchmarks\ImageSharp.Web.Benchmarks.csproj", "{0B15E490-7821-42DF-86A5-4DEAE921DE59}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ImageSharp.Web.Providers.Azure", "src\ImageSharp.Web.Providers.Azure\ImageSharp.Web.Providers.Azure.csproj", "{E2A545EC-B909-4EAD-B95F-397F68588BE3}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Expand Down Expand Up @@ -94,6 +98,18 @@ Global
{0B15E490-7821-42DF-86A5-4DEAE921DE59}.Release|x64.Build.0 = Release|Any CPU
{0B15E490-7821-42DF-86A5-4DEAE921DE59}.Release|x86.ActiveCfg = Release|Any CPU
{0B15E490-7821-42DF-86A5-4DEAE921DE59}.Release|x86.Build.0 = Release|Any CPU
{E2A545EC-B909-4EAD-B95F-397F68588BE3}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{E2A545EC-B909-4EAD-B95F-397F68588BE3}.Debug|Any CPU.Build.0 = Debug|Any CPU
{E2A545EC-B909-4EAD-B95F-397F68588BE3}.Debug|x64.ActiveCfg = Debug|Any CPU
{E2A545EC-B909-4EAD-B95F-397F68588BE3}.Debug|x64.Build.0 = Debug|Any CPU
{E2A545EC-B909-4EAD-B95F-397F68588BE3}.Debug|x86.ActiveCfg = Debug|Any CPU
{E2A545EC-B909-4EAD-B95F-397F68588BE3}.Debug|x86.Build.0 = Debug|Any CPU
{E2A545EC-B909-4EAD-B95F-397F68588BE3}.Release|Any CPU.ActiveCfg = Release|Any CPU
{E2A545EC-B909-4EAD-B95F-397F68588BE3}.Release|Any CPU.Build.0 = Release|Any CPU
{E2A545EC-B909-4EAD-B95F-397F68588BE3}.Release|x64.ActiveCfg = Release|Any CPU
{E2A545EC-B909-4EAD-B95F-397F68588BE3}.Release|x64.Build.0 = Release|Any CPU
{E2A545EC-B909-4EAD-B95F-397F68588BE3}.Release|x86.ActiveCfg = Release|Any CPU
{E2A545EC-B909-4EAD-B95F-397F68588BE3}.Release|x86.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand All @@ -104,6 +120,7 @@ Global
{8864C96C-94AA-454D-BAF5-779216C3745A} = {56801022-D71A-4FBE-BC5B-CBA08E2284EC}
{BD73DBBD-6859-44C2-99FC-84148A6239A5} = {EA4178FC-11E3-496A-B630-0680B35E0AF8}
{0B15E490-7821-42DF-86A5-4DEAE921DE59} = {56801022-D71A-4FBE-BC5B-CBA08E2284EC}
{E2A545EC-B909-4EAD-B95F-397F68588BE3} = {815C0625-CD3D-440F-9F80-2D83856AB7AE}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {C5B38B65-A19E-4359-859C-5B2205429BD1}
Expand Down
11 changes: 0 additions & 11 deletions ImageSharp.ruleset

This file was deleted.

36 changes: 12 additions & 24 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,25 +72,19 @@ services.AddImageSharp(
});
```

Or you can fine-grain control adding the default options and configure all other services.
Or you can fine-grain control adding the default options and configure other services.

``` c#
// Fine-grain control adding the default options and configure all other services. Setting all services is required.
services.AddImageSharpCore()
.SetRequestParser<QueryCollectionRequestParser>()
.SetBufferManager<PooledBufferManager>()
.SetMemoryAllocatorFromMiddlewareOptions()
.SetCacheHash<CacheHash>()
.AddProvider<PhysicalFileSystemProvider>()
.AddProcessor<ResizeWebProcessor>()
.AddProcessor<FormatWebProcessor>()
.AddProcessor<BackgroundColorWebProcessor>();
// Fine-grain control adding the default options and configure other services.
services.AddImageSharp()
.RemoveProcessor<FormatWebProcessor>()
.RemoveProcessor<BackgroundColorWebProcessor>();
```

There are also factory methods for each builder that will allow building from configuration files.

``` c#
// Use the factory methods to configure the PhysicalFileSystemCache
// Use the factory methods to configure the PhysicalFileSystemCacheOptions
services.AddImageSharpCore(
options =>
{
Expand All @@ -104,18 +98,12 @@ services.AddImageSharpCore(
options.OnPrepareResponse = _ => { };
})
.SetRequestParser<QueryCollectionRequestParser>()
.SetMemoryAllocator<ArrayPoolMemoryAllocator>()
.SetCache(provider =>
{
var p = new PhysicalFileSystemCache(
provider.GetRequiredService<IHostingEnvironment>(),
provider.GetRequiredService<IBufferManager>(),
provider.GetRequiredService<IOptions<ImageSharpMiddlewareOptions>>());

p.Settings[PhysicalFileSystemCache.Folder] = PhysicalFileSystemCache.DefaultCacheFolder;

return p;
})
.SetMemoryAllocator(provider => ArrayPoolMemoryAllocator.CreateWithMinimalPooling())
.Configure<PhysicalFileSystemCacheOptions>(options =>
{
options.CacheFolder = "different-cache";
})
.SetCache<PhysicalFileSystemCache>()
.SetCacheHash<CacheHash>()
.AddProvider<PhysicalFileSystemProvider>()
.AddProcessor<ResizeWebProcessor>()
Expand Down
11 changes: 11 additions & 0 deletions appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,20 @@ image: Previous Visual Studio 2017
# prevent the double build when a branch has an active PR
skip_branch_with_pr: true

# Install and run the Azure Storage Emulator
# https://docs.microsoft.com/en-us/azure/storage/common/storage-use-emulator#get-the-storage-emulator
install:
- ps: >-
$msiPath = "$($env:USERPROFILE)\MicrosoftAzureStorageEmulator.msi"
(New-Object Net.WebClient).DownloadFile('https://go.microsoft.com/fwlink/?linkid=717179&clcid=0x409', $msiPath)
cmd /c start /wait msiexec /i $msiPath /quiet
before_build:
- git submodule -q update --init
- cmd: dotnet --info
- cmd: '"%programfiles(x86)%\Microsoft SDKs\Azure\Storage Emulator\AzureStorageEmulator.exe" start'

build_script:
- cmd: build.cmd
Expand All @@ -17,6 +27,7 @@ test_script:

after_test:
- cmd: appveyor PushArtifact "artifacts\SixLabors.ImageSharp.Web.%APPVEYOR_BUILD_VERSION%.nupkg"
- cmd: appveyor PushArtifact "artifacts\SixLabors.ImageSharp.Web.Providers.Azure.%APPVEYOR_BUILD_VERSION%.nupkg"

deploy:
# MyGet Deployment for builds & releases
Expand Down
1 change: 1 addition & 0 deletions build.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -107,4 +107,5 @@ if ($LASTEXITCODE ){ Exit $LASTEXITCODE }

Write-Host "Packaging projects"
dotnet pack ./src/ImageSharp.Web/ -c Release --output ../../artifacts --no-build /p:packageversion=$version
dotnet pack ./src/ImageSharp.Web.Providers.Azure/ -c Release --output ../../artifacts --no-build /p:packageversion=$version
if ($LASTEXITCODE ){ Exit $LASTEXITCODE }
59 changes: 30 additions & 29 deletions samples/ImageSharp.Web.Sample/Startup.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Options;
Expand All @@ -15,22 +16,27 @@ namespace SixLabors.ImageSharp.Web.Sample
{
public class Startup
{
public Startup(IConfiguration configuration) => this.AppConfiguration = configuration;

public IConfiguration AppConfiguration { get; }

// This method gets called by the runtime. Use this method to add services to the container.
// For more information on how to configure your application, visit https://go.microsoft.com/fwlink/?LinkID=398940
public void ConfigureServices(IServiceCollection services)
{
services.AddImageSharpCore()
.SetRequestParser<QueryCollectionRequestParser>()
.SetMemoryAllocatorFromMiddlewareOptions()
.SetCache(provider => new PhysicalFileSystemCache(
provider.GetRequiredService<IHostingEnvironment>(),
provider.GetRequiredService<MemoryAllocator>(),
provider.GetRequiredService<IOptions<ImageSharpMiddlewareOptions>>())
.Configure<PhysicalFileSystemCacheOptions>(options =>
{
Settings =
{
[PhysicalFileSystemCache.Folder] = PhysicalFileSystemCache.DefaultCacheFolder
}
options.CacheFolder = "is-cache";
})
.SetCache(provider =>
{
return new PhysicalFileSystemCache(
provider.GetRequiredService<IOptions<PhysicalFileSystemCacheOptions>>(),
provider.GetRequiredService<IHostingEnvironment>(),
provider.GetRequiredService<IOptions<ImageSharpMiddlewareOptions>>(),
provider.GetRequiredService<FormatUtilities>());
})
.SetCacheHash<CacheHash>()
.AddProvider<PhysicalFileSystemProvider>()
Expand All @@ -40,7 +46,7 @@ public void ConfigureServices(IServiceCollection services)

// Add the default service and options.
//
//services.AddImageSharp();
// services.AddImageSharp();

// Or add the default service and custom options.
//
Expand Down Expand Up @@ -74,15 +80,9 @@ private void ConfigureDefaultServicesAndCustomOptions(IServiceCollection service

private void ConfigureCustomServicesAndDefaultOptions(IServiceCollection services)
{
services.AddImageSharpCore()
.SetRequestParser<QueryCollectionRequestParser>()
.SetMemoryAllocator<ArrayPoolMemoryAllocator>()
.SetCache<PhysicalFileSystemCache>()
.SetCacheHash<CacheHash>()
.AddProvider<PhysicalFileSystemProvider>()
.AddProcessor<ResizeWebProcessor>()
.AddProcessor<FormatWebProcessor>()
.AddProcessor<BackgroundColorWebProcessor>();
services.AddImageSharp()
.RemoveProcessor<FormatWebProcessor>()
.RemoveProcessor<BackgroundColorWebProcessor>();
}

private void ConfigureCustomServicesAndCustomOptions(IServiceCollection services)
Expand All @@ -101,17 +101,18 @@ private void ConfigureCustomServicesAndCustomOptions(IServiceCollection services
})
.SetRequestParser<QueryCollectionRequestParser>()
.SetMemoryAllocator(provider => ArrayPoolMemoryAllocator.CreateWithMinimalPooling())
.Configure<PhysicalFileSystemCacheOptions>(options =>
{
options.CacheFolder = "different-cache";
})
.SetCache(provider =>
{
var p = new PhysicalFileSystemCache(
provider.GetRequiredService<IHostingEnvironment>(),
provider.GetRequiredService<MemoryAllocator>(),
provider.GetRequiredService<IOptions<ImageSharpMiddlewareOptions>>());

p.Settings[PhysicalFileSystemCache.Folder] = PhysicalFileSystemCache.DefaultCacheFolder;

return p;
})
{
return new PhysicalFileSystemCache(
provider.GetRequiredService<IOptions<PhysicalFileSystemCacheOptions>>(),
provider.GetRequiredService<IHostingEnvironment>(),
provider.GetRequiredService<IOptions<ImageSharpMiddlewareOptions>>(),
provider.GetRequiredService<FormatUtilities>());
})
.SetCacheHash<CacheHash>()
.AddProvider<PhysicalFileSystemProvider>()
.AddProcessor<ResizeWebProcessor>()
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<AssemblyTitle>SixLabors.ImageSharp.Web.Providers.Azure</AssemblyTitle>
<Authors>Six Labors and contributors</Authors>
<Company>Six Labors</Company>
<Copyright>Copyright (c) Six Labors and contributors.</Copyright>
<Product>SixLabors.ImageSharp.Web.Providers.Azure</Product>
<Description>A provider for resolving images via Azure Blob Storage.</Description>
<NeutralLanguage>en</NeutralLanguage>

<TargetFramework>netstandard2.0</TargetFramework>
<LangVersion>7.3</LangVersion>

<GenerateDocumentationFile>true</GenerateDocumentationFile>
<AssemblyName>SixLabors.ImageSharp.Web.Providers.Azure</AssemblyName>
<PackageId>SixLabors.ImageSharp.Web.Providers.Azure</PackageId>
<PackageTags>Image Middleware Resize Crop Gif Jpg Jpeg Bitmap Png Azure</PackageTags>
<PackageIconUrl>https://raw.githubusercontent.com/SixLabors/Branding/master/icons/imagesharp/sixlabors.imagesharp.128.png</PackageIconUrl>
<PackageProjectUrl>https://github.com/SixLabors/ImageSharp.Web</PackageProjectUrl>
<PackageLicenseUrl>http://www.apache.org/licenses/LICENSE-2.0</PackageLicenseUrl>
<RepositoryType>git</RepositoryType>
<RepositoryUrl>https://github.com/SixLabors/ImageSharp.Web</RepositoryUrl>

<DebugType Condition="$(codecov) != ''">full</DebugType>
<DebugType Condition="$(codecov) == ''">portable</DebugType>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.Azure.KeyVault.Core" Version="3.0.1" />
<PackageReference Include="Microsoft.Azure.Storage.Blob" Version="10.0.2" />
<PackageReference Include="StyleCop.Analyzers" Version="1.1.118">
<PrivateAssets>All</PrivateAssets>
</PackageReference>
</ItemGroup>

<ItemGroup>
<Compile Include="..\Shared\*.cs" Exclude="bin\**;obj\**;**\*.xproj;packages\**" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\ImageSharp.Web\ImageSharp.Web.csproj" />
</ItemGroup>

<PropertyGroup>
<CodeAnalysisRuleSet>..\..\standards\SixLabors.ruleset</CodeAnalysisRuleSet>
<RootNamespace>SixLabors.ImageSharp.Web</RootNamespace>
</PropertyGroup>

<ItemGroup>
<AdditionalFiles Include="..\..\standards\stylecop.json" />
</ItemGroup>

<PropertyGroup Condition=" '$(Configuration)' == 'Release' ">
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
</PropertyGroup>
</Project>
Loading

0 comments on commit 75fd113

Please sign in to comment.