From 54de574e2bfb39245e3e3a343048b668ec7fc41a Mon Sep 17 00:00:00 2001 From: HashiBot <62622282+hashibot-web@users.noreply.github.com> Date: Thu, 20 Oct 2022 13:04:57 -0500 Subject: [PATCH] chore: Update Digital Team Files (#32037) * Update generated scripts (website-start.sh) * Update generated website Makefile * Update generated scripts (should-build.sh) * Update generated scripts (website-build.sh) * chore: update root `Makefile` Co-authored-by: Kevin Wang --- Makefile | 37 ++++---------------- website/Makefile | 58 ++++++++++++++++++++++++++++++++ website/scripts/should-build.sh | 18 ++++++++++ website/scripts/website-build.sh | 45 ++++++++++++++++--------- website/scripts/website-start.sh | 44 ++++++++++++++++++++++++ 5 files changed, 156 insertions(+), 46 deletions(-) create mode 100644 website/Makefile create mode 100644 website/scripts/should-build.sh create mode 100644 website/scripts/website-start.sh diff --git a/Makefile b/Makefile index 6592e46e92..84a5dfabf5 100644 --- a/Makefile +++ b/Makefile @@ -1,21 +1,3 @@ -WEBSITE_REPO=github.com/hashicorp/terraform-website -VERSION?="0.3.44" -PWD=$$(pwd) -DOCKER_IMAGE="hashicorp/terraform-website:full" -DOCKER_IMAGE_LOCAL="hashicorp-terraform-website-local" -DOCKER_RUN_FLAGS=--interactive \ - --rm \ - --tty \ - --workdir "/website" \ - --volume "$(shell pwd):/website/ext/terraform" \ - --volume "$(shell pwd)/website:/website/preview" \ - --publish "3000:3000" \ - -e "IS_CONTENT_PREVIEW=true" \ - -e "PREVIEW_FROM_REPO=terraform" \ - -e "NAV_DATA_DIRNAME=./preview/data" \ - -e "CONTENT_DIRNAME=./preview/docs" \ - -e "CURRENT_GIT_BRANCH=$$(git rev-parse --abbrev-ref HEAD)" - # generate runs `go generate` to build the dynamically generated # source files, except the protobuf stubs which are built instead with # "make protobuf". @@ -44,26 +26,21 @@ staticcheck: exhaustive: "$(CURDIR)/scripts/exhaustive.sh" -# Default: run this if working on the website locally to run in watch mode. +# Run this if working on the website locally to run in watch mode. website: - @echo "==> Downloading latest Docker image..." - @docker pull ${DOCKER_IMAGE} - @echo "==> Starting website in Docker..." - @docker run ${DOCKER_RUN_FLAGS} ${DOCKER_IMAGE} npm start + $(MAKE) -C website website +# Use this if you have run `website/build-local` to use the locally built image. website/local: - @echo "==> Starting website in Docker..." - @docker run ${DOCKER_RUN_FLAGS} ${DOCKER_IMAGE_LOCAL} npm start + $(MAKE) -C website website/local -.PHONY: website/build-local +# Run this to generate a new local Docker image. website/build-local: - @echo "==> Building local Docker image" - @docker build https://github.com/hashicorp/terraform-website.git\#master \ - -t $(DOCKER_IMAGE_LOCAL) + $(MAKE) -C website website/build-local # disallow any parallelism (-j) for Make. This is necessary since some # commands during the build process create temporary files that collide # under parallel conditions. .NOTPARALLEL: -.PHONY: fmtcheck importscheck generate protobuf website website-test staticcheck website/local website/build-local +.PHONY: fmtcheck importscheck generate protobuf staticcheck website website/local website/build-local \ No newline at end of file diff --git a/website/Makefile b/website/Makefile new file mode 100644 index 0000000000..7072b7be5b --- /dev/null +++ b/website/Makefile @@ -0,0 +1,58 @@ +###################################################### +# NOTE: This file is managed by the Digital Team's # +# Terraform configuration @ hashicorp/mktg-terraform # +###################################################### + +.DEFAULT_GOAL := website + +# Set the preview mode for the website shell to "developer" or "io" +PREVIEW_MODE ?= developer +REPO ?= terraform + +# Enable setting alternate docker tool, e.g. 'make DOCKER_CMD=podman' +DOCKER_CMD ?= docker + +CURRENT_GIT_BRANCH=$$(git rev-parse --abbrev-ref HEAD) +LOCAL_CONTENT_DIR=../docs +PWD=$$(pwd) + +DOCKER_IMAGE="hashicorp/dev-portal" +DOCKER_IMAGE_LOCAL="dev-portal-local" +DOCKER_RUN_FLAGS=-it \ + --publish "3000:3000" \ + --rm \ + --tty \ + --volume "$(PWD)/docs:/app/docs" \ + --volume "$(PWD)/img:/app/public" \ + --volume "$(PWD)/data:/app/data" \ + --volume "$(PWD)/redirects.js:/app/redirects.js" \ + --volume "next-dir:/app/website-preview/.next" \ + --volume "$(PWD)/.env:/app/.env" \ + -e "REPO=$(REPO)" \ + -e "PREVIEW_FROM_REPO=$(REPO)" \ + -e "IS_CONTENT_PREVIEW=true" \ + -e "LOCAL_CONTENT_DIR=$(LOCAL_CONTENT_DIR)" \ + -e "CURRENT_GIT_BRANCH=$(CURRENT_GIT_BRANCH)" \ + -e "PREVIEW_MODE=$(PREVIEW_MODE)" + +# Default: run this if working on the website locally to run in watch mode. +.PHONY: website +website: + @echo "==> Downloading latest Docker image..." + @$(DOCKER_CMD) pull $(DOCKER_IMAGE) + @echo "==> Starting website..." + @$(DOCKER_CMD) run $(DOCKER_RUN_FLAGS) $(DOCKER_IMAGE) + +# Use this if you have run `website/build-local` to use the locally built image. +.PHONY: website/local +website/local: + @echo "==> Starting website from local image..." + @$(DOCKER_CMD) run $(DOCKER_RUN_FLAGS) $(DOCKER_IMAGE_LOCAL) + +# Run this to generate a new local Docker image. +.PHONY: website/build-local +website/build-local: + @echo "==> Building local Docker image" + @$(DOCKER_CMD) build https://github.com/hashicorp/dev-portal.git\#main \ + -t $(DOCKER_IMAGE_LOCAL) + diff --git a/website/scripts/should-build.sh b/website/scripts/should-build.sh new file mode 100644 index 0000000000..9760f47745 --- /dev/null +++ b/website/scripts/should-build.sh @@ -0,0 +1,18 @@ +#!/usr/bin/env bash + +###################################################### +# NOTE: This file is managed by the Digital Team's # +# Terraform configuration @ hashicorp/mktg-terraform # +###################################################### + +# This is run during the website build step to determine if we should skip the build or not. +# More information: https://vercel.com/docs/platform/projects#ignored-build-step + +if [[ "$VERCEL_GIT_COMMIT_REF" == "stable-website" ]] ; then + # Proceed with the build if the branch is stable-website + echo "✅ - Build can proceed" + exit 1; +else + # Check for differences in the website directory + git diff --quiet HEAD^ HEAD ./ +fi \ No newline at end of file diff --git a/website/scripts/website-build.sh b/website/scripts/website-build.sh index 500f61c923..f98e7b59d9 100755 --- a/website/scripts/website-build.sh +++ b/website/scripts/website-build.sh @@ -1,39 +1,52 @@ +###################################################### +# NOTE: This file is managed by the Digital Team's # +# Terraform configuration @ hashicorp/mktg-terraform # +###################################################### + # Repo which we are cloning and executing npm run build:deploy-preview within -REPO_TO_CLONE=terraform-website -# Set the subdirectory name for the terraform-website app +REPO_TO_CLONE=dev-portal +# Set the subdirectory name for the base project PREVIEW_DIR=website-preview +# The directory we want to clone the project into CLONE_DIR=website-preview +# The product for which we are building the deploy preview +PRODUCT=terraform +# Preview mode, controls the UI rendered (either the product site or developer). Can be `io` or `developer` +PREVIEW_MODE=developer + # Get the git branch of the commit that triggered the deploy preview -# - https://vercel.com/docs/concepts/projects/environment-variables#system-environment-variables # This will power remote image assets in local and deploy previews CURRENT_GIT_BRANCH=$VERCEL_GIT_COMMIT_REF -echo "CURRENT_GIT_BRANCH is $CURRENT_GIT_BRANCH" +# This is where content files live, relative to the website-preview dir. If omitted, "../content" will be used +LOCAL_CONTENT_DIR=../docs from_cache=false if [ -d "$PREVIEW_DIR" ]; then - echo "$PREVIEW_DIR found" - CLONE_DIR="$PREVIEW_DIR-tmp" - from_cache=true + echo "$PREVIEW_DIR found" + CLONE_DIR="$PREVIEW_DIR-tmp" + from_cache=true fi -# Clone the terraform-website project, if needed -echo "⏳ Cloning the terraform-website repo, this might take a while..." -git clone --depth=1 https://github.com/hashicorp/$REPO_TO_CLONE.git "$CLONE_DIR" +# Clone the base project, if needed +echo "⏳ Cloning the $REPO_TO_CLONE repo, this might take a while..." +git clone --depth=1 "https://github.com/hashicorp/$REPO_TO_CLONE.git" "$CLONE_DIR" if [ "$from_cache" = true ]; then - echo "Setting up $PREVIEW_DIR" - cp -R "./$CLONE_DIR/." "./$PREVIEW_DIR" + echo "Setting up $PREVIEW_DIR" + cp -R "./$CLONE_DIR/." "./$PREVIEW_DIR" fi # cd into the preview directory project cd "$PREVIEW_DIR" -# Run the terraform-website content-repo start script -PREVIEW_FROM_REPO=terraform \ -NAV_DATA_DIRNAME=../data \ -CONTENT_DIRNAME=../docs \ +# Run the build:deploy-preview start script +PREVIEW_FROM_REPO=$PRODUCT \ IS_CONTENT_PREVIEW=true \ +PREVIEW_MODE=$PREVIEW_MODE \ +REPO=$PRODUCT \ +HASHI_ENV=project-preview \ +LOCAL_CONTENT_DIR=$LOCAL_CONTENT_DIR \ CURRENT_GIT_BRANCH=$CURRENT_GIT_BRANCH \ npm run build:deploy-preview \ No newline at end of file diff --git a/website/scripts/website-start.sh b/website/scripts/website-start.sh new file mode 100644 index 0000000000..a122333218 --- /dev/null +++ b/website/scripts/website-start.sh @@ -0,0 +1,44 @@ +###################################################### +# NOTE: This file is managed by the Digital Team's # +# Terraform configuration @ hashicorp/mktg-terraform # +###################################################### + +# Repo which we are cloning and executing npm run build:deploy-preview within +REPO_TO_CLONE=dev-portal +# Set the subdirectory name for the dev-portal app +PREVIEW_DIR=website-preview +# The product for which we are building the deploy preview +PRODUCT=terraform +# Preview mode, controls the UI rendered (either the product site or developer). Can be `io` or `developer` +PREVIEW_MODE=developer + +# Get the git branch of the commit that triggered the deploy preview +# This will power remote image assets in local and deploy previews +CURRENT_GIT_BRANCH=$(git rev-parse --abbrev-ref HEAD) + +# This is where content files live, relative to the website-preview dir. If omitted, "../content" will be used +LOCAL_CONTENT_DIR=../docs + +should_pull=true + +# Clone the dev-portal project, if needed +if [ ! -d "$PREVIEW_DIR" ]; then + echo "⏳ Cloning the $REPO_TO_CLONE repo, this might take a while..." + git clone --depth=1 https://github.com/hashicorp/$REPO_TO_CLONE.git "$PREVIEW_DIR" + should_pull=false +fi + +cd "$PREVIEW_DIR" + +# If the directory already existed, pull to ensure the clone is fresh +if [ "$should_pull" = true ]; then + git pull origin main +fi + +# Run the dev-portal content-repo start script +REPO=$PRODUCT \ +PREVIEW_FROM_REPO=$PRODUCT \ +LOCAL_CONTENT_DIR=$LOCAL_CONTENT_DIR \ +CURRENT_GIT_BRANCH=$CURRENT_GIT_BRANCH \ +PREVIEW_MODE=$PREVIEW_MODE \ +npm run start:local-preview \ No newline at end of file