From 4e5bb6f65c3c292aeca41de886b72269ccad473c Mon Sep 17 00:00:00 2001 From: HashiBot <62622282+hashibot-web@users.noreply.github.com> Date: Tue, 18 Oct 2022 13:56:17 -0500 Subject: [PATCH 1/5] Update generated scripts (should-build.sh) --- website/scripts/should-build.sh | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 website/scripts/should-build.sh diff --git a/website/scripts/should-build.sh b/website/scripts/should-build.sh new file mode 100644 index 000000000..9760f4774 --- /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 From 3718eb0d784c35b130a3a58de5d23269de7170f9 Mon Sep 17 00:00:00 2001 From: HashiBot <62622282+hashibot-web@users.noreply.github.com> Date: Tue, 18 Oct 2022 13:56:18 -0500 Subject: [PATCH 2/5] Update generated website Makefile --- website/Makefile | 58 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100644 website/Makefile diff --git a/website/Makefile b/website/Makefile new file mode 100644 index 000000000..347021aa3 --- /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-plugin-framework + +# 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) + From 97aeb1870bcfae6251de92b8a1434f4bbaab1e83 Mon Sep 17 00:00:00 2001 From: HashiBot <62622282+hashibot-web@users.noreply.github.com> Date: Tue, 18 Oct 2022 13:56:23 -0500 Subject: [PATCH 3/5] Update generated scripts (website-build.sh) --- website/scripts/website-build.sh | 50 ++++++++++++++++++-------------- 1 file changed, 28 insertions(+), 22 deletions(-) diff --git a/website/scripts/website-build.sh b/website/scripts/website-build.sh index a5cf94dbc..c519c9264 100755 --- a/website/scripts/website-build.sh +++ b/website/scripts/website-build.sh @@ -1,46 +1,52 @@ -############################################################# -# Note: This script is maintained by the Web / Digital team # -# # -# This is meant to be executed during a Vercel CI job, and # -# not locally. # -############################################################# +###################################################### +# 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-plugin-framework +# 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-plugin-framework \ -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 From fb8eecdfb2759ba1ede1378cb000f91dbd3d57ff Mon Sep 17 00:00:00 2001 From: HashiBot <62622282+hashibot-web@users.noreply.github.com> Date: Tue, 18 Oct 2022 13:56:24 -0500 Subject: [PATCH 4/5] Update generated scripts (website-start.sh) --- website/scripts/website-start.sh | 44 ++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 website/scripts/website-start.sh diff --git a/website/scripts/website-start.sh b/website/scripts/website-start.sh new file mode 100644 index 000000000..6d09a2856 --- /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-plugin-framework +# 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 From e8246c6e5405735956824bece01ba8925b170d49 Mon Sep 17 00:00:00 2001 From: Kevin Wang Date: Thu, 20 Oct 2022 15:01:33 -0400 Subject: [PATCH 5/5] chore: update root `Makefile` --- Makefile | 47 +++++++++-------------------------------------- 1 file changed, 9 insertions(+), 38 deletions(-) diff --git a/Makefile b/Makefile index 814cdaa89..8b99958a8 100644 --- a/Makefile +++ b/Makefile @@ -1,43 +1,14 @@ -WEBSITE_REPO=github.com/hashicorp/terraform-website -WEBSITE_BRANCH=master - -CURRENT_GIT_REPO=$$(basename `git rev-parse --show-toplevel`) -CURRENT_GIT_BRANCH=$$(git rev-parse --abbrev-ref HEAD) - -WEBSITE_DOCKER_IMAGE="hashicorp/terraform-website:full" -WEBSITE_DOCKER_IMAGE_LOCAL="hashicorp-terraform-website-local" -WEBSITE_DOCKER_RUN_FLAGS=--interactive \ - --rm \ - --tty \ - --workdir "/website" \ - --volume "$(shell pwd)/website:/website/preview" \ - --publish "3000:3000" \ - -e "IS_CONTENT_PREVIEW=true" \ - -e "PREVIEW_FROM_REPO=$(CURRENT_GIT_REPO)" \ - -e "NAV_DATA_DIRNAME=./preview/data" \ - -e "CONTENT_DIRNAME=./preview/docs" \ - -e "CURRENT_GIT_BRANCH=$(CURRENT_GIT_BRANCH)" - - -# Run the terraform.io website to preview local content changes +# Run this if working on the website locally to run in watch mode. +.PHONY: website website: - @echo "==> Downloading latest Docker image..." - @docker pull ${WEBSITE_DOCKER_IMAGE} - @echo "==> Starting website in Docker..." - @docker run ${WEBSITE_DOCKER_RUN_FLAGS} ${WEBSITE_DOCKER_IMAGE} npm start + $(MAKE) -C website website -# Run the terraform.io website via a locally built docker image -# -# This is useful for development as you may be building an image -# with local changes from the `terraform-website` repo. +# Use this if you have run `website/build-local` to use the locally built image. +.PHONY: website/local website/local: - @echo "==> Starting website in Docker..." - @docker run ${WEBSITE_DOCKER_RUN_FLAGS} ${WEBSITE_DOCKER_IMAGE_LOCAL} npm start + $(MAKE) -C website website/local -# Build the terraform.io image using `terraform-website` git repo as the build context +# Run this to generate a new local Docker image. +.PHONY: website/build-local website/build-local: - @echo "==> Building local Docker image" - @docker build https://github.com/hashicorp/terraform-website.git\#$(WEBSITE_BRANCH) \ - -t $(WEBSITE_DOCKER_IMAGE_LOCAL) - -.PHONY: website website/local website/build-local \ No newline at end of file + $(MAKE) -C website website/build-local \ No newline at end of file