From c56ada043cbf8167a31de3eb37aae0fdf7b7a0e5 Mon Sep 17 00:00:00 2001 From: hc-github-team-secure-vault-core <82990506+hc-github-team-secure-vault-core@users.noreply.github.com> Date: Wed, 19 Oct 2022 10:54:25 -0400 Subject: [PATCH] backport of commit 9e8e78278792c68b512182125021a185acb0e3cb (#17590) Co-authored-by: HashiBot <62622282+hashibot-web@users.noreply.github.com> Co-authored-by: Kyle MacDonald --- website/Makefile | 31 +++++++++++++++++++++++++------ website/scripts/should-build.sh | 9 +++++++-- website/scripts/website-build.sh | 23 +++++++++++++++++++++-- website/scripts/website-start.sh | 21 +++++++++++++++++++-- 4 files changed, 72 insertions(+), 12 deletions(-) diff --git a/website/Makefile b/website/Makefile index a2f37a3127..eeaa9157f5 100644 --- a/website/Makefile +++ b/website/Makefile @@ -1,6 +1,21 @@ +###################################################### +# 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 ?= vault + +# 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= PWD=$$(pwd) + DOCKER_IMAGE="hashicorp/dev-portal" DOCKER_IMAGE_LOCAL="dev-portal-local" DOCKER_RUN_FLAGS=-it \ @@ -13,27 +28,31 @@ DOCKER_RUN_FLAGS=-it \ --volume "$(PWD)/redirects.js:/app/redirects.js" \ --volume "next-dir:/app/website-preview/.next" \ --volume "$(PWD)/.env:/app/.env" \ - -e "REPO=vault" \ - -e "PREVIEW_MODE=io" + -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 pull $(DOCKER_IMAGE) + @$(DOCKER_CMD) pull $(DOCKER_IMAGE) @echo "==> Starting website..." - @docker run $(DOCKER_RUN_FLAGS) $(DOCKER_IMAGE) + @$(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 run $(DOCKER_RUN_FLAGS) $(DOCKER_IMAGE_LOCAL) + @$(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 build https://github.com/hashicorp/dev-portal.git\#main \ + @$(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 index 1d0cb6fd98..9760f47745 100644 --- a/website/scripts/should-build.sh +++ b/website/scripts/should-build.sh @@ -1,4 +1,9 @@ -#!/bin/bash +#!/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 @@ -10,4 +15,4 @@ if [[ "$VERCEL_GIT_COMMIT_REF" == "stable-website" ]] ; then else # Check for differences in the website directory git diff --quiet HEAD^ HEAD ./ -fi +fi \ No newline at end of file diff --git a/website/scripts/website-build.sh b/website/scripts/website-build.sh index 06333293ce..bf54ca9d63 100755 --- a/website/scripts/website-build.sh +++ b/website/scripts/website-build.sh @@ -1,3 +1,8 @@ +###################################################### +# 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 base project @@ -7,7 +12,14 @@ CLONE_DIR=website-preview # The product for which we are building the deploy preview PRODUCT=vault # Preview mode, controls the UI rendered (either the product site or developer). Can be `io` or `developer` -PREVIEW_MODE=io +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=$VERCEL_GIT_COMMIT_REF + +# This is where content files live, relative to the website-preview dir. If omitted, "../content" will be used +LOCAL_CONTENT_DIR= from_cache=false @@ -30,4 +42,11 @@ fi cd "$PREVIEW_DIR" # Run the build:deploy-preview start script -PREVIEW_MODE=$PREVIEW_MODE REPO=$PRODUCT HASHI_ENV=project-preview npm run build:deploy-preview +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 index 10de8829f8..9ead54c530 100755 --- a/website/scripts/website-start.sh +++ b/website/scripts/website-start.sh @@ -1,3 +1,8 @@ +###################################################### +# 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 @@ -5,7 +10,14 @@ PREVIEW_DIR=website-preview # The product for which we are building the deploy preview PRODUCT=vault # Preview mode, controls the UI rendered (either the product site or developer). Can be `io` or `developer` -PREVIEW_MODE=io +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= should_pull=true @@ -24,4 +36,9 @@ if [ "$should_pull" = true ]; then fi # Run the dev-portal content-repo start script -REPO=$PRODUCT PREVIEW_MODE=$PREVIEW_MODE npm run start:local-preview +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