Skip to content

Commit

Permalink
chore: Update Digital Team Files (#517)
Browse files Browse the repository at this point in the history
Co-authored-by: Kevin Wang <kwangsan@gmail.com>
  • Loading branch information
hashibot-web and thiskevinwang committed Oct 20, 2022
1 parent 734074c commit e1bf73e
Show file tree
Hide file tree
Showing 5 changed files with 157 additions and 60 deletions.
47 changes: 9 additions & 38 deletions 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
$(MAKE) -C website website/build-local
58 changes: 58 additions & 0 deletions 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)

18 changes: 18 additions & 0 deletions 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
50 changes: 28 additions & 22 deletions 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
44 changes: 44 additions & 0 deletions 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

0 comments on commit e1bf73e

Please sign in to comment.