Skip to content

Commit

Permalink
added form controller, configured azure dev spaces for SimpleCalculat…
Browse files Browse the repository at this point in the history
…orClient for making calls to SimpleCalculator Service.
  • Loading branch information
blitzard7 committed May 3, 2019
1 parent 4d5c776 commit 9ed33ca
Show file tree
Hide file tree
Showing 20 changed files with 440 additions and 48 deletions.
41 changes: 41 additions & 0 deletions SimpleCalculatorClient/Controllers/FormController.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
using Microsoft.AspNetCore.Mvc;
using SimpleCalculatorClient.Models;
using System;
using System.Collections.Generic;
using System.Net.Http;
using System.Threading.Tasks;

namespace SimpleCalculatorClient.Controllers
{
[Route("api/[controller]")]
public class FormController : Controller
{
[HttpGet]
public IActionResult Index()
{
return View();
}

[HttpPost]
public async Task<IActionResult> Index(FormModel model)
{
using (var client = new HttpClient())
{
// Call *mywebapi*, and display its response in the page
var request = new HttpRequestMessage();
var uri = new Uri($"http://default.simplecalculator.z26kl7w9th.weu.azds.io/api/calculator/add?x={model.NumbOne}&y={model.NumbTwo}");
request.RequestUri = uri;
if (this.Request.Headers.ContainsKey("azds-route-as"))
{
// Propagate the dev space routing header
request.Headers.Add("azds-route-as", this.Request.Headers["azds-route-as"] as IEnumerable<string>);
}
var response = await client.SendAsync(request);
var content = await response.Content.ReadAsStringAsync();
ViewData["Message"] += " and " + content;
}

return Content($"First: {model.NumbOne}\nSecond: {model.NumbTwo}");
}
}
}
29 changes: 0 additions & 29 deletions SimpleCalculatorClient/Controllers/HomeController.cs

This file was deleted.

20 changes: 20 additions & 0 deletions SimpleCalculatorClient/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
FROM mcr.microsoft.com/dotnet/core/aspnet:2.2 AS base
WORKDIR /app
EXPOSE 80

FROM mcr.microsoft.com/dotnet/core/sdk:2.2 AS build
WORKDIR /src
COPY ["SimpleCalculatorClient/SimpleCalculatorClient.csproj", "SimpleCalculatorClient/"]

RUN dotnet restore "SimpleCalculatorClient/SimpleCalculatorClient.csproj"
COPY . .
WORKDIR "/src/SimpleCalculatorClient"
RUN dotnet build "SimpleCalculatorClient.csproj" -c Release -o /app

FROM build AS publish
RUN dotnet publish "SimpleCalculatorClient.csproj" -c Release -o /app

FROM base AS final
WORKDIR /app
COPY --from=publish /app .
ENTRYPOINT ["dotnet", "SimpleCalculatorClient.dll"]
17 changes: 17 additions & 0 deletions SimpleCalculatorClient/Dockerfile.develop
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
FROM mcr.microsoft.com/dotnet/core/sdk:2.2
ARG BUILD_CONFIGURATION=Debug
ENV ASPNETCORE_ENVIRONMENT=Development
ENV DOTNET_USE_POLLING_FILE_WATCHER=true
EXPOSE 80

WORKDIR /src
COPY ["SimpleCalculatorClient/SimpleCalculatorClient.csproj", "SimpleCalculatorClient/"]

RUN dotnet restore "SimpleCalculatorClient/SimpleCalculatorClient.csproj"
COPY . .
WORKDIR "/src/SimpleCalculatorClient"
RUN dotnet build --no-restore "SimpleCalculatorClient.csproj" -c $BUILD_CONFIGURATION

RUN echo "exec dotnet run --no-build --no-launch-profile -c $BUILD_CONFIGURATION --" > /entrypoint.sh

ENTRYPOINT ["/bin/bash", "/entrypoint.sh"]
13 changes: 13 additions & 0 deletions SimpleCalculatorClient/Models/FormModel.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace SimpleCalculatorClient.Models
{
public class FormModel
{
public int NumbOne { get; set; }
public int NumbTwo { get; set; }
}
}
17 changes: 12 additions & 5 deletions SimpleCalculatorClient/Properties/launchSettings.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
{
"iisSettings": {
"windowsAuthentication": false,
"anonymousAuthentication": true,
"windowsAuthentication": false,
"anonymousAuthentication": true,
"iisExpress": {
"applicationUrl": "http://localhost:54166",
"sslPort": 44377
Expand All @@ -18,10 +18,17 @@
"SimpleCalculatorClient": {
"commandName": "Project",
"launchBrowser": true,
"applicationUrl": "https://localhost:5001;http://localhost:5000",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
},
"applicationUrl": "https://localhost:5001;http://localhost:5000"
},
"Azure Dev Spaces": {
"commandName": "AzureDevSpaces",
"launchBrowser": true,
"resourceGroup": "AksDemo",
"aksName": "AksDemoCluster",
"subscriptionId": "d5a78503-b800-41a5-a60b-39a580520bc4"
}
}
}
1 change: 1 addition & 0 deletions SimpleCalculatorClient/SimpleCalculatorClient.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.App" />
<PackageReference Include="Microsoft.AspNetCore.Razor.Design" Version="2.2.0" PrivateAssets="All" />
<PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="2.2.3" />
</ItemGroup>

</Project>
13 changes: 13 additions & 0 deletions SimpleCalculatorClient/Views/Form/Index.cshtml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
@model SimpleCalculatorClient.Models.FormModel;
@{
ViewData["Title"] = "Index";
}

<form method="POST">
<label for="numbOne">First number</label>
<input type="text" id="numbOne" placeholder="first number" name="numbOne" />
<br />
<label for="numbTwo">Second number</label>
<input type="text" id="numbTwo" placeholder="second number" name="numbTwo" />
<input type="submit" />
</form>
8 changes: 0 additions & 8 deletions SimpleCalculatorClient/Views/Home/Index.cshtml

This file was deleted.

6 changes: 0 additions & 6 deletions SimpleCalculatorClient/Views/Home/Privacy.cshtml

This file was deleted.

42 changes: 42 additions & 0 deletions SimpleCalculatorClient/azds.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
kind: helm-release
apiVersion: 1.1
build:
context: ..
dockerfile: Dockerfile
install:
chart: charts/simplecalculatorclient
values:
- values.dev.yaml?
- secrets.dev.yaml?
set:
replicaCount: 1
image:
repository: simplecalculatorclient
tag: $(tag)
pullPolicy: Never
ingress:
annotations:
kubernetes.io/ingress.class: traefik-azds
hosts:
# This expands to form the service's public URL: [space.s.][rootSpace.]simplecalculatorclient.<random suffix>.<region>.azds.io
# Customize the public URL by changing the 'simplecalculatorclient' text between the $(rootSpacePrefix) and $(hostSuffix) tokens
# For more information see https://aka.ms/devspaces/routing
- $(spacePrefix)$(rootSpacePrefix)simplecalculatorclient$(hostSuffix)
configurations:
develop:
build:
dockerfile: Dockerfile.develop
useGitIgnore: true
args:
BUILD_CONFIGURATION: ${BUILD_CONFIGURATION:-Debug}
container:
sync:
- "**/Pages/**"
- "**/Views/**"
- "**/wwwroot/**"
- "!**/*.{sln,csproj}"
command: [dotnet, run, --no-restore, --no-build, --no-launch-profile, -c, "${BUILD_CONFIGURATION:-Debug}"]
iterate:
processesToKill: [dotnet, vsdbg]
buildCommands:
- [dotnet, build, --no-restore, -c, "${BUILD_CONFIGURATION:-Debug}"]
21 changes: 21 additions & 0 deletions SimpleCalculatorClient/charts/simplecalculatorclient/.helmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Patterns to ignore when building packages.
# This supports shell glob matching, relative path matching, and
# negation (prefixed with !). Only one pattern per line.
.DS_Store
# Common VCS dirs
.git/
.gitignore
.bzr/
.bzrignore
.hg/
.hgignore
.svn/
# Common backup files
*.swp
*.bak
*.tmp
*~
# Various IDEs
.project
.idea/
*.tmproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
apiVersion: v1
appVersion: "1.0"
description: A Helm chart for Kubernetes
name: simplecalculatorclient
version: 0.1.0
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
1. Get the application URL by running these commands:
{{- if .Values.ingress.enabled }}
{{- range .Values.ingress.hosts }}
http{{ if $.Values.ingress.tls }}s{{ end }}://{{ . }}{{ $.Values.ingress.path }}
{{- end }}
{{- else if contains "NodePort" .Values.service.type }}
export NODE_PORT=$(kubectl get --namespace {{ .Release.Namespace }} -o jsonpath="{.spec.ports[0].nodePort}" services {{ template "simplecalculatorclient.fullname" . }})
export NODE_IP=$(kubectl get nodes --namespace {{ .Release.Namespace }} -o jsonpath="{.items[0].status.addresses[0].address}")
echo http://$NODE_IP:$NODE_PORT
{{- else if contains "LoadBalancer" .Values.service.type }}
NOTE: It may take a few minutes for the LoadBalancer IP to be available.
You can watch the status of by running 'kubectl get svc -w {{ template "simplecalculatorclient.fullname" . }}'
export SERVICE_IP=$(kubectl get svc --namespace {{ .Release.Namespace }} {{ template "simplecalculatorclient.fullname" . }} -o jsonpath='{.status.loadBalancer.ingress[0].ip}')
echo http://$SERVICE_IP:{{ .Values.service.port }}
{{- else if contains "ClusterIP" .Values.service.type }}
export POD_NAME=$(kubectl get pods --namespace {{ .Release.Namespace }} -l "app={{ template "simplecalculatorclient.name" . }},release={{ .Release.Name }}" -o jsonpath="{.items[0].metadata.name}")
echo "Visit http://127.0.0.1:8080 to use your application"
kubectl port-forward $POD_NAME 8080:80
{{- end }}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
{{/* vim: set filetype=mustache: */}}
{{/*
Expand the name of the chart.
*/}}
{{- define "simplecalculatorclient.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 "simplecalculatorclient.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 "simplecalculatorclient.chart" -}}
{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" -}}
{{- end -}}
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
apiVersion: apps/v1beta2
kind: Deployment
metadata:
name: {{ template "simplecalculatorclient.fullname" . }}
labels:
app: {{ template "simplecalculatorclient.name" . }}
chart: {{ template "simplecalculatorclient.chart" . }}
draft: {{ default "draft-app" .Values.draft }}
release: {{ .Release.Name }}
heritage: {{ .Release.Service }}
spec:
replicas: {{ .Values.replicaCount }}
selector:
matchLabels:
app: {{ template "simplecalculatorclient.name" . }}
release: {{ .Release.Name }}
template:
metadata:
labels:
app: {{ template "simplecalculatorclient.name" . }}
draft: {{ default "draft-app" .Values.draft }}
release: {{ .Release.Name }}
annotations:
buildID: {{ .Values.buildID }}
spec:
containers:
- name: {{ .Chart.Name }}
image: "{{ .Values.image.repository }}:{{ .Values.image.tag }}"
imagePullPolicy: {{ .Values.image.pullPolicy }}
ports:
- name: http
containerPort: 80
protocol: TCP
{{- if .Values.probes.enabled }}
livenessProbe:
httpGet:
path: /
port: http
readinessProbe:
httpGet:
path: /
port: http
{{- end }}
env:
{{- $root := . }}
{{- range $ref, $values := .Values.secrets }}
{{- range $key, $value := $values }}
- name: {{ $ref }}_{{ $key }}
valueFrom:
secretKeyRef:
name: {{ template "simplecalculatorclient.fullname" $root }}-{{ $ref | lower }}
key: {{ $key }}
{{- end }}
{{- end }}
resources:
{{ toYaml .Values.resources | indent 12 }}
{{- with .Values.imagePullSecrets }}
imagePullSecrets:
{{ toYaml . | indent 8 }}
{{- end }}
{{- with .Values.nodeSelector }}
nodeSelector:
{{ toYaml . | indent 8 }}
{{- end }}
{{- with .Values.affinity }}
affinity:
{{ toYaml . | indent 8 }}
{{- end }}
{{- with .Values.tolerations }}
tolerations:
{{ toYaml . | indent 8 }}
{{- end }}
Loading

0 comments on commit 9ed33ca

Please sign in to comment.