diff --git a/.circleci/config.yml b/.circleci/config.yml index 37863c70..5cc307e6 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -79,10 +79,10 @@ jobs: at: ./ - run: name: Compile production backend - command: dev-scripts/build-backend + command: PS_VERSION="$(git describe --tags)" dev-scripts/build-backend - run: name: Compile dev backend - command: dev-scripts/build-backend dev + command: PS_VERSION="$(git describe --tags)" dev-scripts/build-backend dev - persist_to_workspace: root: ./ paths: @@ -129,10 +129,10 @@ jobs: docker buildx build \ --platform "${BUILD_TARGETS}" \ --target=artifact \ - --output "type=local,dest=$(pwd)/build/" \ + --output "type=local,dest=$(pwd)/bin/" \ . - store_artifacts: - path: build + path: bin - run: name: Install compress utility for gzip compression command: | diff --git a/.dockerignore b/.dockerignore index 81a74a29..a7fa809f 100644 --- a/.dockerignore +++ b/.dockerignore @@ -2,7 +2,6 @@ .vscode/ data/ bin/ -build/ dist/ .coverage* *.env diff --git a/.gitignore b/.gitignore index c902e3d6..e1a9c027 100644 --- a/.gitignore +++ b/.gitignore @@ -2,7 +2,6 @@ # Compiled binaries bin/ -build/ dist/ # Persistent data directory diff --git a/Dockerfile b/Dockerfile index ddcda1cb..4073e148 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,7 +1,9 @@ FROM golang:1.21.1 AS builder ARG TARGETPLATFORM +ARG PS_VERSION +COPY ./build /app/build COPY ./cmd /app/cmd COPY ./dev-scripts /app/dev-scripts COPY ./garbagecollect /app/garbagecollect @@ -14,7 +16,9 @@ COPY ./go.* /app/ WORKDIR /app -RUN TARGETPLATFORM="${TARGETPLATFORM}" ./dev-scripts/build-backend "prod" +RUN TARGETPLATFORM="${TARGETPLATFORM}" \ + PS_VERSION="${PS_VERSION}" \ + ./dev-scripts/build-backend "prod" FROM scratch as artifact COPY --from=builder /app/bin/picoshare ./ diff --git a/build/build.go b/build/build.go new file mode 100644 index 00000000..a128e8d6 --- /dev/null +++ b/build/build.go @@ -0,0 +1,21 @@ +package build + +import ( + "log" + "strconv" + "time" +) + +// These values are set by ldflags at build time. +// https://www.digitalocean.com/community/tutorials/using-ldflags-to-set-version-information-for-go-applications +var unixTime string +var Version string + +func Time() time.Time { + t, err := strconv.ParseInt(unixTime, 10, 64) + if err != nil { + log.Printf("no build time specified through ldflags") + return time.Time{} + } + return time.Unix(t, 0) +} diff --git a/dev-scripts/build-backend b/dev-scripts/build-backend index 73d16a5f..b41f20df 100755 --- a/dev-scripts/build-backend +++ b/dev-scripts/build-backend @@ -62,6 +62,6 @@ export CGO_ENABLED=1 go build \ -tags "${BUILD_TAGS_JOINED}" \ - -ldflags '-w -extldflags "-static"' \ + -ldflags "-w -extldflags '-static' -X 'github.com/mtlynch/picoshare/v2/build.Version=${PS_VERSION}' -X 'github.com/mtlynch/picoshare/v2/build.unixTime=$(date +%s)'" \ -o "${BINARY}" \ cmd/picoshare/main.go diff --git a/dev-scripts/package-binaries b/dev-scripts/package-binaries index 47f30894..947ce2c7 100755 --- a/dev-scripts/package-binaries +++ b/dev-scripts/package-binaries @@ -21,7 +21,7 @@ SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )" readonly SCRIPT_DIR cd "${SCRIPT_DIR}/.." -cd build +cd bin readonly OUTPUT_DIR="${PWD}/../dist" mkdir -p "${OUTPUT_DIR}" diff --git a/dev-scripts/run-e2e-tests b/dev-scripts/run-e2e-tests index cb37107d..7e74b61c 100755 --- a/dev-scripts/run-e2e-tests +++ b/dev-scripts/run-e2e-tests @@ -22,7 +22,7 @@ readonly SCRIPT_DIR cd "${SCRIPT_DIR}/.." if [[ "${REBUILD}" == "true" ]]; then - ./dev-scripts/build-backend dev + PS_VERSION="$(git describe --tags)" ./dev-scripts/build-backend dev fi cd e2e diff --git a/e2e/system-info.spec.ts b/e2e/system-info.spec.ts new file mode 100644 index 00000000..fb42ebe9 --- /dev/null +++ b/e2e/system-info.spec.ts @@ -0,0 +1,10 @@ +import { test, expect } from "@playwright/test"; +import { login } from "./helpers/login.js"; + +test("views system info", async ({ page }) => { + await login(page); + + await page.getByRole("menuitem", { name: "System" }).hover(); + await page.getByRole("menuitem", { name: "Information" }).click(); + await expect(page).toHaveURL("/information"); +}); diff --git a/handlers/routes.go b/handlers/routes.go index 58b9f77b..c53a9515 100644 --- a/handlers/routes.go +++ b/handlers/routes.go @@ -43,7 +43,7 @@ func (s *Server) routes() { authenticatedViews := s.router.PathPrefix("/").Subrouter() authenticatedViews.Use(s.requireAuthentication) authenticatedViews.Use(enforceContentSecurityPolicy) - authenticatedViews.HandleFunc("/disk-usage", s.diskUsageGet()).Methods(http.MethodGet) + authenticatedViews.HandleFunc("/information", s.systemInformationGet()).Methods(http.MethodGet) authenticatedViews.HandleFunc("/files", s.fileIndexGet()).Methods(http.MethodGet) authenticatedViews.HandleFunc("/files/{id}/downloads", s.fileDownloadsGet()).Methods(http.MethodGet) authenticatedViews.HandleFunc("/files/{id}/edit", s.fileEditGet()).Methods(http.MethodGet) diff --git a/handlers/templates/pages/disk-usage.html b/handlers/templates/pages/system-information.html similarity index 67% rename from handlers/templates/pages/disk-usage.html rename to handlers/templates/pages/system-information.html index 2cf498d5..db814c50 100644 --- a/handlers/templates/pages/disk-usage.html +++ b/handlers/templates/pages/system-information.html @@ -22,8 +22,9 @@ {{ end }} {{ define "content" }} -
- Used space: - {{ formatFileSize .UsedBytes }} - ({{ percentage .UsedBytes .TotalBytes }}) -
-Total disk space: {{ formatFileSize .TotalBytes }}
+@@ -55,6 +58,15 @@