mirror of
				https://github.com/redhat-developer/odo.git
				synced 2025-10-19 03:06:19 +03:00 
			
		
		
		
	Adds .NET 6.0 as a quickstart example (#5774)
* Adds .NET 6.0 as a quickstart example <!-- Thank you for opening a PR! Here are some things you need to know before submitting: 1. Please read our developer guideline: https://github.com/redhat-developer/odo/wiki/Dev:-odo-Dev-Guidelines 2. Label this PR accordingly with the '/kind' line 3. Ensure you have written and ran the appropriate tests: https://github.com/redhat-developer/odo/wiki/Dev:-Writing-and-running-tests 4. Read how we approve and LGTM each PR: https://github.com/redhat-developer/odo/wiki/Pull-Requests:-Review-guideline Documentation: If you are pushing a change to documentation, please read: https://github.com/redhat-developer/odo/wiki/Documentation:-Contributing --> **What type of PR is this:** <!-- Add one of the following kinds: /kind bug /kind feature /kind cleanup /kind tests Feel free to use other [labels](https://github.com/redhat-developer/odo/labels) as needed. However one of the above labels must be present or the PR will not be reviewed. This instruction is for reviewers as well. --> /kind documentation **What does this PR do / why we need it:** Adds .NET to the quickstart guide as an example. Including building the container, running dev as well as deploy. **Which issue(s) this PR fixes:** <!-- Specifying the issue will automatically close it when this PR is merged --> Fixes 1/2 of https://github.com/redhat-developer/odo/issues/5746 **PR acceptance criteria:** - [X] Documentation **How to test changes / Special notes to the reviewer:** Signed-off-by: Charlie Drage <charlie@charliedrage.com> * Update based on review Signed-off-by: Charlie Drage <charlie@charliedrage.com> * Upddate based on review Signed-off-by: Charlie Drage <charlie@charliedrage.com>
This commit is contained in:
		| @@ -5,7 +5,13 @@ sidebar_position: 5 | ||||
|  | ||||
| # Quickstart Guide | ||||
|  | ||||
| In this guide, we will be using odo to create a "Hello World" application with Node.js | ||||
| In this guide, we will be using odo to create a "Hello World" application. | ||||
|  | ||||
| You have the option of choosing from the following frameworks for the quickstart guide: | ||||
| * Node.js | ||||
| * .NET | ||||
|  | ||||
| A full list of example applications can be viewed with the `odo registry` command. | ||||
|  | ||||
| ## Prerequisites | ||||
|  | ||||
| @@ -63,11 +69,40 @@ $ npx express-generator | ||||
|      $ DEBUG=express:* npm start | ||||
| ``` | ||||
|  | ||||
| Your source code has now been generated and created in the directory. | ||||
|  | ||||
| </TabItem> | ||||
|   <TabItem value="dotnet" label=".NET"> | ||||
|  | ||||
|   For .NET we will use the [ASP.NET Core MVC](https://docs.microsoft.com/en-us/aspnet/core/tutorials/first-mvc-app/start-mvc?view=aspnetcore-6.0&tabs=visual-studio-code) example.  | ||||
|  | ||||
|   ASP.NET MVC is a web application framework that implements the model-view-controller (MVC) pattern. | ||||
|  | ||||
|   1. Generate an example project: | ||||
|  | ||||
| ```console | ||||
| $ dotnet new mvc --name app | ||||
|  | ||||
| Welcome to .NET 6.0! | ||||
| --------------------- | ||||
| SDK Version: 6.0.104 | ||||
|  | ||||
| ... | ||||
|  | ||||
| The template "ASP.NET Core Web App (Model-View-Controller)" was created successfully. | ||||
| This template contains technologies from parties other than Microsoft, see https://aka.ms/aspnetcore/6.0-third-party-notices for details. | ||||
|  | ||||
| Processing post-creation actions... | ||||
| Running 'dotnet restore' on /Users/user/app/app.csproj... | ||||
|   Determining projects to restore... | ||||
|   Restored /Users/user/app/app.csproj (in 84 ms). | ||||
| Restore succeeded. | ||||
| ``` | ||||
|  | ||||
|   </TabItem> | ||||
| </Tabs> | ||||
|  | ||||
| Your source code has now been generated and created in the directory. | ||||
|  | ||||
| ## Step 1. Creating your application (`odo init`) | ||||
|  | ||||
| Now we'll initialize your application by creating a `devfile.yaml` to be deployed. | ||||
| @@ -86,7 +121,7 @@ $ odo init | ||||
|   __ | ||||
|  /  \__     Initializing new component | ||||
|  \__/  \    Files: Source code detected, a Devfile will be determined based upon source code autodetection | ||||
|  /  \__/    odo version: v3.0.0-alpha1 | ||||
|  /  \__/    odo version: v3.0.0-alpha2 | ||||
|  \__/ | ||||
|  | ||||
| Interactive mode enabled, please answer the following questions: | ||||
| @@ -112,6 +147,46 @@ Changes will be directly reflected on the cluster. | ||||
| A `devfile.yaml` has now been added to your directory and now you're ready to start development. | ||||
|  | ||||
|   </TabItem> | ||||
|   <TabItem value="dotnet" label=".NET"> | ||||
|  | ||||
| Let's run `odo init` and select .NET 6.0: | ||||
|  | ||||
| ```console | ||||
| $ odo init | ||||
|   __ | ||||
|  /  \__     Initializing new component | ||||
|  \__/  \    Files: Source code detected, a Devfile will be determined based upon source code autodetection | ||||
|  /  \__/    odo version: v3.0.0-alpha2 | ||||
|  \__/ | ||||
|  | ||||
| Interactive mode enabled, please answer the following questions: | ||||
| Based on the files in the current directory odo detected | ||||
| Language: javascript | ||||
| Project type: nodejs | ||||
| The devfile "nodejs" from the registry "DefaultDevfileRegistry" will be downloaded. | ||||
| ? Is this correct? No | ||||
| ? Select language: dotnet | ||||
| ? Select project type: .NET 6.0 | ||||
|  ✓  Downloading devfile "dotnet60" from registry "DefaultDevfileRegistry" [596ms] | ||||
| Current component configuration: | ||||
| Container "dotnet": | ||||
|   Opened ports: | ||||
|    - 8080 | ||||
|   Environment variables: | ||||
|    - STARTUP_PROJECT = app.csproj | ||||
|    - ASPNETCORE_ENVIRONMENT = Development | ||||
|    - ASPNETCORE_URLS = http://*:8080 | ||||
|    - CONFIGURATION = Debug | ||||
| ? Select container for which you want to change configuration? NONE - configuration is correct | ||||
| ? Enter component name: my-dotnet60-app | ||||
|  | ||||
| Your new component 'my-dotnet60-app' is ready in the current directory. | ||||
| To start editing your component, use 'odo dev' and open this folder in your favorite IDE. | ||||
| Changes will be directly reflected on the cluster. | ||||
| ``` | ||||
|  | ||||
| A `devfile.yaml` has now been added to your directory and now you're ready to start development. | ||||
|   </TabItem> | ||||
| </Tabs> | ||||
|  | ||||
| ## Step 2. Developing your application continuously (`odo dev`) | ||||
| @@ -131,7 +206,7 @@ $ odo dev | ||||
|   __ | ||||
|  /  \__     Developing using the my-nodejs-app Devfile | ||||
|  \__/  \    Namespace: default | ||||
|  /  \__/    odo version: v3.0.0-alpha1 | ||||
|  /  \__/    odo version: v3.0.0-alpha2 | ||||
|  \__/ | ||||
|  | ||||
| ↪ Deploying to the cluster in developer mode | ||||
| @@ -143,15 +218,43 @@ $ odo dev | ||||
| Your application is now running on the cluster | ||||
|  - Forwarding from 127.0.0.1:40001 -> 3000 | ||||
|  | ||||
| Watching for changes in the current directory /Users/user/syncthing/dev/k8s/devfiles/express | ||||
| Watching for changes in the current directory /Users/user/express | ||||
| Press Ctrl+c to exit `odo dev` and delete resources from the cluster | ||||
| ``` | ||||
|   </TabItem> | ||||
|  | ||||
|   <TabItem value="dotnet" label=".NET"> | ||||
|  | ||||
| Let's run `odo dev` to start development on your .NET application: | ||||
|  | ||||
| ```console | ||||
| $ odo dev | ||||
|   __ | ||||
|  /  \__     Developing using the my-dotnet60-app Devfile | ||||
|  \__/  \    Namespace: default | ||||
|  /  \__/    odo version: v3.0.0-alpha2 | ||||
|  \__/ | ||||
|  | ||||
| ↪ Deploying to the cluster in developer mode | ||||
|  ✓  Waiting for Kubernetes resources [3s] | ||||
|  ✓  Syncing files into the container [2s] | ||||
|  ✓  Building your application in container on cluster [5s] | ||||
|  ✓  Executing the application [1s] | ||||
|  | ||||
| Your application is now running on the cluster | ||||
|  - Forwarding from 127.0.0.1:40001 -> 8080 | ||||
|  | ||||
| Watching for changes in the current directory /Users/user/dotnet | ||||
| Press Ctrl+c to exit `odo dev` and delete resources from the cluster | ||||
| ``` | ||||
|  | ||||
| You can now access the application at [127.0.0.1:40001](http://127.0.0.1:40001) in your local browser and start your development loop. `odo` will watch for changes and push the code for real-time updates. | ||||
|  | ||||
|   </TabItem> | ||||
| </Tabs> | ||||
|  | ||||
| You can now access the application at [127.0.0.1:40001](http://127.0.0.1:40001) in your local browser and start your development loop. `odo` will watch for changes and push the code for real-time updates. | ||||
|  | ||||
|  | ||||
| ## Step 3. Deploying your application to the world (`odo deploy`) | ||||
|  | ||||
| **Prerequisites:** | ||||
| @@ -300,7 +403,7 @@ components: | ||||
|               app: {{RESOURCE_NAME}} | ||||
|           spec: | ||||
|             containers: | ||||
|               - name: nodejs | ||||
|               - name: {{RESOURCE_NAME}} | ||||
|                 image: {{CONTAINER_IMAGE}} | ||||
|                 ports: | ||||
|                   - name: http | ||||
| @@ -363,7 +466,7 @@ $ odo deploy | ||||
|   __ | ||||
|  /  \__     Deploying the application using my-nodejs-app Devfile | ||||
|  \__/  \    Namespace: default | ||||
|  /  \__/    odo version: v3.0.0-alpha1 | ||||
|  /  \__/    odo version: v3.0.0-alpha2 | ||||
|  \__/ | ||||
|  | ||||
| ↪ Building & Pushing Container: MYUSERNAME/test | ||||
| @@ -389,6 +492,204 @@ Your Devfile has been successfully deployed | ||||
|  | ||||
| Your application has now been deployed to the Kubernetes cluster with Deployment, Service, and Ingress resources. | ||||
|  | ||||
| Test your application by visiting the `DOMAIN_NAME` variable that you had set in the `devfile.yaml`. | ||||
|  | ||||
|   </TabItem> | ||||
|   <TabItem value="dotnet" label=".NET"> | ||||
|  | ||||
| #### 1. Containerize the application | ||||
|  | ||||
| In order to deploy our application, we must containerize it in order to build and push to a registry. Create the following `Dockerfile` in the same directory: | ||||
|  | ||||
| ```dockerfile | ||||
| FROM registry.access.redhat.com/ubi8/dotnet-60:6.0 as builder | ||||
| WORKDIR /opt/app-root/src | ||||
| COPY --chown=1001 . . | ||||
| RUN dotnet publish -c Release | ||||
|  | ||||
|  | ||||
| FROM registry.access.redhat.com/ubi8/dotnet-60:6.0 | ||||
| EXPOSE 8080 | ||||
| COPY --from=builder /opt/app-root/src/bin /opt/app-root/src/bin | ||||
| WORKDIR /opt/app-root/src/bin/Release/net6.0/publish | ||||
| CMD ["dotnet", "app.dll"] | ||||
| ``` | ||||
|  | ||||
| #### 2. Modify the Devfile | ||||
|  | ||||
| Let's modify the `devfile.yaml` and add the respective deployment code. | ||||
|  | ||||
| `odo deploy` uses Devfile schema **2.2.0**. Change the schema to reflect the change: | ||||
|  | ||||
| ```yaml | ||||
| # Deploy "kind" ID's use schema 2.2.0+ | ||||
| schemaVersion: 2.2.0 | ||||
| ``` | ||||
|  | ||||
| Add the `variables` section: | ||||
|  | ||||
| ```yaml | ||||
| # 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 | ||||
| ``` | ||||
|  | ||||
| Add the commands used to deploy: | ||||
|  | ||||
| ```yaml | ||||
| # This is the main "composite" command that will run all below commands | ||||
| - id: deploy | ||||
|   composite: | ||||
|     commands: | ||||
|     - build-image | ||||
|     - k8s-deployment | ||||
|     - k8s-service | ||||
|     - k8s-ingress | ||||
|     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-ingress | ||||
|   apply: | ||||
|     component: outerloop-ingress | ||||
| ``` | ||||
|  | ||||
| Add the Kubernetes Service and Ingress inline code to `components`: | ||||
| ```yaml | ||||
| components: | ||||
|  | ||||
| # 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: ClusterIP | ||||
|  | ||||
| # Let's create an Ingress so we can access the application via a domain name | ||||
| - name: outerloop-ingress | ||||
|   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}} | ||||
| ``` | ||||
|  | ||||
|  | ||||
| #### 3. Run the `odo deploy` command | ||||
|  | ||||
| Now we're ready to run `odo deploy`: | ||||
|  | ||||
| ```console | ||||
| $ odo deploy | ||||
|   __ | ||||
|  /  \__     Deploying the application using my-dotnet-app Devfile | ||||
|  \__/  \    Namespace: default | ||||
|  /  \__/    odo version: v3.0.0-alpha2 | ||||
|  \__/ | ||||
|  | ||||
| ↪ Building & Pushing Container: MYUSERNAME/test | ||||
|  •  Building image locally  ... | ||||
|  ✓  Building image locally [880ms] | ||||
|  •  Pushing image to container registry  ... | ||||
|  ✓  Pushing image to container registry [5s] | ||||
|  | ||||
| ↪ Deploying Kubernetes Component: dotnet-example | ||||
|  ✓  Searching resource in cluster | ||||
|  ✓  Creating kind Deployment [48ms] | ||||
|  | ||||
| ↪ Deploying Kubernetes Component: dotnet-example | ||||
|  ✓  Searching resource in cluster | ||||
|  ✓  Creating kind Service [51ms] | ||||
|  | ||||
| ↪ Deploying Kubernetes Component: dotnet-example | ||||
|  ✓  Searching resource in cluster | ||||
|  ✓  Creating kind Ingress [49ms] | ||||
|  | ||||
| Your Devfile has been successfully deployed | ||||
| ``` | ||||
|  | ||||
| Your application has now been deployed to the Kubernetes cluster with Deployment, Service, and Ingress resources. | ||||
|  | ||||
| Test your application by visiting the `DOMAIN_NAME` variable that you had set in the `devfile.yaml`. | ||||
|  | ||||
|   </TabItem> | ||||
|   | ||||
		Reference in New Issue
	
	Block a user
	 Charlie Drage
					Charlie Drage