* Assert what the image endpoints promise rather than the compressor's output Three tests pinned the exact bytes or the exact length of an encoded image, so they fail on any toolchain whose deflate or png encoder emits something different. CI pins go 1.25 and passes; go 1.27 fails all three, while the images themselves are perfectly valid. TestRest_QR now decodes both the golden file and the response and compares the pixels, which is the same assertion about the qr code and none about the encoder. The two resize cases assert the decoded image fits the box resize was given and touches one of its sides, which is what fitting to a box means and what the function actually promises. Resolves #2200. * Fill the instance URL into the embedded frontend at serve time The widget falls back to a compiled-in URL whenever a page omits `remark_config.host`. The bundler cannot know that URL, so it emits `{% REMARK_URL %}` and each distribution substitutes it: the docker image rewrites the files under its web root at container start, and the release binary, which serves the build embedded in itself, had nothing doing it. `prepare-release-assets.sh` filled the marker with `http://127.0.0.1:8080` before the embed instead, so every copy of the binary shipped pointing at the visitor's own loopback address, and on an https site the request is blocked as mixed content besides. It has been that way since v1.11.0, the first release to embed the frontend, and the earlier binaries embedded none, so the tarball has never served a correctly addressed widget. The placeholder now survives into the embedded copy and the file server fills it with the configured `REMARK_URL` as it serves, which is what the docker image already does to its own copy. The image no longer bakes the loopback address into its embedded copy either, so the fallback it keeps for a missing web root is correct rather than misleading. Substituted in html, js and mjs, the same set `docker-init.sh` rewrites, and the served size is the substituted one so a response is neither truncated nor left hanging. Nothing exercised the marker the frontend build emits wherever the instance url belongs. Every page in the suite sets `remark_config.host` from its own origin, so the compiled-in fallback is never read, and a distribution that stopped substituting would keep the suite green. Two tests. The first reads the served bundles and pages back and asserts the marker is gone from each and that what replaced it is this instance. The second covers what the substitution is for: the widget document carries no host of its own, since `iframe.html` builds its config from a query string the parent never puts one in, so everything it requests is addressed with the compiled-in url. It asserts the widget renders and that the config request went to this instance. The demo pages cannot show the second. Their loader builds the bundle's own script url from `remark_config.host`, so a page without one never gets as far as loading the widget. Verified by disabling both substitution paths, the serve-time one and the docker image's, and rebuilding: both tests fail. Editing the files on disk is not enough, since the file server substitutes as it serves. The served body now depends on remarkURL, but cacheControl builds its etag from version and path only. An operator who notices the widget is addressed to the wrong host, corrects REMARK_URL and restarts the same binary gets 304 on revalidation, so the client keeps a bundle pointing at the old host. Cache-Control is no-cache, so it revalidates every time and never ages out of that state either. That is the exact situation this substitution exists to fix, so the validator has to carry the url.
115 lines
3.5 KiB
Docker
115 lines
3.5 KiB
Docker
FROM --platform=$BUILDPLATFORM node:24-alpine AS frontend-deps
|
|
|
|
ARG SKIP_FRONTEND_TEST
|
|
ARG SKIP_FRONTEND_BUILD
|
|
# the manifest's prepare script installs husky hooks, which needs a git repository the build
|
|
# context does not have. husky itself skips on CI, and this is the same flag the build stage sets
|
|
ENV CI=true
|
|
|
|
WORKDIR /srv/frontend/apps/remark42/
|
|
|
|
COPY ./frontend/apps/remark42/package.json ./frontend/apps/remark42/pnpm-lock.yaml /srv/frontend/apps/remark42/
|
|
|
|
RUN \
|
|
if [[ -z "$SKIP_FRONTEND_BUILD" || -z "$SKIP_FRONTEND_TEST" ]]; then \
|
|
apk add --no-cache --update git && \
|
|
npm i -g pnpm@10.10.0; \
|
|
fi
|
|
|
|
RUN --mount=type=cache,id=pnpm,target=/root/.pnpm-store/v3 \
|
|
if [[ -z "$SKIP_FRONTEND_BUILD" || -z "$SKIP_FRONTEND_TEST" ]]; then \
|
|
pnpm i; \
|
|
fi
|
|
|
|
|
|
FROM --platform=$BUILDPLATFORM frontend-deps AS build-frontend
|
|
|
|
ARG SKIP_FRONTEND_TEST
|
|
ARG SKIP_FRONTEND_BUILD
|
|
ENV CI=true
|
|
|
|
WORKDIR /srv/frontend/apps/remark42/
|
|
|
|
COPY ./frontend/apps/remark42/ /srv/frontend/apps/remark42/
|
|
|
|
RUN \
|
|
if [ -z "$SKIP_FRONTEND_TEST" ]; then \
|
|
pnpm lint type-check translation-check test; \
|
|
else \
|
|
echo 'Skip frontend test'; \
|
|
fi
|
|
|
|
RUN \
|
|
if [ -z "$SKIP_FRONTEND_BUILD" ]; then \
|
|
pnpm build; \
|
|
else \
|
|
mkdir /srv/frontend/apps/remark42/public; \
|
|
echo 'Skip frontend build'; \
|
|
fi
|
|
|
|
FROM umputun/baseimage:buildgo-v1.17.0 AS build-backend
|
|
|
|
ARG CI
|
|
ARG GITHUB_REF
|
|
ARG GITHUB_SHA
|
|
ARG GIT_BRANCH
|
|
ARG SKIP_BACKEND_TEST
|
|
ARG BACKEND_TEST_TIMEOUT
|
|
|
|
# install gcc in order to be able to go test package with -race
|
|
RUN apk --no-cache add gcc libc-dev
|
|
|
|
ADD backend /build/backend
|
|
# to embed the frontend files statically into Remark42 binary
|
|
COPY --from=build-frontend /srv/frontend/apps/remark42/public/ /build/backend/app/cmd/web/
|
|
WORKDIR /build/backend
|
|
|
|
RUN echo go version: `go version`
|
|
|
|
# run tests
|
|
RUN \
|
|
cd app && \
|
|
if [ -z "$SKIP_BACKEND_TEST" ] ; then \
|
|
CGO_ENABLED=1 go test -race -p 1 -timeout="${BACKEND_TEST_TIMEOUT:-300s}" -covermode=atomic -coverprofile=/profile.cov_tmp ./... && \
|
|
cat /profile.cov_tmp | grep -v "_mock.go" > /profile.cov && \
|
|
golangci-lint run --config ../.golangci.yml ./... ; \
|
|
else \
|
|
echo "skip backend tests and linter" \
|
|
; fi
|
|
|
|
RUN \
|
|
version="$(/script/version.sh)" && \
|
|
echo "version=$version" && \
|
|
go build -o remark42 -ldflags "-X main.revision=${version} -s -w" ./app
|
|
|
|
FROM umputun/baseimage:app-v1.17.0
|
|
|
|
ARG GITHUB_SHA
|
|
|
|
LABEL org.opencontainers.image.authors="Umputun <umputun@gmail.com>" \
|
|
org.opencontainers.image.description="Remark42 comment engine" \
|
|
org.opencontainers.image.documentation="https://remark42.com/docs/getting-started/" \
|
|
org.opencontainers.image.licenses="MIT" \
|
|
org.opencontainers.image.source="https://github.com/umputun/remark42" \
|
|
org.opencontainers.image.title="Remark42" \
|
|
org.opencontainers.image.url="https://remark42.com/" \
|
|
org.opencontainers.image.revision="${GITHUB_SHA}"
|
|
|
|
WORKDIR /srv
|
|
|
|
COPY docker-init.sh /srv/init.sh
|
|
ADD backend/scripts/backup.sh /usr/local/bin/backup
|
|
ADD backend/scripts/restore.sh /usr/local/bin/restore
|
|
ADD backend/scripts/import.sh /usr/local/bin/import
|
|
RUN chmod +x /srv/init.sh /usr/local/bin/backup /usr/local/bin/restore /usr/local/bin/import
|
|
|
|
COPY --from=build-backend /build/backend/remark42 /srv/remark42
|
|
COPY --from=build-frontend /srv/frontend/apps/remark42/public/ /srv/web/
|
|
RUN chown -R app:app /srv
|
|
RUN ln -s /srv/remark42 /usr/bin/remark42
|
|
|
|
EXPOSE 8080
|
|
HEALTHCHECK --interval=30s --timeout=3s CMD curl --fail http://localhost:8080/ping || exit 1
|
|
|
|
CMD ["/srv/remark42", "server"]
|