Skip to content

Commit

Permalink
Add complete devfiles to advanced guides (#6388)
Browse files Browse the repository at this point in the history
  • Loading branch information
valaparthvi authored Dec 8, 2022
1 parent 9815b60 commit ec59ad2
Show file tree
Hide file tree
Showing 4 changed files with 1,515 additions and 0 deletions.
370 changes: 370 additions & 0 deletions docs/website/docs/user-guides/advanced/deploy/dotnet.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,376 @@ import EditingDevfile from './_editing_devfile.mdx';

<EditingDevfile name="dotnet" port="8080"/>

import Tabs from '@theme/Tabs';
import TabItem from '@theme/TabItem';

<details>
<summary> Your final Devfile should look something like this:</summary>

:::note
Your Devfile might slightly vary from the example above, but the example should give you an idea about the placements of all the components and commands.
:::
<Tabs groupId="quickstart">
<TabItem value="kubernetes" label="Kubernetes">

```yaml showLineNumbers
commands:
- exec:
commandLine: kill $(pidof dotnet); dotnet build -c $CONFIGURATION $STARTUP_PROJECT
/p:UseSharedCompilation=false
component: dotnet
group:
isDefault: true
kind: build
workingDir: ${PROJECT_SOURCE}
id: build
- exec:
commandLine: dotnet run -c $CONFIGURATION --no-build --project $STARTUP_PROJECT
--no-launch-profile
component: dotnet
group:
isDefault: true
kind: run
workingDir: ${PROJECT_SOURCE}
id: run
# highlight-start
# This is the main "composite" command that will run all below commands
- id: deploy
composite:
commands:
- build-image
- k8s-deployment
- k8s-service
- k8s-url
group:
isDefault: true
kind: deploy
# Below are the commands and their respective components that they are "linked" to deploy
- id: build-image
apply:
component: outerloop-build
- id: k8s-deployment
apply:
component: outerloop-deployment
- id: k8s-service
apply:
component: outerloop-service
- id: k8s-url
apply:
component: outerloop-url
# highlight-end
components:
- container:
args:
- tail
- -f
- /dev/null
endpoints:
- name: http-dotnet60
targetPort: 8080
env:
- name: CONFIGURATION
value: Debug
- name: STARTUP_PROJECT
value: app.csproj
- name: ASPNETCORE_ENVIRONMENT
value: Development
- name: ASPNETCORE_URLS
value: http://*:8080
image: registry.access.redhat.com/ubi8/dotnet-60:6.0
mountSources: true
name: dotnet
# highlight-start
# This will build the container image before deployment
- name: outerloop-build
image:
dockerfile:
buildContext: ${PROJECT_SOURCE}
rootRequired: false
uri: ./Dockerfile
imageName: "{{CONTAINER_IMAGE}}"
# This will create a Deployment in order to run your container image across
# the cluster.
- name: outerloop-deployment
kubernetes:
inlined: |
kind: Deployment
apiVersion: apps/v1
metadata:
name: {{RESOURCE_NAME}}
spec:
replicas: 1
selector:
matchLabels:
app: {{RESOURCE_NAME}}
template:
metadata:
labels:
app: {{RESOURCE_NAME}}
spec:
containers:
- name: {{RESOURCE_NAME}}
image: {{CONTAINER_IMAGE}}
ports:
- name: http
containerPort: {{CONTAINER_PORT}}
protocol: TCP
resources:
limits:
memory: "1024Mi"
cpu: "500m"
# This will create a Service so your Deployment is accessible.
# Depending on your cluster, you may modify this code so it's a
# NodePort, ClusterIP or a LoadBalancer service.
- name: outerloop-service
kubernetes:
inlined: |
apiVersion: v1
kind: Service
metadata:
name: {{RESOURCE_NAME}}
spec:
ports:
- name: "{{CONTAINER_PORT}}"
port: {{CONTAINER_PORT}}
protocol: TCP
targetPort: {{CONTAINER_PORT}}
selector:
app: {{RESOURCE_NAME}}
type: NodePort
- name: outerloop-url
kubernetes:
inlined: |
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: {{RESOURCE_NAME}}
spec:
rules:
- host: "{{DOMAIN_NAME}}"
http:
paths:
- path: "/"
pathType: Prefix
backend:
service:
name: {{RESOURCE_NAME}}
port:
number: {{CONTAINER_PORT}}
# highlight-end
metadata:
description: Stack with .NET 6.0
displayName: .NET 6.0
icon: https://github.com/dotnet/brand/raw/main/logo/dotnet-logo.png
language: .NET
name: my-dotnet-app
projectType: dotnet
tags:
- .NET
version: 1.0.2
# highlight-next-line
schemaVersion: 2.2.0
starterProjects:
- git:
checkoutFrom:
remote: origin
revision: dotnet-6.0
remotes:
origin: https://github.com/redhat-developer/s2i-dotnetcore-ex
name: dotnet60-example
subDir: app
# highlight-start
# Add the following variables code anywhere in devfile.yaml
# This MUST be a container registry you are able to access
variables:
CONTAINER_IMAGE: quay.io/MYUSERNAME/dotnet-odo-example
RESOURCE_NAME: my-dotnet-app
CONTAINER_PORT: "8080"
DOMAIN_NAME: dotnet.example.com
# highlight-end
```
</TabItem>
<TabItem value="openshift" label="OpenShift">


```yaml showLineNumbers
commands:
- exec:
commandLine: kill $(pidof dotnet); dotnet build -c $CONFIGURATION $STARTUP_PROJECT
/p:UseSharedCompilation=false
component: dotnet
group:
isDefault: true
kind: build
workingDir: ${PROJECT_SOURCE}
id: build
- exec:
commandLine: dotnet run -c $CONFIGURATION --no-build --project $STARTUP_PROJECT
--no-launch-profile
component: dotnet
group:
isDefault: true
kind: run
workingDir: ${PROJECT_SOURCE}
id: run
# highlight-start
# This is the main "composite" command that will run all below commands
- id: deploy
composite:
commands:
- build-image
- k8s-deployment
- k8s-service
- k8s-url
group:
isDefault: true
kind: deploy
# Below are the commands and their respective components that they are "linked" to deploy
- id: build-image
apply:
component: outerloop-build
- id: k8s-deployment
apply:
component: outerloop-deployment
- id: k8s-service
apply:
component: outerloop-service
- id: k8s-url
apply:
component: outerloop-url
# highlight-end
components:
- container:
args:
- tail
- -f
- /dev/null
endpoints:
- name: http-dotnet60
targetPort: 8080
env:
- name: CONFIGURATION
value: Debug
- name: STARTUP_PROJECT
value: app.csproj
- name: ASPNETCORE_ENVIRONMENT
value: Development
- name: ASPNETCORE_URLS
value: http://*:8080
image: registry.access.redhat.com/ubi8/dotnet-60:6.0
mountSources: true
name: dotnet
# highlight-start
# This will build the container image before deployment
- name: outerloop-build
image:
dockerfile:
buildContext: ${PROJECT_SOURCE}
rootRequired: false
uri: ./Dockerfile
imageName: "{{CONTAINER_IMAGE}}"
# This will create a Deployment in order to run your container image across
# the cluster.
- name: outerloop-deployment
kubernetes:
inlined: |
kind: Deployment
apiVersion: apps/v1
metadata:
name: {{RESOURCE_NAME}}
spec:
replicas: 1
selector:
matchLabels:
app: {{RESOURCE_NAME}}
template:
metadata:
labels:
app: {{RESOURCE_NAME}}
spec:
containers:
- name: {{RESOURCE_NAME}}
image: {{CONTAINER_IMAGE}}
ports:
- name: http
containerPort: {{CONTAINER_PORT}}
protocol: TCP
resources:
limits:
memory: "1024Mi"
cpu: "500m"
# This will create a Service so your Deployment is accessible.
# Depending on your cluster, you may modify this code so it's a
# NodePort, ClusterIP or a LoadBalancer service.
- name: outerloop-service
kubernetes:
inlined: |
apiVersion: v1
kind: Service
metadata:
name: {{RESOURCE_NAME}}
spec:
ports:
- name: "{{CONTAINER_PORT}}"
port: {{CONTAINER_PORT}}
protocol: TCP
targetPort: {{CONTAINER_PORT}}
selector:
app: {{RESOURCE_NAME}}
type: NodePort
- name: outerloop-url
kubernetes:
inlined: |
apiVersion: route.openshift.io/v1
kind: Route
metadata:
name: {{RESOURCE_NAME}}
spec:
path: /
to:
kind: Service
name: {{RESOURCE_NAME}}
port:
targetPort: {{CONTAINER_PORT}}
# highlight-end
metadata:
description: Stack with .NET 6.0
displayName: .NET 6.0
icon: https://github.com/dotnet/brand/raw/main/logo/dotnet-logo.png
language: .NET
name: my-dotnet-app
projectType: dotnet
tags:
- .NET
version: 1.0.2
# highlight-next-line
schemaVersion: 2.2.0
starterProjects:
- git:
checkoutFrom:
remote: origin
revision: dotnet-6.0
remotes:
origin: https://github.com/redhat-developer/s2i-dotnetcore-ex
name: dotnet60-example
subDir: app
# highlight-start
# Add the following variables code anywhere in devfile.yaml
# This MUST be a container registry you are able to access
variables:
CONTAINER_IMAGE: quay.io/MYUSERNAME/dotnet-odo-example
RESOURCE_NAME: my-dotnet-app
CONTAINER_PORT: "8080"
DOMAIN_NAME: dotnet.example.com
# highlight-end
```
</TabItem>
</Tabs>

</details>


## Step 4. Run the `odo deploy` command

Expand Down
Loading

0 comments on commit ec59ad2

Please sign in to comment.