Skip to content
This repository has been archived by the owner on Oct 23, 2021. It is now read-only.

Commit

Permalink
Add support for Apple M1 as development platform. (#431)
Browse files Browse the repository at this point in the history
* Update backend base container images and frontend dependencies to support development on Apple M1

* Update remaining dependencies (except Stripe API)

* Upgrade backend

* Remove useless comment in Dockerfile

* Update test job to latest docker as well

* Upgrade mailchimp (no longer suited for DI)

* Specify build node version for Netlify

Co-authored-by: Gilles Magalhaes <[email protected]>
Co-authored-by: Tim Stokman <[email protected]>
  • Loading branch information
3 people committed Jul 24, 2021
1 parent 6b874ad commit 5aa7951
Show file tree
Hide file tree
Showing 117 changed files with 6,095 additions and 5,310 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/test_backend.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ on:
jobs:
test_backend:
runs-on: ubuntu-latest
container: mcr.microsoft.com/dotnet/core/sdk:3.1-buster
container: mcr.microsoft.com/dotnet/sdk:5.0

env:
Db: CollActionDb
Expand Down
19 changes: 12 additions & 7 deletions CollAction.Tests/CollAction.Tests.csproj
Original file line number Diff line number Diff line change
@@ -1,26 +1,31 @@
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>netcoreapp3.1</TargetFramework>
<TargetFramework>net5.0</TargetFramework>
<UserSecretsId>aspnet-CollAction-29a5d7b8-3530-4482-9ed6-572bd6c178fa</UserSecretsId>
<LangVersion>8.0</LangVersion>
<LangVersion>9.0</LangVersion>
<PreserveCompilationReferences>true</PreserveCompilationReferences>
<PreserveCompilationContext>true</PreserveCompilationContext>
<AnalysisMode>AllEnabledByDefault</AnalysisMode>
<ApplicationIcon />
<OutputType>Library</OutputType>
<StartupObject />
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.TestHost" Version="3.1.4" />
<PackageReference Include="Microsoft.CodeAnalysis.FxCopAnalyzers" Version="2.9.9">
<PackageReference Include="Microsoft.AspNetCore.TestHost" Version="5.0.8" />
<PackageReference Include="Microsoft.CodeAnalysis.NetAnalyzers" Version="5.0.3">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Moq" Version="4.14.1" />
<PackageReference Include="Verify.Xunit" Version="5.1.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.10.0" />
<PackageReference Include="Moq" Version="4.16.1" />
<PackageReference Include="Verify.Xunit" Version="11.20.3" />
<PackageReference Include="xunit" Version="2.4.1" />
<PackageReference Include="xunit.runner.console" Version="2.4.1">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.1">
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.3">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
Expand Down
3 changes: 3 additions & 0 deletions CollAction.Tests/GlobalSuppressions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,13 @@
// Crowdaction-level suppressions either have no target or are given
// a specific target and scoped to a namespace, type, member, etc.

using System;
using System.Diagnostics.CodeAnalysis;

[assembly:CLSCompliant(false)]
[assembly: SuppressMessage("Design", "CA1062:Validate arguments of public methods", Justification = "Test project")]
[assembly: SuppressMessage("Globalization", "CA1303:Do not pass literals as localized parameters", Justification = "Test project")]
[assembly: SuppressMessage("Usage", "CA1816:Dispose methods should call SuppressFinalize", Justification = "Test project")]
[assembly: SuppressMessage("Design", "CA1063:Implement IDisposable Correctly", Justification = "Test project")]
[assembly: SuppressMessage("Reliability", "CA2007:Consider calling ConfigureAwait on the awaited task", Justification = "Not needed in test project")]
[assembly: SuppressMessage("Security", "CA5394: Do not use insecure randomness", Justification = "We're not using randomness for security")]
55 changes: 28 additions & 27 deletions CollAction/CollAction.csproj
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>netcoreapp3.1</TargetFramework>
<TargetFramework>net5.0</TargetFramework>
<UserSecretsId>aspnet-CollAction-29a5d7b8-3530-4482-9ed6-572bd6c178fa</UserSecretsId>
<LangVersion>8.0</LangVersion>
<LangVersion>9.0</LangVersion>
<Nullable>enable</Nullable>
<PreserveCompilationReferences>true</PreserveCompilationReferences>
<PreserveCompilationContext>true</PreserveCompilationContext>
<AnalysisMode>AllEnabledByDefault</AnalysisMode>
</PropertyGroup>
<ItemGroup>
<Content Remove="Views\Emails\CrowdactionAddedAdmin.cshtml" />
Expand Down Expand Up @@ -34,43 +35,43 @@

<ItemGroup>
<PackageReference Include="AspNetCore.IServiceCollection.AddIUrlHelper" Version="1.1.0" />
<PackageReference Include="AWSSDK.S3" Version="3.3.111.2" />
<PackageReference Include="AWSSDK.SimpleEmail" Version="3.3.101.152" />
<PackageReference Include="Faker.Net" Version="1.3.77" />
<PackageReference Include="AWSSDK.S3" Version="3.7.1.16" />
<PackageReference Include="AWSSDK.SimpleEmail" Version="3.7.0.44" />
<PackageReference Include="Faker.Net" Version="1.5.138" />
<PackageReference Include="GraphiQL" Version="2.0.0" />
<PackageReference Include="GraphQL" Version="2.4.0" />
<PackageReference Include="GraphQL.Authorization" Version="2.1.29" />
<PackageReference Include="GraphQL.EntityFramework" Version="9.4.0" />
<PackageReference Include="Hangfire.AspNetCore" Version="1.7.11" />
<PackageReference Include="Hangfire.PostgreSql" Version="1.6.4.2" />
<PackageReference Include="HtmlAgilityPack" Version="1.11.23" />
<PackageReference Include="HtmlSanitizer" Version="5.0.372" />
<PackageReference Include="MailChimp.Net.V3" Version="4.2.1" />
<PackageReference Include="Microsoft.ApplicationInsights.AspNetCore" Version="2.14.0" />
<PackageReference Include="Microsoft.AspNetCore.Authentication.Facebook" Version="3.1.4" />
<PackageReference Include="Microsoft.AspNetCore.Authentication.Google" Version="3.1.4" />
<PackageReference Include="Microsoft.AspNetCore.Authentication.Twitter" Version="3.1.4" />
<PackageReference Include="Microsoft.AspNetCore.DataProtection.EntityFrameworkCore" Version="3.1.4" />
<PackageReference Include="Microsoft.AspNetCore.Identity.EntityFrameworkCore" Version="3.1.4" />
<PackageReference Include="Microsoft.AspNetCore.Mvc.NewtonsoftJson" Version="3.1.4" />
<PackageReference Include="Microsoft.CodeAnalysis.FxCopAnalyzers" Version="2.9.9">
<PackageReference Include="Hangfire.AspNetCore" Version="1.7.24" />
<PackageReference Include="Hangfire.PostgreSql" Version="1.8.5.4" />
<PackageReference Include="HtmlAgilityPack" Version="1.11.34" />
<PackageReference Include="HtmlSanitizer" Version="5.0.404" />
<PackageReference Include="MailChimp.Net.V3" Version="5.2.0" />
<PackageReference Include="Microsoft.ApplicationInsights.AspNetCore" Version="2.17.0" />
<PackageReference Include="Microsoft.AspNetCore.Authentication.Facebook" Version="5.0.8" />
<PackageReference Include="Microsoft.AspNetCore.Authentication.Google" Version="5.0.8" />
<PackageReference Include="Microsoft.AspNetCore.Authentication.Twitter" Version="5.0.8" />
<PackageReference Include="Microsoft.AspNetCore.DataProtection.EntityFrameworkCore" Version="5.0.8" />
<PackageReference Include="Microsoft.AspNetCore.Identity.EntityFrameworkCore" Version="5.0.8" />
<PackageReference Include="Microsoft.AspNetCore.Mvc.NewtonsoftJson" Version="5.0.8" />
<PackageReference Include="Microsoft.CodeAnalysis.NetAnalyzers" Version="5.0.3">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="3.1.4" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="3.1.4" PrivateAssets="all">
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="5.0.8" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="5.0.8" PrivateAssets="all">
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.Extensions.Diagnostics.HealthChecks.EntityFrameworkCore" Version="3.1.4" />
<PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="3.1.3" PrivateAssets="All" />
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="3.1.3" />
<PackageReference Include="Microsoft.Extensions.Diagnostics.HealthChecks.EntityFrameworkCore" Version="5.0.8" />
<PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="5.0.2" PrivateAssets="All" />
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="5.0.7" />
<PackageReference Include="RazorLight" Version="2.0.0-beta9" />
<PackageReference Include="Serilog.AspNetCore" Version="3.2.0" />
<PackageReference Include="Serilog.AspNetCore" Version="4.1.0" />
<PackageReference Include="Serilog.Extensions.Logging" Version="3.0.1" />
<PackageReference Include="Serilog.Sinks.ApplicationInsights" Version="3.1.0" />
<PackageReference Include="Serilog.Sinks.Console" Version="3.1.1" />
<PackageReference Include="Serilog.Sinks.Slack" Version="1.2.63" />
<PackageReference Include="SixLabors.ImageSharp" Version="1.0.0-beta0007" />
<PackageReference Include="Serilog.Sinks.Console" Version="4.0.0" />
<PackageReference Include="Serilog.Sinks.Slack" Version="2.0.3" />
<PackageReference Include="SixLabors.ImageSharp" Version="1.0.3" />
<PackageReference Include="Stripe.net" Version="26.0.0" />
</ItemGroup>
</Project>
14 changes: 8 additions & 6 deletions CollAction/Controllers/GraphQlController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
using Microsoft.AspNetCore.Mvc.ModelBinding;
using Microsoft.Extensions.Caching.Memory;
using Microsoft.Extensions.Logging;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using System;
using System.Collections.Generic;
Expand Down Expand Up @@ -47,13 +48,14 @@ public CacheKey(string query, JObject? variables)
public bool Equals([AllowNull] CacheKey? other)
=> other != null &&
Query == other.Query &&
jtokenComparer.Equals(Variables, other.Variables);
((Variables == null && other.Variables == null) ||
(Variables != null && other.Variables != null && jtokenComparer.Equals(Variables, other.Variables)));

public override bool Equals(object? obj)
=> Equals(obj as CacheKey);

public override int GetHashCode()
=> HashCode.Combine(Query, jtokenComparer.GetHashCode(Variables));
=> Variables == null ? -1 : HashCode.Combine(Query, jtokenComparer.GetHashCode(Variables));
}

public GraphQlController(ISchema schema, IDocumentExecuter executer, IEnumerable<IValidationRule> validationRules, ApplicationDbContext context, ILogger<GraphQlController> logger, IServiceProvider serviceProvider, IMemoryCache cache)
Expand All @@ -70,7 +72,7 @@ public GraphQlController(ISchema schema, IDocumentExecuter executer, IEnumerable
[HttpPost]
public Task<ExecutionResult> Post([BindRequired, FromBody] GraphQlPostBody body, CancellationToken cancellation)
{
if (!User.Identity.IsAuthenticated && body.Query.StartsWith("query", StringComparison.OrdinalIgnoreCase))
if (!(User.Identity?.IsAuthenticated ?? false) && body.Query.StartsWith("query", StringComparison.OrdinalIgnoreCase))
{
logger.LogInformation("Executing graphql query with caching");
return cache.GetOrCreateAsync(
Expand All @@ -93,7 +95,7 @@ public Task<ExecutionResult> Post([BindRequired, FromBody] GraphQlPostBody body,
public Task<ExecutionResult> Get([FromQuery] GraphQlGetQuery getQuery, CancellationToken cancellation)
{
JObject? jsonVariables = ParseVariables(getQuery.Variables);
if (!User.Identity.IsAuthenticated && getQuery.Query.StartsWith("query", StringComparison.OrdinalIgnoreCase))
if (!(User.Identity?.IsAuthenticated ?? false) && getQuery.Query.StartsWith("query", StringComparison.OrdinalIgnoreCase))
{
logger.LogInformation("Executing graphql query with caching");
return cache.GetOrCreateAsync(
Expand Down Expand Up @@ -123,9 +125,9 @@ public Task<ExecutionResult> Get([FromQuery] GraphQlGetQuery getQuery, Cancellat
{
return JObject.Parse(variables);
}
catch (Exception exception)
catch (JsonReaderException exception)
{
throw new Exception("Could not parse variables.", exception);
throw new InvalidOperationException("Could not parse variables.", exception);
}
}

Expand Down
2 changes: 1 addition & 1 deletion CollAction/Controllers/HomeController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public async Task<IActionResult> Sitemap(CancellationToken token)
XDocument sitemap = await sitemapService.GetSitemap(token).ConfigureAwait(false);
return new ContentResult()
{
Content = sitemap.Declaration.ToString() + sitemap.ToString(SaveOptions.DisableFormatting),
Content = $"{sitemap.Declaration}{sitemap.ToString(SaveOptions.DisableFormatting)}",
ContentType = "text/xml",
StatusCode = 200
};
Expand Down
5 changes: 2 additions & 3 deletions CollAction/Data/ApplicationDbContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ protected override void OnModelCreating(ModelBuilder builder)
.HasAlternateKey(t => t.Name);
builder.Entity<Crowdaction>()
.HasIndex(c => c.Name)
.HasName("IX_Crowdactions_Name").IsUnique();
.HasDatabaseName("IX_Crowdactions_Name").IsUnique();
builder.Entity<Crowdaction>()
.HasMany(c => c.Comments)
.WithOne(c => c.Crowdaction!)
Expand Down Expand Up @@ -87,8 +87,7 @@ protected override void OnModelCreating(ModelBuilder builder)

// All stored dates are UTC
ValueConverter<DateTime, DateTime> dateTimeConverter =
new ValueConverter<DateTime, DateTime>(
v => v, v => DateTime.SpecifyKind(v, DateTimeKind.Utc));
new(v => v, v => DateTime.SpecifyKind(v, DateTimeKind.Utc));

foreach (IMutableEntityType entityType in builder.Model.GetEntityTypes())
{
Expand Down
4 changes: 2 additions & 2 deletions CollAction/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM mcr.microsoft.com/dotnet/core/sdk:3.1-buster AS build
FROM mcr.microsoft.com/dotnet/sdk:5.0 AS build
ARG BUILD_CONFIG=Release
ARG DOTNET_CLI_TELEMETRY_OPTOUT=1
WORKDIR /src
Expand All @@ -10,7 +10,7 @@ RUN dotnet build CollAction.csproj -c $BUILD_CONFIG -o /app/build
RUN dotnet publish CollAction.csproj -c $BUILD_CONFIG -o /app/publish
RUN if [ "$BUILD_CONFIG" = "Debug" ] ; then dotnet dev-certs https -ep /app/publish/collaction.pfx -p test ; else echo skipping ssl ; fi

FROM mcr.microsoft.com/dotnet/core/aspnet:3.1-buster-slim
FROM mcr.microsoft.com/dotnet/aspnet:5.0-alpine
WORKDIR /app
COPY --from=build /app/publish .
ENTRYPOINT ["dotnet", "CollAction.dll"]
13 changes: 8 additions & 5 deletions CollAction/GlobalSuppressions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,11 @@
// Project-level suppressions either have no target or are given
// a specific target and scoped to a namespace, type, member, etc.

[assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1031:Do not catch general exception types", Justification = "Too many exceptions to this rule, also seems a little buggy")]
[assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Globalization", "CA1303:Do not pass literals as localized parameters", Justification = "We're not internationalized currently")]
[assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Globalization", "CA1308:Normalize strings to uppercase", Justification = "We're mostly not normalizing strings when we're doing ToLower")]
[assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2227:Collection properties should be read only", Justification = "Property setters needed for EF core and for options objects")]
[assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1062:Validate arguments of public methods", Justification = "We're not a library")]
using System.Diagnostics.CodeAnalysis;

[assembly: SuppressMessage("Design", "CA1031:Do not catch general exception types", Justification = "Too many exceptions to this rule, also seems a little buggy")]
[assembly: SuppressMessage("Globalization", "CA1303:Do not pass literals as localized parameters", Justification = "We're not internationalized currently")]
[assembly: SuppressMessage("Globalization", "CA1308:Normalize strings to uppercase", Justification = "We're mostly not normalizing strings when we're doing ToLower")]
[assembly: SuppressMessage("Usage", "CA2227:Collection properties should be read only", Justification = "Property setters needed for EF core and for options objects")]
[assembly: SuppressMessage("Design", "CA1062:Validate arguments of public methods", Justification = "We're not a library")]
[assembly: SuppressMessage("Security", "CA5394: Do not use insecure randomness", Justification = "We're not using randomness for security")]
6 changes: 3 additions & 3 deletions CollAction/Helpers/ValidationHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,22 +9,22 @@ namespace CollAction.Helpers
{
public static class ValidationHelper
{
public static IEnumerable<ValidationResult> Validate<TItem>(TItem item, IServiceProvider serviceProvider)
public static IEnumerable<ValidationResult> Validate<TItem>(TItem item, IServiceProvider serviceProvider) where TItem: class
{
var validationContext = new ValidationContext(item, serviceProvider: serviceProvider, items: null);
var validationResults = new List<ValidationResult>();
Validator.TryValidateObject(item, validationContext, validationResults, true);
return validationResults;
}

public static IEnumerable<IdentityError> ValidateAsIdentity<TItem>(TItem item, IServiceProvider serviceProvider)
public static IEnumerable<IdentityError> ValidateAsIdentity<TItem>(TItem item, IServiceProvider serviceProvider) where TItem: class
=> Validate(item, serviceProvider).Select(ValidationResultToIdentityError);

public static string GetValidationString(this ModelStateDictionary modelState)
=> string.Join(", ", modelState.Values.SelectMany(state => state.Errors).Select(error => error.ErrorMessage));

private static IdentityError ValidationResultToIdentityError(ValidationResult result)
=> new IdentityError()
=> new()
{
Code = string.Join("_", result.MemberNames),
Description = result.ErrorMessage
Expand Down
8 changes: 4 additions & 4 deletions CollAction/Migrations/20170301234659_Initial.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 5aa7951

Please sign in to comment.