Skip to content

Commit

Permalink
Use image selector feature in "Deploying application" guides (redhat-…
Browse files Browse the repository at this point in the history
…developer#7013)

* Update introduction message in Deploy guide

* Fix syntax highlighting for Shell commands

* Bump PrismJS to 1.29.0 to have syntax highlighting for things like Dockerfiles

* Enable syntax highlighting for Dockerfile content in the Deploy guides

* Update instructions on how to login to the container registry

* Add instructions on how to register the image registry in odo

This is to be able to use image selectors.

* Use a relative image name in the Devfile

* Add comment about the ingress domain name variable

* Update the deploy guide for .NET

* Highlight items that need to be changed in the Devfile

* Register the image registry first and make it clear that permissions might need to be updated

To make things simple, use a public registry like ttl.sh that does not require authentication.

* Add more details on how to access the application
  • Loading branch information
rm3l authored Aug 2, 2023
1 parent 2a95404 commit 6c1c8b2
Show file tree
Hide file tree
Showing 36 changed files with 289 additions and 171 deletions.
2 changes: 1 addition & 1 deletion docs/website/docs/user-guides/advanced/deploy/deploy.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
title: Deploying an Application
---

In this guide, we will be using `odo` to deploy to production a "Hello World" application.
In this guide, we will be using `odo` to run a "Hello World" application into a production-like mode.

You are expected to complete the [quickstart](../../quickstart) guide first with the respective example.

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import Tabs from '@theme/Tabs';
import TabItem from '@theme/TabItem';
import CodeBlock from '@theme/CodeBlock';

You can now determine how to access the application by running `odo describe component`:

Expand All @@ -20,3 +21,41 @@ Check for _Kubernetes Ingresses_ if you are on a Kubernetes cluster or _OpenShif
</TabItem>
</Tabs>
</details>


<Tabs groupId="quickstart">
<TabItem value="kubernetes" label="Kubernetes">

Since we are using Ingress, we can check if an IP address has been set.

<div>
<CodeBlock language="console">
{`
$ kubectl get ingress my-`}{props.name}{`-app
NAME CLASS HOSTS ADDRESS PORTS AGE
my-`}{props.name}{`-app traefik `}{props.name}{`.example.com 172.19.0.2 80 2m2s
`}
</CodeBlock>
</div>

Once the IP address appears, you can now access the application, like so:

<div>
<CodeBlock language="console">
{`curl --resolve "`}{props.name}{`.example.com:80:172.19.0.2" -i http://`}{props.name}{`.example.com/`}
</CodeBlock>
</div>

</TabItem>
<TabItem value="openshift" label="OpenShift">

We can directly access the application by using the OpenShift Route displayed in the `odo describe component` output above:

<div>
<CodeBlock language="console">
{`curl -i http://my-`}{props.name}{`-app-user-crt-dev.apps.sandbox-m2.ll9k.p1.openshiftapps.com/`}
</CodeBlock>
</div>

</TabItem>
</Tabs>
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
```dockerfile
```docker
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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@ $ odo deploy
/ \__/ odo version: v3.13.0
\__/

↪ Building & Pushing Container: quay.io/MYUSERNAME/dotnet-odo-example
↪ Building & Pushing Container: ttl.sh/my-dotnet-app-my-dotnet-app:411242
• Building image locally ...
build -t quay.io/MYUSERNAME/dotnet-odo-example -f /home/user/quickstart-demo/dotnet-demo/Dockerfile /home/user/quickstart-demo/dotnet-demo
build -t ttl.sh/my-dotnet-app-my-dotnet-app -f /home/user/quickstart-demo/dotnet-demo/Dockerfile /home/user/quickstart-demo/dotnet-demo
✓ Building image locally
• Pushing image to container registry ...
push quay.io/MYUSERNAME/dotnet-odo-example
push ttl.sh/my-dotnet-app-my-dotnet-app
✓ Pushing image to container registry

↪ Deploying Kubernetes Component: my-dotnet-app
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,10 @@ Kubernetes components:
• outerloop-service
• outerloop-url

# highlight-start
Kubernetes Ingresses:
• my-dotnet-app: dotnet.example.com/
# highlight-end


```
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,10 @@ Kubernetes components:
• outerloop-service
• outerloop-url

# highlight-start
OpenShift Routes:
• my-dotnet-app: my-dotnet-app-pvala-crt-dev.apps.sandbox-m2.ll9k.p1.openshiftapps.com/
• my-dotnet-app: my-dotnet-app-user-crt-dev.apps.sandbox-m2.ll9k.p1.openshiftapps.com/
# highlight-end


```
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ commands:
kind: run
workingDir: ${PROJECT_SOURCE}
id: run

# highlight-start
# This is the main "composite" command that will run all below commands
- id: deploy
composite:
Expand All @@ -42,6 +44,7 @@ commands:
- id: k8s-url
apply:
component: outerloop-url
# highlight-end
components:
- container:
args:
Expand All @@ -63,14 +66,16 @@ components:
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}}"
imageName: "{{APP_NAME}}"
# This will create a Deployment in order to run your container image across
# the cluster.
- name: outerloop-deployment
Expand All @@ -79,20 +84,20 @@ components:
kind: Deployment
apiVersion: apps/v1
metadata:
name: {{RESOURCE_NAME}}
name: {{APP_NAME}}
spec:
replicas: 1
selector:
matchLabels:
app: {{RESOURCE_NAME}}
app: {{APP_NAME}}
template:
metadata:
labels:
app: {{RESOURCE_NAME}}
app: {{APP_NAME}}
spec:
containers:
- name: {{RESOURCE_NAME}}
image: {{CONTAINER_IMAGE}}
- name: {{APP_NAME}}
image: {{APP_NAME}}
ports:
- name: http
containerPort: {{CONTAINER_PORT}}
Expand All @@ -111,23 +116,23 @@ components:
apiVersion: v1
kind: Service
metadata:
name: {{RESOURCE_NAME}}
name: {{APP_NAME}}
spec:
ports:
- name: "{{CONTAINER_PORT}}"
port: {{CONTAINER_PORT}}
protocol: TCP
targetPort: {{CONTAINER_PORT}}
selector:
app: {{RESOURCE_NAME}}
app: {{APP_NAME}}
type: NodePort
- name: outerloop-url
kubernetes:
inlined: |
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: {{RESOURCE_NAME}}
name: {{APP_NAME}}
spec:
rules:
- host: "{{DOMAIN_NAME}}"
Expand All @@ -137,9 +142,10 @@ components:
pathType: Prefix
backend:
service:
name: {{RESOURCE_NAME}}
name: {{APP_NAME}}
port:
number: {{CONTAINER_PORT}}
# highlight-end
metadata:
description: Stack with .NET 6.0
displayName: .NET 6.0
Expand All @@ -150,6 +156,7 @@ metadata:
tags:
- .NET
version: 1.0.2
# highlight-next-line
schemaVersion: 2.2.0
starterProjects:
- git:
Expand All @@ -160,11 +167,10 @@ starterProjects:
origin: https://github.com/redhat-developer/s2i-dotnetcore-ex
name: dotnet60-example
subDir: app
# Add the following variables code anywhere in devfile.yaml
# This MUST be a container registry you are able to access
# highlight-start
variables:
CONTAINER_IMAGE: quay.io/MYUSERNAME/dotnet-odo-example
RESOURCE_NAME: my-dotnet-app
APP_NAME: my-dotnet-app
CONTAINER_PORT: "8080"
DOMAIN_NAME: dotnet.example.com
# highlight-end
```
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ commands:
kind: run
workingDir: ${PROJECT_SOURCE}
id: run
# highlight-start
# This is the main "composite" command that will run all below commands
- id: deploy
composite:
Expand All @@ -42,6 +43,7 @@ commands:
- id: k8s-url
apply:
component: outerloop-url
# highlight-end
components:
- container:
args:
Expand All @@ -63,14 +65,15 @@ components:
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}}"
imageName: "{{APP_NAME}}"
# This will create a Deployment in order to run your container image across
# the cluster.
- name: outerloop-deployment
Expand All @@ -79,20 +82,20 @@ components:
kind: Deployment
apiVersion: apps/v1
metadata:
name: {{RESOURCE_NAME}}
name: {{APP_NAME}}
spec:
replicas: 1
selector:
matchLabels:
app: {{RESOURCE_NAME}}
app: {{APP_NAME}}
template:
metadata:
labels:
app: {{RESOURCE_NAME}}
app: {{APP_NAME}}
spec:
containers:
- name: {{RESOURCE_NAME}}
image: {{CONTAINER_IMAGE}}
- name: {{APP_NAME}}
image: {{APP_NAME}}
ports:
- name: http
containerPort: {{CONTAINER_PORT}}
Expand All @@ -111,30 +114,32 @@ components:
apiVersion: v1
kind: Service
metadata:
name: {{RESOURCE_NAME}}
name: {{APP_NAME}}
spec:
ports:
- name: "{{CONTAINER_PORT}}"
port: {{CONTAINER_PORT}}
protocol: TCP
targetPort: {{CONTAINER_PORT}}
selector:
app: {{RESOURCE_NAME}}
app: {{APP_NAME}}
type: NodePort
- name: outerloop-url
kubernetes:
inlined: |
apiVersion: route.openshift.io/v1
kind: Route
metadata:
name: {{RESOURCE_NAME}}
name: {{APP_NAME}}
spec:
path: /
to:
kind: Service
name: {{RESOURCE_NAME}}
name: {{APP_NAME}}
port:
targetPort: {{CONTAINER_PORT}}
# highlight-end
metadata:
description: Stack with .NET 6.0
displayName: .NET 6.0
Expand All @@ -145,6 +150,7 @@ metadata:
tags:
- .NET
version: 1.0.2
# highlight-next-line
schemaVersion: 2.2.0
starterProjects:
- git:
Expand All @@ -155,10 +161,10 @@ starterProjects:
origin: https://github.com/redhat-developer/s2i-dotnetcore-ex
name: dotnet60-example
subDir: app
# Add the following variables code anywhere in devfile.yaml
# This MUST be a container registry you are able to access

# highlight-start
variables:
CONTAINER_IMAGE: quay.io/MYUSERNAME/dotnet-odo-example
RESOURCE_NAME: my-dotnet-app
APP_NAME: my-dotnet-app
CONTAINER_PORT: "8080"
# highlight-end
```
Loading

0 comments on commit 6c1c8b2

Please sign in to comment.