Skip to content

Commit 16d504d

Browse files
KitLykosKit Nunnallyndouglastjheffner
authored
VACMS-15240 Stand up running next-build server per tugboat instance (#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]>
1 parent ba2b98e commit 16d504d

12 files changed

+246
-3
lines changed

.gitignore

+3
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,9 @@ datadog-setup.php
102102
# web
103103
# @TODO: Installer paths is not working. Leaving symlink for now.
104104

105+
# Ignore Next (next-build)
106+
next
107+
105108
# Temporary .deb packages
106109
*.deb
107110

.next/403-error-document.j2.html

+51
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
<!-- This is a Jinja2 template without a *.j2 extension because it isn't testable in a browser with *.j2. -->
2+
<html lang="en">
3+
<head>
4+
<meta charset="utf-8">
5+
<title>Next-build Preview not built yet</title>
6+
<meta name="viewport" content="width=device-width, initial-scale=1">
7+
<meta http-equiv="refresh" content="2" />
8+
9+
<style>
10+
body {
11+
/* VA.gov dark blue */
12+
background: #112e51;
13+
text-align: center;
14+
color: white;
15+
}
16+
17+
p {
18+
font-size: large;
19+
}
20+
21+
a {
22+
text-decoration: underline;
23+
color: white;
24+
}
25+
26+
.hero {
27+
margin-top: 25px;
28+
width: 70%;
29+
height: 20%;
30+
object-fit: cover;
31+
object-position: 0 80%;
32+
}
33+
34+
.container-info {
35+
margin-bottom: 100px;
36+
}
37+
</style>
38+
</head>
39+
40+
<body>
41+
<img class="hero" src="/.next/artur-pokusin-unsplash.jpg">
42+
<h1>Next-build not ready yet</h1>
43+
<div class="container-info">
44+
<p>The next-build server is not built & running yet.</p>
45+
<p>Check the status of the <code>composer va:next:start</code> command in the logs to learn more.</p>
46+
</div>
47+
<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>
48+
</footer>
49+
</body>
50+
51+
</html>

.next/503-error-document.j2.html

+51
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
<!-- This is a Jinja2 template without a *.j2 extension because it isn't testable in a browser with *.j2. -->
2+
<html lang="en">
3+
<head>
4+
<meta charset="utf-8">
5+
<title>Next-build Preview Server 503 Error</title>
6+
<meta name="viewport" content="width=device-width, initial-scale=1">
7+
<meta http-equiv="refresh" content="2" />
8+
9+
<style>
10+
body {
11+
/* VA.gov dark blue */
12+
background: #112e51;
13+
text-align: center;
14+
color: white;
15+
}
16+
17+
p {
18+
font-size: large;
19+
}
20+
21+
a {
22+
text-decoration: underline;
23+
color: white;
24+
}
25+
26+
.hero {
27+
margin-top: 25px;
28+
width: 70%;
29+
height: 20%;
30+
object-fit: cover;
31+
object-position: 0 80%;
32+
}
33+
34+
.container-info {
35+
margin-bottom: 100px;
36+
}
37+
</style>
38+
</head>
39+
40+
<body>
41+
<img class="hero" src="/.next/artur-pokusin-unsplash.jpg">
42+
<h1>Next-build server 503 response</h1>
43+
<div class="container-info">
44+
<p>There was a 503 error returned from the next-build server when it asked for this route.</p>
45+
<p>Check the status of the <code>composer va:next:start</code> command in the logs to learn more.</p>
46+
</div>
47+
<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>
48+
</footer>
49+
</body>
50+
51+
</html>

.next/README.md

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
See /.tugboat/vhost-next.conf.

.next/artur-pokusin-unsplash.jpg

53.9 KB
Loading

.tugboat/config.yml

+13-2
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ services:
88
- cms
99
- web
1010
- storybook
11+
- next
1112

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

5051
# Install opcache, and Apache modules
5152
- docker-php-ext-install opcache
52-
- a2enmod headers rewrite vhost_alias
53+
- a2enmod headers rewrite vhost_alias proxy proxy_http
5354
# Install datadog agent for application tracing and profiling.
5455
- 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)"
5556

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

66+
# Setup next-*. vhost to serve static website.
67+
- cp "${TUGBOAT_ROOT}"/.tugboat/vhost-next.conf /etc/apache2/sites-enabled/
68+
6569
# Configure KeepAliveTimeout in apache2.conf. This is set 5 seconds longer than the internal tools ALB.
6670
# The internal tools ALB idle timeout is set to longer than a typical GQL query takes.
6771
- sed -e 's/KeepAliveTimeout 5/KeepAliveTimeout 185/' -i /etc/apache2/apache2.conf
@@ -184,11 +188,14 @@ services:
184188
# This command is shared by the clone and build stages, make sure to update both stages.
185189
- j2 "${TUGBOAT_ROOT}/.web/403-error-document.j2.html" -o "${TUGBOAT_ROOT}/.web/403-error-document.html"
186190
- j2 "${TUGBOAT_ROOT}/.storybook/403-error-document.j2.html" -o "${TUGBOAT_ROOT}/.storybook/403-error-document.html"
191+
- j2 "${TUGBOAT_ROOT}/.next/403-error-document.j2.html" -o "${TUGBOAT_ROOT}/.next/403-error-document.html"
192+
- j2 "${TUGBOAT_ROOT}/.next/503-error-document.j2.html" -o "${TUGBOAT_ROOT}/.next/503-error-document.html"
187193
- composer install
188194
- bash -lc 'nvm install'
189195
- bash -lc 'npm install'
190196
- bash -lc 'composer va:theme:compile'
191197
- bash -lc 'composer va:web:install'
198+
- bash -lc 'composer va:next:install'
192199
# https://www.drush.org/latest/deploycommand/ (updatedb, cache:rebuild, config:import, deploy:hook)
193200
- drush deploy
194201

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

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

227-
# Build storybook and the frontend in parallel
236+
# Build storybook and the frontends in parallel
228237
- bash -lc 'time task --taskfile=tugboat.yml'
238+
# Build next build server
239+
- bash -lc 'composer va:next:start'
229240

230241
memcache:
231242
image: tugboatqa/memcached:1.6

.tugboat/vhost-next.conf

+48
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
# If testing changes to this file on the tugboatqa/php:7.1-apache image (current),
2+
# use `apache2ctl -S` to check for syntax issues then `killall apache2` to get changes to take.
3+
# Or "Stop" then "Start" the preview as that will restart apache2 too. Worth noting that
4+
# `service apache2 reload|restart` doesn't work on this image as `runit` is used.
5+
# Also `sv restart apache` acts like it works but it doesn't and doesn't bubble up any errors.
6+
7+
<VirtualHost *:80>
8+
9+
ServerName next-wildcard
10+
# Route preview URLs with prefix of `next-` to folder where the generated site output is symlinked.
11+
# e.g. https://next-msecydk1vl7ncmpkgh8vevjhzq25vacv.ci.cms.va.gov/
12+
ServerAlias next-*
13+
VirtualDocumentRoot /var/lib/tugboat/docroot/next/.next
14+
15+
Alias "/.next" "/var/lib/tugboat/.next"
16+
ErrorDocument 403 /.next/403-error-document.html
17+
ErrorDocument 503 /.next/503-error-document.html
18+
19+
<Directory /var/lib/tugboat/docroot/next/.next/>
20+
Options FollowSymLinks
21+
Require all granted
22+
</Directory>
23+
24+
<Directory /var/lib/tugboat/.next/>
25+
Require all granted
26+
</Directory>
27+
28+
ProxyPreserveHost on
29+
# Ignore redirecting error doc directory
30+
ProxyPass /.next/ !
31+
# Redirect requests to the running node server from next-build
32+
ProxyPass / http://localhost:3000/
33+
ProxyPassReverse / http://localhost:3000/
34+
35+
# Available loglevels: trace8, ..., trace1, debug, info, notice, warn,
36+
# error, crit, alert, emerg.
37+
# It is also possible to configure the loglevel for particular
38+
# modules, e.g.
39+
#LogLevel debug
40+
41+
# On Tugboat these are symlinks to /dev/null by default.
42+
# `rm /var/log/apache2/*.log` and they will be generated.
43+
# Then `tail -f /var/log/apache2/*` will work.
44+
ErrorLog ${APACHE_LOG_DIR}/error.log
45+
CustomLog ${APACHE_LOG_DIR}/access.log combined
46+
47+
SetEnvIf X-Forwarded-Proto "^https" HTTPS=on
48+
</VirtualHost>

composer.json

+19-1
Original file line numberDiff line numberDiff line change
@@ -571,7 +571,10 @@
571571
"va:theme:watch": "Watch VA.gov Claro theme source and compile as needed.",
572572
"va:web:build": "Perform a content build.",
573573
"va:web:install": "Prepare the content-build project.",
574-
"va:web:prepare-dotenv": "Prepare the ./web/.env file."
574+
"va:web:prepare-dotenv": "Prepare the ./web/.env file.",
575+
"va:next:install": "Prepare the next-build project",
576+
"va:next:build": "Build the next-build server for preview",
577+
"va:next:start": "Start the next-build server for preview"
575578
},
576579
"scripts": {
577580
"pre-install-cmd": [
@@ -817,6 +820,21 @@
817820
"# Prepare the ./web/.env file.",
818821
"! ./scripts/should-run-directly.sh || ./scripts/web-prepare-dotenv.sh",
819822
"./scripts/should-run-directly.sh || ddev composer va:web:prepare-dotenv --"
823+
],
824+
"va:next:install": [
825+
"# Prepare the next build project",
826+
"! ./scripts/should-run-directly.sh || ./scripts/next-install.sh",
827+
"./scripts/should-run-directly.sh || ddev composer va:next:install --"
828+
],
829+
"va:next:build": [
830+
"# Prepare the next build server",
831+
"! ./scripts/should-run-directly.sh || ./scripts/next-build.sh",
832+
"./scripts/should-run-directly.sh || ddev composer va:next:build --"
833+
],
834+
"va:next:start": [
835+
"# Start the next build server",
836+
"! ./scripts/should-run-directly.sh || ./scripts/next-start.sh",
837+
"./scripts/should-run-directly.sh || ddev composer va:next:start --"
820838
]
821839
}
822840
}

scripts/next-build.sh

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#!/usr/bin/env bash
2+
#preview
3+
4+
export NVM_DIR="$HOME/.nvm"
5+
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"
6+
[ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion"
7+
source ~/.bashrc
8+
9+
cd next
10+
11+
APP_ENV=tugboat yarn build:preview

scripts/next-install.sh

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
#!/usr/bin/env bash
2+
3+
export NVM_DIR="$HOME/.nvm"
4+
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"
5+
[ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion"
6+
source ~/.bashrc
7+
8+
# Installs the content-build dependencies.
9+
10+
if [ ! -d next ]; then
11+
git clone --single-branch --depth 1 https://github.com/department-of-veterans-affairs/next-build.git next
12+
else
13+
echo "Repo next-build already cloned."
14+
fi
15+
16+
cd next
17+
#repo_root="$(git rev-parse --show-toplevel)"
18+
#pushd "${repo_root}" > /dev/null
19+
20+
nvm install 18.17.0
21+
nvm use 18.17.0
22+
corepack enable
23+
corepack prepare yarn@stable --activate
24+
echo "Node $(node -v)"
25+
echo "NPM $(npm -v)"
26+
echo "Yarn $(yarn -v)"
27+
28+
#not sure how popd works
29+
#pushd "./next"
30+
yarn install
31+
#popd
32+
33+
#popd > /dev/null

scripts/next-start.sh

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#!/usr/bin/env bash
2+
3+
export NVM_DIR="$HOME/.nvm"
4+
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"
5+
[ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion"
6+
source ~/.bashrc
7+
8+
cd next
9+
10+
APP_ENV=tugboat yarn start

tugboat.yml

+6
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,16 @@ tasks:
1313
cmds:
1414
- drush va-gov:content-release:request-frontend-build
1515

16+
build-next:
17+
desc: build next.js preview server
18+
cmds:
19+
- composer va:next:build
20+
1621
build:
1722
deps:
1823
- build-storybook
1924
- build-frontend
25+
- build-next
2026

2127
default:
2228
cmds:

0 commit comments

Comments
 (0)