From c73eb820c1fb2249daf91e8d3c93139a362e3576 Mon Sep 17 00:00:00 2001 From: Elliot Voris Date: Wed, 18 Dec 2024 09:44:37 -0600 Subject: [PATCH] build: only build translations in production (set via docker arg) --- Dockerfile | 17 +++++++++-------- Makefile | 4 +++- package.json | 5 +++-- 3 files changed, 15 insertions(+), 11 deletions(-) diff --git a/Dockerfile b/Dockerfile index 953768226..ab31dfa0d 100644 --- a/Dockerfile +++ b/Dockerfile @@ -16,18 +16,19 @@ RUN apt-get update && apt-get install --no-install-recommends -y gpg curl git ma COPY . /app/ ARG CROWDIN_PERSONAL_TOKEN +ARG BUILD_TRANSLATIONS="False" RUN yarn install RUN yarn rpcspec:build RUN yarn stellar-cli:build -# TODO: This takes a bit of time, we should probably make sure it's only done -# for production builds -# See: https://docusaurus.io/docs/3.4.0/i18n/crowdin#automate-with-ci -RUN CROWDIN_PERSONAL_TOKEN=${CROWDIN_PERSONAL_TOKEN} yarn crowdin:sync -RUN yarn crowdin:fix -# TODO: It's actually this part that is more time-consuming. The best way to -# speed this up is to generate the preview for only `--locale en` -RUN NODE_OPTIONS="--max-old-space-size=4096" yarn build + +ENV NODE_OPTIONS="--max-old-space-size=4096" +RUN if [ "$BUILD_TRANSLATIONS" = "True" ]; then \ + CROWDIN_PERSONAL_TOKEN=${CROWDIN_PERSONAL_TOKEN} yarn build:production; \ + else \ + # In the preview build, we only want to build for English. Much quicker + yarn build; \ + fi FROM nginx:1.27 diff --git a/Makefile b/Makefile index d0f21ebab..5f6e07272 100644 --- a/Makefile +++ b/Makefile @@ -7,9 +7,11 @@ LABEL ?= $(shell git rev-parse --short HEAD)$(and $(shell git status -s),-dirty- TAG ?= stellar/stellar-docs:$(LABEL) # https://github.com/opencontainers/image-spec/blob/master/annotations.md BUILD_DATE := $(shell date -u +%FT%TZ) +# If we're not in production, don't build translations +BUILD_TRANSLATIONS ?= "False" docker-build: - $(SUDO) docker build --no-cache --pull --label org.opencontainers.image.created="$(BUILD_DATE)" -t $(TAG) . --build-arg CROWDIN_PERSONAL_TOKEN=${CROWDIN_PERSONAL_TOKEN} + $(SUDO) docker build --no-cache --pull --label org.opencontainers.image.created="$(BUILD_DATE)" -t $(TAG) . --build-arg CROWDIN_PERSONAL_TOKEN=${CROWDIN_PERSONAL_TOKEN} --build-arg BUILD_TRANSLATIONS=${BUILD_TRANSLATIONS} docker-push: $(SUDO) docker push $(TAG) diff --git a/package.json b/package.json index 4b79e1abf..e16ed41fe 100644 --- a/package.json +++ b/package.json @@ -5,7 +5,8 @@ "scripts": { "docusaurus": "docusaurus", "start": "docusaurus start", - "build": "docusaurus build", + "build": "docusaurus build --locale en", + "build:production": "yarn crowdin:sync && yarn crowdin:fix && yarn build", "swizzle": "docusaurus swizzle", "deploy": "docusaurus deploy", "clear": "docusaurus clear", @@ -30,7 +31,7 @@ "stellar-cli:build": "node scripts/stellar_cli.mjs", "crowdin": "crowdin", "crowdin:fix": "node scripts/copyIgnoredFiles.mjs && ./scripts/fix_translations.sh", - "crowdin:sync": "docusaurus write-translations && crowdin upload --delete-obsolete --no-progress && crowdin download --no-progress", + "crowdin:sync": "docusaurus write-translations && crowdin upload --no-progress && crowdin download --no-progress", "ap:versions:clean": "docusaurus clean-api-docs:version -p ap-apis ap_platform:all && docusaurus clean-api-docs:version -p ap-apis ap_callbacks:all && docusaurus clean-api-docs:version -p ap-apis ap_custody:all", "ap:versions:gen": "docusaurus gen-api-docs:version -p ap-apis ap_platform:all && docusaurus gen-api-docs:version -p ap-apis ap_callbacks:all && docusaurus gen-api-docs:version -p ap-apis ap_custody:all && rm ap_versioned_docs/version-*/api-reference/{callbacks,custody,platform/transactions}/*.info.mdx", "ap:versions:regen": "yarn ap:versions:clean && yarn ap:versions:gen",