diff --git a/porch/config/samples/apps/hello-server/Dockerfile b/porch/config/samples/apps/hello-server/Dockerfile new file mode 100644 index 0000000000..1c7191938e --- /dev/null +++ b/porch/config/samples/apps/hello-server/Dockerfile @@ -0,0 +1,29 @@ +# Copyright 2022 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +FROM golang:1.17-bullseye as builder + +WORKDIR /src +COPY go.mod go.sum ./ + +WORKDIR /src +COPY *.go . + +RUN CGO_ENABLED=0 go build -o /hello-server -v . + +FROM gcr.io/distroless/static +WORKDIR / +COPY --from=builder /hello-server /hello-server + +ENTRYPOINT ["/hello-server"] diff --git a/porch/config/samples/apps/hello-server/Makefile b/porch/config/samples/apps/hello-server/Makefile new file mode 100644 index 0000000000..98cf5f959e --- /dev/null +++ b/porch/config/samples/apps/hello-server/Makefile @@ -0,0 +1,27 @@ +# Copyright 2022 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# GCP project to use for development +GCP_PROJECT_ID ?= $(shell gcloud config get-value project) +IMAGE_TAG ?= latest +IMAGE_REPO ?= gcr.io/$(GCP_PROJECT_ID) +IMAGE_NAME ?= hello-server + +.PHONY: push-image +push-image: + docker buildx build --push --tag $(IMAGE_REPO)/$(IMAGE_NAME):$(IMAGE_TAG) . + +.PHONY: build-image +build-image: + docker buildx build --load --tag $(IMAGE_REPO)/$(IMAGE_NAME):$(IMAGE_TAG) . diff --git a/porch/config/samples/apps/hello-server/go.mod b/porch/config/samples/apps/hello-server/go.mod new file mode 100644 index 0000000000..87355781b5 --- /dev/null +++ b/porch/config/samples/apps/hello-server/go.mod @@ -0,0 +1,3 @@ +module github.com/GoogleContainerTools/kpt/porch/config/samples/apps/hello + +go 1.17 diff --git a/porch/config/samples/apps/hello-server/go.sum b/porch/config/samples/apps/hello-server/go.sum new file mode 100644 index 0000000000..e69de29bb2 diff --git a/porch/config/samples/apps/hello-server/k8s/Kptfile b/porch/config/samples/apps/hello-server/k8s/Kptfile new file mode 100644 index 0000000000..e99bae3694 --- /dev/null +++ b/porch/config/samples/apps/hello-server/k8s/Kptfile @@ -0,0 +1,13 @@ +apiVersion: kpt.dev/v1 +kind: Kptfile +metadata: + name: hello-server +info: + emails: + - kpt-team@google.com + description: This is an example package. +# pipeline: +# validators: +# - image: gcr.io/kpt-fn/kubeval:v0.1 +# configMap: +# strict: "true" diff --git a/porch/config/samples/apps/hello-server/k8s/deployment.yaml b/porch/config/samples/apps/hello-server/k8s/deployment.yaml new file mode 100644 index 0000000000..0650ec039d --- /dev/null +++ b/porch/config/samples/apps/hello-server/k8s/deployment.yaml @@ -0,0 +1,32 @@ +# Copyright 2021 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +apiVersion: apps/v1 +kind: Deployment +metadata: + name: hello-server + namespace: hello-server +spec: + replicas: 2 + selector: + matchLabels: + app: hello-server + template: + metadata: + labels: + app: hello-server + spec: + containers: + - name: hello-server + image: "gcr.io/example-google-project-id/hello-server:latest" diff --git a/porch/config/samples/apps/hello-server/k8s/ns.yaml b/porch/config/samples/apps/hello-server/k8s/ns.yaml new file mode 100644 index 0000000000..298821f123 --- /dev/null +++ b/porch/config/samples/apps/hello-server/k8s/ns.yaml @@ -0,0 +1,18 @@ +# Copyright 2021 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +apiVersion: v1 +kind: Namespace +metadata: + name: hello-server diff --git a/porch/config/samples/apps/hello-server/k8s/svc.yaml b/porch/config/samples/apps/hello-server/k8s/svc.yaml new file mode 100644 index 0000000000..98aa21cdae --- /dev/null +++ b/porch/config/samples/apps/hello-server/k8s/svc.yaml @@ -0,0 +1,27 @@ +# Copyright 2021 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +apiVersion: v1 +kind: Service +metadata: + name: hello-server + namespace: hello-server +spec: + type: LoadBalancer + selector: + app: hello-server + ports: + - protocol: TCP + port: 80 + targetPort: 8080 diff --git a/porch/config/samples/apps/hello-server/main.go b/porch/config/samples/apps/hello-server/main.go new file mode 100644 index 0000000000..fd072f9431 --- /dev/null +++ b/porch/config/samples/apps/hello-server/main.go @@ -0,0 +1,45 @@ +// Copyright 2022 Google LLC +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package main + +import ( + "context" + "fmt" + "net/http" + "os" +) + +func main() { + if err := run(context.Background()); err != nil { + fmt.Fprintf(os.Stderr, "%v\n", err) + os.Exit(1) + } +} + +func run(ctx context.Context) error { + http.HandleFunc("/", HelloHandler) + + listen := ":8080" + if err := http.ListenAndServe(listen, nil); err != nil { + return fmt.Errorf("error listening on %q: %w", listen, err) + } + + // This is documented not to happen + return fmt.Errorf("error:: ListenAndServe returned nil error") +} + +func HelloHandler(w http.ResponseWriter, r *http.Request) { + fmt.Fprintf(w, "Hello world\n") +}