build Documentation

The official build framework for the Armbian Linux distribution. This repository contains the complete toolchain and scripts required to compile custom OS...

5,342 stars Shell Shell 1 file ยท ~13,654 tokens #aarch64#arm#debian#firmware#framework#image#iso#kernel
RAW Doc

1. Project Overview & Quickstart (alexellis/build)

build

The official build framework for the Armbian Linux distribution. This repository contains the complete toolchain and scripts required to compile custom OS images from source, including kernel configuration, U-Boot handling, and board-specific tweaks for various ARM and ARM64 single-board computers.

Repository Details

  • Repository: alexellis/build
  • GitHub Stars: โญ 5,342
  • Primary Language: Shell

Note: High-volume repository documentation is actively indexed and synchronized by YakaAI.

2. Official Technical Reference & Guides (alexellis/docs)

File: README.md

Welcome to the source file repository for Knative documentation

View published docs

Use the Knative Documentation website to view the
docs and learn about Knative.

Source files

View the source files if you want to contribute a fix or add new content. Each
release of the Knative docs are
branched. If you are looking for an
archived doc set, see the list of available versions in
Knative doc releases.


File: community/samples/serving/helloworld-vertx/README.md

Hello World - Eclipse Vert.x sample

Learn how to deploy a simple web app that is written in Java and uses Eclipse
Vert.x. This samples uses Docker to build locally. The app reads in a TARGET
env variable and then prints "Hello World: ${TARGET}!". If a value for TARGET
is not specified, the "NOT SPECIFIED" default value is used.

Use this sample to walk you through the steps of creating and modifying the
sample app, building and pushing your container image to a registry, and then
deploying your app to your Knative cluster.

Before you begin

You must meet the following requirements to complete this sample:

Tip: You can clone the Knatve/docs repo
and then modify the source files. Alternatively, learn more by manually creating
the files youself.

Creating and configuring the sample code

To create and configure the source files in the root of your working directory:

  1. Create the pom.xml file:

    text

/* Detailed source-code truncated for AI context efficiency. */

text
1. Create the `HelloWorld.java` file in the
   `src/main/java/com/example/helloworld` directory. The
   `[ROOT]/src/main/java/com/example/helloworld/HelloWorld.java` file creates a
   basic web server that listens on port `8080`.

   ```java
    package com.example.helloworld;

    import io.reactivex.Flowable;
    import io.vertx.reactivex.core.AbstractVerticle;
    import io.vertx.reactivex.core.http.HttpServer;
    import io.vertx.reactivex.core.http.HttpServerRequest;

    public class HelloWorld extends AbstractVerticle {

        public void start() {

            final HttpServer server = vertx.createHttpServer();
            final Flowable<HttpServerRequest> requestFlowable = server.requestStream().toFlowable();

            requestFlowable.subscribe(httpServerRequest -> {

                String target = System.getenv("TARGET");
                if (target == null) {
                    target = "NOT SPECIFIED";
                }

                httpServerRequest.response().setChunked(true)
                        .putHeader("content-type", "text/plain")
                        .setStatusCode(200) // OK
                        .end("Hello World: " + target);
            });

            server.listen(8080);
        }
    }
  1. Create the Dockerfile file:

    docker
    # Use fabric8's s2i Builder image.
    # https://hub.docker.com/r/fabric8/s2i-java
    FROM fabric8/s2i-java:2.0
    
    # Service must listen to $PORT environment variable.
    # This default value facilitates local development.
    ENV PORT 8080
    
    # Copy the JAR file to the deployment directory.
    ENV JAVA_APP_DIR=/deployments
    COPY target/helloworld-1.0.0-SNAPSHOT.jar /deployments/
  2. Create the service.yaml file. You must specify your Docker Hub username in
    {username}. You can also configure the TARGET, for example you can modify
    the Eclipse Vert.x Sample v1 value.

    yaml
    apiVersion: serving.knative.dev/v1alpha1
    kind: Service
    metadata:
      name: helloworld-vertx
      namespace: default
    spec:
      runLatest:
        configuration:
          revisionTemplate:
            spec:
              container:
                image: docker.io/{username}/helloworld-vertx
                env:
                  - name: TARGET
                    value: "Eclipse Vert.x Sample v1"

Building and deploying the sample

To build a container image, push your image to the registry, and then deploy
your sample app to your cluster:

  1. Use Docker to build your container image and then push that image to your
    Docker Hub registry. You must replace the {username} variables in the
    following commands with your Docker Hub username.

    shell
    # Build the container on your local machine
    docker build -t {username}/helloworld-vertx .
    
    # Push the container to docker registry
    docker push {username}/helloworld-vertx
  2. Now that your container image is in the registry, you can deploy it to your
    Knative cluster by running the kubectl apply command:

    shell
    kubectl apply --filename service.yaml

    Result: A service name helloworld-vertx is created in your cluster along
    with the following resources:

    • A new immutable revision for the version of the app that you just deployed.
    • The following networking resources are created for your app:
      • route
      • ingress
      • service
      • load balancer
    • Auto scaling is enable to allow your pods to scale up to meet traffic, and
      also back down to zero when there is no traffic.

Testing the sample app

To verify that your sample app has been successfully deployed:

  1. View your the ingress IP address of your service by running the following
    kubectl get command. Note that it may take sometime for the new service to
    get asssigned an external IP address, especially if your cluster was newly
    created.

    shell
    # In Knative 0.2.x and prior versions, the `knative-ingressgateway` service was used instead of `istio-ingressgateway`.
    INGRESSGATEWAY=knative-ingressgateway
    
    # The use of `knative-ingressgateway` is deprecated in Knative v0.3.x.
    # Use `istio-ingressgateway` instead, since `knative-ingressgateway`
    # will be removed in Knative v0.4.
    if kubectl get configmap config-istio -n knative-serving &> /dev/null; then
        INGRESSGATEWAY=istio-ingressgateway
    fi
    
    kubectl get svc $INGRESSGATEWAY --namespace istio-system

    Example result:

    shell
    NAME                     TYPE           CLUSTER-IP     EXTERNAL-IP      PORT(S)                                      AGE
    xxxxxxx-ingressgateway   LoadBalancer   10.23.247.74   35.203.155.229   80:32380/TCP,443:32390/TCP,32400:32400/TCP   2d
  2. Retrieve the URL for your service, by running the following kubectl get
    command:

    shell
    kubectl get services.serving.knative.dev helloworld-vertx  --output=custom-columns=NAME:.metadata.name,DOMAIN:.status.domain

    Example result:

    shell
    NAME                DOMAIN
    helloworld-vertx     helloworld-vertx.default.example.com
  3. Run the following curl command to test your deployed sample app. You must
    replace the {IP_ADDRESS} variable the URL that your retrieve in the
    previous step.

    shell
    curl -H "Host: helloworld-vertx.default.example.com" http://{IP_ADDRESS}

    Example result:

    shell
    Hello World: Eclipse Vert.x Sample v1

Congtratualations on deploying your sample Java app to Knative!

Removing the sample app deployment

To remove the sample app from your cluster, run the following kubectl delete
command:

shell
kubectl delete --filename service.yaml

File: community/samples/serving/helloworld-swift/README.md

Hello World - Swift sample

A simple web app written in Swift that you can use for testing. The app reads in
an env variable TARGET and prints "Hello ${TARGET}!". If TARGET is not
specified, the app uses "World" as the TARGET.

Prerequisites

  • You must have a Kubernetes cluster with Knative installed. If you need to
    create a cluster, follow the
    installation instructions.
  • You must have Docker installed and running on your
    local machine, and a Docker Hub account configured (used for container
    registry).

Recreating the sample code

While you can clone all of the code from this directory, it might be more useful
if you build this app step-by-step. The following instructions recreate the
source files from this folder.

  1. Create a the Package.swift to declare your package and its dependencies.
    This app uses Swifter, a tiny http
    server engine for Swift.

    swift
    // swift-tools-version:4.0
    
     import PackageDescription
    
     let package = Package(
         name: "HelloSwift",
         dependencies: [
             .package(url: "https://github.com/httpswift/swifter.git", .upToNextMajor(from: "1.4.5"))
         ],
         targets: [
             .target(
             name: "HelloSwift",
             dependencies: ["Swifter"],
             path: "./Sources")
         ]
     )
  2. Add the web server code to a file named main.swift in a
    Sources/HelloSwift/ folder:

    swift
    import Swifter
     import Dispatch
     import Foundation
    
     let server = HttpServer()
     server["/"] = { r in
         let target = ProcessInfo.processInfo.environment["TARGET"] ?? "World"
         return HttpResponse.ok(.html("Hello \(target)"))
     }
    
     let semaphore = DispatchSemaphore(value: 0)
     do {
         let port = UInt16(ProcessInfo.processInfo.environment["PORT"] ?? "8080")
         try server.start(port!, forceIPv4: true)
         print("Server has started ( port = \(try server.port()) ). Try to connect now...")
         semaphore.wait()
     } catch {
         print("Server start error: \(error)")
         semaphore.signal()
     }
  3. In your project directory, create a file named Dockerfile and copy the code
    block below into it.

    dockerfile
    # Use the official Swift image.
     # https://hub.docker.com/_/swift
     FROM swift:4.2
    
     # Copy local code to the container image.
     WORKDIR /app
     COPY . .
    
     # Install dependencies and build.
     RUN swift build -c release
    
     # Run the web service on container startup.
     CMD [ ".build/release/HelloSwift"]
  4. Create a new file, service.yaml, and copy the following service definition
    into the file. Replace {username} with your Docker Hub username.

    yaml
    apiVersion: serving.knative.dev/v1alpha1
    kind: Service
    metadata:
    name: helloworld-swift
    namespace: default
    spec:
    runLatest:
      configuration:
      revisionTemplate:
        spec:
        container:
          image: docker.io/{username}/helloworld-swift
          env:
            - name: TARGET
          value: "Swift"

Building and deploying the sample

Once you have recreated the sample code files (or used the files in the sample
folder) you're ready to build and deploy the sample app.

  1. Use Docker to build the sample code into a container. To build and push with
    Docker Hub, run these commands, replacing {username} with your Docker Hub
    username:

    shell
    # Build the container on your local machine
    docker build -t {username}/helloworld-swift .
    
    # Push the container to docker registry
    docker push {username}/helloworld-swift
  2. After the build has completed and the container is pushed to Docker Hub, you
    can deploy the app into your cluster. Ensure that the container image value
    in the service.yaml file matches the container you built in the previous
    step. Apply the configuration using the kubectl command:

    shell
    kubectl apply --filename service.yaml
  3. Now that your service is created, Knative performs the following steps:

    • Creates a new immutable revision for this version of the app.
    • Network programming to create a route, ingress, service, and load balancing
      for your app.
    • Automatically scales your pods up and down (including to zero active pods).
  4. To find the IP address for your service, use
    kubectl get svc knative-ingressgateway --namespace istio-system to get the
    ingress IP for your cluster. If your cluster is new, it might take sometime
    for the service to get asssigned an external IP address.

    shell
    kubectl get svc knative-ingressgateway --namespace istio-system
    
    NAME                     TYPE           CLUSTER-IP     EXTERNAL-IP      PORT(S)                                      AGE
    knative-ingressgateway   LoadBalancer   10.23.247.74   35.203.155.229   80:32380/TCP,443:32390/TCP,32400:32400/TCP   2d
  5. To find the URL for your service, use the following command:

    text
    kubectl get ksvc helloworld-swift  --output=custom-columns=NAME:.metadata.name,DOMAIN:.status.domain
    NAME                DOMAIN
    helloworld-swift   helloworld-swift.default.example.com
  6. Now you can make a request to your app to see the result. Replace
    {IP_ADDRESS} with the address you see returned in the previous step:

    shell
    curl -H "Host: helloworld-swift.default.example.com" http://{IP_ADDRESS}
    Hello Swift

Removing the sample app deployment

To remove the sample app from your cluster, delete the service record:

shell
kubectl delete --filename service.yaml

File: community/samples/serving/helloworld-rust/README.md

Hello World - Rust sample

A simple web app written in Rust that you can use for testing. It reads in an
env variable TARGET and prints "Hello ${TARGET}!". If

TARGET is not specified, it will use "World" as the TARGET.

Prerequisites

  • A Kubernetes cluster with Knative installed. Follow the
    installation instructions if you need to create
    one.
  • Docker installed and running on your local machine,
    and a Docker Hub account configured (we'll use it for a container registry).

Steps to recreate the sample code

While you can clone all of the code from this directory, hello world apps are
generally more useful if you build them step-by-step. The following instructions
recreate the source files from this folder.

  1. Create a new file named Cargo.toml and paste the following code:

    toml
    [package]
    name = "hellorust"
    version = "0.0.0"
    publish = false
    
    [dependencies]
    hyper = "0.12.3"
    pretty_env_logger = "0.2.3"
  2. Create a src folder, then create a new file named main.rs in that folder
    and paste the following code. This code creates a basic web server which
    listens on port 8080:

    rust
    #![deny(warnings)]
    extern crate hyper;
    extern crate pretty_env_logger;
    
    use hyper::{Body, Response, Server};
    use hyper::service::service_fn_ok;
    use hyper::rt::{self, Future};
    use std::env;
    
    fn main() {
        pretty_env_logger::init();
    
        let mut port: u16 = 8080;
        match env::var("PORT") {
            Ok(p) => {
                match p.parse::() {
                    Ok(n) => {port = n;},
                    Err(_e) => {},
                };
            }
            Err(_e) => {},
        };
        let addr = ([0, 0, 0, 0], port).into();
    
        let new_service = || {
            service_fn_ok(|_| {
    
                let mut hello = "Hello ".to_string();
                match env::var("TARGET") {
                    Ok(target) => {hello.push_str(&target);},
                    Err(_e) => {hello.push_str("World")},
                };
    
                Response::new(Body::from(hello))
            })
        };
    
        let server = Server::bind(&addr)
            .serve(new_service)
            .map_err(|e| eprintln!("server error: {}", e));
    
        println!("Listening on http://{}", addr);
    
        rt::run(server);
    }
  3. In your project directory, create a file named Dockerfile and copy the code
    block below into it.

    docker
    # Use the official Rust image.
    # https://hub.docker.com/_/rust
    FROM rust:1.27.0
    
    # Copy local code to the container image.
    WORKDIR /usr/src/app
    COPY . .
    
    # Install production dependencies and build a release artifact.
    RUN cargo install
    
    # Service must listen to $PORT environment variable.
    # This default value facilitates local development.
    ENV PORT 8080
    
    # Run the web service on container startup.
    CMD ["hellorust"]
  4. Create a new file, service.yaml and copy the following service definition
    into the file. Make sure to replace {username} with your Docker Hub
    username.

    yaml
    apiVersion: serving.knative.dev/v1alpha1
    kind: Service
    metadata:
    name: helloworld-rust
    namespace: default
    spec:
    runLatest:
      configuration:
      revisionTemplate:
        spec:
        container:
          image: docker.io/{username}/helloworld-rust
          env:
            - name: TARGET
          value: "Rust Sample v1"

Build and deploy this sample

Once you have recreated the sample code files (or used the files in the sample
folder) you're ready to build and deploy the sample app.

  1. Use Docker to build the sample code into a container. To build and push with
    Docker Hub, enter these commands replacing {username} with your Docker Hub
    username:

    shell
    # Build the container on your local machine
    docker build -t {username}/helloworld-rust .
    
    # Push the container to docker registry
    docker push {username}/helloworld-rust
  2. After the build has completed and the container is pushed to Docker Hub, you
    can deploy the app into your cluster. Ensure that the container image value
    in service.yaml matches the container you built in the previous step. Apply
    the configuration using kubectl:

    shell
    kubectl apply --filename service.yaml
  3. Now that your service is created, Knative will perform the following steps:

    • Create a new immutable revision for this version of the app.
    • Network programming to create a route, ingress, service, and load balance
      for your app.
    • Automatically scale your pods up and down (including to zero active pods).
  4. To find the IP address for your service, enter these commands to get the
    ingress IP for your cluster. If your cluster is new, it may take sometime for
    the service to get asssigned an external IP address.

    shell
    # In Knative 0.2.x and prior versions, the `knative-ingressgateway` service was used instead of `istio-ingressgateway`.
    INGRESSGATEWAY=knative-ingressgateway
    
    # The use of `knative-ingressgateway` is deprecated in Knative v0.3.x.
    # Use `istio-ingressgateway` instead, since `knative-ingressgateway`
    # will be removed in Knative v0.4.
    if kubectl get configmap config-istio -n knative-serving &> /dev/null; then
        INGRESSGATEWAY=istio-ingressgateway
    fi
    
    kubectl get svc $INGRESSGATEWAY --namespace istio-system
    
    NAME                     TYPE           CLUSTER-IP     EXTERNAL-IP      PORT(S)                                      AGE
    xxxxxxx-ingressgateway   LoadBalancer   10.23.247.74   35.203.155.229   80:32380/TCP,443:32390/TCP,32400:32400/TCP   2d
  5. To find the URL for your service, enter:

    text
    kubectl get ksvc helloworld-rust  --output=custom-columns=NAME:.metadata.name,DOMAIN:.status.domain
    NAME                DOMAIN
    helloworld-rust     helloworld-rust.default.example.com
  6. Now you can make a request to your app and see the result. Replace
    {IP_ADDRESS} with the address you see returned in the previous step.

    shell
    curl -H "Host: helloworld-rust.default.example.com" http://{IP_ADDRESS}
    Hello World!

Removing the sample app deployment

To remove the sample app from your cluster, delete the service record:

shell
kubectl delete --filename service.yaml

File: community/samples/serving/helloworld-haskell/README.md

Hello World - Haskell sample

A simple web app written in Haskell that you can use for testing. It reads in an
env variable TARGET and prints "Hello ${TARGET}!". If TARGET is not
specified, it will use "World" as the TARGET.

Prerequisites

  • A Kubernetes cluster with Knative installed. Follow the
    installation instructions if you need to create
    one.
  • Docker installed and running on your local machine,
    and a Docker Hub account configured (we'll use it for a container registry).

Recreating the sample code

While you can clone all of the code from this directory, hello world apps are
generally more useful if you build them step-by-step. The following instructions
recreate the source files from this folder.

  1. Create a new file named stack.yaml and paste the following code:

    yaml
    flags: {}
    packages:
      - .
    extra-deps: []
    resolver: lts-10.7
  2. Create a new file named package.yaml and paste the following code

    yaml
    name: helloworld-haskell
    version: 0.1.0.0
    dependencies:
      - base >= 4.7 && < 5
      - scotty
      - text
    
    executables:
      helloworld-haskell-exe:
        main: Main.hs
        source-dirs: app
        ghc-options:
          - -threaded
          - -rtsopts
          - -with-rtsopts=-N
  3. Create a app folder, then create a new file named Main.hs in that folder
    and paste the following code. This code creates a basic web server which
    listens on port 8080:

    haskell
    {-# LANGUAGE OverloadedStrings #-}
    
    import           Data.Maybe
    import           Data.Monoid        ((<>))
    import           Data.Text.Lazy     (Text)
    import           Data.Text.Lazy
    import           System.Environment (lookupEnv)
    import           Web.Scotty         (ActionM, ScottyM, scotty)
    import           Web.Scotty.Trans
    
    main :: IO ()
    main = do
      t <- fromMaybe "World" <$> lookupEnv "TARGET"
      pStr <- fromMaybe "8080" <$> lookupEnv "PORT"
      let p = read pStr :: Int
      scotty p (route t)
    
    route :: String -> ScottyM()
    route t = get "/" $ hello t
    
    hello :: String -> ActionM()
    hello t = text $ pack ("Hello " ++ t)
  4. In your project directory, create a file named Dockerfile and copy the code
    block below into it.

    docker
    # Use the official Haskell image to create a build artifact.
    # https://hub.docker.com/_/haskell/
    FROM haskell:8.2.2 as builder
    
    # Copy local code to the container image.
    WORKDIR /app
    COPY . .
    
    # Build and test our code, then build the โ€œhelloworld-haskell-exeโ€ executable.
    RUN stack setup
    RUN stack build --copy-bins
    
    # Use a Docker multi-stage build to create a lean production image.
    # https://docs.docker.com/develop/develop-images/multistage-build/#use-multi-stage-builds
    FROM fpco/haskell-scratch:integer-gmp
    
    # Copy the "helloworld-haskell-exe" executable from the builder stage to the production image.
    WORKDIR /root/
    COPY --from=builder /root/.local/bin/helloworld-haskell-exe .
    
    # Service must listen to $PORT environment variable.
    # This default value facilitates local development.
    ENV PORT 8080
    
    # Run the web service on container startup.
    CMD ["./helloworld-haskell-exe"]
  5. Create a new file, service.yaml and copy the following service definition
    into the file. Make sure to replace {username} with your Docker Hub
    username.

    yaml
    apiVersion: serving.knative.dev/v1alpha1
    kind: Service
    metadata:
      name: helloworld-haskell
      namespace: default
    spec:
      runLatest:
        configuration:
          revisionTemplate:
            spec:
              container:
                image: docker.io/{username}/helloworld-haskell
                env:
                  - name: TARGET
                    value: "Haskell Sample v1"

Build and deploy this sample

Once you have recreated the sample code files (or used the files in the sample
folder) you're ready to build and deploy the sample app.

  1. Use Docker to build the sample code into a container. To build and push with
    Docker Hub, enter these commands replacing {username} with your Docker Hub
    username:

    shell
    # Build the container on your local machine
    docker build -t {username}/helloworld-haskell .
    
    # Push the container to docker registry
    docker push {username}/helloworld-haskell
  2. After the build has completed and the container is pushed to Docker Hub, you
    can deploy the app into your cluster. Ensure that the container image value
    in service.yaml matches the container you built in the previous step. Apply
    the configuration using kubectl:

    shell
    kubectl apply --filename service.yaml
  3. Now that your service is created, Knative will perform the following steps:

    • Create a new immutable revision for this version of the app.
    • Network programming to create a route, ingress, service, and load balance
      for your app.
    • Automatically scale your pods up and down (including to zero active pods).
  4. To find the IP address for your service, enter these commands to get the
    ingress IP for your cluster. If your cluster is new, it may take some time
    for the service to get assigned an external IP address.

    shell
    # In Knative 0.2.x and prior versions, the `knative-ingressgateway` service was used instead of `istio-ingressgateway`.
    INGRESSGATEWAY=knative-ingressgateway
    
    # The use of `knative-ingressgateway` is deprecated in Knative v0.3.x.
    # Use `istio-ingressgateway` instead, since `knative-ingressgateway`
    # will be removed in Knative v0.4.
    if kubectl get configmap config-istio -n knative-serving &> /dev/null; then
        INGRESSGATEWAY=istio-ingressgateway
    fi
    
    kubectl get svc $INGRESSGATEWAY --namespace istio-system
    
    NAME                     TYPE           CLUSTER-IP     EXTERNAL-IP      PORT(S)                                      AGE
    xxxxxxx-ingressgateway   LoadBalancer   10.23.247.74   35.203.155.229   80:32380/TCP,443:32390/TCP,32400:32400/TCP   2d

    For minikube or bare-metal, get IP_ADDRESS by running the following command

    shell
    echo $(kubectl get node  --output 'jsonpath={.items[0].status.addresses[0].address}'):$(kubectl get svc $INGRESSGATEWAY --namespace istio-system   --output 'jsonpath={.spec.ports[?(@.port==80)].nodePort}')
  5. To find the URL for your service, enter:

    text
    kubectl get ksvc helloworld-haskell  --output=custom-columns=NAME:.metadata.name,DOMAIN:.status.domain
    NAME                   DOMAIN
    helloworld-haskell     helloworld-haskell.default.example.com
  6. Now you can make a request to your app and see the result. Replace
    {IP_ADDRESS} with the address you see returned in the previous step.

    shell
    curl -H "Host: helloworld-haskell.default.example.com" http://{IP_ADDRESS}
    Hello world: Haskell Sample v1

Removing the sample app deployment

To remove the sample app from your cluster, delete the service record:

shell
kubectl delete --filename service.yaml

File: community/samples/serving/helloworld-dart/README.md

Hello World - Dart sample

A simple web app written in the Dart programming language
that you can use for testing. It reads in the env variable TARGET and prints
"Hello $TARGET". If TARGET is not specified, it will use "World" as
TARGET.

Prerequisites

  • A Kubernetes cluster with Knative installed. Follow the
    installation instructions if you need to create
    one.
  • Docker installed and running on your local machine,
    and a Docker Hub account configured (we'll use it for a container registry).
  • dart-sdk installed and
    configured if you want to run the program locally.

Recreating the sample code

While you can clone all of the code from this directory, it is useful to know
how to build a hello world Dart application step-by-step. This application can
be created using the following instructions.

  1. Create a new directory and write pubspec.yaml as follows:

    yaml
    name: hello_world_dart
    publish_to: none # let's not accidentally publish this to pub.dartlang.org
      Hello world server example in dart.
    dependencies:
      shelf: ^0.7.3
    environment:
      sdk: ">=2.0.0 <3.0.0"
  2. If you want to run locally, install dependencies. If you only want to run in
    Docker or Knative, you can skip this step.

    shell
    pub get
  3. Create a new file bin/main.dart and write the following code:

    dart
    import 'dart:io';
    
    import 'package:shelf/shelf.dart';
    import 'package:shelf/shelf_io.dart';
    
    void main() {
      // Find port to listen on from environment variable.
      var port = int.tryParse(Platform.environment['PORT']);
    
      // Read $TARGET from environment variable.
      var target = Platform.environment['TARGET'] ?? 'World';
    
      // Create handler.
      var handler = Pipeline().addMiddleware(logRequests()).addHandler((request) {
        return Response.ok('Hello $target');
      });
    
      // Serve handler on given port.
      serve(handler, InternetAddress.anyIPv4, port).then((server) {
        print('Serving at http://${server.address.host}:${server.port}');
      });
    }
  4. Create a new file named Dockerfile, this file defines instructions for
    dockerizing your applications, for dart apps this can be done as follows:

    dockerfile
    # Use Google's official Dart image.
    # https://hub.docker.com/r/google/dart-runtime/
    FROM google/dart-runtime
    
    # Service must listen to $PORT environment variable.
    # This default value facilitates local development.
    ENV PORT 8080
  5. Create a new file, service.yaml and copy the following service definition
    into the file. Make sure to replace {username} with your Docker Hub
    username.

    yaml
    apiVersion: serving.knative.dev/v1alpha1
    kind: Service
    metadata:
      name: helloworld-dart
      namespace: default
    spec:
      runLatest:
        configuration:
          revisionTemplate:
            spec:
              container:
                image: docker.io/{username}/helloworld-dart
                env:
                  - name: TARGET
                    value: "Dart Sample v1"

Building and deploying the sample

Once you have recreated the sample code files (or used the files in the sample
folder) you're ready to build and deploy the sample app.

  1. Use Docker to build the sample code into a container. To build and push with
    Docker Hub, run these commands replacing {username} with your Docker Hub
    username:

    shell
    # Build the container on your local machine
    docker build -t {username}/helloworld-dart .
    
    # Push the container to docker registry
    docker push {username}/helloworld-dart
  2. After the build has completed and the container is pushed to docker hub, you
    can deploy the app into your cluster. Ensure that the container image value
    in service.yaml matches the container you built in the previous step. Apply
    the configuration using kubectl:

    shell
    kubectl apply --filename service.yaml
  3. Now that your service is created, Knative will perform the following steps:

    • Create a new immutable revision for this version of the app.
    • Network programming to create a route, ingress, service, and load balance
      for your app.
    • Automatically scale your pods up and down (including to zero active pods).
  4. To find the IP address for your service, use these commands to get the
    ingress IP for your cluster. If your cluster is new, it may take sometime for
    the service to get asssigned an external IP address.

    shell
    # In Knative 0.2.x and prior versions, the `knative-ingressgateway` service was used instead of `istio-ingressgateway`.
    INGRESSGATEWAY=knative-ingressgateway
    
    # The use of `knative-ingressgateway` is deprecated in Knative v0.3.x.
    # Use `istio-ingressgateway` instead, since `knative-ingressgateway`
    # will be removed in Knative v0.4.
    if kubectl get configmap config-istio -n knative-serving &> /dev/null; then
        INGRESSGATEWAY=istio-ingressgateway
    fi
    
    kubectl get svc $INGRESSGATEWAY --namespace istio-system
    
    NAME                     TYPE           CLUSTER-IP     EXTERNAL-IP      PORT(S)                                      AGE
    xxxxxxx-ingressgateway   LoadBalancer   10.23.247.74   35.203.155.229   80:32380/TCP,443:32390/TCP,32400:32400/TCP   2d
  5. To find the URL for your service, use

    text
    kubectl get ksvc helloworld-dart  --output=custom-columns=NAME:.metadata.name,DOMAIN:.status.domain
    NAME                DOMAIN
    helloworld-dart   helloworld-dart.default.example.com
  6. Now you can make a request to your app to see the result. Replace
    {IP_ADDRESS} with the address you see returned in the previous step.

    shell
    curl -H "Host: helloworld-dart.default.example.com" http://{IP_ADDRESS}
    Hello Dart Sample v1

Removing the sample app deployment

To remove the sample app from your cluster, delete the service record:

shell
kubectl delete --filename service.yaml

File: community/samples/serving/helloworld-clojure/README.md

Hello World - Clojure sample

A simple web app written in Clojure that you can use for testing. It reads in an
env variable TARGET and prints "Hello ${TARGET}!". If TARGET is not
specified, it will use "World" as the TARGET.

Prerequisites

  • A Kubernetes cluster with Knative installed. Follow the
    installation instructions if you need to create
    one.
  • Docker installed and running on your local machine,
    and a Docker Hub account configured (we'll use it for a container registry).

Recreating the sample code

While you can clone all of the code from this directory, hello world apps are
generally more useful if you build them step-by-step. The following instructions
recreate the source files from this folder.

  1. Create a new file named src/helloworld/core.clj and paste the following
    code. This code creates a basic web server which listens on port 8080:

    clojure
    (ns helloworld.core
      (:use ring.adapter.jetty)
      (:gen-class))
    
    (defn handler [request]
      {:status 200
       :headers {"Content-Type" "text/html"}
       :body (str "Hello "
                  (if-let [target (System/getenv "TARGET")]
                    target
                    "World")
                  "!\n")})
    
    (defn -main [& args]
      (run-jetty handler {:port (if-let [port (System/getenv "PORT")]
                                  (Integer/parseInt port)
                                  8080)}))
  2. In your project directory, create a file named project.clj and copy the
    code below into it. This code defines the project's dependencies and
    entrypoint.

    clojure
    (defproject helloworld "1.0.0-SNAPSHOT"
      :description "Hello World - Clojure sample"
      :dependencies [[org.clojure/clojure "1.9.0"]
                     [ring/ring-core "1.6.3"]
                     [ring/ring-jetty-adapter "1.6.3"]]
      :main helloworld.core)
  3. In your project directory, create a file named Dockerfile and copy the code
    block below into it. For detailed instructions on dockerizing a Clojure app,
    see
    the clojure image documentation.

    docker
    # Use the official Clojure image.
    # https://hub.docker.com/_/clojure
    FROM clojure
    
    # Create the project and download dependencies.
    WORKDIR /usr/src/app
    COPY project.clj .
    RUN lein deps
    
    # Copy local code to the container image.
    COPY . .
    
    # Build an uberjar release artifact.
    RUN mv "$(lein uberjar | sed -n 's/^Created \(.*standalone\.jar\)/\1/p')" app-standalone.jar
    
    # Service must listen to $PORT environment variable.
    # This default value facilitates local development.
    ENV PORT 8080
    
    # Run the web service on container startup.
    CMD ["java", "-jar", "app-standalone.jar"]
  4. Create a new file, service.yaml and copy the following service definition
    into the file. Make sure to replace {username} with your Docker Hub
    username.

    yaml
    apiVersion: serving.knative.dev/v1alpha1
    kind: Service
    metadata:
      name: helloworld-clojure
      namespace: default
    spec:
      runLatest:
        configuration:
          revisionTemplate:
            spec:
              container:
                image: docker.io/{username}/helloworld-clojure
                env:
                  - name: TARGET
                    value: "Clojure Sample v1"

Building and deploying the sample

Once you have recreated the sample code files (or used the files in the sample
folder) you're ready to build and deploy the sample app.

  1. Use Docker to build the sample code into a container. To build and push with
    Docker Hub, run these commands replacing {username} with your Docker Hub
    username:

    shell
    # Build the container on your local machine
    docker build -t {username}/helloworld-clojure .
    
    # Push the container to docker registry
    docker push {username}/helloworld-clojure
  2. After the build has completed and the container is pushed to docker hub, you
    can deploy the app into your cluster. Ensure that the container image value
    in service.yaml matches the container you built in the previous step. Apply
    the configuration using kubectl:

    shell
    kubectl apply --filename service.yaml
  3. Now that your service is created, Knative will perform the following steps:

    • Create a new immutable revision for this version of the app.
    • Network programming to create a route, ingress, service, and load balance
      for your app.
    • Automatically scale your pods up and down (including to zero active pods).
  4. To find the IP address for your service, use these commands to get the
    ingress IP for your cluster. If your cluster is new, it may take sometime for
    the service to get asssigned an external IP address.

    shell
    # In Knative 0.2.x and prior versions, the `knative-ingressgateway` service was used instead of `istio-ingressgateway`.
    INGRESSGATEWAY=knative-ingressgateway
    
    # The use of `knative-ingressgateway` is deprecated in Knative v0.3.x.
    # Use `istio-ingressgateway` instead, since `knative-ingressgateway`
    # will be removed in Knative v0.4.
    if kubectl get configmap config-istio -n knative-serving &> /dev/null; then
        INGRESSGATEWAY=istio-ingressgateway
    fi
    
    kubectl get svc $INGRESSGATEWAY --namespace istio-system
    
    NAME                     TYPE           CLUSTER-IP     EXTERNAL-IP      PORT(S)                                      AGE
    xxxxxxx-ingressgateway   LoadBalancer   10.23.247.74   35.203.155.229   80:32380/TCP,443:32390/TCP,32400:32400/TCP   2d
  5. To find the URL for your service, use

    text
    kubectl get ksvc helloworld-clojure --output=custom-columns=NAME:.metadata.name,DOMAIN:.status.domain
    NAME                DOMAIN
    helloworld-clojure  helloworld-clojure.default.example.com
  6. Now you can make a request to your app to see the results. Replace
    {IP_ADDRESS} with the address you see returned in the previous step.

    shell
    curl -H "Host: helloworld-clojure.default.example.com" http://{$IP_ADDRESS}
    Hello World: Clojure Sample v1!

Removing the sample app deployment

To remove the sample app from your cluster, delete the service record:

shell
kubectl delete --filename service.yaml

File: community/samples/README.md

Sample apps

Sample Name Knative Component Description Language(s)
Hello World Serving A quick introduction that highlights how to deploy an app. Clojure, Dart, Elixir, Haskell, Rust, Shell, Swift, Vertx

File: contributing/README.md

Important. Before proceeding, please review the Knative community
Code of Conduct.

If you any have questions or concerns, please contact the authors at
[email protected].

Welcome!

Welcome to the Knative community!

This is the starting point for becoming a contributor - improving code,
improving docs, giving talks, etc.

Other Documents

Introduction

Knative is a Kubernetes-based platform to build, deploy, and manage modern
serverless workloads. See Knative docs for in-depth
information about using Knative.

Knative authors

Knative is an open source project with an active development community. The
project was started by Google but has contributions from a growing number of
industry-leading companies. For a current list of the authors, see
Authors.

Authoring samples

Beyond the official documentation there are endless possibilities for combining
tools, platforms, languages, and products. By submitting a tutorial you can
share your experience and help others who are solving similar problems.

Community tutorials are stored in Markdown files under the community folder
Community Samples. These documents are
contributed, reviewed, and maintained by the community.

Submit a Pull Request to the community sample directory under the Knative
component folder that aligns with your document. For example, Knative Serving
samples are under the serving folder. A reviewer will be assigned to review
your submission. They'll work with you to ensure that your submission is clear,
correct, and meets the style guide, but it helps if
you follow it as you write your tutorial.

Meetings and work groups

Knative has public and recorded bi-weekly community meetings.

Each project has one or more working groups driving the
project, and Knative as a single
technical oversight community monitoring the
overall project.

How can I help

If you're looking for something to do to get your feet wet working on Knative,
look for GitHub issues marked with the Help Wanted label:

Even if there's not an issue opened for it, we can always use more testing
throughout the platform. Similarly, we can always use more docs, richer docs,
insightful docs. Or maybe a cool blog post? And if you're a web developer, we
could use your help in spiffing up our public-facing web site.

Questions and issues

If you're a developer, operator, or contributor trying to use Knative, the
following resources are available for you:

For contributors to Knative, we also have
Knative Slack.


Except as otherwise noted, the content of this page is licensed under the
Creative Commons Attribution 4.0 License,
and code samples are licensed under the
Apache 2.0 License.