From e429472e15efa0c4772e32ee656670a9e25e32cc Mon Sep 17 00:00:00 2001 From: Alex Finnarn Date: Mon, 4 Mar 2024 14:53:57 -0500 Subject: [PATCH] restart next server in start command --- .tugboat/config.yml | 8 +++++++- scripts/next-build-frontend.sh | 9 +++++++++ scripts/next-build.sh | 2 +- scripts/next-install.sh | 18 ++++++++++-------- scripts/next-start.sh | 23 +++++++++++++++++++---- scripts/vets-web-setup.sh | 13 +++++++++++-- 6 files changed, 57 insertions(+), 16 deletions(-) diff --git a/.tugboat/config.yml b/.tugboat/config.yml index e1f37c407e..1f5a83dfa2 100644 --- a/.tugboat/config.yml +++ b/.tugboat/config.yml @@ -37,6 +37,7 @@ services: # General useful development tools - apt-get install jq nano +# @todo Can cypress/included image be used instead? # cypress-axe dependencies - https://docs.cypress.io/guides/getting-started/installing-cypress.html#System-requirements - apt-get install libgtk2.0-0 libgtk-3-0 libgbm-dev libnotify-dev libgconf-2-4 libnss3 libxss1 libasound2 libxtst6 xauth xvfb @@ -73,6 +74,7 @@ services: # 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 +# @todo These should be aligned with other environments... # BRD Environments are set to 1G, Tugboat and Lando are -1 (unlimited). - echo "memory_limit = 4G" >> /usr/local/etc/php/conf.d/my-php.ini # Set unlimited memory limit for PHP CLI to allow Composer to run. @@ -141,6 +143,7 @@ services: - ./scripts/install-nvm.sh # Ensure that we're using version 2 of composer. +# @todo I'm guessing it is always version two now... - composer self-update --2 # Install the Task task runner/build tool. @@ -163,6 +166,7 @@ services: update: # Install/update packages managed by composer, including drush. # Composer options are in composer.json, 'config' key. +# @todo Isn't this already done in the build step? - composer install - bash -lc 'nvm install' - bash -lc 'npm install' @@ -192,6 +196,7 @@ services: # This j2 command is shared in both the build & clone stages. If modifying, change the other too. - j2 "${TUGBOAT_ROOT}/.tugboat/.env.j2" -o "${TUGBOAT_ROOT}/.env" +# @todo If this is shared, why not abstract it to a script? # 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" @@ -209,7 +214,6 @@ services: - mkdir -p "${TUGBOAT_ROOT}/next/public" - ln -snf "${TUGBOAT_ROOT}/vets-website/build/localhost/generated" "${TUGBOAT_ROOT}/next/public/generated" - # https://www.drush.org/latest/deploycommand/ (updatedb, cache:rebuild, config:import, deploy:hook) - bash -lc 'drush deploy' @@ -256,6 +260,8 @@ services: # Put necessary env variables in place for next's Drupal Preview before building server # Need to construct this way instead of TUGBOAT_DEFAULT_SERVICE_URL in order to drop the trailing / +# @todo Can the config file use set env vars and these commands set them? +# @todo e.g. TUGBOAT_DEFAULT_SERVICE_URL=https://cms-${TUGBOAT_SERVICE_TOKEN}.${TUGBOAT_SERVICE_CONFIG_DOMAIN} - echo "NEXT_PUBLIC_DRUPAL_BASE_URL=https://cms-${TUGBOAT_SERVICE_TOKEN}.${TUGBOAT_SERVICE_CONFIG_DOMAIN}" >> ${TUGBOAT_ROOT}/next/envs/.env.tugboat - echo "NEXT_IMAGE_DOMAIN=https://cms-${TUGBOAT_SERVICE_TOKEN}.${TUGBOAT_SERVICE_CONFIG_DOMAIN}" >> ${TUGBOAT_ROOT}/next/envs/.env.tugboat - echo "DRUPAL_CLIENT_ID=${DRUPAL_CLIENT_ID}" >> ${TUGBOAT_ROOT}/next/envs/.env.tugboat diff --git a/scripts/next-build-frontend.sh b/scripts/next-build-frontend.sh index a94b95d7b0..106a53a1d1 100644 --- a/scripts/next-build-frontend.sh +++ b/scripts/next-build-frontend.sh @@ -78,6 +78,8 @@ else echo "==> Using default next-build version" >> ${logfile} fi +# Stop the next server. + # Install 3rd party deps. echo "==> Installing yarn dependencies" >> ${logfile} composer va:next:install &>> ${logfile} @@ -99,10 +101,17 @@ else echo "==> Using default vets-website version" >> ${logfile} fi +# Build vets-website again. +${reporoot}/scripts/vets-web-setup.sh + # Run the build. echo "==> Starting build" >> ${logfile} composer va:next:build &>> ${logfile} +# Start next server. +echo "==> Starting next server" >> ${logfile} +composer va:next:start &>> ${logfile} + # After this point, we are less concerned with errors; the build has completed. set +e diff --git a/scripts/next-build.sh b/scripts/next-build.sh index f322083dbf..549ef741e6 100755 --- a/scripts/next-build.sh +++ b/scripts/next-build.sh @@ -17,4 +17,4 @@ source ~/.bashrc cd "${ROOT}/next" -APP_ENV=${APP_ENV} yarn build:preview +yarn build:preview diff --git a/scripts/next-install.sh b/scripts/next-install.sh index 11f3ba5c85..d75e3dd451 100755 --- a/scripts/next-install.sh +++ b/scripts/next-install.sh @@ -1,11 +1,20 @@ #!/usr/bin/env bash +ROOT=${TUGBOAT_ROOT:-${DDEV_APPROOT:-/var/www/html}} +if [ -n "${IS_DDEV_PROJECT}" ]; then + APP_ENV="local" +elif [ -n "${TUGBOAT_ROOT}" ]; then + APP_ENV="tugboat" +else + APP_ENV="tugboat" +fi + 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. +cd ${ROOT} if [ ! -d next ]; then # Clone full so git information is available for content release form. @@ -17,8 +26,6 @@ else 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 @@ -31,9 +38,4 @@ 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 diff --git a/scripts/next-start.sh b/scripts/next-start.sh index 99f1e59994..99e451d759 100755 --- a/scripts/next-start.sh +++ b/scripts/next-start.sh @@ -1,14 +1,29 @@ #!/usr/bin/env bash +ROOT=${TUGBOAT_ROOT:-${DDEV_APPROOT:-/var/www/html}} +if [ -n "${IS_DDEV_PROJECT}" ]; then + APP_ENV="local" +elif [ -n "${TUGBOAT_ROOT}" ]; then + APP_ENV="tugboat" +else + APP_ENV="tugboat" +fi + 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 +cd ${ROOT}/next + +# Kill any current running server. +# We can look for "/scripts/yarn/start.js" since that is what "yarn start" runs. +NEXT_SERVER_PIDS=$(ps aux | grep '[.]/scripts/yarn/start.js' | awk '{print $2}') -# Start the dev server. Vets-website assets will be available to the preview server after content-build builds them. -# APP_ENV=tugboat yarn dev +# In case we have multiple processes, loop through them. +for pid in ${NEXT_SERVER_PIDS}; do + kill $pid +done # Start the dev server. Vets-website assets need to be in place prior to this build. -APP_ENV=tugboat yarn start +yarn start diff --git a/scripts/vets-web-setup.sh b/scripts/vets-web-setup.sh index b2be1e6a31..9c86d3ccf3 100755 --- a/scripts/vets-web-setup.sh +++ b/scripts/vets-web-setup.sh @@ -1,12 +1,22 @@ #!/usr/bin/env bash +ROOT=${TUGBOAT_ROOT:-${DDEV_APPROOT:-/var/www/html}} +if [ -n "${IS_DDEV_PROJECT}" ]; then + APP_ENV="local" +elif [ -n "${TUGBOAT_ROOT}" ]; then + APP_ENV="tugboat" +else + APP_ENV="tugboat" +fi + 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 ${ROOT} + # Installs & builds vets-website dependencies for next-build preview. -#if [ ! -d docroot/vendor/va-gov/vets-website ]; then if [ ! -d vets-website ]; then # Clone full so git information is available for content release form. # I don't think this should be necessary, but branch information was not @@ -16,7 +26,6 @@ else echo "Repo vets-website already cloned." fi -#cd docroot/vendor/va-gov/vets-website cd vets-website nvm install 14.15.1