Skip to content

Commit

Permalink
VACMS-15240 Stand up running next-build server per tugboat instance (#…
Browse files Browse the repository at this point in the history
…15429)

* Stubbing out next server config

* Updating config values to be spaces

* Updating to add splash page

* changing line endings

* Scripts for next build

* Fixed permissions issues

* Attempting file permission fix

* trying one more permission thing

* Change permissions.

* Removed tab character

* Removed the actual white space that was the issue

* Added yarn start to next build

* Adjusting scripts for next start

* Resolving issues from review

* Resolving more review stuff

* adding rest of the path to next-start

* Adjusting scope for output

* update perms

* add apache proxy settings for next-build node server

* add 503 error page for next-*

* 503 j2 to html

---------

Co-authored-by: Kit Nunnally <[email protected]>
Co-authored-by: Nathan Douglas <[email protected]>
Co-authored-by: Tanner Heffner <[email protected]>
  • Loading branch information
4 people authored Oct 25, 2023
1 parent ba2b98e commit 16d504d
Show file tree
Hide file tree
Showing 12 changed files with 246 additions and 3 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,9 @@ datadog-setup.php
# web
# @TODO: Installer paths is not working. Leaving symlink for now.

# Ignore Next (next-build)
next

# Temporary .deb packages
*.deb

Expand Down
51 changes: 51 additions & 0 deletions .next/403-error-document.j2.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
<!-- This is a Jinja2 template without a *.j2 extension because it isn't testable in a browser with *.j2. -->
<html lang="en">
<head>
<meta charset="utf-8">
<title>Next-build Preview not built yet</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta http-equiv="refresh" content="2" />

<style>
body {
/* VA.gov dark blue */
background: #112e51;
text-align: center;
color: white;
}

p {
font-size: large;
}

a {
text-decoration: underline;
color: white;
}

.hero {
margin-top: 25px;
width: 70%;
height: 20%;
object-fit: cover;
object-position: 0 80%;
}

.container-info {
margin-bottom: 100px;
}
</style>
</head>

<body>
<img class="hero" src="/.next/artur-pokusin-unsplash.jpg">
<h1>Next-build not ready yet</h1>
<div class="container-info">
<p>The next-build server is not built & running yet.</p>
<p>Check the status of the <code>composer va:next:start</code> command in the logs to learn more.</p>
</div>
<footer>Photo by <a href="https://unsplash.com/@arturpokusin?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">Artur Pokusin</a> on <a href="https://unsplash.com/s/photos/void?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">Unsplash</a>
</footer>
</body>

</html>
51 changes: 51 additions & 0 deletions .next/503-error-document.j2.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
<!-- This is a Jinja2 template without a *.j2 extension because it isn't testable in a browser with *.j2. -->
<html lang="en">
<head>
<meta charset="utf-8">
<title>Next-build Preview Server 503 Error</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta http-equiv="refresh" content="2" />

<style>
body {
/* VA.gov dark blue */
background: #112e51;
text-align: center;
color: white;
}

p {
font-size: large;
}

a {
text-decoration: underline;
color: white;
}

.hero {
margin-top: 25px;
width: 70%;
height: 20%;
object-fit: cover;
object-position: 0 80%;
}

.container-info {
margin-bottom: 100px;
}
</style>
</head>

<body>
<img class="hero" src="/.next/artur-pokusin-unsplash.jpg">
<h1>Next-build server 503 response</h1>
<div class="container-info">
<p>There was a 503 error returned from the next-build server when it asked for this route.</p>
<p>Check the status of the <code>composer va:next:start</code> command in the logs to learn more.</p>
</div>
<footer>Photo by <a href="https://unsplash.com/@arturpokusin?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">Artur Pokusin</a> on <a href="https://unsplash.com/s/photos/void?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">Unsplash</a>
</footer>
</body>

</html>
1 change: 1 addition & 0 deletions .next/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
See /.tugboat/vhost-next.conf.
Binary file added .next/artur-pokusin-unsplash.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
15 changes: 13 additions & 2 deletions .tugboat/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ services:
- cms
- web
- storybook
- next

# Set this as the default service. This does a few things
# 1. Clones the git repository into the service container
Expand Down Expand Up @@ -49,7 +50,7 @@ services:

# Install opcache, and Apache modules
- docker-php-ext-install opcache
- a2enmod headers rewrite vhost_alias
- a2enmod headers rewrite vhost_alias proxy proxy_http
# Install datadog agent for application tracing and profiling.
- DD_API_KEY=" " DD_INSTALL_ONLY=true DD_SITE="ddog-gov.com" bash -c "$(curl -L https://s3.amazonaws.com/dd-agent/scripts/install_script_agent7.sh)"

Expand All @@ -62,6 +63,9 @@ services:
# Setup storybook-*. vhost to serve static website.
- cp "${TUGBOAT_ROOT}"/.tugboat/vhost-storybook.conf /etc/apache2/sites-enabled/

# Setup next-*. vhost to serve static website.
- cp "${TUGBOAT_ROOT}"/.tugboat/vhost-next.conf /etc/apache2/sites-enabled/

# Configure KeepAliveTimeout in apache2.conf. This is set 5 seconds longer than the internal tools ALB.
# The internal tools ALB idle timeout is set to longer than a typical GQL query takes.
- sed -e 's/KeepAliveTimeout 5/KeepAliveTimeout 185/' -i /etc/apache2/apache2.conf
Expand Down Expand Up @@ -184,11 +188,14 @@ services:
# This command is shared by the clone and build stages, make sure to update both stages.
- j2 "${TUGBOAT_ROOT}/.web/403-error-document.j2.html" -o "${TUGBOAT_ROOT}/.web/403-error-document.html"
- j2 "${TUGBOAT_ROOT}/.storybook/403-error-document.j2.html" -o "${TUGBOAT_ROOT}/.storybook/403-error-document.html"
- j2 "${TUGBOAT_ROOT}/.next/403-error-document.j2.html" -o "${TUGBOAT_ROOT}/.next/403-error-document.html"
- j2 "${TUGBOAT_ROOT}/.next/503-error-document.j2.html" -o "${TUGBOAT_ROOT}/.next/503-error-document.html"
- composer install
- bash -lc 'nvm install'
- bash -lc 'npm install'
- bash -lc 'composer va:theme:compile'
- bash -lc 'composer va:web:install'
- bash -lc 'composer va:next:install'
# https://www.drush.org/latest/deploycommand/ (updatedb, cache:rebuild, config:import, deploy:hook)
- drush deploy

Expand All @@ -212,6 +219,8 @@ services:
# This command is shared by the clone and build stages, make sure to update both stages.
- j2 "${TUGBOAT_ROOT}/.web/403-error-document.j2.html" -o "${TUGBOAT_ROOT}/.web/403-error-document.html"
- j2 "${TUGBOAT_ROOT}/.storybook/403-error-document.j2.html" -o "${TUGBOAT_ROOT}/.storybook/403-error-document.html"
- j2 "${TUGBOAT_ROOT}/.next/403-error-document.j2.html" -o "${TUGBOAT_ROOT}/.next/403-error-document.html"
- j2 "${TUGBOAT_ROOT}/.next/503-error-document.j2.html" -o "${TUGBOAT_ROOT}/.next/503-error-document.html"

online:
# We only want tests running on PRs, not branches like the base preview build of main.
Expand All @@ -224,8 +233,10 @@ services:
- find -L "${DOCROOT}/vendor/va-gov/content-build/node_modules/.bin" -type f -exec chmod +x {} \+
- find "${DOCROOT}/vendor/va-gov/content-build/script" -type f -exec chmod +x {} \+

# Build storybook and the frontend in parallel
# Build storybook and the frontends in parallel
- bash -lc 'time task --taskfile=tugboat.yml'
# Build next build server
- bash -lc 'composer va:next:start'

memcache:
image: tugboatqa/memcached:1.6
Expand Down
48 changes: 48 additions & 0 deletions .tugboat/vhost-next.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
# If testing changes to this file on the tugboatqa/php:7.1-apache image (current),
# use `apache2ctl -S` to check for syntax issues then `killall apache2` to get changes to take.
# Or "Stop" then "Start" the preview as that will restart apache2 too. Worth noting that
# `service apache2 reload|restart` doesn't work on this image as `runit` is used.
# Also `sv restart apache` acts like it works but it doesn't and doesn't bubble up any errors.

<VirtualHost *:80>

ServerName next-wildcard
# Route preview URLs with prefix of `next-` to folder where the generated site output is symlinked.
# e.g. https://next-msecydk1vl7ncmpkgh8vevjhzq25vacv.ci.cms.va.gov/
ServerAlias next-*
VirtualDocumentRoot /var/lib/tugboat/docroot/next/.next

Alias "/.next" "/var/lib/tugboat/.next"
ErrorDocument 403 /.next/403-error-document.html
ErrorDocument 503 /.next/503-error-document.html

<Directory /var/lib/tugboat/docroot/next/.next/>
Options FollowSymLinks
Require all granted
</Directory>

<Directory /var/lib/tugboat/.next/>
Require all granted
</Directory>

ProxyPreserveHost on
# Ignore redirecting error doc directory
ProxyPass /.next/ !
# Redirect requests to the running node server from next-build
ProxyPass / http://localhost:3000/
ProxyPassReverse / http://localhost:3000/

# Available loglevels: trace8, ..., trace1, debug, info, notice, warn,
# error, crit, alert, emerg.
# It is also possible to configure the loglevel for particular
# modules, e.g.
#LogLevel debug

# On Tugboat these are symlinks to /dev/null by default.
# `rm /var/log/apache2/*.log` and they will be generated.
# Then `tail -f /var/log/apache2/*` will work.
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined

SetEnvIf X-Forwarded-Proto "^https" HTTPS=on
</VirtualHost>
20 changes: 19 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -571,7 +571,10 @@
"va:theme:watch": "Watch VA.gov Claro theme source and compile as needed.",
"va:web:build": "Perform a content build.",
"va:web:install": "Prepare the content-build project.",
"va:web:prepare-dotenv": "Prepare the ./web/.env file."
"va:web:prepare-dotenv": "Prepare the ./web/.env file.",
"va:next:install": "Prepare the next-build project",
"va:next:build": "Build the next-build server for preview",
"va:next:start": "Start the next-build server for preview"
},
"scripts": {
"pre-install-cmd": [
Expand Down Expand Up @@ -817,6 +820,21 @@
"# Prepare the ./web/.env file.",
"! ./scripts/should-run-directly.sh || ./scripts/web-prepare-dotenv.sh",
"./scripts/should-run-directly.sh || ddev composer va:web:prepare-dotenv --"
],
"va:next:install": [
"# Prepare the next build project",
"! ./scripts/should-run-directly.sh || ./scripts/next-install.sh",
"./scripts/should-run-directly.sh || ddev composer va:next:install --"
],
"va:next:build": [
"# Prepare the next build server",
"! ./scripts/should-run-directly.sh || ./scripts/next-build.sh",
"./scripts/should-run-directly.sh || ddev composer va:next:build --"
],
"va:next:start": [
"# Start the next build server",
"! ./scripts/should-run-directly.sh || ./scripts/next-start.sh",
"./scripts/should-run-directly.sh || ddev composer va:next:start --"
]
}
}
11 changes: 11 additions & 0 deletions scripts/next-build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/usr/bin/env bash
#preview

export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"
[ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion"
source ~/.bashrc

cd next

APP_ENV=tugboat yarn build:preview
33 changes: 33 additions & 0 deletions scripts/next-install.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#!/usr/bin/env bash

export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"
[ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion"
source ~/.bashrc

# Installs the content-build dependencies.

if [ ! -d next ]; then
git clone --single-branch --depth 1 https://github.com/department-of-veterans-affairs/next-build.git next
else
echo "Repo next-build already cloned."
fi

cd next
#repo_root="$(git rev-parse --show-toplevel)"
#pushd "${repo_root}" > /dev/null

nvm install 18.17.0
nvm use 18.17.0
corepack enable
corepack prepare yarn@stable --activate
echo "Node $(node -v)"
echo "NPM $(npm -v)"
echo "Yarn $(yarn -v)"

#not sure how popd works
#pushd "./next"
yarn install
#popd

#popd > /dev/null
10 changes: 10 additions & 0 deletions scripts/next-start.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#!/usr/bin/env bash

export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"
[ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion"
source ~/.bashrc

cd next

APP_ENV=tugboat yarn start
6 changes: 6 additions & 0 deletions tugboat.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,16 @@ tasks:
cmds:
- drush va-gov:content-release:request-frontend-build

build-next:
desc: build next.js preview server
cmds:
- composer va:next:build

build:
deps:
- build-storybook
- build-frontend
- build-next

default:
cmds:
Expand Down

0 comments on commit 16d504d

Please sign in to comment.