Skip to content

Commit 3140574

Browse files
authored
porch: create simple standalone app (#2830)
We need an app that doesn't have validators etc.
1 parent 1fa0898 commit 3140574

File tree

9 files changed

+194
-0
lines changed

9 files changed

+194
-0
lines changed
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# Copyright 2022 Google LLC
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
FROM golang:1.17-bullseye as builder
16+
17+
WORKDIR /src
18+
COPY go.mod go.sum ./
19+
20+
WORKDIR /src
21+
COPY *.go .
22+
23+
RUN CGO_ENABLED=0 go build -o /hello-server -v .
24+
25+
FROM gcr.io/distroless/static
26+
WORKDIR /
27+
COPY --from=builder /hello-server /hello-server
28+
29+
ENTRYPOINT ["/hello-server"]
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# Copyright 2022 Google LLC
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
# GCP project to use for development
16+
GCP_PROJECT_ID ?= $(shell gcloud config get-value project)
17+
IMAGE_TAG ?= latest
18+
IMAGE_REPO ?= gcr.io/$(GCP_PROJECT_ID)
19+
IMAGE_NAME ?= hello-server
20+
21+
.PHONY: push-image
22+
push-image:
23+
docker buildx build --push --tag $(IMAGE_REPO)/$(IMAGE_NAME):$(IMAGE_TAG) .
24+
25+
.PHONY: build-image
26+
build-image:
27+
docker buildx build --load --tag $(IMAGE_REPO)/$(IMAGE_NAME):$(IMAGE_TAG) .
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
module github.com/GoogleContainerTools/kpt/porch/config/samples/apps/hello
2+
3+
go 1.17

porch/config/samples/apps/hello-server/go.sum

Whitespace-only changes.
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
apiVersion: kpt.dev/v1
2+
kind: Kptfile
3+
metadata:
4+
name: hello-server
5+
info:
6+
emails:
7+
8+
description: This is an example package.
9+
# pipeline:
10+
# validators:
11+
# - image: gcr.io/kpt-fn/kubeval:v0.1
12+
# configMap:
13+
# strict: "true"
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
# Copyright 2021 Google LLC
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
apiVersion: apps/v1
16+
kind: Deployment
17+
metadata:
18+
name: hello-server
19+
namespace: hello-server
20+
spec:
21+
replicas: 2
22+
selector:
23+
matchLabels:
24+
app: hello-server
25+
template:
26+
metadata:
27+
labels:
28+
app: hello-server
29+
spec:
30+
containers:
31+
- name: hello-server
32+
image: "gcr.io/example-google-project-id/hello-server:latest"
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# Copyright 2021 Google LLC
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
apiVersion: v1
16+
kind: Namespace
17+
metadata:
18+
name: hello-server
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# Copyright 2021 Google LLC
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
apiVersion: v1
16+
kind: Service
17+
metadata:
18+
name: hello-server
19+
namespace: hello-server
20+
spec:
21+
type: LoadBalancer
22+
selector:
23+
app: hello-server
24+
ports:
25+
- protocol: TCP
26+
port: 80
27+
targetPort: 8080
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
// Copyright 2022 Google LLC
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
package main
16+
17+
import (
18+
"context"
19+
"fmt"
20+
"net/http"
21+
"os"
22+
)
23+
24+
func main() {
25+
if err := run(context.Background()); err != nil {
26+
fmt.Fprintf(os.Stderr, "%v\n", err)
27+
os.Exit(1)
28+
}
29+
}
30+
31+
func run(ctx context.Context) error {
32+
http.HandleFunc("/", HelloHandler)
33+
34+
listen := ":8080"
35+
if err := http.ListenAndServe(listen, nil); err != nil {
36+
return fmt.Errorf("error listening on %q: %w", listen, err)
37+
}
38+
39+
// This is documented not to happen
40+
return fmt.Errorf("error:: ListenAndServe returned nil error")
41+
}
42+
43+
func HelloHandler(w http.ResponseWriter, r *http.Request) {
44+
fmt.Fprintf(w, "Hello world\n")
45+
}

0 commit comments

Comments
 (0)