Skip to content

Commit 515e1e1

Browse files
committed
Add splashy - the placeholder bootstrap app
This commit introduces a new Go app, under `tools`, which is a simple web server listening on multiple ports to serve a simple "splash" page for newly created Deployments. This app is aptly called "splashy". The Dockerfile is updated with an entrypoint that uses heuristics to determine whether to start splashy (if running in Kubernetes Pod) or not. Ref: https://issues.redhat.com/browse/RHTAP-5218 Signed-off-by: Luiz Carvalho <[email protected]>
1 parent 5f821e5 commit 515e1e1

File tree

8 files changed

+179
-1
lines changed

8 files changed

+179
-1
lines changed

.tekton/rhtap-task-runner-pull-request.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ spec:
3939
[
4040
{"type": "gomod", "path": "tools/syft"},
4141
{"type": "gomod", "path": "tools/yq"},
42+
{"type": "gomod", "path": "tools/splashy"},
4243
{"type": "rpm", "path": "tools/rpm-manifests"}
4344
]
4445
- name: build-source-image

.tekton/rhtap-task-runner-push.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ spec:
3535
[
3636
{"type": "gomod", "path": "tools/syft"},
3737
{"type": "gomod", "path": "tools/yq"},
38+
{"type": "gomod", "path": "tools/splashy"},
3839
{"type": "rpm", "path": "tools/rpm-manifests"}
3940
]
4041
- name: build-source-image

Dockerfile

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,10 @@ RUN \
2222
go install -trimpath --mod=readonly github.com/anchore/syft/cmd/syft && \
2323
syft version
2424

25+
RUN \
26+
cd splashy && \
27+
go install -trimpath --mod=readonly github.com/redhat-appstudio/tssc-dev-multi-ci/tools/splashy
28+
2529
FROM registry.access.redhat.com/ubi9/ubi-minimal:9.6@sha256:92b1d5747a93608b6adb64dfd54515c3c5a360802db4706765ff3d8470df6290
2630

2731
# required per https://github.com/release-engineering/rhtap-ec-policy/blob/main/data/rule_data.yml
@@ -46,9 +50,12 @@ COPY --from=cosign /usr/local/bin/cosign /usr/bin/cosign
4650
COPY --from=ec /usr/local/bin/ec /usr/bin/ec
4751
COPY --from=go-builder /usr/local/bin/yq /usr/bin/yq
4852
COPY --from=go-builder /usr/local/bin/syft /usr/bin/syft
53+
COPY --from=go-builder /usr/local/bin/splashy /usr/bin/splashy
4954

5055
WORKDIR /work
5156

5257
COPY ./rhtap ./rhtap/
5358

54-
CMD ["/bin/bash"]
59+
COPY ./entrypoint.sh /usr/local/bin/
60+
61+
ENTRYPOINT ["/usr/local/bin/entrypoint.sh"]

entrypoint.sh

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#!/bin/bash
2+
3+
set -euo pipefail
4+
5+
# These variables are automatically injected by Kubernetes. NOTE: If this image is executed
6+
# via a Tekton Task, the entrypoint is not used so we don't need to take that use case into
7+
# account in this script.
8+
if [[ -n "${KUBERNETES_SERVICE_HOST:-}${KUBERNETES_SERVICE_PORT:-}" ]]; then
9+
echo "Running in Kubernetes Deployment - starting web server..."
10+
exec splashy
11+
else
12+
echo "Not running in Kubernetes Deployment - executing command..."
13+
exec "$@"
14+
fi

tools/splashy/README.md

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# Splashy
2+
3+
A minimal web server that listens on multiple ports (8080, 8081, and 3001) simultaneously. The
4+
server responds with a simple static splash page. This is intended to be used as a placeholder
5+
image for Deployments created via RHADS-SSC.
6+
7+
## Usage
8+
9+
To run the server:
10+
11+
```bash
12+
go run main.go
13+
```
14+
15+
The server will start listening on:
16+
- http://localhost:8080
17+
- http://localhost:8081
18+
- http://localhost:3001
19+
20+
## Config
21+
22+
The GIT_REPO environment variable is injected into the index page in order to provide additional
23+
context to clients.

tools/splashy/go.mod

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
module github.com/redhat-appstudio/tssc-dev-multi-ci/tools/splashy
2+
3+
go 1.23.6

tools/splashy/main.go

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
package main
2+
3+
import (
4+
"bytes"
5+
_ "embed"
6+
"log"
7+
"net/http"
8+
"os"
9+
"sync"
10+
)
11+
12+
//go:embed www/index.html
13+
var index_html []byte
14+
15+
func init() {
16+
gitRepo := "UNKNOWN"
17+
if env_git_repo := os.Getenv("GIT_REPO"); env_git_repo != "" {
18+
gitRepo = env_git_repo
19+
}
20+
index_html = bytes.Replace(index_html, []byte("GIT_REPO"), []byte(gitRepo), -1)
21+
}
22+
23+
func handler(w http.ResponseWriter, r *http.Request) {
24+
w.Header().Set("Content-Type", "text/html; charset=utf-8")
25+
w.Write(index_html)
26+
}
27+
28+
func startServer(port string, wg *sync.WaitGroup) {
29+
defer wg.Done()
30+
31+
mux := http.NewServeMux()
32+
mux.HandleFunc("/", handler)
33+
34+
server := &http.Server{
35+
Addr: ":" + port,
36+
Handler: mux,
37+
}
38+
39+
log.Printf("Starting server on port %s\n", port)
40+
if err := server.ListenAndServe(); err != nil {
41+
log.Printf("Server on port %s failed: %v\n", port, err)
42+
}
43+
}
44+
45+
func main() {
46+
ports := []string{"8080", "8081", "3001"}
47+
var wg sync.WaitGroup
48+
49+
for _, port := range ports {
50+
wg.Add(1)
51+
go startServer(port, &wg)
52+
}
53+
54+
wg.Wait()
55+
}

tools/splashy/www/index.html

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<title>RHADS-SSC Bootstrap App</title>
5+
<meta charset="UTF-8">
6+
<meta name="viewport" content="width=device-width, initial-scale=1">
7+
<link rel="stylesheet" href="https://www.w3schools.com/w3css/4/w3.css">
8+
<link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Lato">
9+
<link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Montserrat">
10+
<link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.15.1/css/all.css">
11+
12+
<style>
13+
body,
14+
h1 {
15+
font-family: "Lato", sans-serif;
16+
}
17+
18+
.w3-bar,
19+
h1,
20+
button {
21+
font-family: "Montserrat", sans-serif;
22+
}
23+
24+
.column {
25+
float: left;
26+
width: 80%;
27+
text-align: center;
28+
}
29+
30+
.columnr {
31+
float: right;
32+
width: 20%;
33+
text-align: center;
34+
}
35+
36+
.row:after {
37+
content: "";
38+
display: table;
39+
clear: both;
40+
}
41+
</style>
42+
</head>
43+
44+
<body>
45+
<!-- Header -->
46+
<header class="w3-container w3-red w3-center" style="padding:64px 16px">
47+
<i class="fab fa-redhat fa-5x"></i>
48+
<h1 class="w3-margin w3-jumbo">Red Hat Advanced Developer Suite - Software Supply Chain</h1>
49+
</header>
50+
51+
<div class="w3-row-padding w3-padding-64 w3-container">
52+
<div class="w3-content">
53+
<p class="w3-xlarge">
54+
Please wait, your application is still building...
55+
</p>
56+
57+
<h1>Deployed from gitops repository GIT_REPO</h1>
58+
59+
<p class="w3-xlarge">
60+
This is a simple landing page bootstrapped by Red Hat Advanced Developer Suite -
61+
Software Supply Chain. This default container was installed into the generated
62+
gitops repository as a placeholder image while the source application builds.
63+
When the application completes its build and validation, it will replace this
64+
landing page via the gitops repository shown above.
65+
</p>
66+
67+
<p>
68+
As a demo application this container responds to ports 8080, 8081, and 3001 to
69+
enable reuse across multiple deployment ports.
70+
</p>
71+
</div>
72+
</div>
73+
</body>
74+
</html>

0 commit comments

Comments
 (0)