photos-ui: dockerfile + make paths relative
diff --git a/apps/photos-ui/Dockerfile b/apps/photos-ui/Dockerfile
new file mode 100644
index 0000000..8e02ed9
--- /dev/null
+++ b/apps/photos-ui/Dockerfile
@@ -0,0 +1,30 @@
+FROM golang:1-alpine AS build
+
+RUN apk update && apk upgrade && \
+ apk add --no-cache bash git openssh
+
+WORKDIR /app
+COPY *.go .
+
+ENV CGO_ENABLED 0
+ENV GO111MODULE off
+RUN go build -o photos-ui -trimpath -ldflags="-s -w" main.go
+
+FROM alpine:latest
+WORKDIR /app
+COPY --from=build /app/photos-ui .
+COPY *.html .
+WORKDIR /app/static
+COPY static/photos.js .
+WORKDIR /app
+
+RUN chmod a+x /app/photos-ui
+
+ENV PATH="/app:${PATH}"
+
+ENV PORT 80
+EXPOSE ${PORT}
+ENV PCLOUD_API_ADDR ""
+CMD photos-ui --port=${PORT} --pcloud_api_addr=${PCLOUD_API_ADDR}
+
+
diff --git a/apps/photos-ui/main.go b/apps/photos-ui/main.go
index 97e0126..b85036e 100644
--- a/apps/photos-ui/main.go
+++ b/apps/photos-ui/main.go
@@ -11,7 +11,7 @@
)
var port = flag.Int("port", 3000, "Port to listen on.")
-var pcloudApiServer = flag.String("pcloud_api_server", "", "PCloud API Server address.")
+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")
@@ -42,8 +42,8 @@
}
}
-func newGqlProxy(pcloudApiServer string) *httputil.ReverseProxy {
- u, err := url.Parse(pcloudApiServer)
+func newGqlProxy(pcloudApiAddr string) *httputil.ReverseProxy {
+ u, err := url.Parse(pcloudApiAddr)
if err != nil {
panic(err)
}
@@ -54,7 +54,7 @@
flag.Parse()
fs := http.FileServer(http.Dir("./static"))
http.Handle("/static/", http.StripPrefix("/static/", fs))
- http.Handle("/graphql", newGqlProxy(*pcloudApiServer))
+ http.Handle("/graphql", newGqlProxy(*pcloudApiAddr))
http.HandleFunc("/photo", handle_photo)
http.HandleFunc("/", handle_gallery)
log.Fatal(http.ListenAndServe(fmt.Sprintf(":%d", *port), nil))
diff --git a/apps/photos-ui/static/photos.js b/apps/photos-ui/static/photos.js
index dac17f9..ed33e0d 100644
--- a/apps/photos-ui/static/photos.js
+++ b/apps/photos-ui/static/photos.js
@@ -1,5 +1,5 @@
async function fetchAllPhotos() {
- return await fetch("/graphql?query={queryImage(){id objectPath}}")
+ return await fetch("graphql?query={queryImage(){id objectPath}}")
.then(resp => resp.json())
.then(resp => resp.queryImage)
.catch(error => {
@@ -10,7 +10,7 @@
}
async function fetchImage(id) {
- return await fetch("/graphql?query={getImage(id: \"" + id + "\"){id objectPath}}")
+ return await fetch("graphql?query={getImage(id: \"" + id + "\"){id objectPath}}")
.then(resp => resp.json())
.then(resp => resp.getImage)
.catch(error => {
@@ -21,7 +21,7 @@
}
async function fetchAllImageSegments(id) {
- return await fetch("/graphql?query={getImage(id: \"" + id + "\"){segments { upperLeftX upperLeftY lowerRightX lowerRightY }}}")
+ return await fetch("graphql?query={getImage(id: \"" + id + "\"){segments { upperLeftX upperLeftY lowerRightX lowerRightY }}}")
.then(resp => resp.json())
.then(resp => resp.getImage.segments)
.catch(error => {