Skip to content

Commit

Permalink
updated dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
goncalo-oliveira committed Aug 26, 2024
1 parent 7304c07 commit 49119e9
Show file tree
Hide file tree
Showing 5 changed files with 88 additions and 28 deletions.
54 changes: 32 additions & 22 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,18 +1,20 @@
# Build the application
#FROM mcr.microsoft.com/dotnet/sdk:7.0 as build
FROM --platform=$BUILDPLATFORM mcr.microsoft.com/dotnet/nightly/sdk:8.0-preview AS build
ARG TARGETARCH
WORKDIR /app
# syntax=docker/dockerfile:1.3

# Create a stage for building the application.
FROM --platform=$BUILDPLATFORM mcr.microsoft.com/dotnet/sdk:8.0-alpine AS build
ENV DOTNET_CLI_TELEMETRY_OPTOUT 1

# restore dependencies
COPY ./src/faas-metrics.csproj ./
RUN dotnet restore -a $TARGETARCH
COPY src /source

COPY ./src/. ./
WORKDIR /source

# This is the architecture you’re building for, which is passed in by the builder.
# Placing it here allows the previous steps to be cached across architectures.
ARG TARGETARCH

# generate random password for self-signed certificate
RUN cat /dev/urandom | LC_ALL=C tr -dc 'a-zA-Z0-9' | fold -w 12 | head -n 1 > certpassword
RUN truncate -s -1 certpassword
RUN sed -i '$ d' certpassword

# generate self-signed certificate
#RUN dotnet dev-certs https -ep dist/cert.pfx -p $(cat certpassword) -v
Expand All @@ -21,18 +23,26 @@ RUN truncate -s -1 certpassword
RUN sed -i'' s/'CertFilename = string.Empty/CertFilename = "cert.pfx"'/ HttpsOptions.cs
RUN sed -i'' s/'CertPassword = string.Empty/CertPassword = "'$(cat certpassword | base64)'"'/ HttpsOptions.cs

# build application
RUN dotnet publish -c release -a $TARGETARCH -o dist faas-metrics.csproj

# The runner for the application
FROM mcr.microsoft.com/dotnet/aspnet:7.0 as final

RUN addgroup faas-metrics && useradd -G faas-metrics metrics-user

# Build the application.
# Leverage a cache mount to /root/.nuget/packages so that subsequent builds don't have to re-download packages.
# If TARGETARCH is "amd64", replace it with "x64" - "x64" is .NET's canonical name for this and "amd64" doesn't
# work in .NET 6.0.
RUN --mount=type=cache,id=nuget,target=/root/.nuget/packages \
dotnet publish -a ${TARGETARCH/amd64/x64} --use-current-runtime --self-contained false -o /app

# Create a new stage for running the application that contains the minimal
# runtime dependencies for the application. This often uses a different base
# image from the build stage where the necessary files are copied from the build
# stage.
FROM mcr.microsoft.com/dotnet/aspnet:8.0-alpine AS final
WORKDIR /app
COPY --from=build /app/dist/ ./
RUN chown metrics-user:faas-metrics -R .

USER metrics-user
# Copy everything needed to run the app from the "build" stage.
COPY --from=build /app .

# Switch to a non-privileged user (defined in the base image) that the app will run under.
# See https://docs.docker.com/go/dockerfile-user-best-practices/
# and https://github.com/dotnet/dotnet-docker/discussions/4764
USER $APP_UID

ENTRYPOINT [ "dotnet", "faas-metrics.dll" ]
ENTRYPOINT ["dotnet", "faas-metrics.dll"]
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@

END OF TERMS AND CONDITIONS

Copyright 2023 Goncalo Oliveira
Copyright 2024 Goncalo Oliveira

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand Down
25 changes: 25 additions & 0 deletions metrics.sln
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.5.002.0
MinimumVisualStudioVersion = 10.0.40219.1
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "faas-metrics", "src\faas-metrics.csproj", "{FDCFBC51-D7A7-4D1A-9FBE-9626D034E822}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{FDCFBC51-D7A7-4D1A-9FBE-9626D034E822}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{FDCFBC51-D7A7-4D1A-9FBE-9626D034E822}.Debug|Any CPU.Build.0 = Debug|Any CPU
{FDCFBC51-D7A7-4D1A-9FBE-9626D034E822}.Release|Any CPU.ActiveCfg = Release|Any CPU
{FDCFBC51-D7A7-4D1A-9FBE-9626D034E822}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {A5213363-8D95-455E-BCDC-594F3DB7B6A0}
EndGlobalSection
EndGlobal
23 changes: 23 additions & 0 deletions src/AppVersion.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
using System.Reflection;

namespace System;

internal static class AppVersion
{
private static readonly Lazy<string> lazyValue = new( () =>
{
var assembly = Assembly.GetExecutingAssembly();
var value = assembly.GetName().Version?.ToString( 3 ) ?? "0.0.0";
var infoVerAttr = assembly.GetCustomAttribute<AssemblyInformationalVersionAttribute>();
if ( infoVerAttr != null )
{
return infoVerAttr.InformationalVersion;
}
return value;
} );

public static string Value => lazyValue.Value;
}
12 changes: 7 additions & 5 deletions src/faas-metrics.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,18 @@

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net7.0</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
<RootNamespace>Faactory.Kubernetes.Metrics</RootNamespace>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>

<Version>0.2.0</Version>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.Extensions.Configuration.CommandLine" Version="7.0.0" />
<PackageReference Include="System.CommandLine" Version="2.0.0-beta4.22272.1" />
<PackageReference Include="YamlDotNet" Version="13.0.1" />
<ItemGroup>
<PackageReference Include="Microsoft.Extensions.Configuration.CommandLine" Version="8.0.0" />
<PackageReference Include="System.CommandLine" Version="2.0.0-beta4.22272.1" />
<PackageReference Include="YamlDotNet" Version="16.0.0" />
</ItemGroup>

</Project>

0 comments on commit 49119e9

Please sign in to comment.