diff --git a/.travis.yml b/.travis.yml index e1f6a71..b5a0fda 100644 --- a/.travis.yml +++ b/.travis.yml @@ -5,8 +5,24 @@ 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 . - - docker tag frontend-server flotte-docker-registry.spdns.org/frontend-server - - docker push flotte-docker-registry.spdns.org/frontend-server:latest + - 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 + - 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:arm64 flotte-docker-registry.spdns.org/frontend-server:arm64 + - 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 diff --git a/Dockerfile b/Dockerfile index 649fd72..a33ada4 100644 --- a/Dockerfile +++ b/Dockerfile @@ -9,6 +9,7 @@ COPY . . RUN ng build --prod --crossOrigin=anonymous FROM golang:1.13.4-alpine as builder2 +ARG 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 / 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)) }