Browse Source

Pass version to build.

pull/381/head
Sebastian Stehle 7 years ago
parent
commit
4f0f02a4f8
  1. 6
      .drone.yml
  2. 7
      Dockerfile
  3. 4
      Dockerfile.build
  4. 11
      src/Squidex.Web/ExposedValues.cs
  5. 2
      src/Squidex/Config/Web/WebServices.cs
  6. 10
      tests/Squidex.Web.Tests/ExposedValuesTests.cs

6
.drone.yml

@ -20,7 +20,7 @@ steps:
image: docker
commands:
- docker login -u $DOCKER_USERNAME -p $DOCKER_PASSWORD
- docker build -t squidex/squidex:dev -t squidex/squidex:dev-$${DRONE_BUILD_NUMBER} .
- docker build -t squidex/squidex:dev -t squidex/squidex:dev-$${DRONE_BUILD_NUMBER} --build-arg SQUIDEX__VERSION=dev-$${DRONE_BUILD_NUMBER} .
- docker push squidex/squidex:dev
- docker push squidex/squidex:dev-$${DRONE_BUILD_NUMBER}
volumes:
@ -43,7 +43,7 @@ steps:
image: docker
commands:
- docker login -u $DOCKER_USERNAME -p $DOCKER_PASSWORD
- docker build -t squidex/squidex:latest -t squidex/squidex:$${DRONE_TAG} .
- docker build -t squidex/squidex:latest -t squidex/squidex:$${DRONE_TAG} --build-arg SQUIDEX__VERSION=$${DRONE_TAG} .
- docker push squidex/squidex:latest
- docker push squidex/squidex:$${DRONE_TAG}
volumes:
@ -63,7 +63,7 @@ steps:
- name: build_binaries
image: docker
commands:
- docker build . -t squidex-build-image -f Dockerfile.build
- docker build -t squidex-build-image -f Dockerfile.build --build-arg SQUIDEX__VERSION=$${DRONE_TAG} .
- docker create --name squidex-build-container squidex-build-image
- docker cp squidex-build-container:/out /build
volumes:

7
Dockerfile

@ -3,6 +3,8 @@
#
FROM squidex/dotnet:2.2-sdk-chromium-phantomjs-node as builder
ARG SQUIDEX__VERSION=3.0.0
WORKDIR /src
# Copy Node project files.
@ -35,7 +37,7 @@ RUN dotnet test tests/Squidex.Infrastructure.Tests/Squidex.Infrastructure.Tests.
&& dotnet test tests/Squidex.Web.Tests/Squidex.Web.Tests.csproj
# Publish
RUN dotnet publish src/Squidex/Squidex.csproj --output /out/alpine --configuration Release -r alpine.3.7-x64
RUN dotnet publish src/Squidex/Squidex.csproj --output /out/alpine --configuration Release -r alpine.3.7-x64 -p:version=$SQUIDEX__VERSION
#
# Stage 2, Build runtime
@ -55,9 +57,6 @@ RUN apk update \
# Copy from build stage
COPY --from=builder /out/alpine .
ARG SQUIDEX__VERSION
ENV SQUIDEX__VERSION ${SQUIDEX__VERSION:-dev}
EXPOSE 80
EXPOSE 11111

4
Dockerfile.build

@ -1,5 +1,7 @@
FROM squidex/dotnet:2.2-sdk-chromium-phantomjs-node as builder
ARG SQUIDEX__VERSION=3.0.0
WORKDIR /src
# Copy Node project files.
@ -32,4 +34,4 @@ RUN dotnet test tests/Squidex.Infrastructure.Tests/Squidex.Infrastructure.Tests.
&& dotnet test tests/Squidex.Web.Tests/Squidex.Web.Tests.csproj
# Publish
RUN dotnet publish src/Squidex/Squidex.csproj --output /out/ --configuration Release
RUN dotnet publish src/Squidex/Squidex.csproj --output /out/ --configuration Release -p:version=$SQUIDEX__VERSION

11
src/Squidex.Web/ExposedValues.cs

@ -6,6 +6,7 @@
// ==========================================================================
using System.Collections.Generic;
using System.Reflection;
using System.Text;
using Microsoft.Extensions.Configuration;
using Squidex.Infrastructure;
@ -18,7 +19,7 @@ namespace Squidex.Web
{
}
public ExposedValues(ExposedConfiguration configured, IConfiguration configuration)
public ExposedValues(ExposedConfiguration configured, IConfiguration configuration, Assembly assembly = null)
{
Guard.NotNull(configured, nameof(configured));
Guard.NotNull(configuration, nameof(configuration));
@ -32,6 +33,14 @@ namespace Squidex.Web
this[kvp.Key] = value;
}
}
if (assembly != null)
{
if (!ContainsKey("version"))
{
this["version"] = assembly.GetName().Version.ToString();
}
}
}
public override string ToString()

2
src/Squidex/Config/Web/WebServices.cs

@ -22,7 +22,7 @@ namespace Squidex.Config.Web
{
public static void AddMyMvcWithPlugins(this IServiceCollection services, IConfiguration config)
{
services.AddSingletonAs(c => new ExposedValues(c.GetRequiredService<IOptions<ExposedConfiguration>>().Value, config))
services.AddSingletonAs(c => new ExposedValues(c.GetRequiredService<IOptions<ExposedConfiguration>>().Value, config, typeof(WebServices).Assembly))
.AsSelf();
services.AddSingletonAs<FileCallbackResultExecutor>()

10
tests/Squidex.Web.Tests/ExposedValuesTests.cs

@ -35,6 +35,16 @@ namespace Squidex.Web
Assert.Equal("value2", values["name2"]);
}
[Fact]
public void Should_use_version_from_assembly()
{
var source = new ExposedConfiguration();
var values = new ExposedValues(source, A.Fake<IConfiguration>(), typeof(ExposedValuesTests).Assembly);
Assert.Equal("1.0.0.0", values["version"]);
}
[Fact]
public void Should_format_empty_values()
{

Loading…
Cancel
Save