photos-ui: move to bazel
diff --git a/apps/photos-ui/BUILD b/apps/photos-ui/BUILD
new file mode 100644
index 0000000..e25c31e
--- /dev/null
+++ b/apps/photos-ui/BUILD
@@ -0,0 +1,55 @@
+load("@io_bazel_rules_go//go:def.bzl", "go_binary")
+load("@io_bazel_rules_docker//container:container.bzl", "container_push", "container_image")
+load("@rules_pkg//:pkg.bzl", "pkg_tar")
+
+go_binary(
+ name = "photos_ui",
+ srcs = ["main.go"],
+ data = glob([
+ "static/**",
+ "*.html",
+ ]),
+ deps = [
+ "@io_bazel_rules_go//go/tools/bazel:bazel",
+ ],
+)
+
+filegroup(
+ name = "runfiles",
+ srcs = glob([
+ "static/**",
+ "*.html",
+ "photos_ui.runfiles_manifest",
+ ]),
+)
+
+container_image(
+ name = "container",
+ base = "@alpine_base//image",
+ files = [":photos_ui", ":runfiles"],
+ data_path = "/",
+ cmd = ["/photos_ui"],
+ env = {
+ "RUNFILES_DIR": "/",
+ "RUNFILES_MANIFEST_FILE": "/photos_ui.runfiles_manifest",
+ },
+ symlinks = {
+ "/photos_ui": "/apps/photos-ui/photos_ui_/photos_ui",
+ },
+)
+
+container_push(
+ name = "push_to_dev",
+ image = ":container",
+ format = "Docker",
+ registry = "localhost:30500",
+ repository = "giolekva/photos-ui",
+ tag = "latest",
+)
+
+pkg_tar(
+ name = "chart",
+ srcs = glob(["chart/**"]),
+ extension = "tar.gz",
+ strip_prefix = "./chart",
+)
diff --git a/apps/photos-ui/chart/templates/install.yaml b/apps/photos-ui/chart/templates/install.yaml
index 1e88645..1978b10 100644
--- a/apps/photos-ui/chart/templates/install.yaml
+++ b/apps/photos-ui/chart/templates/install.yaml
@@ -52,4 +52,4 @@
imagePullPolicy: {{ .Values.image.pullPolicy }}
ports:
- containerPort: {{ .Values.containerPort }}
- command: ["photos-ui", "--port={{ .Values.containerPort }}", "--pcloud_api_addr={{ .Values.pcloudApiAddr }}"]
+ command: ["/photos_ui", "--port={{ .Values.containerPort }}", "--pcloud_api_addr={{ .Values.pcloudApiAddr }}"]
diff --git a/apps/photos-ui/chart/values.yaml b/apps/photos-ui/chart/values.yaml
index 74618e6..bfb5260 100644
--- a/apps/photos-ui/chart/values.yaml
+++ b/apps/photos-ui/chart/values.yaml
@@ -1,6 +1,6 @@
replicas: 1
image:
- name: giolekva/photos-ui
+ name: localhost:30500/giolekva/photos-ui
tag: latest
pullPolicy: Always
servicePort: 80
diff --git a/apps/photos-ui/gallery.html b/apps/photos-ui/gallery.html
index a8001d0..68e200d 100644
--- a/apps/photos-ui/gallery.html
+++ b/apps/photos-ui/gallery.html
@@ -3,7 +3,7 @@
<head>
<title>Photos</title>
</head>
- <script src="static/photos.js"></script>
+ <script src="static/photos.js?v4"></script>
<body onload="initGallery('gallery')">
<div id="gallery" />
</body>
diff --git a/apps/photos-ui/main.go b/apps/photos-ui/main.go
index b85036e..e170a73 100644
--- a/apps/photos-ui/main.go
+++ b/apps/photos-ui/main.go
@@ -8,13 +8,19 @@
"net/http/httputil"
"net/url"
"text/template"
+
+ "github.com/bazelbuild/rules_go/go/tools/bazel"
)
var port = flag.Int("port", 3000, "Port to listen on.")
var pcloudApiAddr = flag.String("pcloud_api_addr", "", "PCloud API Server address.")
func handle_gallery(w http.ResponseWriter, r *http.Request) {
- http.ServeFile(w, r, "./gallery.html")
+ gallery_html, err := bazel.Runfile("apps/photos-ui/gallery.html")
+ if err != nil {
+ http.Error(w, err.Error(), http.StatusInternalServerError)
+ }
+ http.ServeFile(w, r, gallery_html)
}
func handle_photo(w http.ResponseWriter, r *http.Request) {
@@ -28,7 +34,11 @@
http.Error(w, "Photo id must be provided", http.StatusBadRequest)
return
}
- t, err := template.ParseFiles("photo.html")
+ photo_html, err := bazel.Runfile("apps/photos-ui/photo.html")
+ if err != nil {
+ http.Error(w, err.Error(), http.StatusInternalServerError)
+ }
+ t, err := template.ParseFiles(photo_html)
if err != nil {
log.Print(err)
http.Error(w, "Could not process page", http.StatusInternalServerError)
@@ -52,7 +62,11 @@
func main() {
flag.Parse()
- fs := http.FileServer(http.Dir("./static"))
+ static_dir, err := bazel.Runfile("apps/photos-ui/static")
+ if err != nil {
+ log.Fatal(err)
+ }
+ fs := http.FileServer(http.Dir(static_dir))
http.Handle("/static/", http.StripPrefix("/static/", fs))
http.Handle("/graphql", newGqlProxy(*pcloudApiAddr))
http.HandleFunc("/photo", handle_photo)
diff --git a/apps/photos-ui/photo.html b/apps/photos-ui/photo.html
index d41bb29..d2dd612 100644
--- a/apps/photos-ui/photo.html
+++ b/apps/photos-ui/photo.html
@@ -3,7 +3,7 @@
<head>
<title>Photos</title>
</head>
- <script src="static/photos.js"></script>
+ <script src="static/photos.js?v4"></script>
<body onload="initImg('photo', '{{ .Id }}')">
<img id="photo" onload="drawFaces('photo', 'faces', '{{ .Id }}')" src=""></img>
<canvas id="faces"></canvas>
diff --git a/apps/photos-ui/photos_ui.runfiles_manifest b/apps/photos-ui/photos_ui.runfiles_manifest
new file mode 100644
index 0000000..b604c19
--- /dev/null
+++ b/apps/photos-ui/photos_ui.runfiles_manifest
@@ -0,0 +1,3 @@
+/apps/photos-ui/gallery.html /gallery.html
+/apps/photos-ui/photo.html /photo.html
+/apps/photos-ui/static/photos.js /static/photos.js
diff --git a/apps/photos-ui/static/photos.js b/apps/photos-ui/static/photos.js
index ed33e0d..d098829 100644
--- a/apps/photos-ui/static/photos.js
+++ b/apps/photos-ui/static/photos.js
@@ -35,7 +35,7 @@
imgs = await fetchAllPhotos();
img_list = "<ul>";
for (img of imgs) {
- img_list += "<li><a href='/photo?id=" + img.id + "'><img style='max-width: 300px' src='http://minio/" + img.objectPath + "' /></a></li>";
+ img_list += "<li><a href='/photo?id=" + img.id + "'><img style='max-width: 300px' src='http://minio:8080/" + img.objectPath + "' /></a></li>";
}
img_list += "</ul>";
document.getElementById(gallery_elem_id).innerHTML = img_list;
@@ -43,7 +43,7 @@
async function initImg(img_elem_id, id) {
img = await fetchImage(id);
- document.getElementById(img_elem_id).setAttribute("src", "http://minio/" + img.objectPath);
+ document.getElementById(img_elem_id).setAttribute("src", "http://minio:8080/" + img.objectPath);
}
async function drawFaces(photo_elem_id, faces_canvas_elem_id, id){