From f9ec2419abbeae33bf788bd85c3725c7327a1c04 Mon Sep 17 00:00:00 2001 From: leonnicolas Date: Fri, 13 Nov 2020 08:45:41 +0100 Subject: [PATCH 1/7] main.go: fixed routing for url with dots When a url contained a dot and the user refreshed the site, the server would have returned a 404. Now it will always return index.html, if the requested file is not found. --- main.go | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/main.go b/main.go index b795268..5aacf50 100644 --- a/main.go +++ b/main.go @@ -3,28 +3,26 @@ package main import ( "log" "net/http" - "strings" "github.com/rakyll/statik/fs" _ "github.com/fLotte-meets-HWR-DB/frontend/statik" ) -func strip(handler http.Handler) http.Handler { - return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { - if !strings.Contains(r.URL.Path, ".") { - r.URL.Path = "/" - } - handler.ServeHTTP(w, r) - }) -} func main() { statikFS, err := fs.New() if err != nil { log.Fatal(err) } + fserver := http.FileServer(statikFS) m := http.NewServeMux() - m.Handle("/", strip(http.FileServer(statikFS))) + m.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) { + if _, err := statikFS.Open(r.URL.Path); err != nil { + r.URL.Path = "/" + } + fserver.ServeHTTP(w, r) + }) + log.Fatal(http.ListenAndServe(":8080", m)) } From 553d4da0eca39bf07f1cf5c5599551c7a9f87cca Mon Sep 17 00:00:00 2001 From: leonnicolas Date: Fri, 13 Nov 2020 09:14:12 +0100 Subject: [PATCH 2/7] .travis.yml: create multi arch image and docker manifest Now you can just pull the image from an arm64 (armV8), arm(armV7) or amd64 architecture without specifying any tag. --- .travis.yml | 16 +++++++++++++--- Dockerfile | 3 ++- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/.travis.yml b/.travis.yml index e1f6a71..d101271 100644 --- a/.travis.yml +++ b/.travis.yml @@ -7,6 +7,16 @@ services: script: - docker login -u="$DOCKER_USER" -p="$DOCKER_PW" https://flotte-docker-registry.spdns.org/ - - docker build -t frontend-server . - - docker tag frontend-server flotte-docker-registry.spdns.org/frontend-server - - docker push flotte-docker-registry.spdns.org/frontend-server:latest + - docker build -t frontend-server:amd64 . --build-arg ARCH=amd64 + - docker build -t frontend-server:arm . --build-arg ARCH=arm + - docker build -t frontend-server:arm64 . --build-arg ARCH=arm64 + - docker tag frontend-server:amd64 flotte-docker-registry.spdns.org/frontend-server:amd64 + - docker push flotte-docker-registry.spdns.org/frontend-server:amd64 + - docker tag frontend-server flotte-docker-registry.spdns.org/frontend-server:arm64 + - docker push flotte-docker-registry.spdns.org/frontend-server:arm64 + - docker tag frontend-server flotte-docker-registry.spdns.org/frontend-server:arm + - docker push flotte-docker-registry.spdns.org/frontend-server:arm + - docker manifest create --amend flotte-docker-registry.spdns.org/frontend-server:latest flotte-docker-registry.spdns.org/frontend-server:arm flotte-docker-registry.spdns.org/frontend-server:arm64 flotte-docker-registry.spdns.org/frontend-server:amd64 + - docker manifest annotate flotte-docker-registry.spdns.org/frontend-server:latest flotte-docker-registry.spdns.org/frontend-server:arm --os linux --arch arm --variant v7 + - docker manifest annotate flotte-docker-registry.spdns.org/frontend-server:latest flotte-docker-registry.spdns.org/frontend-server:arm64 --os linux --arch arm64 --variant v8 + - docker manifest push flotte-docker-registry.spdns.org/frontend-server:latest diff --git a/Dockerfile b/Dockerfile index 649fd72..62c6f31 100644 --- a/Dockerfile +++ b/Dockerfile @@ -9,6 +9,7 @@ COPY . . RUN ng build --prod --crossOrigin=anonymous FROM golang:1.13.4-alpine as builder2 +ENV ARCH=amd64 RUN apk add git WORKDIR / COPY --from=builder /frontend/dist /dist @@ -16,7 +17,7 @@ RUN go get github.com/rakyll/statik RUN statik --src=/dist/flotte-frontend COPY *.go *.sum *.mod / COPY vendor /vendor -RUN CGO_ENABLED=0 GOOS=linux go build --mod=vendor -o frontend_server +RUN CGO_ENABLED=0 GOARCH=$ARCH GOOS=linux go build --mod=vendor -o frontend_server FROM scratch WORKDIR / From cbd702569ebb78a130e24c28a3197d5879f482e3 Mon Sep 17 00:00:00 2001 From: leonnicolas Date: Fri, 13 Nov 2020 09:31:18 +0100 Subject: [PATCH 3/7] .travis.yml: fixed tags I forgot some tags --- .travis.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index d101271..8a72860 100644 --- a/.travis.yml +++ b/.travis.yml @@ -12,9 +12,9 @@ script: - docker build -t frontend-server:arm64 . --build-arg ARCH=arm64 - docker tag frontend-server:amd64 flotte-docker-registry.spdns.org/frontend-server:amd64 - docker push flotte-docker-registry.spdns.org/frontend-server:amd64 - - docker tag frontend-server flotte-docker-registry.spdns.org/frontend-server:arm64 + - docker tag frontend-server:arm64 flotte-docker-registry.spdns.org/frontend-server:arm64 - docker push flotte-docker-registry.spdns.org/frontend-server:arm64 - - docker tag frontend-server flotte-docker-registry.spdns.org/frontend-server:arm + - docker tag frontend-server:arm flotte-docker-registry.spdns.org/frontend-server:arm - docker push flotte-docker-registry.spdns.org/frontend-server:arm - docker manifest create --amend flotte-docker-registry.spdns.org/frontend-server:latest flotte-docker-registry.spdns.org/frontend-server:arm flotte-docker-registry.spdns.org/frontend-server:arm64 flotte-docker-registry.spdns.org/frontend-server:amd64 - docker manifest annotate flotte-docker-registry.spdns.org/frontend-server:latest flotte-docker-registry.spdns.org/frontend-server:arm --os linux --arch arm --variant v7 From e55c85ef95b5a69f2b344f4834ae33c828660e99 Mon Sep 17 00:00:00 2001 From: leonnicolas Date: Fri, 13 Nov 2020 09:39:52 +0100 Subject: [PATCH 4/7] .travis.yml: enable experimental features for manifest --- .travis.yml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.travis.yml b/.travis.yml index 8a72860..cbd7b69 100644 --- a/.travis.yml +++ b/.travis.yml @@ -5,6 +5,10 @@ language: bash services: - docker +env: + global: + - DOCKER_CLI_EXPERIMENTAL=enabled + script: - docker login -u="$DOCKER_USER" -p="$DOCKER_PW" https://flotte-docker-registry.spdns.org/ - docker build -t frontend-server:amd64 . --build-arg ARCH=amd64 From bfdaf44ff498af278fd6ed2a3f027a3d182246c5 Mon Sep 17 00:00:00 2001 From: leonnicolas Date: Fri, 13 Nov 2020 09:48:25 +0100 Subject: [PATCH 5/7] Dockerfile: fixed ARCH argument --- Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index 62c6f31..a33ada4 100644 --- a/Dockerfile +++ b/Dockerfile @@ -9,7 +9,7 @@ COPY . . RUN ng build --prod --crossOrigin=anonymous FROM golang:1.13.4-alpine as builder2 -ENV ARCH=amd64 +ARG ARCH=amd64 RUN apk add git WORKDIR / COPY --from=builder /frontend/dist /dist From 248e00bf916faca1368010537716bc0b8d078e71 Mon Sep 17 00:00:00 2001 From: leonnicolas Date: Fri, 13 Nov 2020 10:52:08 +0100 Subject: [PATCH 6/7] .travis.yml: fix access rights for docker create manifest --- .travis.yml | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/.travis.yml b/.travis.yml index cbd7b69..c1952f6 100644 --- a/.travis.yml +++ b/.travis.yml @@ -11,6 +11,8 @@ env: script: - docker login -u="$DOCKER_USER" -p="$DOCKER_PW" https://flotte-docker-registry.spdns.org/ + - sudo chmod o+xr -R /home/travis/.docker + - sudo chmod o+xr -R /etc/docker - docker build -t frontend-server:amd64 . --build-arg ARCH=amd64 - docker build -t frontend-server:arm . --build-arg ARCH=arm - docker build -t frontend-server:arm64 . --build-arg ARCH=arm64 @@ -20,7 +22,7 @@ script: - docker push flotte-docker-registry.spdns.org/frontend-server:arm64 - docker tag frontend-server:arm flotte-docker-registry.spdns.org/frontend-server:arm - docker push flotte-docker-registry.spdns.org/frontend-server:arm - - docker manifest create --amend flotte-docker-registry.spdns.org/frontend-server:latest flotte-docker-registry.spdns.org/frontend-server:arm flotte-docker-registry.spdns.org/frontend-server:arm64 flotte-docker-registry.spdns.org/frontend-server:amd64 - - docker manifest annotate flotte-docker-registry.spdns.org/frontend-server:latest flotte-docker-registry.spdns.org/frontend-server:arm --os linux --arch arm --variant v7 - - docker manifest annotate flotte-docker-registry.spdns.org/frontend-server:latest flotte-docker-registry.spdns.org/frontend-server:arm64 --os linux --arch arm64 --variant v8 - - docker manifest push flotte-docker-registry.spdns.org/frontend-server:latest + - sudo docker manifest create --amend flotte-docker-registry.spdns.org/frontend-server:latest flotte-docker-registry.spdns.org/frontend-server:arm flotte-docker-registry.spdns.org/frontend-server:arm64 flotte-docker-registry.spdns.org/frontend-server:amd64 + - sudo docker manifest annotate flotte-docker-registry.spdns.org/frontend-server:latest flotte-docker-registry.spdns.org/frontend-server:arm --os linux --arch arm --variant v7 + - sudo docker manifest annotate flotte-docker-registry.spdns.org/frontend-server:latest flotte-docker-registry.spdns.org/frontend-server:arm64 --os linux --arch arm64 --variant v8 + - sudo docker manifest push flotte-docker-registry.spdns.org/frontend-server:latest From 9f0f2c4fc986715c59c1ce6b6f113d2964430617 Mon Sep 17 00:00:00 2001 From: leonnicolas Date: Fri, 13 Nov 2020 11:00:50 +0100 Subject: [PATCH 7/7] .travis.yml: remoe sudo for create manifest --- .travis.yml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.travis.yml b/.travis.yml index c1952f6..b5a0fda 100644 --- a/.travis.yml +++ b/.travis.yml @@ -22,7 +22,7 @@ script: - docker push flotte-docker-registry.spdns.org/frontend-server:arm64 - docker tag frontend-server:arm flotte-docker-registry.spdns.org/frontend-server:arm - docker push flotte-docker-registry.spdns.org/frontend-server:arm - - sudo docker manifest create --amend flotte-docker-registry.spdns.org/frontend-server:latest flotte-docker-registry.spdns.org/frontend-server:arm flotte-docker-registry.spdns.org/frontend-server:arm64 flotte-docker-registry.spdns.org/frontend-server:amd64 - - sudo docker manifest annotate flotte-docker-registry.spdns.org/frontend-server:latest flotte-docker-registry.spdns.org/frontend-server:arm --os linux --arch arm --variant v7 - - sudo docker manifest annotate flotte-docker-registry.spdns.org/frontend-server:latest flotte-docker-registry.spdns.org/frontend-server:arm64 --os linux --arch arm64 --variant v8 - - sudo docker manifest push flotte-docker-registry.spdns.org/frontend-server:latest + - docker manifest create --amend flotte-docker-registry.spdns.org/frontend-server:latest flotte-docker-registry.spdns.org/frontend-server:arm flotte-docker-registry.spdns.org/frontend-server:arm64 flotte-docker-registry.spdns.org/frontend-server:amd64 + - docker manifest annotate flotte-docker-registry.spdns.org/frontend-server:latest flotte-docker-registry.spdns.org/frontend-server:arm --os linux --arch arm --variant v7 + - docker manifest annotate flotte-docker-registry.spdns.org/frontend-server:latest flotte-docker-registry.spdns.org/frontend-server:arm64 --os linux --arch arm64 --variant v8 + - docker manifest push flotte-docker-registry.spdns.org/frontend-server:latest