Skip to content

Commit

Permalink
Add a TestApp.Cli project to emulate running migrations.
Browse files Browse the repository at this point in the history
Add Helm chart, update build
  • Loading branch information
andrewlock committed Oct 4, 2020
1 parent 6f4a280 commit 68bbac8
Show file tree
Hide file tree
Showing 14 changed files with 214 additions and 1 deletion.
18 changes: 18 additions & 0 deletions helmcharts/TestApp/TestApp.Cli.Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
FROM mcr.microsoft.com/dotnet/core/sdk:3.1-alpine3.12 AS build
WORKDIR /sln

# Copy project file and restore
COPY "./src/TestApp.Cli/TestApp.Cli.csproj" "./src/TestApp.Cli/"
RUN dotnet restore ./src/TestApp.Cli/TestApp.Cli.csproj

# Copy the actual source code
COPY "./src/TestApp.Cli" "./src/TestApp.Cli"

# Build and publish the app
RUN dotnet publish "./src/TestApp.Cli/TestApp.Cli.csproj" -c Release -o /app/publish

#FINAL image
FROM mcr.microsoft.com/dotnet/core/aspnet:3.1-alpine3.12
WORKDIR /app
COPY --from=build /app/publish .
ENTRYPOINT ["dotnet", "TestApp.Cli.dll"]
15 changes: 15 additions & 0 deletions helmcharts/TestApp/TestApp.sln
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TestApp.Api", "src\TestApp.
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TestApp.Service", "src\TestApp.Service\TestApp.Service.csproj", "{E9F0BF62-6816-4AA8-9967-FA7A51D88E21}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TestApp.Cli", "src\TestApp.Cli\TestApp.Cli.csproj", "{DC52C136-F30E-452C-9B98-92B3A89C8161}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -46,9 +48,22 @@ Global
{E9F0BF62-6816-4AA8-9967-FA7A51D88E21}.Release|x64.Build.0 = Release|Any CPU
{E9F0BF62-6816-4AA8-9967-FA7A51D88E21}.Release|x86.ActiveCfg = Release|Any CPU
{E9F0BF62-6816-4AA8-9967-FA7A51D88E21}.Release|x86.Build.0 = Release|Any CPU
{DC52C136-F30E-452C-9B98-92B3A89C8161}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{DC52C136-F30E-452C-9B98-92B3A89C8161}.Debug|Any CPU.Build.0 = Debug|Any CPU
{DC52C136-F30E-452C-9B98-92B3A89C8161}.Debug|x64.ActiveCfg = Debug|Any CPU
{DC52C136-F30E-452C-9B98-92B3A89C8161}.Debug|x64.Build.0 = Debug|Any CPU
{DC52C136-F30E-452C-9B98-92B3A89C8161}.Debug|x86.ActiveCfg = Debug|Any CPU
{DC52C136-F30E-452C-9B98-92B3A89C8161}.Debug|x86.Build.0 = Debug|Any CPU
{DC52C136-F30E-452C-9B98-92B3A89C8161}.Release|Any CPU.ActiveCfg = Release|Any CPU
{DC52C136-F30E-452C-9B98-92B3A89C8161}.Release|Any CPU.Build.0 = Release|Any CPU
{DC52C136-F30E-452C-9B98-92B3A89C8161}.Release|x64.ActiveCfg = Release|Any CPU
{DC52C136-F30E-452C-9B98-92B3A89C8161}.Release|x64.Build.0 = Release|Any CPU
{DC52C136-F30E-452C-9B98-92B3A89C8161}.Release|x86.ActiveCfg = Release|Any CPU
{DC52C136-F30E-452C-9B98-92B3A89C8161}.Release|x86.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(NestedProjects) = preSolution
{3648E36A-D429-448F-B0F8-5FA5106217A0} = {805C705B-1AAF-4911-A058-E5B0271F0CA4}
{E9F0BF62-6816-4AA8-9967-FA7A51D88E21} = {805C705B-1AAF-4911-A058-E5B0271F0CA4}
{DC52C136-F30E-452C-9B98-92B3A89C8161} = {805C705B-1AAF-4911-A058-E5B0271F0CA4}
EndGlobalSection
EndGlobal
2 changes: 1 addition & 1 deletion helmcharts/TestApp/charts/test-app/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ type: application
# This is the chart version. This version number should be incremented each time you make changes
# to the chart and its templates, including the app version.
# Versions are expected to follow Semantic Versioning (https://semver.org/)
version: 0.1.0
version: 0.1.1

# This is the version number of the application being deployed. This version number should be
# incremented each time you make changes to the application. Versions are not expected to
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,13 @@ spec:
serviceAccountName: {{ include "test-app-api.serviceAccountName" . }}
securityContext:
{{- toYaml .Values.podSecurityContext | nindent 8 }}
initContainers:
- name: "{{ .Chart.Name }}-init"
image: "groundnuty/k8s-wait-for:1.3"
imagePullPolicy: {{ .Values.image.pullPolicy }}
args:
- "job"
- "{{ .Release.Name }}-test-app-cli-{{ .Release.Revision}}"
containers:
- name: {{ .Chart.Name }}
securityContext:
Expand Down
23 changes: 23 additions & 0 deletions helmcharts/TestApp/charts/test-app/charts/test-app-cli/Chart.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
apiVersion: v2
name: test-app-cli
description: A Helm chart for Kubernetes

# A chart can be either an 'application' or a 'library' chart.
#
# Application charts are a collection of templates that can be packaged into versioned archives
# to be deployed.
#
# Library charts provide useful utilities or functions for the chart developer. They're included as
# a dependency of application charts to inject those utilities and functions into the rendering
# pipeline. Library charts do not define any templates and therefore cannot be deployed.
type: application

# This is the chart version. This version number should be incremented each time you make changes
# to the chart and its templates, including the app version.
# Versions are expected to follow Semantic Versioning (https://semver.org/)
version: 0.1.1

# This is the version number of the application being deployed. This version number should be
# incremented each time you make changes to the application. Versions are not expected to
# follow Semantic Versioning. They should reflect the version the application is using.
appVersion: 1.16.0
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
{{/*
Expand the name of the chart.
*/}}
{{- define "test-app-cli.name" -}}
{{- default .Chart.Name .Values.nameOverride | trunc 63 | trimSuffix "-" }}
{{- end }}

{{/*
Create a default fully qualified app name.
We truncate at 63 chars because some Kubernetes name fields are limited to this (by the DNS naming spec).
If release name contains chart name it will be used as a full name.
*/}}
{{- define "test-app-cli.fullname" -}}
{{- if .Values.fullnameOverride }}
{{- .Values.fullnameOverride | trunc 63 | trimSuffix "-" }}
{{- else }}
{{- $name := default .Chart.Name .Values.nameOverride }}
{{- if contains $name .Release.Name }}
{{- .Release.Name | trunc 63 | trimSuffix "-" }}
{{- else }}
{{- printf "%s-%s" .Release.Name $name | trunc 63 | trimSuffix "-" }}
{{- end }}
{{- end }}
{{- end }}

{{/*
Create chart name and version as used by the chart label.
*/}}
{{- define "test-app-cli.chart" -}}
{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" }}
{{- end }}

{{/*
Common labels
*/}}
{{- define "test-app-cli.labels" -}}
helm.sh/chart: {{ include "test-app-cli.chart" . }}
{{ include "test-app-cli.selectorLabels" . }}
{{- if .Chart.AppVersion }}
app.kubernetes.io/version: {{ .Chart.AppVersion | quote }}
{{- end }}
app.kubernetes.io/managed-by: {{ .Release.Service }}
{{- end }}

{{/*
Selector labels
*/}}
{{- define "test-app-cli.selectorLabels" -}}
app.kubernetes.io/name: {{ include "test-app-cli.name" . }}
app.kubernetes.io/instance: {{ .Release.Name }}
{{- end }}

{{/*
Create the name of the service account to use
*/}}
{{- define "test-app-cli.serviceAccountName" -}}
{{- if .Values.serviceAccount.create }}
{{- default (include "test-app-cli.fullname" .) .Values.serviceAccount.name }}
{{- else }}
{{- default "default" .Values.serviceAccount.name }}
{{- end }}
{{- end }}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
apiVersion: batch/v1
kind: Job
metadata:
name: {{ include "test-app-cli.fullname" . }}-{{ .Release.Revision }}
labels:
{{- include "test-app-cli.labels" . | nindent 4 }}
spec:
backoffLimit: 1
template:
metadata:
labels:
{{- include "test-app-cli.selectorLabels" . | nindent 8 }}
spec:
containers:
- name: {{ .Chart.Name }}
image: "{{ .Values.image.repository }}:{{ .Values.image.tag | default .Chart.AppVersion }}"
imagePullPolicy: {{ .Values.image.pullPolicy }}
command: ["dotnet"]
args: ["TestApp.Cli.dll", "migrate-database"]
env:

{{- $env := merge (.Values.env | default dict) (.Values.global.env | default dict) -}}
{{ range $k, $v := $env }}
- name: {{ $k | quote }}
value: {{ $v | quote }}
{{- end }}
restartPolicy: {{ .Values.job.restartPolicy }}
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,13 @@ spec:
serviceAccountName: {{ include "test-app-service.serviceAccountName" . }}
securityContext:
{{- toYaml .Values.podSecurityContext | nindent 8 }}
initContainers:
- name: "{{ .Chart.Name }}-init"
image: "groundnuty/k8s-wait-for:1.3"
imagePullPolicy: {{ .Values.image.pullPolicy }}
args:
- "job"
- "{{ .Release.Name }}-test-app-cli-{{ .Release.Revision}}"
containers:
- name: {{ .Chart.Name }}
securityContext:
Expand Down
11 changes: 11 additions & 0 deletions helmcharts/TestApp/charts/test-app/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,17 @@ global:
"ASPNETCORE_ENVIRONMENT": "Staging"
"ASPNETCORE_FORWARDEDHEADERS_ENABLED": "true"

test-app-cli:

image:
repository: andrewlock/my-test-cli
pullPolicy: IfNotPresent
tag: ""

job:
## Should the job be rescheduled on the same node if it fails, or just stopped
restartPolicy: Never

test-app-api:

replicaCount: 1
Expand Down
1 change: 1 addition & 0 deletions helmcharts/TestApp/docker_build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,6 @@ if [ -z "$*" ]; then
exit 1;
fi

docker build -f TestApp.Cli.Dockerfile . -t andrewlock/my-test-cli:$1
docker build -f TestApp.Api.Dockerfile . -t andrewlock/my-test-api:$1
docker build -f TestApp.Service.Dockerfile . -t andrewlock/my-test-service:$1
12 changes: 12 additions & 0 deletions helmcharts/TestApp/src/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
using System;

namespace src
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Hello World!");
}
}
}
14 changes: 14 additions & 0 deletions helmcharts/TestApp/src/TestApp.Cli/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
using System;
using System.Threading;

namespace TestApp.Cli
{
class Program
{
static void Main(string[] args)
{
Thread.Sleep(30_000);
Console.WriteLine("Hello World!");
}
}
}
8 changes: 8 additions & 0 deletions helmcharts/TestApp/src/TestApp.Cli/TestApp.Cli.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp3.1</TargetFramework>
</PropertyGroup>

</Project>
8 changes: 8 additions & 0 deletions helmcharts/TestApp/src/src.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp3.1</TargetFramework>
</PropertyGroup>

</Project>

0 comments on commit 68bbac8

Please sign in to comment.