From 29593bd497840757c7e70984e91d7878071e5953 Mon Sep 17 00:00:00 2001 From: Alex Finnarn Date: Mon, 19 Feb 2024 13:13:45 -0500 Subject: [PATCH 01/25] Reapply "VACMS-16853: next build branches ftw (#17154)" (#17261) This reverts commit dfc8eec8290e98894c7aa35f2374b1208204ee72. --- .tugboat/config.yml | 7 + READMES/cms-content-release.md | 30 +- ...xt.next_site.next_build_preview_server.yml | 4 +- .../custom/va_gov_content_release/README.md | 13 + .../src/Form/NextGitForm.php | 399 ++++++++++++++++++ .../FrontendVersionSearch.php | 30 +- .../va_gov_content_release.module | 6 - .../va_gov_content_release.routing.yml | 8 + .../va_gov_content_release.services.yml | 2 + .../Factory/BranchSearchFactory.php | 8 + .../Factory/BranchSearchFactoryInterface.php | 8 + .../Repository/Factory/RepositoryFactory.php | 7 + .../Factory/RepositoryFactoryInterface.php | 11 +- .../Settings/RepositorySettings.php | 2 +- .../Settings/RepositorySettingsInterface.php | 5 + .../custom/va_gov_git/va_gov_git.services.yml | 4 + .../Api/Client/Factory/ApiClientFactory.php | 9 + .../Factory/ApiClientFactoryInterface.php | 11 + .../va_gov_github/va_gov_github.services.yml | 4 + docroot/sites/default/settings.php | 1 + .../default/settings/settings.tugboat.php | 1 + scripts/next-build-frontend.sh | 120 ++++++ scripts/next-build.sh | 13 +- scripts/next-install.sh | 14 +- scripts/queue_runner/next_queue_runner.sh | 6 + .../Settings/RepositorySettingsTest.php | 5 + .../Settings/RepositorySettingsTest.php | 7 + 27 files changed, 717 insertions(+), 18 deletions(-) create mode 100644 docroot/modules/custom/va_gov_content_release/README.md create mode 100644 docroot/modules/custom/va_gov_content_release/src/Form/NextGitForm.php delete mode 100644 docroot/modules/custom/va_gov_content_release/va_gov_content_release.module create mode 100644 scripts/next-build-frontend.sh create mode 100644 scripts/queue_runner/next_queue_runner.sh diff --git a/.tugboat/config.yml b/.tugboat/config.yml index 6e628ef6c4..e1f37c407e 100644 --- a/.tugboat/config.yml +++ b/.tugboat/config.yml @@ -226,6 +226,13 @@ services: - mv "${TUGBOAT_ROOT}/scripts/queue_runner/queue_runner.sh" /etc/service/drupal_events/run - chmod +x /etc/service/drupal_events/run + # Separate process for next-build preview. + - mkdir -p /etc/service/next_build + - mv "${TUGBOAT_ROOT}/scripts/queue_runner/next_queue_runner.sh" /etc/service/next_build/run + - chmod +x /etc/service/next_build/run + # Need to make build script executable so the runner can run it. + - chmod +x "${TUGBOAT_ROOT}/scripts/next-build-frontend.sh" + clone: # 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" diff --git a/READMES/cms-content-release.md b/READMES/cms-content-release.md index 8d9119600e..0c8c93e598 100644 --- a/READMES/cms-content-release.md +++ b/READMES/cms-content-release.md @@ -116,7 +116,6 @@ sequenceDiagram Complete->>+Ready: Content release workflow has completed ``` - # Environment specific details ## BRD Production @@ -144,6 +143,35 @@ The Tugboat and local development versions of the release content page do not tr For more information on creating or releasing content from a preview environment, see [Environments](./environments.md). +### Next Build Releases + +The upcoming static frontend "next-build" can be rebuilt using different versions of next-build and vets-website. It +is a simpler process than the current content-build workflow. + +1. Go to "/admin/content/deploy/next". +2. If the form elements are disabled, then a lock file exists preventing another build from being triggered. You + can skip to step #6. +2. Choose a version for next-build or leave at default. +3. Choose a version for vets-website or leave at default. When content-build is releasing, these form fields might + be disabled. We can't change the vets-website version while another frontend build is running. +4. Click "Release Content" to set the versions of next-build and vets-website as well as write a "buildrequest" file. +5. A `scripts/queue_runner/next_queue_runner.sh` script continuously runs in the background looking for the + "buildrequest" file and then start a build if found. Locally, the script has to be triggered manually. See the + [caveats](#caveats) section for more information. +6. Back on "/admin/content/deploy/next" you can view the build log via a link in the "Status" section of the + "Next Build Information" block. +7. Once the build completes no new build will be triggered until you click to release content again. +8. View the frontend at the provided "View Preview" link in the "Next Build Information" block. + +#### Caveats + +There are some caveats to the process outlined above. + +- **Manually running the background script** - On `ddev` the `queue_runner` scripts aren't running continuously in + background jobs. So you must `ddev ssh && ./scripts/queue_runner/` to kick off the content build or next build + release locally. In the future, it might be a good idea to use `system.d` or `supervisor` or something else to + keep the background jobs going locally just like on Tugoboat. + ## Troubleshooting Sometimes the state gets stuck and needs to be reset. It can be done with a drush command diff --git a/config/sync/next.next_site.next_build_preview_server.yml b/config/sync/next.next_site.next_build_preview_server.yml index 3e3a99c8bb..caf6c88f5d 100644 --- a/config/sync/next.next_site.next_build_preview_server.yml +++ b/config/sync/next.next_site.next_build_preview_server.yml @@ -4,8 +4,8 @@ status: true dependencies: { } id: next_build_preview_server label: 'Next Build Preview Server' -base_url: 'http://localhost:3000' -preview_url: 'http://localhost:3000/api/preview' +base_url: 'http://localhost:3999' +preview_url: 'http://localhost:3999/api/preview' preview_secret: secret revalidate_url: '' revalidate_secret: '' diff --git a/docroot/modules/custom/va_gov_content_release/README.md b/docroot/modules/custom/va_gov_content_release/README.md new file mode 100644 index 0000000000..226790fb81 --- /dev/null +++ b/docroot/modules/custom/va_gov_content_release/README.md @@ -0,0 +1,13 @@ +# VA.gov Content Release + +va.gov is built using two separate frontend systems with a third being built: + +- content-build - This is the frontend for generating static content files. You can read more about the project here: + https://github.com/department-of-veterans-affairs/content-build +- vets-website - This is the frontend for integrating React widgets. You can read more about the project here: + https://github.com/department-of-veterans-affairs/vets-website +- next-build - This is the new frontend for generating static content files. You can read more about the project here: + https://github.com/department-of-veterans-affairs/next-build + +More detailed documentation about how these frontends are build and released can be found in the main READMEs +directory on the [CMS Content Release](../../../../READMES/cms-content-release.md) page. diff --git a/docroot/modules/custom/va_gov_content_release/src/Form/NextGitForm.php b/docroot/modules/custom/va_gov_content_release/src/Form/NextGitForm.php new file mode 100644 index 0000000000..e20b3870b9 --- /dev/null +++ b/docroot/modules/custom/va_gov_content_release/src/Form/NextGitForm.php @@ -0,0 +1,399 @@ +frontendVersion = $frontendVersion; + $this->fileSystem = $fileSystem; + $this->config = $config; + $this->state = $state; + } + + /** + * {@inheritdoc} + */ + public static function create(ContainerInterface $container) { + return new static( + $container->get('va_gov_content_release.frontend_version'), + $container->get('file_system'), + $container->get('config.factory'), + $container->get('state') + ); + } + + /** + * Build the form. + * + * @param array $form + * Default form array structure. + * @param \Drupal\Core\Form\FormStateInterface $form_state + * Object containing current form state. + */ + public function buildForm(array $form, FormStateInterface $form_state) { + $form['build_request']['description'] = [ + '#prefix' => '

', + '#markup' => $this->t('Release content to update the front end of this environment with the latest published content changes.'), + '#suffix' => '

', + ]; + + $form['build_request']['next_build_selection'] = [ + '#title' => $this->t('Which version of next-build would you like to use?'), + '#type' => 'radios', + '#options' => [ + 'default' => $this->t('Use default - the next-build version from the time this demo environment was created.'), + 'choose' => $this->t('Select a different next-build branch/pull request - for example, to see your content in a newer frontend design.'), + ], + '#default_value' => 'default', + ]; + + $form['build_request']['next_build_git_ref'] = [ + '#type' => 'textfield', + '#title' => $this->t('Select branch/pull request'), + '#description' => $this->t('Start typing to select a branch for the next-build version you want to use.'), + '#autocomplete_route_name' => 'va_gov_content_release.frontend_version_autocomplete', + '#autocomplete_route_parameters' => [ + 'frontend' => 'next_build', + 'count' => 10, + ], + '#size' => 72, + '#maxlength' => 1024, + '#hidden' => TRUE, + '#states' => [ + 'visible' => [':input[name="next_build_selection"]' => ['value' => 'choose']], + ], + ]; + + $form['build_request']['vets_website_selection'] = [ + '#title' => $this->t('Which version of vets-website would you like to use?'), + '#type' => 'radios', + '#options' => [ + 'default' => $this->t('Use default - the vets-website version from the time this demo environment was created.'), + 'choose' => $this->t('Select a different vets-website branch/pull request - for example, to see your content in a newer frontend design.'), + ], + '#default_value' => 'default', + ]; + + $form['build_request']['vets_website_git_ref'] = [ + '#type' => 'textfield', + '#title' => $this->t('Select branch/pull request'), + '#description' => $this->t('Start typing to select a branch for the vets-website version you want to use.'), + '#autocomplete_route_name' => 'va_gov_content_release.frontend_version_autocomplete', + '#autocomplete_route_parameters' => [ + 'frontend' => 'vets_website', + 'count' => 10, + ], + '#size' => 72, + '#maxlength' => 1024, + '#hidden' => TRUE, + '#states' => [ + 'visible' => [':input[name="vets_website_selection"]' => ['value' => 'choose']], + ], + ]; + + $form['build_request']['actions']['#type'] = 'actions'; + $form['build_request']['actions']['submit'] = [ + '#type' => 'submit', + '#value' => $this->t('Release Content'), + '#button_type' => 'primary', + ]; + + // Lock the vets-website form fields if a content-build is in progress. + $build_status = $this->state->get('va_gov_build_trigger.release_state'); + if ($build_status !== ReleaseStateManager::STATE_READY) { + $form['build_request']['vets_website_selection']['#disabled'] = TRUE; + $form['build_request']['vets_website_git_ref']['#disabled'] = TRUE; + } + + // Disable form changes and submission if a build is in progress. + if (file_exists($this->fileSystem->realpath('public://' . self::LOCK_FILE_NAME))) { + $form['build_request']['next_build_selection']['#disabled'] = TRUE; + $form['build_request']['next_build_git_ref']['#disabled'] = TRUE; + $form['build_request']['vets_website_selection']['#disabled'] = TRUE; + $form['build_request']['vets_website_git_ref']['#disabled'] = TRUE; + $form['build_request']['actions']['submit']['#disabled'] = TRUE; + + $target_url = Url::fromUserInput("/sites/default/files/next-build.txt"); + $build_log_text = Link::fromTextAndUrl('Build is in progress. View log file', $target_url); + } + else { + $build_log_text = 'Build is not in progress.'; + } + + // Set variables needed for build status information. + $lock_file_text = $this->getFileLink(self::LOCK_FILE_NAME); + $request_file_text = $this->getFileLink(self::REQUEST_FILE_NAME); + $next_build_version = $this->frontendVersion->getVersion(Frontend::NextBuild); + $vets_website_version = $this->frontendVersion->getVersion(Frontend::VetsWebsite); + $view_preview = $this->getPreviewLink(); + $last_build_time = $this->state->get('next_build.status.last_build_date', 'N/A'); + $form['content_release_status_block'] = [ + '#theme' => 'status_report_grouped', + '#grouped_requirements' => [ + [ + 'title' => $this->t('Next Build Information'), + 'type' => 'content-release-status', + 'items' => [ + 'status' => [ + 'title' => $this->t('Status'), + 'value' => $build_log_text, + ], + 'lock_file' => [ + 'title' => $this->t('Lock File'), + 'value' => $lock_file_text, + ], + 'request_file' => [ + 'title' => $this->t('Request File'), + 'value' => $request_file_text, + ], + 'next_build_version' => [ + 'title' => $this->t('Next-build Version'), + 'value' => $next_build_version, + ], + 'vets_website_version' => [ + 'title' => $this->t('Vets-website Version'), + 'value' => $vets_website_version, + ], + 'view_preview' => [ + 'title' => $this->t('View Preview'), + 'value' => $view_preview, + ], + 'last_build_time' => [ + 'title' => $this->t('Last Build Time'), + 'value' => $last_build_time, + ], + ], + ], + ], + ]; + + return $form; + } + + /** + * Get the text for a file. + * + * @param string $file_name + * The name of the file. + * + * @return \Drupal\Core\Link|string + * The file link. + */ + private function getFileLink(string $file_name): Link|string { + $file_path = $this->fileSystem->realpath("public://$file_name"); + if (file_exists($file_path)) { + $target_url = Url::fromUserInput("/sites/default/files/$file_name"); + return Link::fromTextAndUrl($file_name, $target_url); + } + else { + return 'does not exist'; + } + } + + /** + * Get the preview link. + * + * @return \Drupal\Core\Link + * The preview link. + */ + private function getPreviewLink(): Link { + $frontend_base_url = $this->config + ->get('next.next_site.next_build_preview_server') + ->get('base_url'); + $target_url = Url::fromUri($frontend_base_url, ['attributes' => ['target' => '_blank']]); + return Link::fromTextAndUrl($this->t('View front end'), $target_url); + } + + /** + * Submit the build trigger form. + * + * @param array $form + * Default form array structure. + * @param \Drupal\Core\Form\FormStateInterface $form_state + * Object containing current form state. + */ + public function submitForm(array &$form, FormStateInterface $form_state) { + $this->submitFormForFrontend(Frontend::NextBuild, $form_state); + $this->submitFormForFrontend(Frontend::VetsWebsite, $form_state); + + $lock_file = $this->fileSystem->realpath('public://' . self::LOCK_FILE_NAME); + if (file_exists($lock_file)) { + $this->messenger() + ->addMessage($this->t('The build is in progress. Please wait for the build to complete.')); + } + else { + $this->fileSystem->saveData( + 'Build me, Seymour!', + 'public://' . self::REQUEST_FILE_NAME, + 1); + $this->messenger()->addMessage($this->t('Build request file set.')); + } + } + + /** + * Submit the form. + * + * @param \Drupal\va_gov_content_release\Frontend\FrontendInterface $frontend + * The frontend whose version we are managing. + * @param \Drupal\Core\Form\FormStateInterface $form_state + * Object containing current form state. + */ + protected function submitFormForFrontend( + FrontendInterface $frontend, + FormStateInterface $form_state + ) { + $selectionName = $frontend->getRawValue() . '_selection'; + if ($form_state->getValue($selectionName) === 'default') { + $this->resetFrontendVersion($frontend, $form_state); + } + else { + $this->setFrontendVersion($frontend, $form_state); + } + } + + /** + * {@inheritdoc} + */ + public function validateForm(array &$form, FormStateInterface $form_state) { + $this->validateFormForFrontend(Frontend::NextBuild, $form_state); + $this->validateFormForFrontend(Frontend::VetsWebsite, $form_state); + } + + /** + * Validate the form. + * + * @param \Drupal\va_gov_content_release\Frontend\FrontendInterface $frontend + * The frontend whose version we are managing. + * @param \Drupal\Core\Form\FormStateInterface $form_state + * Object containing current form state. + */ + protected function validateFormForFrontend( + FrontendInterface $frontend, + FormStateInterface $form_state + ) { + $selectionName = $frontend->getRawValue() . '_selection'; + $gitRefName = $frontend->getRawValue() . '_git_ref'; + if ($form_state->getValue($selectionName) !== 'default') { + if (empty($this->getGitRef($frontend, $form_state))) { + $form_state->setErrorByName($gitRefName, + $this->t('Invalid selection.')); + } + } + } + + /** + * Reset the frontend version. + * + * @param \Drupal\va_gov_content_release\Frontend\FrontendInterface $frontend + * The frontend whose version we are resetting. + */ + public function resetFrontendVersion(FrontendInterface $frontend) { + $this->frontendVersion->resetVersion($frontend); + } + + /** + * Set the frontend version according to the form. + * + * @param \Drupal\va_gov_content_release\Frontend\FrontendInterface $frontend + * The frontend whose version we are setting. + * @param \Drupal\Core\Form\FormStateInterface $form_state + * Object containing current form state. + */ + public function setFrontendVersion( + FrontendInterface $frontend, + FormStateInterface $form_state + ) { + $this->frontendVersion->setVersion($frontend, + $this->getGitRef($frontend, $form_state)); + } + + /** + * Parse a git ref out of the `git_ref` field value. + * + * @param \Drupal\va_gov_content_release\Frontend\FrontendInterface $frontend + * The frontend whose version we are setting. + * @param \Drupal\Core\Form\FormStateInterface $form_state + * Object containing current form state. + * + * @return string + * A standalone git ref, or an empty string. + */ + public function getGitRef( + FrontendInterface $frontend, + FormStateInterface $form_state + ): string { + // If they selected a specific git ref, use that. + $gitRefName = $frontend->getRawValue() . '_git_ref'; + $formValue = $form_state->getValue($gitRefName); + $result = ''; + if (preg_match("/.+\\s\\(([^\\)]+)\\)/", $formValue, $matches)) { + $result = $matches[1]; + } + return $result; + } + + /** + * {@inheritdoc} + */ + public function getFormId(): string { + return 'va_gov_content_release_next_git_form'; + } + +} diff --git a/docroot/modules/custom/va_gov_content_release/src/FrontendVersionSearch/FrontendVersionSearch.php b/docroot/modules/custom/va_gov_content_release/src/FrontendVersionSearch/FrontendVersionSearch.php index d2d6145d39..1420453091 100644 --- a/docroot/modules/custom/va_gov_content_release/src/FrontendVersionSearch/FrontendVersionSearch.php +++ b/docroot/modules/custom/va_gov_content_release/src/FrontendVersionSearch/FrontendVersionSearch.php @@ -50,6 +50,20 @@ class FrontendVersionSearch implements FrontendVersionSearchInterface { */ protected $logger; + /** + * The branch search service for `vets-website`. + * + * @var \Drupal\va_gov_git\BranchSearch\BranchSearchInterface + */ + protected $nbBranchSearch; + + /** + * The API client for `vets-website`. + * + * @var \Drupal\va_gov_github\Api\Client\ApiClientInterface + */ + protected $nbApiClient; + /** * Constructor. * @@ -63,19 +77,27 @@ class FrontendVersionSearch implements FrontendVersionSearchInterface { * The API client for `vets-website`. * @param \Drupal\Core\Logger\LoggerChannelFactoryInterface $loggerFactory * The logger factory service. + * @param \Drupal\va_gov_git\BranchSearch\BranchSearchInterface $nbBranchSearch + * The branch search service for `next-build`. + * @param \Drupal\va_gov_github\Api\Client\ApiClientInterface $nbApiClient + * The API client for `next-build`. */ public function __construct( BranchSearchInterface $cbBranchSearch, ApiClientInterface $cbApiClient, BranchSearchInterface $vwBranchSearch, ApiClientInterface $vwApiClient, - LoggerChannelFactoryInterface $loggerFactory + LoggerChannelFactoryInterface $loggerFactory, + BranchSearchInterface $nbBranchSearch, + ApiClientInterface $nbApiClient, ) { $this->cbBranchSearch = $cbBranchSearch; $this->cbApiClient = $cbApiClient; $this->vwBranchSearch = $vwBranchSearch; $this->vwApiClient = $vwApiClient; $this->logger = $loggerFactory->get('va_gov_content_release'); + $this->nbBranchSearch = $nbBranchSearch; + $this->nbApiClient = $nbApiClient; } /** @@ -95,6 +117,9 @@ protected function getBranchSearch(FrontendInterface $frontend) : BranchSearchIn case $frontend->isVetsWebsite(): return $this->vwBranchSearch; + case $frontend->isNextBuild(): + return $this->nbBranchSearch; + default: throw new \InvalidArgumentException('Invalid frontend: ' . $frontend->getRawValue()); } @@ -117,6 +142,9 @@ protected function getApiClient(FrontendInterface $frontend) : ApiClientInterfac case $frontend->isVetsWebsite(): return $this->vwApiClient; + case $frontend->isNextBuild(): + return $this->nbApiClient; + default: throw new \InvalidArgumentException('Invalid frontend: ' . $frontend->getRawValue()); } diff --git a/docroot/modules/custom/va_gov_content_release/va_gov_content_release.module b/docroot/modules/custom/va_gov_content_release/va_gov_content_release.module deleted file mode 100644 index 35beaf8b98..0000000000 --- a/docroot/modules/custom/va_gov_content_release/va_gov_content_release.module +++ /dev/null @@ -1,6 +0,0 @@ -repositoryFactory->getVetsWebsite(), $this->loggerFactory); } + /** + * {@inheritDoc} + */ + public function getNextBuild(): BranchSearchInterface { + return new BranchSearch($this->repositoryFactory->getNextBuild(), + $this->loggerFactory); + } + } diff --git a/docroot/modules/custom/va_gov_git/src/BranchSearch/Factory/BranchSearchFactoryInterface.php b/docroot/modules/custom/va_gov_git/src/BranchSearch/Factory/BranchSearchFactoryInterface.php index 8d67cb0b1f..616cc686ce 100644 --- a/docroot/modules/custom/va_gov_git/src/BranchSearch/Factory/BranchSearchFactoryInterface.php +++ b/docroot/modules/custom/va_gov_git/src/BranchSearch/Factory/BranchSearchFactoryInterface.php @@ -55,4 +55,12 @@ public function getContentBuild(): BranchSearchInterface; */ public function getVetsWebsite(): BranchSearchInterface; + /** + * Get the next-build branch search service. + * + * @return \Drupal\va_gov_git\BranchSearch\BranchSearchInterface + * The next-build branch search object. + */ + public function getNextBuild(): BranchSearchInterface; + } diff --git a/docroot/modules/custom/va_gov_git/src/Repository/Factory/RepositoryFactory.php b/docroot/modules/custom/va_gov_git/src/Repository/Factory/RepositoryFactory.php index fe70477b26..4a1f8a93d4 100644 --- a/docroot/modules/custom/va_gov_git/src/Repository/Factory/RepositoryFactory.php +++ b/docroot/modules/custom/va_gov_git/src/Repository/Factory/RepositoryFactory.php @@ -65,4 +65,11 @@ public function getVetsWebsite(): RepositoryInterface { return $this->get(RepositorySettingsInterface::VETS_WEBSITE); } + /** + * {@inheritDoc} + */ + public function getNextBuild(): RepositoryInterface { + return $this->get(RepositorySettingsInterface::NEXT_BUILD); + } + } diff --git a/docroot/modules/custom/va_gov_git/src/Repository/Factory/RepositoryFactoryInterface.php b/docroot/modules/custom/va_gov_git/src/Repository/Factory/RepositoryFactoryInterface.php index 3e0a3350f2..877b59e3ae 100644 --- a/docroot/modules/custom/va_gov_git/src/Repository/Factory/RepositoryFactoryInterface.php +++ b/docroot/modules/custom/va_gov_git/src/Repository/Factory/RepositoryFactoryInterface.php @@ -10,10 +10,11 @@ * This service provides a way to create services corresponding to specific Git * repositories. * - * At this time, we're primarily interested in three repositories: + * At this time, we're primarily interested in four repositories: * - The `va.gov-cms` repository. * - The `content-build` repository. * - The `vets-website` repository. + * - The `next-build` repository. */ interface RepositoryFactoryInterface { @@ -55,4 +56,12 @@ public function getContentBuild(): RepositoryInterface; */ public function getVetsWebsite(): RepositoryInterface; + /** + * Get the next-build repository. + * + * @return \Drupal\va_gov_git\Repository\RepositoryInterface + * The next-build repository. + */ + public function getNextBuild(): RepositoryInterface; + } diff --git a/docroot/modules/custom/va_gov_git/src/Repository/Settings/RepositorySettings.php b/docroot/modules/custom/va_gov_git/src/Repository/Settings/RepositorySettings.php index 4d131e6043..c2f09cbdea 100644 --- a/docroot/modules/custom/va_gov_git/src/Repository/Settings/RepositorySettings.php +++ b/docroot/modules/custom/va_gov_git/src/Repository/Settings/RepositorySettings.php @@ -59,7 +59,7 @@ public function getPath(string $name): string { } $path = $this->settings->get($pathKey); if (empty($path)) { - throw new RepositoryPathNotSetException('Path not set for repository: ' . $name); + throw new RepositoryPathNotSetException('Path not set for repository: ' . $name . ' (' . $pathKey . ')'); } return $path; } diff --git a/docroot/modules/custom/va_gov_git/src/Repository/Settings/RepositorySettingsInterface.php b/docroot/modules/custom/va_gov_git/src/Repository/Settings/RepositorySettingsInterface.php index 15615705cc..dfcfbbca84 100644 --- a/docroot/modules/custom/va_gov_git/src/Repository/Settings/RepositorySettingsInterface.php +++ b/docroot/modules/custom/va_gov_git/src/Repository/Settings/RepositorySettingsInterface.php @@ -14,10 +14,12 @@ interface RepositorySettingsInterface { const VA_GOV_CMS = 'va.gov-cms'; const CONTENT_BUILD = 'content-build'; const VETS_WEBSITE = 'vets-website'; + const NEXT_BUILD = 'next-build'; const REPOSITORY_NAMES = [ self::VA_GOV_CMS, self::CONTENT_BUILD, self::VETS_WEBSITE, + self::NEXT_BUILD, ]; // Settings keys for the repositories' filesystem paths. @@ -26,10 +28,13 @@ interface RepositorySettingsInterface { const VA_GOV_CMS_PATH_KEY = 'va_gov_app_root'; const CONTENT_BUILD_PATH_KEY = 'va_gov_web_root'; const VETS_WEBSITE_PATH_KEY = 'va_gov_vets_website_root'; + const NEXT_BUILD_PATH_KEY = 'va_gov_next_build_root'; + const PATH_KEYS = [ self::VA_GOV_CMS => self::VA_GOV_CMS_PATH_KEY, self::CONTENT_BUILD => self::CONTENT_BUILD_PATH_KEY, self::VETS_WEBSITE => self::VETS_WEBSITE_PATH_KEY, + self::NEXT_BUILD => self::NEXT_BUILD_PATH_KEY, ]; /** diff --git a/docroot/modules/custom/va_gov_git/va_gov_git.services.yml b/docroot/modules/custom/va_gov_git/va_gov_git.services.yml index bd4757fffe..3d02a62691 100644 --- a/docroot/modules/custom/va_gov_git/va_gov_git.services.yml +++ b/docroot/modules/custom/va_gov_git/va_gov_git.services.yml @@ -32,4 +32,8 @@ services: class: Drupal\va_gov_git\BranchSearch\BranchSearch factory: ['@va_gov_git.branch_search_factory', 'getVetsWebsite'] arguments: [] + va_gov_git.branch_search.next_build: + class: Drupal\va_gov_git\BranchSearch\BranchSearch + factory: [ '@va_gov_git.branch_search_factory', 'getNextBuild' ] + arguments: [] diff --git a/docroot/modules/custom/va_gov_github/src/Api/Client/Factory/ApiClientFactory.php b/docroot/modules/custom/va_gov_github/src/Api/Client/Factory/ApiClientFactory.php index f4f59cc7ed..5244d41b29 100644 --- a/docroot/modules/custom/va_gov_github/src/Api/Client/Factory/ApiClientFactory.php +++ b/docroot/modules/custom/va_gov_github/src/Api/Client/Factory/ApiClientFactory.php @@ -18,6 +18,7 @@ class ApiClientFactory implements ApiClientFactoryInterface { const VA_GOV_CMS = 'va.gov-cms'; const CONTENT_BUILD = 'content-build'; const VETS_WEBSITE = 'vets-website'; + const NEXT_BUILD = 'next-build'; /** * The settings service. @@ -64,4 +65,12 @@ public function getVetsWebsite(): ApiClientInterface { return $this->get(static::OWNER, static::VETS_WEBSITE, $this->settings->getApiToken()); } + /** + * {@inheritDoc} + */ + public function getNextBuild(): ApiClientInterface { + return $this->get(static::OWNER, static::NEXT_BUILD, + $this->settings->getApiToken()); + } + } diff --git a/docroot/modules/custom/va_gov_github/src/Api/Client/Factory/ApiClientFactoryInterface.php b/docroot/modules/custom/va_gov_github/src/Api/Client/Factory/ApiClientFactoryInterface.php index 4dbd126985..e97d8c7ae0 100644 --- a/docroot/modules/custom/va_gov_github/src/Api/Client/Factory/ApiClientFactoryInterface.php +++ b/docroot/modules/custom/va_gov_github/src/Api/Client/Factory/ApiClientFactoryInterface.php @@ -67,4 +67,15 @@ public function getContentBuild(): ApiClientInterface; */ public function getVetsWebsite(): ApiClientInterface; + /** + * Retrieve an API client for the Next Build repository. + * + * @return \Drupal\va_gov_github\Api\Client\ApiClientInterface + * The GitHub Api Client instance. + * + * @throws \Drupal\va_gov_github\Exception\InvalidApiTokenException + * If the GitHub API token is provided, but is invalid. + */ + public function getNextBuild(): ApiClientInterface; + } diff --git a/docroot/modules/custom/va_gov_github/va_gov_github.services.yml b/docroot/modules/custom/va_gov_github/va_gov_github.services.yml index 60aa99976c..f881f35ab4 100644 --- a/docroot/modules/custom/va_gov_github/va_gov_github.services.yml +++ b/docroot/modules/custom/va_gov_github/va_gov_github.services.yml @@ -17,3 +17,7 @@ services: class: Drupal\va_gov_github\Api\Client\ApiClientInterface factory: ['@va_gov_github.api_client_factory', 'getVetsWebsite'] arguments: [] + va_gov_github.api_client.next_build: + class: Drupal\va_gov_github\Api\Client\ApiClientInterface + factory: [ '@va_gov_github.api_client_factory', 'getNextBuild' ] + arguments: [] diff --git a/docroot/sites/default/settings.php b/docroot/sites/default/settings.php index b22fa5300e..99271a5dd2 100755 --- a/docroot/sites/default/settings.php +++ b/docroot/sites/default/settings.php @@ -126,6 +126,7 @@ $settings['va_gov_web_root'] = '/var/www/cms/web'; $settings['va_gov_app_root'] = '/var/www/cms'; $settings['va_gov_vets_website_root'] = '/var/www/cms/docroot/vendor/va-gov/vets-website'; +$settings['va_gov_next_build_root'] = '../next'; // Defaults (should only be local that doesn't set these), default to dev for config_split $config['config_split.config_split.dev']['status'] = TRUE; diff --git a/docroot/sites/default/settings/settings.tugboat.php b/docroot/sites/default/settings/settings.tugboat.php index 5bcd14b1e3..c6ab9b0c63 100644 --- a/docroot/sites/default/settings/settings.tugboat.php +++ b/docroot/sites/default/settings/settings.tugboat.php @@ -64,6 +64,7 @@ $settings['va_gov_app_root'] = getenv('TUGBOAT_ROOT'); $settings['va_gov_web_root'] = getenv('TUGBOAT_ROOT') . '/web'; $settings['va_gov_vets_website_root'] = getenv('TUGBOAT_ROOT') . '/docroot/vendor/va-gov/vets-website'; +$settings['va_gov_next_build_root'] = getenv('TUGBOAT_ROOT') . '/next'; $settings['memcache']['servers'] = [ 'memcache:11211' => 'default', diff --git a/scripts/next-build-frontend.sh b/scripts/next-build-frontend.sh new file mode 100644 index 0000000000..c6e32d1d4a --- /dev/null +++ b/scripts/next-build-frontend.sh @@ -0,0 +1,120 @@ +#!/usr/bin/env bash + +# Exit if a command fails with a non-zero status code. +set -ex + +# Find repo root -> $reporoot +reporoot="unknown" +if [ ! -z "$IS_DDEV_PROJECT" ]; then + reporoot="/var/www/html" +fi +if [ ! -z "$TUGBOAT_ROOT" ]; then + reporoot="$TUGBOAT_ROOT" +fi +if [ "$reporoot" == "unknown" ]; then + echo "[!] Could not determine the environment type. Aborting!" + exit 1 +fi + +# For convenience. +cd $reporoot + +# Store path to site default files directory. +filesdir="${reporoot}/docroot/sites/default/files" + +# We really only want one build running at a time on any given environment. +if [ -f "${filesdir}/next-buildlock.txt" ]; then + echo "[!] There is already a build in progress. Aborting!" + exit 1 +fi +touch ${filesdir}/next-buildlock.txt + +# Make sure we clean up the build lock file if an error occurs or the build is killed. +trap "rm -f ${filesdir}/next-buildlock.txt && rm -f ${filesdir}/next-buildrequest.txt" INT TERM EXIT + +# Just because the path is really long: +logfile="${filesdir}/next-build.txt" + +# The currently selected version of next-build (may be "__default", a PR#, or a git ref) +next_build_version=$(drush va-gov-content-release:frontend-version:get next_build | tail -1) + +# The currently selected version of vets-website (may be "__default", a PR#, or a git ref) +vets_website_version=$(drush va-gov-content-release:frontend-version:get vets_website | tail -1) + +# Create a fresh log file. +[ -f "${logfile}" ] && rm ${logfile} +touch ${logfile} + +date >> ${logfile} + +echo "next-build version: ${next_build_version}" >> ${logfile} +echo "vets-website version: ${vets_website_version}" >> ${logfile} + +# Tell the frontend (and the user) that we're starting. +#drush va-gov:content-release:advance-state starting +echo "==> Starting a frontend build. This file will be updated as the build progresses." >> ${logfile} + +# Reset the repos to defaults. +#echo "==> Resetting VA repos to default versions" >> ${logfile} +#rm -rf ${reporoot}/docroot/vendor/va-gov +#composer install --no-scripts &>> ${logfile} + +# Get the requested next-build version +if [ "${next_build_version}" != "__default" ]; then + echo "==> Checking out the requested frontend version" >> ${logfile} + pushd ${reporoot}/next + if echo "${next_build_version}" | grep -qE '^[0-9]+$' > /dev/null; then + echo "==> Checking out PR #${next_build_version}" + git fetch origin pull/${next_build_version}/head &>> ${logfile} + else + echo "==> Checking out git ref ${next_build_version}" + git fetch origin ${next_build_version} &>> ${logfile} + fi + git checkout FETCH_HEAD &>> ${logfile} + popd +else + echo "==> Using default next-build version" >> ${logfile} +fi + +# Install 3rd party deps. +echo "==> Installing yarn dependencies" >> ${logfile} +composer va:next:install &>> ${logfile} + +# Get the requested vets-website version +if [ "${vets_website_version}" != "__default" ]; then + echo "==> Checking out the requested vets-website version" >> ${logfile} + pushd ${reporoot}/docroot/vendor/va-gov/vets-website + if echo "$vets_website_version" | grep -qE '^[0-9]+$' > /dev/null; then + echo "==> Checking out PR #${vets_website_version}" + git fetch origin pull/${vets_website_version}/head &>> ${logfile} + else + echo "==> Checking out git ref ${vets_website_version}" + git fetch origin ${vets_website_version} &>> ${logfile} + fi + git checkout FETCH_HEAD &>> ${logfile} + popd +else + echo "==> Using default vets-website version" >> ${logfile} +fi + +# Run the build. +echo "==> Starting build" >> ${logfile} +#drush va-gov:content-release:advance-state inprogress +composer va:next:build &>> ${logfile} + +# Advance the state in the frontend so another build can start. +echo "==> Build complete" >> ${logfile} +#drush va-gov:content-release:advance-state complete +#drush va-gov:content-release:advance-state ready + +# After this point, we are less concerned with errors; the build has completed. +set +e + +# Switch to the docroot to run drush commands. +cd "${reporoot}/docroot" + +# Log the timestamp of the build for reporting purposes. +drush state:set next_build.status.last_build_date "$(date)" + +# Just in case it wasn't clear :) +echo "==> Done" >> ${logfile} diff --git a/scripts/next-build.sh b/scripts/next-build.sh index ff134cf6fe..f322083dbf 100755 --- a/scripts/next-build.sh +++ b/scripts/next-build.sh @@ -1,11 +1,20 @@ #!/usr/bin/env bash #preview +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" -APP_ENV=tugboat yarn build:preview \ No newline at end of file +APP_ENV=${APP_ENV} yarn build:preview diff --git a/scripts/next-install.sh b/scripts/next-install.sh index e7063b52c2..11f3ba5c85 100755 --- a/scripts/next-install.sh +++ b/scripts/next-install.sh @@ -8,7 +8,10 @@ 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 + # Clone full so git information is available for content release form. + # I don't think this should be necessary, but branch information was not + # available in the content release form until I pulled down all information. + git clone https://github.com/department-of-veterans-affairs/next-build.git next else echo "Repo next-build already cloned." fi @@ -17,10 +20,13 @@ cd next #repo_root="$(git rev-parse --show-toplevel)" #pushd "${repo_root}" > /dev/null -nvm install 18.17.0 +nvm install 18.17.0 nvm use 18.17.0 -corepack enable -corepack prepare yarn@stable --activate + +# These steps caused the build to fail for me so I disabled temporarily. +#corepack enable +#corepack prepare yarn@stable --activate + echo "Node $(node -v)" echo "NPM $(npm -v)" echo "Yarn $(yarn -v)" diff --git a/scripts/queue_runner/next_queue_runner.sh b/scripts/queue_runner/next_queue_runner.sh new file mode 100644 index 0000000000..b636f6c686 --- /dev/null +++ b/scripts/queue_runner/next_queue_runner.sh @@ -0,0 +1,6 @@ +#!/bin/bash -l + +ROOT=${TUGBOAT_ROOT:-${DDEV_APPROOT:-/var/www/html}} +cd "${ROOT}" +[ -f "./docroot/sites/default/files/next-buildrequest.txt" ] && ./scripts/next-build-frontend.sh +sleep 10s diff --git a/tests/phpunit/va_gov_git/functional/Repository/Settings/RepositorySettingsTest.php b/tests/phpunit/va_gov_git/functional/Repository/Settings/RepositorySettingsTest.php index b50b2de832..ba8fc95b2d 100644 --- a/tests/phpunit/va_gov_git/functional/Repository/Settings/RepositorySettingsTest.php +++ b/tests/phpunit/va_gov_git/functional/Repository/Settings/RepositorySettingsTest.php @@ -47,6 +47,7 @@ public function testGetPathKey() { $this->assertEquals(RepositorySettingsInterface::PATH_KEYS['va.gov-cms'], $repositorySettings->getPathKey('va.gov-cms')); $this->assertEquals(RepositorySettingsInterface::PATH_KEYS['content-build'], $repositorySettings->getPathKey('content-build')); $this->assertEquals(RepositorySettingsInterface::PATH_KEYS['vets-website'], $repositorySettings->getPathKey('vets-website')); + $this->assertEquals(RepositorySettingsInterface::PATH_KEYS['next-build'], $repositorySettings->getPathKey('next-build')); } /** @@ -69,6 +70,10 @@ public function testList() { 'name' => RepositorySettingsInterface::VETS_WEBSITE, 'path' => Settings::get('va_gov_vets_website_root'), ], + [ + 'name' => RepositorySettingsInterface::NEXT_BUILD, + 'path' => Settings::get('va_gov_next_build_root'), + ], ], $repositorySettings->list()); } diff --git a/tests/phpunit/va_gov_git/unit/Repository/Settings/RepositorySettingsTest.php b/tests/phpunit/va_gov_git/unit/Repository/Settings/RepositorySettingsTest.php index 20b5d104d3..b0b3813dc8 100644 --- a/tests/phpunit/va_gov_git/unit/Repository/Settings/RepositorySettingsTest.php +++ b/tests/phpunit/va_gov_git/unit/Repository/Settings/RepositorySettingsTest.php @@ -30,6 +30,7 @@ public function getRepositorySettings() { 'va_gov_app_root' => '/srv/cms', 'va_gov_web_root' => '/srv/web', 'va_gov_vets_website_root' => '/srv/vets-website', + 'va_gov_next_build_root' => '/srv/next', ]); return new RepositorySettings($settings); } @@ -68,6 +69,7 @@ public function getPathKeyDataProvider() { ['va.gov-cms', RepositorySettings::VA_GOV_CMS_PATH_KEY], ['content-build', RepositorySettings::CONTENT_BUILD_PATH_KEY], ['vets-website', RepositorySettings::VETS_WEBSITE_PATH_KEY], + ['next-build', RepositorySettings::NEXT_BUILD_PATH_KEY], ]; } @@ -97,6 +99,7 @@ public function getPathDataProvider() { ['va.gov-cms', '/srv/cms'], ['content-build', '/srv/web'], ['vets-website', '/srv/vets-website'], + ['next-build', '/srv/next'], ]; } @@ -146,6 +149,10 @@ public function testList() { 'name' => RepositorySettingsInterface::VETS_WEBSITE, 'path' => '/srv/vets-website', ], + [ + 'name' => RepositorySettingsInterface::NEXT_BUILD, + 'path' => '/srv/next', + ], ], $repositorySettings->list()); } From 8c688966d9985a76c6c61c6997b6580c7e62621e Mon Sep 17 00:00:00 2001 From: Alex Finnarn Date: Tue, 20 Feb 2024 13:57:16 -0500 Subject: [PATCH 02/25] Update READMES/cms-content-release.md Co-authored-by: Tim Cosgrove --- READMES/cms-content-release.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/READMES/cms-content-release.md b/READMES/cms-content-release.md index 0c8c93e598..0b6d54de81 100644 --- a/READMES/cms-content-release.md +++ b/READMES/cms-content-release.md @@ -154,7 +154,7 @@ is a simpler process than the current content-build workflow. 2. Choose a version for next-build or leave at default. 3. Choose a version for vets-website or leave at default. When content-build is releasing, these form fields might be disabled. We can't change the vets-website version while another frontend build is running. -4. Click "Release Content" to set the versions of next-build and vets-website as well as write a "buildrequest" file. +4. Click "Restart Next Build Server" to set the versions of next-build and vets-website as well as write a "buildrequest" file. 5. A `scripts/queue_runner/next_queue_runner.sh` script continuously runs in the background looking for the "buildrequest" file and then start a build if found. Locally, the script has to be triggered manually. See the [caveats](#caveats) section for more information. From a6440b8c29a6b9a6471aa5718ed30e58c098fd7b Mon Sep 17 00:00:00 2001 From: Alex Finnarn Date: Tue, 20 Feb 2024 13:57:27 -0500 Subject: [PATCH 03/25] Update READMES/cms-content-release.md Co-authored-by: Tim Cosgrove --- READMES/cms-content-release.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/READMES/cms-content-release.md b/READMES/cms-content-release.md index 0b6d54de81..bb75ac8a33 100644 --- a/READMES/cms-content-release.md +++ b/READMES/cms-content-release.md @@ -158,7 +158,7 @@ is a simpler process than the current content-build workflow. 5. A `scripts/queue_runner/next_queue_runner.sh` script continuously runs in the background looking for the "buildrequest" file and then start a build if found. Locally, the script has to be triggered manually. See the [caveats](#caveats) section for more information. -6. Back on "/admin/content/deploy/next" you can view the build log via a link in the "Status" section of the +6. Back on "/admin/content/deploy/next" you can view the server restart log via a link in the "Status" section of the "Next Build Information" block. 7. Once the build completes no new build will be triggered until you click to release content again. 8. View the frontend at the provided "View Preview" link in the "Next Build Information" block. From 906b8ae9533252cd56ea8e89bc18894580c00644 Mon Sep 17 00:00:00 2001 From: Alex Finnarn Date: Tue, 20 Feb 2024 13:58:57 -0500 Subject: [PATCH 04/25] Apply suggestions from code review Co-authored-by: Tim Cosgrove --- READMES/cms-content-release.md | 2 +- .../custom/va_gov_content_release/src/Form/NextGitForm.php | 6 +++--- .../va_gov_content_release.routing.yml | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/READMES/cms-content-release.md b/READMES/cms-content-release.md index bb75ac8a33..6f6f237186 100644 --- a/READMES/cms-content-release.md +++ b/READMES/cms-content-release.md @@ -160,7 +160,7 @@ is a simpler process than the current content-build workflow. [caveats](#caveats) section for more information. 6. Back on "/admin/content/deploy/next" you can view the server restart log via a link in the "Status" section of the "Next Build Information" block. -7. Once the build completes no new build will be triggered until you click to release content again. +7. Once the restart completes no new restart will be triggered unless you request another restart. 8. View the frontend at the provided "View Preview" link in the "Next Build Information" block. #### Caveats diff --git a/docroot/modules/custom/va_gov_content_release/src/Form/NextGitForm.php b/docroot/modules/custom/va_gov_content_release/src/Form/NextGitForm.php index e20b3870b9..1d6258fc6e 100644 --- a/docroot/modules/custom/va_gov_content_release/src/Form/NextGitForm.php +++ b/docroot/modules/custom/va_gov_content_release/src/Form/NextGitForm.php @@ -90,7 +90,7 @@ public static function create(ContainerInterface $container) { public function buildForm(array $form, FormStateInterface $form_state) { $form['build_request']['description'] = [ '#prefix' => '

', - '#markup' => $this->t('Release content to update the front end of this environment with the latest published content changes.'), + '#markup' => $this->t('Choose specific branches for the next-build preview server and restart the server. Note: this does not perform any content-build actions.'), '#suffix' => '

', ]; @@ -134,7 +134,7 @@ public function buildForm(array $form, FormStateInterface $form_state) { $form['build_request']['vets_website_git_ref'] = [ '#type' => 'textfield', '#title' => $this->t('Select branch/pull request'), - '#description' => $this->t('Start typing to select a branch for the vets-website version you want to use.'), + '#description' => $this->t('Start typing to select a branch for the vets-website version you want to use. Note: this vets-website branch is not connected to the vets-website branch used by content-build on this Tugboat instance. If you are testing vets-website changes with both next-build and content-build, both will need the branch updated.'), '#autocomplete_route_name' => 'va_gov_content_release.frontend_version_autocomplete', '#autocomplete_route_parameters' => [ 'frontend' => 'vets_website', @@ -151,7 +151,7 @@ public function buildForm(array $form, FormStateInterface $form_state) { $form['build_request']['actions']['#type'] = 'actions'; $form['build_request']['actions']['submit'] = [ '#type' => 'submit', - '#value' => $this->t('Release Content'), + '#value' => $this->t('Restart Next Build Server'), '#button_type' => 'primary', ]; diff --git a/docroot/modules/custom/va_gov_content_release/va_gov_content_release.routing.yml b/docroot/modules/custom/va_gov_content_release/va_gov_content_release.routing.yml index a54e466807..244595280d 100644 --- a/docroot/modules/custom/va_gov_content_release/va_gov_content_release.routing.yml +++ b/docroot/modules/custom/va_gov_content_release/va_gov_content_release.routing.yml @@ -19,7 +19,7 @@ va_gov_content_release.form.git: va_gov_content_release.form.next_git: path: "/admin/content/deploy/next" defaults: - _title: 'Next Build manual content release' + _title: 'Choose code branch for Next Build server' _form: '\Drupal\va_gov_content_release\Form\NextGitForm' requirements: _permission: "va gov deploy content build" From 005f6fc1550f93a2172b3713003889b424d5a87b Mon Sep 17 00:00:00 2001 From: Alex Finnarn Date: Tue, 20 Feb 2024 16:40:16 -0500 Subject: [PATCH 05/25] add separate frontend for next-vets-website --- .gitignore | 2 ++ READMES/cms-content-release.md | 3 +- .../src/Form/NextGitForm.php | 26 ++++++----------- .../src/Frontend/Frontend.php | 16 +++++++---- .../FrontendVersionSearch.php | 28 +++++++++++++++++++ .../va_gov_content_release.services.yml | 2 ++ .../Factory/BranchSearchFactory.php | 8 ++++++ .../Factory/BranchSearchFactoryInterface.php | 8 ++++++ .../Repository/Factory/RepositoryFactory.php | 13 ++++++++- .../Factory/RepositoryFactoryInterface.php | 11 ++++++++ .../Settings/RepositorySettingsInterface.php | 5 ++++ .../custom/va_gov_git/va_gov_git.services.yml | 4 +++ .../Api/Client/Factory/ApiClientFactory.php | 9 ++++++ .../Factory/ApiClientFactoryInterface.php | 11 ++++++++ .../va_gov_github/va_gov_github.services.yml | 3 ++ docroot/sites/default/settings.php | 1 - .../sites/default/settings/settings.local.php | 2 ++ .../default/settings/settings.tugboat.php | 1 + scripts/next-build-frontend.sh | 4 +-- scripts/remove-git-dirs.sh | 1 + .../Settings/RepositorySettingsTest.php | 5 ++++ .../Settings/RepositorySettingsTest.php | 7 +++++ 22 files changed, 142 insertions(+), 28 deletions(-) diff --git a/.gitignore b/.gitignore index 89b52fc6b7..f71405af45 100644 --- a/.gitignore +++ b/.gitignore @@ -104,6 +104,8 @@ datadog-setup.php # Ignore Next (next-build) next +# Ignore vets-wesite that is used for next-build. +vets-website # Ignore oauth keys used for validating next-build preview api requests public.key private.key diff --git a/READMES/cms-content-release.md b/READMES/cms-content-release.md index 6f6f237186..449fd35c36 100644 --- a/READMES/cms-content-release.md +++ b/READMES/cms-content-release.md @@ -152,8 +152,7 @@ is a simpler process than the current content-build workflow. 2. If the form elements are disabled, then a lock file exists preventing another build from being triggered. You can skip to step #6. 2. Choose a version for next-build or leave at default. -3. Choose a version for vets-website or leave at default. When content-build is releasing, these form fields might - be disabled. We can't change the vets-website version while another frontend build is running. +3. Choose a version for vets-website or leave at default. 4. Click "Restart Next Build Server" to set the versions of next-build and vets-website as well as write a "buildrequest" file. 5. A `scripts/queue_runner/next_queue_runner.sh` script continuously runs in the background looking for the "buildrequest" file and then start a build if found. Locally, the script has to be triggered manually. See the diff --git a/docroot/modules/custom/va_gov_content_release/src/Form/NextGitForm.php b/docroot/modules/custom/va_gov_content_release/src/Form/NextGitForm.php index 1d6258fc6e..97f494099f 100644 --- a/docroot/modules/custom/va_gov_content_release/src/Form/NextGitForm.php +++ b/docroot/modules/custom/va_gov_content_release/src/Form/NextGitForm.php @@ -9,7 +9,6 @@ use Drupal\Core\Link; use Drupal\Core\State\State; use Drupal\Core\Url; -use Drupal\va_gov_build_trigger\Service\ReleaseStateManager; use Drupal\va_gov_content_release\Frontend\Frontend; use Drupal\va_gov_content_release\Frontend\FrontendInterface; use Drupal\va_gov_content_release\FrontendVersion\FrontendVersionInterface; @@ -121,7 +120,7 @@ public function buildForm(array $form, FormStateInterface $form_state) { ], ]; - $form['build_request']['vets_website_selection'] = [ + $form['build_request']['next_vets_website_selection'] = [ '#title' => $this->t('Which version of vets-website would you like to use?'), '#type' => 'radios', '#options' => [ @@ -131,20 +130,20 @@ public function buildForm(array $form, FormStateInterface $form_state) { '#default_value' => 'default', ]; - $form['build_request']['vets_website_git_ref'] = [ + $form['build_request']['next_vets_website_git_ref'] = [ '#type' => 'textfield', '#title' => $this->t('Select branch/pull request'), '#description' => $this->t('Start typing to select a branch for the vets-website version you want to use. Note: this vets-website branch is not connected to the vets-website branch used by content-build on this Tugboat instance. If you are testing vets-website changes with both next-build and content-build, both will need the branch updated.'), '#autocomplete_route_name' => 'va_gov_content_release.frontend_version_autocomplete', '#autocomplete_route_parameters' => [ - 'frontend' => 'vets_website', + 'frontend' => 'next_vets_website', 'count' => 10, ], '#size' => 72, '#maxlength' => 1024, '#hidden' => TRUE, '#states' => [ - 'visible' => [':input[name="vets_website_selection"]' => ['value' => 'choose']], + 'visible' => [':input[name="next_vets_website_selection"]' => ['value' => 'choose']], ], ]; @@ -155,19 +154,12 @@ public function buildForm(array $form, FormStateInterface $form_state) { '#button_type' => 'primary', ]; - // Lock the vets-website form fields if a content-build is in progress. - $build_status = $this->state->get('va_gov_build_trigger.release_state'); - if ($build_status !== ReleaseStateManager::STATE_READY) { - $form['build_request']['vets_website_selection']['#disabled'] = TRUE; - $form['build_request']['vets_website_git_ref']['#disabled'] = TRUE; - } - // Disable form changes and submission if a build is in progress. if (file_exists($this->fileSystem->realpath('public://' . self::LOCK_FILE_NAME))) { $form['build_request']['next_build_selection']['#disabled'] = TRUE; $form['build_request']['next_build_git_ref']['#disabled'] = TRUE; - $form['build_request']['vets_website_selection']['#disabled'] = TRUE; - $form['build_request']['vets_website_git_ref']['#disabled'] = TRUE; + $form['build_request']['next_vets_website_selection']['#disabled'] = TRUE; + $form['build_request']['next_vets_website_git_ref']['#disabled'] = TRUE; $form['build_request']['actions']['submit']['#disabled'] = TRUE; $target_url = Url::fromUserInput("/sites/default/files/next-build.txt"); @@ -181,7 +173,7 @@ public function buildForm(array $form, FormStateInterface $form_state) { $lock_file_text = $this->getFileLink(self::LOCK_FILE_NAME); $request_file_text = $this->getFileLink(self::REQUEST_FILE_NAME); $next_build_version = $this->frontendVersion->getVersion(Frontend::NextBuild); - $vets_website_version = $this->frontendVersion->getVersion(Frontend::VetsWebsite); + $vets_website_version = $this->frontendVersion->getVersion(Frontend::NextVetsWebsite); $view_preview = $this->getPreviewLink(); $last_build_time = $this->state->get('next_build.status.last_build_date', 'N/A'); $form['content_release_status_block'] = [ @@ -271,7 +263,7 @@ private function getPreviewLink(): Link { */ public function submitForm(array &$form, FormStateInterface $form_state) { $this->submitFormForFrontend(Frontend::NextBuild, $form_state); - $this->submitFormForFrontend(Frontend::VetsWebsite, $form_state); + $this->submitFormForFrontend(Frontend::NextVetsWebsite, $form_state); $lock_file = $this->fileSystem->realpath('public://' . self::LOCK_FILE_NAME); if (file_exists($lock_file)) { @@ -313,7 +305,7 @@ protected function submitFormForFrontend( */ public function validateForm(array &$form, FormStateInterface $form_state) { $this->validateFormForFrontend(Frontend::NextBuild, $form_state); - $this->validateFormForFrontend(Frontend::VetsWebsite, $form_state); + $this->validateFormForFrontend(Frontend::NextVetsWebsite, $form_state); } /** diff --git a/docroot/modules/custom/va_gov_content_release/src/Frontend/Frontend.php b/docroot/modules/custom/va_gov_content_release/src/Frontend/Frontend.php index ce935f8188..582f9a0004 100644 --- a/docroot/modules/custom/va_gov_content_release/src/Frontend/Frontend.php +++ b/docroot/modules/custom/va_gov_content_release/src/Frontend/Frontend.php @@ -1,10 +1,5 @@ TRUE, + default => FALSE, + }; + } + } diff --git a/docroot/modules/custom/va_gov_content_release/src/FrontendVersionSearch/FrontendVersionSearch.php b/docroot/modules/custom/va_gov_content_release/src/FrontendVersionSearch/FrontendVersionSearch.php index 1420453091..e966e6e854 100644 --- a/docroot/modules/custom/va_gov_content_release/src/FrontendVersionSearch/FrontendVersionSearch.php +++ b/docroot/modules/custom/va_gov_content_release/src/FrontendVersionSearch/FrontendVersionSearch.php @@ -64,6 +64,20 @@ class FrontendVersionSearch implements FrontendVersionSearchInterface { */ protected $nbApiClient; + /** + * The branch search service for `next-vets-website`. + * + * @var \Drupal\va_gov_git\BranchSearch\BranchSearchInterface + */ + protected $nvwBranchSearch; + + /** + * The API client for `next-vets-website`. + * + * @var \Drupal\va_gov_github\Api\Client\ApiClientInterface + */ + protected $nvwApiClient; + /** * Constructor. * @@ -81,6 +95,10 @@ class FrontendVersionSearch implements FrontendVersionSearchInterface { * The branch search service for `next-build`. * @param \Drupal\va_gov_github\Api\Client\ApiClientInterface $nbApiClient * The API client for `next-build`. + * @param \Drupal\va_gov_git\BranchSearch\BranchSearchInterface $nvwBranchSearch + * The branch search service for `next-vets-website`. + * @param \Drupal\va_gov_github\Api\Client\ApiClientInterface $nvwApiClient + * The API client for `next-vets-website`. */ public function __construct( BranchSearchInterface $cbBranchSearch, @@ -90,6 +108,8 @@ public function __construct( LoggerChannelFactoryInterface $loggerFactory, BranchSearchInterface $nbBranchSearch, ApiClientInterface $nbApiClient, + BranchSearchInterface $nvwBranchSearch, + ApiClientInterface $nvwApiClient, ) { $this->cbBranchSearch = $cbBranchSearch; $this->cbApiClient = $cbApiClient; @@ -98,6 +118,8 @@ public function __construct( $this->logger = $loggerFactory->get('va_gov_content_release'); $this->nbBranchSearch = $nbBranchSearch; $this->nbApiClient = $nbApiClient; + $this->nvwBranchSearch = $nvwBranchSearch; + $this->nvwApiClient = $nvwApiClient; } /** @@ -120,6 +142,9 @@ protected function getBranchSearch(FrontendInterface $frontend) : BranchSearchIn case $frontend->isNextBuild(): return $this->nbBranchSearch; + case $frontend->isNextVetsWebsite(): + return $this->nvwBranchSearch; + default: throw new \InvalidArgumentException('Invalid frontend: ' . $frontend->getRawValue()); } @@ -145,6 +170,9 @@ protected function getApiClient(FrontendInterface $frontend) : ApiClientInterfac case $frontend->isNextBuild(): return $this->nbApiClient; + case $frontend->isNextVetsWebsite(): + return $this->nvwApiClient; + default: throw new \InvalidArgumentException('Invalid frontend: ' . $frontend->getRawValue()); } diff --git a/docroot/modules/custom/va_gov_content_release/va_gov_content_release.services.yml b/docroot/modules/custom/va_gov_content_release/va_gov_content_release.services.yml index 7353b27462..56126b03ec 100644 --- a/docroot/modules/custom/va_gov_content_release/va_gov_content_release.services.yml +++ b/docroot/modules/custom/va_gov_content_release/va_gov_content_release.services.yml @@ -47,6 +47,8 @@ services: - '@logger.factory' - '@va_gov_git.branch_search.next_build' - '@va_gov_github.api_client.next_build' + - '@va_gov_git.branch_search.next_vets_website' + - '@va_gov_github.api_client.next_vets_website' va_gov_content_release.entity_event_subscriber: class: Drupal\va_gov_content_release\EventSubscriber\EntityEventSubscriber arguments: diff --git a/docroot/modules/custom/va_gov_git/src/BranchSearch/Factory/BranchSearchFactory.php b/docroot/modules/custom/va_gov_git/src/BranchSearch/Factory/BranchSearchFactory.php index f661673bb9..da105c8a96 100644 --- a/docroot/modules/custom/va_gov_git/src/BranchSearch/Factory/BranchSearchFactory.php +++ b/docroot/modules/custom/va_gov_git/src/BranchSearch/Factory/BranchSearchFactory.php @@ -95,4 +95,12 @@ public function getNextBuild(): BranchSearchInterface { $this->loggerFactory); } + /** + * {@inheritDoc} + */ + public function getNextVetsWebsite(): BranchSearchInterface { + return new BranchSearch($this->repositoryFactory->getNextVetsWebsite(), + $this->loggerFactory); + } + } diff --git a/docroot/modules/custom/va_gov_git/src/BranchSearch/Factory/BranchSearchFactoryInterface.php b/docroot/modules/custom/va_gov_git/src/BranchSearch/Factory/BranchSearchFactoryInterface.php index 616cc686ce..788c006954 100644 --- a/docroot/modules/custom/va_gov_git/src/BranchSearch/Factory/BranchSearchFactoryInterface.php +++ b/docroot/modules/custom/va_gov_git/src/BranchSearch/Factory/BranchSearchFactoryInterface.php @@ -63,4 +63,12 @@ public function getVetsWebsite(): BranchSearchInterface; */ public function getNextBuild(): BranchSearchInterface; + /** + * Get the next-vets-website branch search service. + * + * @return \Drupal\va_gov_git\BranchSearch\BranchSearchInterface + * The next-vets-website branch search object. + */ + public function getNextVetsWebsite(): BranchSearchInterface; + } diff --git a/docroot/modules/custom/va_gov_git/src/Repository/Factory/RepositoryFactory.php b/docroot/modules/custom/va_gov_git/src/Repository/Factory/RepositoryFactory.php index 4a1f8a93d4..53262c10f4 100644 --- a/docroot/modules/custom/va_gov_git/src/Repository/Factory/RepositoryFactory.php +++ b/docroot/modules/custom/va_gov_git/src/Repository/Factory/RepositoryFactory.php @@ -12,10 +12,14 @@ * This service provides a way to create services corresponding to specific Git * repositories. * - * At this time, we're primarily interested in three repositories: + * At this time, we're primarily interested in four repositories: * - The `va.gov-cms` repository. * - The `content-build` repository. * - The `vets-website` repository. + * - The `next-build` repository. + * + * Additionally, we have `next-vets-website` key which is a duplicate of + * `vets-website` repository used exclusively with the `next-build` repository. */ class RepositoryFactory implements RepositoryFactoryInterface { @@ -72,4 +76,11 @@ public function getNextBuild(): RepositoryInterface { return $this->get(RepositorySettingsInterface::NEXT_BUILD); } + /** + * {@inheritDoc} + */ + public function getNextVetsWebsite(): RepositoryInterface { + return $this->get(RepositorySettingsInterface::NEXT_VETS_WEBSITE); + } + } diff --git a/docroot/modules/custom/va_gov_git/src/Repository/Factory/RepositoryFactoryInterface.php b/docroot/modules/custom/va_gov_git/src/Repository/Factory/RepositoryFactoryInterface.php index 877b59e3ae..0dd646d18f 100644 --- a/docroot/modules/custom/va_gov_git/src/Repository/Factory/RepositoryFactoryInterface.php +++ b/docroot/modules/custom/va_gov_git/src/Repository/Factory/RepositoryFactoryInterface.php @@ -15,6 +15,9 @@ * - The `content-build` repository. * - The `vets-website` repository. * - The `next-build` repository. + * + * Additionally, we have `next-vets-website` key which is a duplicate of + * `vets-website` repository used exclusively with the `next-build` repository. */ interface RepositoryFactoryInterface { @@ -64,4 +67,12 @@ public function getVetsWebsite(): RepositoryInterface; */ public function getNextBuild(): RepositoryInterface; + /** + * Get the next-vets-website repository. + * + * @return \Drupal\va_gov_git\Repository\RepositoryInterface + * The next-vets-website repository. + */ + public function getNextVetsWebsite(): RepositoryInterface; + } diff --git a/docroot/modules/custom/va_gov_git/src/Repository/Settings/RepositorySettingsInterface.php b/docroot/modules/custom/va_gov_git/src/Repository/Settings/RepositorySettingsInterface.php index dfcfbbca84..5d9a7203ce 100644 --- a/docroot/modules/custom/va_gov_git/src/Repository/Settings/RepositorySettingsInterface.php +++ b/docroot/modules/custom/va_gov_git/src/Repository/Settings/RepositorySettingsInterface.php @@ -15,11 +15,14 @@ interface RepositorySettingsInterface { const CONTENT_BUILD = 'content-build'; const VETS_WEBSITE = 'vets-website'; const NEXT_BUILD = 'next-build'; + const NEXT_VETS_WEBSITE = 'next-vets-website'; + const REPOSITORY_NAMES = [ self::VA_GOV_CMS, self::CONTENT_BUILD, self::VETS_WEBSITE, self::NEXT_BUILD, + self::NEXT_VETS_WEBSITE, ]; // Settings keys for the repositories' filesystem paths. @@ -29,12 +32,14 @@ interface RepositorySettingsInterface { const CONTENT_BUILD_PATH_KEY = 'va_gov_web_root'; const VETS_WEBSITE_PATH_KEY = 'va_gov_vets_website_root'; const NEXT_BUILD_PATH_KEY = 'va_gov_next_build_root'; + const NEXT_VETS_WEBSITE_PATH_KEY = 'va_gov_next_vets_website_root'; const PATH_KEYS = [ self::VA_GOV_CMS => self::VA_GOV_CMS_PATH_KEY, self::CONTENT_BUILD => self::CONTENT_BUILD_PATH_KEY, self::VETS_WEBSITE => self::VETS_WEBSITE_PATH_KEY, self::NEXT_BUILD => self::NEXT_BUILD_PATH_KEY, + self::NEXT_VETS_WEBSITE => self::NEXT_VETS_WEBSITE_PATH_KEY, ]; /** diff --git a/docroot/modules/custom/va_gov_git/va_gov_git.services.yml b/docroot/modules/custom/va_gov_git/va_gov_git.services.yml index 3d02a62691..26436dd130 100644 --- a/docroot/modules/custom/va_gov_git/va_gov_git.services.yml +++ b/docroot/modules/custom/va_gov_git/va_gov_git.services.yml @@ -36,4 +36,8 @@ services: class: Drupal\va_gov_git\BranchSearch\BranchSearch factory: [ '@va_gov_git.branch_search_factory', 'getNextBuild' ] arguments: [] + va_gov_git.branch_search.next_vets_website: + class: Drupal\va_gov_git\BranchSearch\BranchSearch + factory: [ '@va_gov_git.branch_search_factory', 'getNextVetsWebsite' ] + diff --git a/docroot/modules/custom/va_gov_github/src/Api/Client/Factory/ApiClientFactory.php b/docroot/modules/custom/va_gov_github/src/Api/Client/Factory/ApiClientFactory.php index 5244d41b29..1565b44c48 100644 --- a/docroot/modules/custom/va_gov_github/src/Api/Client/Factory/ApiClientFactory.php +++ b/docroot/modules/custom/va_gov_github/src/Api/Client/Factory/ApiClientFactory.php @@ -19,6 +19,7 @@ class ApiClientFactory implements ApiClientFactoryInterface { const CONTENT_BUILD = 'content-build'; const VETS_WEBSITE = 'vets-website'; const NEXT_BUILD = 'next-build'; + const NEXT_VETS_WEBSITE = 'next-vets-website'; /** * The settings service. @@ -73,4 +74,12 @@ public function getNextBuild(): ApiClientInterface { $this->settings->getApiToken()); } + /** + * {@inheritDoc} + */ + public function getNextVetsWebsite(): ApiClientInterface { + return $this->get(static::OWNER, static::NEXT_VETS_WEBSITE, + $this->settings->getApiToken()); + } + } diff --git a/docroot/modules/custom/va_gov_github/src/Api/Client/Factory/ApiClientFactoryInterface.php b/docroot/modules/custom/va_gov_github/src/Api/Client/Factory/ApiClientFactoryInterface.php index e97d8c7ae0..c511028cd4 100644 --- a/docroot/modules/custom/va_gov_github/src/Api/Client/Factory/ApiClientFactoryInterface.php +++ b/docroot/modules/custom/va_gov_github/src/Api/Client/Factory/ApiClientFactoryInterface.php @@ -78,4 +78,15 @@ public function getVetsWebsite(): ApiClientInterface; */ public function getNextBuild(): ApiClientInterface; + /** + * Retrieve an API client for the Next Vets-Website repository. + * + * @return \Drupal\va_gov_github\Api\Client\ApiClientInterface + * The GitHub Api Client instance. + * + * @throws \Drupal\va_gov_github\Exception\InvalidApiTokenException + * If the GitHub API token is provided, but is invalid. + */ + public function getNextVetsWebsite(): ApiClientInterface; + } diff --git a/docroot/modules/custom/va_gov_github/va_gov_github.services.yml b/docroot/modules/custom/va_gov_github/va_gov_github.services.yml index f881f35ab4..7369d76f49 100644 --- a/docroot/modules/custom/va_gov_github/va_gov_github.services.yml +++ b/docroot/modules/custom/va_gov_github/va_gov_github.services.yml @@ -21,3 +21,6 @@ services: class: Drupal\va_gov_github\Api\Client\ApiClientInterface factory: [ '@va_gov_github.api_client_factory', 'getNextBuild' ] arguments: [] + va_gov_github.api_client.next_vets_website: + class: Drupal\va_gov_github\Api\Client\ApiClientInterface + factory: [ '@va_gov_github.api_client_factory', 'getNextVetsWebsite' ] diff --git a/docroot/sites/default/settings.php b/docroot/sites/default/settings.php index 99271a5dd2..b22fa5300e 100755 --- a/docroot/sites/default/settings.php +++ b/docroot/sites/default/settings.php @@ -126,7 +126,6 @@ $settings['va_gov_web_root'] = '/var/www/cms/web'; $settings['va_gov_app_root'] = '/var/www/cms'; $settings['va_gov_vets_website_root'] = '/var/www/cms/docroot/vendor/va-gov/vets-website'; -$settings['va_gov_next_build_root'] = '../next'; // Defaults (should only be local that doesn't set these), default to dev for config_split $config['config_split.config_split.dev']['status'] = TRUE; diff --git a/docroot/sites/default/settings/settings.local.php b/docroot/sites/default/settings/settings.local.php index 29610f0852..673465a748 100644 --- a/docroot/sites/default/settings/settings.local.php +++ b/docroot/sites/default/settings/settings.local.php @@ -47,6 +47,8 @@ $settings['va_gov_app_root'] = getenv('DDEV_APPROOT'); $settings['va_gov_web_root'] = getenv('DDEV_APPROOT') . '/web'; $settings['va_gov_vets_website_root'] = getenv('DDEV_APPROOT') . '/docroot/vendor/va-gov/vets-website'; +$settings['va_gov_next_build_root'] = getenv('DDEV_APPROOT') . '/next'; +$settings['va_gov_next_vets_website_root'] = getenv('DDEV_APPROOT') . '/vets-website'; $settings['memcache']['servers'] = [ 'memcached:11211' => 'default', diff --git a/docroot/sites/default/settings/settings.tugboat.php b/docroot/sites/default/settings/settings.tugboat.php index c6ab9b0c63..ee9d474743 100644 --- a/docroot/sites/default/settings/settings.tugboat.php +++ b/docroot/sites/default/settings/settings.tugboat.php @@ -65,6 +65,7 @@ $settings['va_gov_web_root'] = getenv('TUGBOAT_ROOT') . '/web'; $settings['va_gov_vets_website_root'] = getenv('TUGBOAT_ROOT') . '/docroot/vendor/va-gov/vets-website'; $settings['va_gov_next_build_root'] = getenv('TUGBOAT_ROOT') . '/next'; +$settings['va_gov_next_vets_website_root'] = getenv('TUGBOAT_ROOT') . '/vets-website'; $settings['memcache']['servers'] = [ 'memcache:11211' => 'default', diff --git a/scripts/next-build-frontend.sh b/scripts/next-build-frontend.sh index c6e32d1d4a..149bce6c1b 100644 --- a/scripts/next-build-frontend.sh +++ b/scripts/next-build-frontend.sh @@ -39,7 +39,7 @@ logfile="${filesdir}/next-build.txt" next_build_version=$(drush va-gov-content-release:frontend-version:get next_build | tail -1) # The currently selected version of vets-website (may be "__default", a PR#, or a git ref) -vets_website_version=$(drush va-gov-content-release:frontend-version:get vets_website | tail -1) +vets_website_version=$(drush va-gov-content-release:frontend-version:get next_vets_website | tail -1) # Create a fresh log file. [ -f "${logfile}" ] && rm ${logfile} @@ -83,7 +83,7 @@ composer va:next:install &>> ${logfile} # Get the requested vets-website version if [ "${vets_website_version}" != "__default" ]; then echo "==> Checking out the requested vets-website version" >> ${logfile} - pushd ${reporoot}/docroot/vendor/va-gov/vets-website + pushd ${reporoot}/vets-website if echo "$vets_website_version" | grep -qE '^[0-9]+$' > /dev/null; then echo "==> Checking out PR #${vets_website_version}" git fetch origin pull/${vets_website_version}/head &>> ${logfile} diff --git a/scripts/remove-git-dirs.sh b/scripts/remove-git-dirs.sh index 0458d9c94f..eeeccb99e1 100755 --- a/scripts/remove-git-dirs.sh +++ b/scripts/remove-git-dirs.sh @@ -15,6 +15,7 @@ find . \ -path './docroot/vendor/va-gov/content-build/.git' \ -or -path './docroot/vendor/va-gov/vets-website/.git' \ -or -path './next/.git' \ + -or -path './vets-website/.git' \ \) \ -print \ -exec rm -rf {} + diff --git a/tests/phpunit/va_gov_git/functional/Repository/Settings/RepositorySettingsTest.php b/tests/phpunit/va_gov_git/functional/Repository/Settings/RepositorySettingsTest.php index ba8fc95b2d..24c76adce2 100644 --- a/tests/phpunit/va_gov_git/functional/Repository/Settings/RepositorySettingsTest.php +++ b/tests/phpunit/va_gov_git/functional/Repository/Settings/RepositorySettingsTest.php @@ -48,6 +48,7 @@ public function testGetPathKey() { $this->assertEquals(RepositorySettingsInterface::PATH_KEYS['content-build'], $repositorySettings->getPathKey('content-build')); $this->assertEquals(RepositorySettingsInterface::PATH_KEYS['vets-website'], $repositorySettings->getPathKey('vets-website')); $this->assertEquals(RepositorySettingsInterface::PATH_KEYS['next-build'], $repositorySettings->getPathKey('next-build')); + $this->assertEquals(RepositorySettingsInterface::PATH_KEYS['next-vets-website'], $repositorySettings->getPathKey('next-vets-website')); } /** @@ -74,6 +75,10 @@ public function testList() { 'name' => RepositorySettingsInterface::NEXT_BUILD, 'path' => Settings::get('va_gov_next_build_root'), ], + [ + 'name' => RepositorySettingsInterface::NEXT_VETS_WEBSITE, + 'path' => Settings::get('va_gov_next_vets_website_root'), + ], ], $repositorySettings->list()); } diff --git a/tests/phpunit/va_gov_git/unit/Repository/Settings/RepositorySettingsTest.php b/tests/phpunit/va_gov_git/unit/Repository/Settings/RepositorySettingsTest.php index b0b3813dc8..39f2191e58 100644 --- a/tests/phpunit/va_gov_git/unit/Repository/Settings/RepositorySettingsTest.php +++ b/tests/phpunit/va_gov_git/unit/Repository/Settings/RepositorySettingsTest.php @@ -31,6 +31,7 @@ public function getRepositorySettings() { 'va_gov_web_root' => '/srv/web', 'va_gov_vets_website_root' => '/srv/vets-website', 'va_gov_next_build_root' => '/srv/next', + 'va_gov_next_vets_website_root' => '/srv/next-vets-website', ]); return new RepositorySettings($settings); } @@ -70,6 +71,7 @@ public function getPathKeyDataProvider() { ['content-build', RepositorySettings::CONTENT_BUILD_PATH_KEY], ['vets-website', RepositorySettings::VETS_WEBSITE_PATH_KEY], ['next-build', RepositorySettings::NEXT_BUILD_PATH_KEY], + ['next-vets-website', RepositorySettings::NEXT_VETS_WEBSITE_PATH_KEY], ]; } @@ -100,6 +102,7 @@ public function getPathDataProvider() { ['content-build', '/srv/web'], ['vets-website', '/srv/vets-website'], ['next-build', '/srv/next'], + ['next-vets-website', '/srv/next-vets-website'], ]; } @@ -153,6 +156,10 @@ public function testList() { 'name' => RepositorySettingsInterface::NEXT_BUILD, 'path' => '/srv/next', ], + [ + 'name' => RepositorySettingsInterface::NEXT_VETS_WEBSITE, + 'path' => '/srv/next-vets-website', + ], ], $repositorySettings->list()); } From 55e3c58d6f8beaee53b9afb079b13517c260ee70 Mon Sep 17 00:00:00 2001 From: Alex Finnarn Date: Tue, 20 Feb 2024 17:10:19 -0500 Subject: [PATCH 06/25] change key used for next-vets-website repo --- .../src/Repository/Settings/RepositorySettingsInterface.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docroot/modules/custom/va_gov_git/src/Repository/Settings/RepositorySettingsInterface.php b/docroot/modules/custom/va_gov_git/src/Repository/Settings/RepositorySettingsInterface.php index 5d9a7203ce..beb79861e6 100644 --- a/docroot/modules/custom/va_gov_git/src/Repository/Settings/RepositorySettingsInterface.php +++ b/docroot/modules/custom/va_gov_git/src/Repository/Settings/RepositorySettingsInterface.php @@ -15,7 +15,7 @@ interface RepositorySettingsInterface { const CONTENT_BUILD = 'content-build'; const VETS_WEBSITE = 'vets-website'; const NEXT_BUILD = 'next-build'; - const NEXT_VETS_WEBSITE = 'next-vets-website'; + const NEXT_VETS_WEBSITE = 'vets-website'; const REPOSITORY_NAMES = [ self::VA_GOV_CMS, @@ -39,7 +39,7 @@ interface RepositorySettingsInterface { self::CONTENT_BUILD => self::CONTENT_BUILD_PATH_KEY, self::VETS_WEBSITE => self::VETS_WEBSITE_PATH_KEY, self::NEXT_BUILD => self::NEXT_BUILD_PATH_KEY, - self::NEXT_VETS_WEBSITE => self::NEXT_VETS_WEBSITE_PATH_KEY, + 'next-vets-website' => self::NEXT_VETS_WEBSITE_PATH_KEY, ]; /** From f723624452090eca2ce1ac21a28be360bece3eb0 Mon Sep 17 00:00:00 2001 From: Alex Finnarn Date: Wed, 21 Feb 2024 10:08:03 -0500 Subject: [PATCH 07/25] try cloning vets-website a different way to have more git informaiton --- scripts/next-build-frontend.sh | 14 +------------- scripts/vets-web-setup.sh | 5 ++++- .../Repository/Settings/RepositorySettingsTest.php | 12 +++++++----- 3 files changed, 12 insertions(+), 19 deletions(-) diff --git a/scripts/next-build-frontend.sh b/scripts/next-build-frontend.sh index 149bce6c1b..188c7b6cd1 100644 --- a/scripts/next-build-frontend.sh +++ b/scripts/next-build-frontend.sh @@ -51,15 +51,9 @@ echo "next-build version: ${next_build_version}" >> ${logfile} echo "vets-website version: ${vets_website_version}" >> ${logfile} # Tell the frontend (and the user) that we're starting. -#drush va-gov:content-release:advance-state starting echo "==> Starting a frontend build. This file will be updated as the build progresses." >> ${logfile} -# Reset the repos to defaults. -#echo "==> Resetting VA repos to default versions" >> ${logfile} -#rm -rf ${reporoot}/docroot/vendor/va-gov -#composer install --no-scripts &>> ${logfile} - -# Get the requested next-build version +# Get the requested next-build version. if [ "${next_build_version}" != "__default" ]; then echo "==> Checking out the requested frontend version" >> ${logfile} pushd ${reporoot}/next @@ -99,14 +93,8 @@ fi # Run the build. echo "==> Starting build" >> ${logfile} -#drush va-gov:content-release:advance-state inprogress composer va:next:build &>> ${logfile} -# Advance the state in the frontend so another build can start. -echo "==> Build complete" >> ${logfile} -#drush va-gov:content-release:advance-state complete -#drush va-gov:content-release:advance-state ready - # After this point, we are less concerned with errors; the build has completed. set +e diff --git a/scripts/vets-web-setup.sh b/scripts/vets-web-setup.sh index 97234edab9..b2be1e6a31 100755 --- a/scripts/vets-web-setup.sh +++ b/scripts/vets-web-setup.sh @@ -8,7 +8,10 @@ source ~/.bashrc # Installs & builds vets-website dependencies for next-build preview. #if [ ! -d docroot/vendor/va-gov/vets-website ]; then if [ ! -d vets-website ]; then - git clone --single-branch --depth 1 https://github.com/department-of-veterans-affairs/vets-website.git vets-website + # Clone full so git information is available for content release form. + # I don't think this should be necessary, but branch information was not + # available in the content release form until I pulled down all information. + git clone https://github.com/department-of-veterans-affairs/vets-website.git vets-website else echo "Repo vets-website already cloned." fi diff --git a/tests/phpunit/va_gov_git/functional/Repository/Settings/RepositorySettingsTest.php b/tests/phpunit/va_gov_git/functional/Repository/Settings/RepositorySettingsTest.php index 24c76adce2..c01d4aab50 100644 --- a/tests/phpunit/va_gov_git/functional/Repository/Settings/RepositorySettingsTest.php +++ b/tests/phpunit/va_gov_git/functional/Repository/Settings/RepositorySettingsTest.php @@ -48,7 +48,9 @@ public function testGetPathKey() { $this->assertEquals(RepositorySettingsInterface::PATH_KEYS['content-build'], $repositorySettings->getPathKey('content-build')); $this->assertEquals(RepositorySettingsInterface::PATH_KEYS['vets-website'], $repositorySettings->getPathKey('vets-website')); $this->assertEquals(RepositorySettingsInterface::PATH_KEYS['next-build'], $repositorySettings->getPathKey('next-build')); - $this->assertEquals(RepositorySettingsInterface::PATH_KEYS['next-vets-website'], $repositorySettings->getPathKey('next-vets-website')); + // $this->assertEquals( + // RepositorySettingsInterface::PATH_KEYS['next-vets-website'], + // $repositorySettings->getPathKey('next-vets-website')); } /** @@ -75,10 +77,10 @@ public function testList() { 'name' => RepositorySettingsInterface::NEXT_BUILD, 'path' => Settings::get('va_gov_next_build_root'), ], - [ - 'name' => RepositorySettingsInterface::NEXT_VETS_WEBSITE, - 'path' => Settings::get('va_gov_next_vets_website_root'), - ], + // [ + // 'name' => RepositorySettingsInterface::NEXT_VETS_WEBSITE, + // 'path' => Settings::get('va_gov_next_vets_website_root'), + // ], ], $repositorySettings->list()); } From 49d14f69dd33c82d39894fc0be5ba80a04aff2f1 Mon Sep 17 00:00:00 2001 From: Alex Finnarn Date: Wed, 21 Feb 2024 10:18:10 -0500 Subject: [PATCH 08/25] adjust unit test --- .../Settings/RepositorySettingsInterface.php | 5 ++--- .../Repository/Settings/RepositorySettingsTest.php | 11 ++++------- 2 files changed, 6 insertions(+), 10 deletions(-) diff --git a/docroot/modules/custom/va_gov_git/src/Repository/Settings/RepositorySettingsInterface.php b/docroot/modules/custom/va_gov_git/src/Repository/Settings/RepositorySettingsInterface.php index beb79861e6..e926446459 100644 --- a/docroot/modules/custom/va_gov_git/src/Repository/Settings/RepositorySettingsInterface.php +++ b/docroot/modules/custom/va_gov_git/src/Repository/Settings/RepositorySettingsInterface.php @@ -15,14 +15,13 @@ interface RepositorySettingsInterface { const CONTENT_BUILD = 'content-build'; const VETS_WEBSITE = 'vets-website'; const NEXT_BUILD = 'next-build'; - const NEXT_VETS_WEBSITE = 'vets-website'; + const NEXT_VETS_WEBSITE = 'next-vets-website'; const REPOSITORY_NAMES = [ self::VA_GOV_CMS, self::CONTENT_BUILD, self::VETS_WEBSITE, self::NEXT_BUILD, - self::NEXT_VETS_WEBSITE, ]; // Settings keys for the repositories' filesystem paths. @@ -39,7 +38,7 @@ interface RepositorySettingsInterface { self::CONTENT_BUILD => self::CONTENT_BUILD_PATH_KEY, self::VETS_WEBSITE => self::VETS_WEBSITE_PATH_KEY, self::NEXT_BUILD => self::NEXT_BUILD_PATH_KEY, - 'next-vets-website' => self::NEXT_VETS_WEBSITE_PATH_KEY, + self::NEXT_VETS_WEBSITE => self::NEXT_VETS_WEBSITE_PATH_KEY, ]; /** diff --git a/tests/phpunit/va_gov_git/functional/Repository/Settings/RepositorySettingsTest.php b/tests/phpunit/va_gov_git/functional/Repository/Settings/RepositorySettingsTest.php index c01d4aab50..cb9c4d175d 100644 --- a/tests/phpunit/va_gov_git/functional/Repository/Settings/RepositorySettingsTest.php +++ b/tests/phpunit/va_gov_git/functional/Repository/Settings/RepositorySettingsTest.php @@ -48,9 +48,6 @@ public function testGetPathKey() { $this->assertEquals(RepositorySettingsInterface::PATH_KEYS['content-build'], $repositorySettings->getPathKey('content-build')); $this->assertEquals(RepositorySettingsInterface::PATH_KEYS['vets-website'], $repositorySettings->getPathKey('vets-website')); $this->assertEquals(RepositorySettingsInterface::PATH_KEYS['next-build'], $repositorySettings->getPathKey('next-build')); - // $this->assertEquals( - // RepositorySettingsInterface::PATH_KEYS['next-vets-website'], - // $repositorySettings->getPathKey('next-vets-website')); } /** @@ -77,10 +74,10 @@ public function testList() { 'name' => RepositorySettingsInterface::NEXT_BUILD, 'path' => Settings::get('va_gov_next_build_root'), ], - // [ - // 'name' => RepositorySettingsInterface::NEXT_VETS_WEBSITE, - // 'path' => Settings::get('va_gov_next_vets_website_root'), - // ], + [ + 'name' => RepositorySettingsInterface::NEXT_VETS_WEBSITE, + 'path' => Settings::get('va_gov_next_vets_website_root'), + ], ], $repositorySettings->list()); } From 5bc83b2c74a25adab989bf38a4451827cdfb6f3c Mon Sep 17 00:00:00 2001 From: Alex Finnarn Date: Wed, 21 Feb 2024 10:48:09 -0500 Subject: [PATCH 09/25] adjust code after adjusting unit test --- .../src/Repository/Settings/RepositorySettingsInterface.php | 1 + .../functional/Repository/Settings/RepositorySettingsTest.php | 1 + 2 files changed, 2 insertions(+) diff --git a/docroot/modules/custom/va_gov_git/src/Repository/Settings/RepositorySettingsInterface.php b/docroot/modules/custom/va_gov_git/src/Repository/Settings/RepositorySettingsInterface.php index e926446459..5d9a7203ce 100644 --- a/docroot/modules/custom/va_gov_git/src/Repository/Settings/RepositorySettingsInterface.php +++ b/docroot/modules/custom/va_gov_git/src/Repository/Settings/RepositorySettingsInterface.php @@ -22,6 +22,7 @@ interface RepositorySettingsInterface { self::CONTENT_BUILD, self::VETS_WEBSITE, self::NEXT_BUILD, + self::NEXT_VETS_WEBSITE, ]; // Settings keys for the repositories' filesystem paths. diff --git a/tests/phpunit/va_gov_git/functional/Repository/Settings/RepositorySettingsTest.php b/tests/phpunit/va_gov_git/functional/Repository/Settings/RepositorySettingsTest.php index cb9c4d175d..24c76adce2 100644 --- a/tests/phpunit/va_gov_git/functional/Repository/Settings/RepositorySettingsTest.php +++ b/tests/phpunit/va_gov_git/functional/Repository/Settings/RepositorySettingsTest.php @@ -48,6 +48,7 @@ public function testGetPathKey() { $this->assertEquals(RepositorySettingsInterface::PATH_KEYS['content-build'], $repositorySettings->getPathKey('content-build')); $this->assertEquals(RepositorySettingsInterface::PATH_KEYS['vets-website'], $repositorySettings->getPathKey('vets-website')); $this->assertEquals(RepositorySettingsInterface::PATH_KEYS['next-build'], $repositorySettings->getPathKey('next-build')); + $this->assertEquals(RepositorySettingsInterface::PATH_KEYS['next-vets-website'], $repositorySettings->getPathKey('next-vets-website')); } /** From daa4ac9756e61eff8dcbbec72ae82c65d08fad38 Mon Sep 17 00:00:00 2001 From: Alex Finnarn Date: Thu, 22 Feb 2024 15:30:12 -0500 Subject: [PATCH 10/25] add stash and pop to next build frontend script --- scripts/next-build-frontend.sh | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/scripts/next-build-frontend.sh b/scripts/next-build-frontend.sh index 188c7b6cd1..a94b95d7b0 100644 --- a/scripts/next-build-frontend.sh +++ b/scripts/next-build-frontend.sh @@ -57,6 +57,10 @@ echo "==> Starting a frontend build. This file will be updated as the build prog if [ "${next_build_version}" != "__default" ]; then echo "==> Checking out the requested frontend version" >> ${logfile} pushd ${reporoot}/next + + # Stash any local changes. + git stash &>> ${logfile} + if echo "${next_build_version}" | grep -qE '^[0-9]+$' > /dev/null; then echo "==> Checking out PR #${next_build_version}" git fetch origin pull/${next_build_version}/head &>> ${logfile} @@ -65,6 +69,10 @@ if [ "${next_build_version}" != "__default" ]; then git fetch origin ${next_build_version} &>> ${logfile} fi git checkout FETCH_HEAD &>> ${logfile} + + # Pop the stash if we stashed anything. + git stash pop &>> ${logfile} + popd else echo "==> Using default next-build version" >> ${logfile} From c4d1356f0e1b78b7e94fdb4b0a04c13b15fe0e0e Mon Sep 17 00:00:00 2001 From: Alex Finnarn Date: Thu, 29 Feb 2024 13:04:18 -0500 Subject: [PATCH 11/25] update links on next content release form --- .../src/Form/NextGitForm.php | 29 ++++++++----------- 1 file changed, 12 insertions(+), 17 deletions(-) diff --git a/docroot/modules/custom/va_gov_content_release/src/Form/NextGitForm.php b/docroot/modules/custom/va_gov_content_release/src/Form/NextGitForm.php index 97f494099f..f8f996d9cd 100644 --- a/docroot/modules/custom/va_gov_content_release/src/Form/NextGitForm.php +++ b/docroot/modules/custom/va_gov_content_release/src/Form/NextGitForm.php @@ -161,21 +161,12 @@ public function buildForm(array $form, FormStateInterface $form_state) { $form['build_request']['next_vets_website_selection']['#disabled'] = TRUE; $form['build_request']['next_vets_website_git_ref']['#disabled'] = TRUE; $form['build_request']['actions']['submit']['#disabled'] = TRUE; - - $target_url = Url::fromUserInput("/sites/default/files/next-build.txt"); - $build_log_text = Link::fromTextAndUrl('Build is in progress. View log file', $target_url); + $build_log_text = 'Build is in progress. View log file below'; } else { $build_log_text = 'Build is not in progress.'; } - // Set variables needed for build status information. - $lock_file_text = $this->getFileLink(self::LOCK_FILE_NAME); - $request_file_text = $this->getFileLink(self::REQUEST_FILE_NAME); - $next_build_version = $this->frontendVersion->getVersion(Frontend::NextBuild); - $vets_website_version = $this->frontendVersion->getVersion(Frontend::NextVetsWebsite); - $view_preview = $this->getPreviewLink(); - $last_build_time = $this->state->get('next_build.status.last_build_date', 'N/A'); $form['content_release_status_block'] = [ '#theme' => 'status_report_grouped', '#grouped_requirements' => [ @@ -187,29 +178,33 @@ public function buildForm(array $form, FormStateInterface $form_state) { 'title' => $this->t('Status'), 'value' => $build_log_text, ], + 'log_file' => [ + 'title' => $this->t('Log File'), + 'value' => $this->getFileLink('next-build.txt'), + ], 'lock_file' => [ 'title' => $this->t('Lock File'), - 'value' => $lock_file_text, + 'value' => $this->getFileLink(self::LOCK_FILE_NAME), ], 'request_file' => [ 'title' => $this->t('Request File'), - 'value' => $request_file_text, + 'value' => $this->getFileLink(self::REQUEST_FILE_NAME), ], 'next_build_version' => [ 'title' => $this->t('Next-build Version'), - 'value' => $next_build_version, + 'value' => $this->frontendVersion->getVersion(Frontend::NextBuild), ], 'vets_website_version' => [ 'title' => $this->t('Vets-website Version'), - 'value' => $vets_website_version, + 'value' => $this->frontendVersion->getVersion(Frontend::NextVetsWebsite), ], 'view_preview' => [ 'title' => $this->t('View Preview'), - 'value' => $view_preview, + 'value' => $this->getPreviewLink(), ], 'last_build_time' => [ 'title' => $this->t('Last Build Time'), - 'value' => $last_build_time, + 'value' => $this->state->get('next_build.status.last_build_date', 'N/A'), ], ], ], @@ -231,7 +226,7 @@ public function buildForm(array $form, FormStateInterface $form_state) { private function getFileLink(string $file_name): Link|string { $file_path = $this->fileSystem->realpath("public://$file_name"); if (file_exists($file_path)) { - $target_url = Url::fromUserInput("/sites/default/files/$file_name"); + $target_url = Url::fromUserInput("/sites/default/files/$file_name", ['attributes' => ['target' => '_blank']]); return Link::fromTextAndUrl($file_name, $target_url); } else { From e429472e15efa0c4772e32ee656670a9e25e32cc Mon Sep 17 00:00:00 2001 From: Alex Finnarn Date: Mon, 4 Mar 2024 14:53:57 -0500 Subject: [PATCH 12/25] 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 From 7b401d82769fb93fb6cf88efe15c24d1f21e3a10 Mon Sep 17 00:00:00 2001 From: Alex Finnarn Date: Wed, 6 Mar 2024 12:46:46 -0500 Subject: [PATCH 13/25] update scripts --- .tugboat/config.yml | 14 -------------- scripts/next-build-frontend.sh | 15 +++++++-------- scripts/next-install.sh | 2 ++ scripts/next-start.sh | 13 +++++++++++++ 4 files changed, 22 insertions(+), 22 deletions(-) diff --git a/.tugboat/config.yml b/.tugboat/config.yml index 1f5a83dfa2..b5caf1add9 100644 --- a/.tugboat/config.yml +++ b/.tugboat/config.yml @@ -37,7 +37,6 @@ 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 @@ -74,7 +73,6 @@ 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. @@ -143,7 +141,6 @@ 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. @@ -166,7 +163,6 @@ 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' @@ -196,7 +192,6 @@ 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" @@ -258,15 +253,6 @@ 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 {} \+ - # 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 - - echo "DRUPAL_CLIENT_SECRET=${DRUPAL_CLIENT_SECRET}" >> ${TUGBOAT_ROOT}/next/envs/.env.tugboat - # Build storybook and the frontends (web, next) in parallel - bash -lc 'time task --taskfile=tugboat.yml' diff --git a/scripts/next-build-frontend.sh b/scripts/next-build-frontend.sh index 106a53a1d1..fd3d37e9f6 100644 --- a/scripts/next-build-frontend.sh +++ b/scripts/next-build-frontend.sh @@ -58,8 +58,10 @@ if [ "${next_build_version}" != "__default" ]; then echo "==> Checking out the requested frontend version" >> ${logfile} pushd ${reporoot}/next - # Stash any local changes. - git stash &>> ${logfile} + # Reset the working directory to the last commit. + # This is necessary because we set some env vars in "next-start.sh" for Tugboat + # which prevents the checkout from working if the working directory is dirty. + git reset --hard &>> ${logfile} if echo "${next_build_version}" | grep -qE '^[0-9]+$' > /dev/null; then echo "==> Checking out PR #${next_build_version}" @@ -70,16 +72,11 @@ if [ "${next_build_version}" != "__default" ]; then fi git checkout FETCH_HEAD &>> ${logfile} - # Pop the stash if we stashed anything. - git stash pop &>> ${logfile} - popd 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} @@ -102,7 +99,9 @@ else fi # Build vets-website again. -${reporoot}/scripts/vets-web-setup.sh +# @todo Do the symlinks need to be re-created? +echo "==> Re-building Vets Website" >> ${logfile} +${reporoot}/scripts/vets-web-setup.sh &>> ${logfile} # Run the build. echo "==> Starting build" >> ${logfile} diff --git a/scripts/next-install.sh b/scripts/next-install.sh index d75e3dd451..e2edfd0146 100755 --- a/scripts/next-install.sh +++ b/scripts/next-install.sh @@ -38,4 +38,6 @@ echo "Node $(node -v)" echo "NPM $(npm -v)" echo "Yarn $(yarn -v)" +# @todo Should the manual steps go here like copying the .env file? or maybe in next-start.sh? + yarn install diff --git a/scripts/next-start.sh b/scripts/next-start.sh index 99e451d759..595ef7389c 100755 --- a/scripts/next-start.sh +++ b/scripts/next-start.sh @@ -22,8 +22,21 @@ NEXT_SERVER_PIDS=$(ps aux | grep '[.]/scripts/yarn/start.js' | awk '{print $2}') # In case we have multiple processes, loop through them. for pid in ${NEXT_SERVER_PIDS}; do + echo "Killing process ${pid}..." kill $pid done +# Set environment variables if on Tugboat. +if [ "${APP_ENV}" == "tugboat" ]; then + echo "Setting up Tugboat environment variables for Next.js..." + + # 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 / + echo "NEXT_PUBLIC_DRUPAL_BASE_URL=https://cms-${TUGBOAT_SERVICE_TOKEN}.${TUGBOAT_SERVICE_CONFIG_DOMAIN}" >> ${ROOT}/next/envs/.env.tugboat + echo "NEXT_IMAGE_DOMAIN=https://cms-${TUGBOAT_SERVICE_TOKEN}.${TUGBOAT_SERVICE_CONFIG_DOMAIN}" >> ${ROOT}/next/envs/.env.tugboat + echo "DRUPAL_CLIENT_ID=${DRUPAL_CLIENT_ID}" >> ${ROOT}/next/envs/.env.tugboat + echo "DRUPAL_CLIENT_SECRET=${DRUPAL_CLIENT_SECRET}" >> ${ROOT}/next/envs/.env.tugboat +fi + # Start the dev server. Vets-website assets need to be in place prior to this build. yarn start From 9e4e8103c5d81a8dd6a75749e30183f73911a64d Mon Sep 17 00:00:00 2001 From: Alex Finnarn Date: Thu, 7 Mar 2024 16:01:11 -0500 Subject: [PATCH 14/25] update scripts --- scripts/next-build-frontend.sh | 28 +++++++++++++--------------- scripts/next-start.sh | 5 ++++- 2 files changed, 17 insertions(+), 16 deletions(-) diff --git a/scripts/next-build-frontend.sh b/scripts/next-build-frontend.sh index fd3d37e9f6..3b0167b189 100644 --- a/scripts/next-build-frontend.sh +++ b/scripts/next-build-frontend.sh @@ -3,24 +3,18 @@ # Exit if a command fails with a non-zero status code. set -ex -# Find repo root -> $reporoot -reporoot="unknown" -if [ ! -z "$IS_DDEV_PROJECT" ]; then - reporoot="/var/www/html" -fi -if [ ! -z "$TUGBOAT_ROOT" ]; then - reporoot="$TUGBOAT_ROOT" -fi -if [ "$reporoot" == "unknown" ]; then +# Find repo root -> $ROOT +ROOT=${TUGBOAT_ROOT:-${DDEV_APPROOT:-unknown}} +if [ "$ROOT" == "unknown" ]; then echo "[!] Could not determine the environment type. Aborting!" exit 1 fi # For convenience. -cd $reporoot +cd $ROOT # Store path to site default files directory. -filesdir="${reporoot}/docroot/sites/default/files" +filesdir="${ROOT}/docroot/sites/default/files" # We really only want one build running at a time on any given environment. if [ -f "${filesdir}/next-buildlock.txt" ]; then @@ -56,7 +50,7 @@ echo "==> Starting a frontend build. This file will be updated as the build prog # Get the requested next-build version. if [ "${next_build_version}" != "__default" ]; then echo "==> Checking out the requested frontend version" >> ${logfile} - pushd ${reporoot}/next + pushd ${ROOT}/next # Reset the working directory to the last commit. # This is necessary because we set some env vars in "next-start.sh" for Tugboat @@ -84,7 +78,7 @@ composer va:next:install &>> ${logfile} # Get the requested vets-website version if [ "${vets_website_version}" != "__default" ]; then echo "==> Checking out the requested vets-website version" >> ${logfile} - pushd ${reporoot}/vets-website + pushd ${ROOT}/vets-website if echo "$vets_website_version" | grep -qE '^[0-9]+$' > /dev/null; then echo "==> Checking out PR #${vets_website_version}" git fetch origin pull/${vets_website_version}/head &>> ${logfile} @@ -98,10 +92,14 @@ else echo "==> Using default vets-website version" >> ${logfile} fi +# Create symlink between vets-website assets and next-build. +mkdir -p "${ROOT}/next/public" +ln -snf "${ROOT}/vets-website/build/localhost/generated" "${ROOT}/next/public/generated" + # Build vets-website again. # @todo Do the symlinks need to be re-created? echo "==> Re-building Vets Website" >> ${logfile} -${reporoot}/scripts/vets-web-setup.sh &>> ${logfile} +${ROOT}/scripts/vets-web-setup.sh &>> ${logfile} # Run the build. echo "==> Starting build" >> ${logfile} @@ -115,7 +113,7 @@ composer va:next:start &>> ${logfile} set +e # Switch to the docroot to run drush commands. -cd "${reporoot}/docroot" +cd "${ROOT}/docroot" # Log the timestamp of the build for reporting purposes. drush state:set next_build.status.last_build_date "$(date)" diff --git a/scripts/next-start.sh b/scripts/next-start.sh index 595ef7389c..6e9c3f6203 100755 --- a/scripts/next-start.sh +++ b/scripts/next-start.sh @@ -39,4 +39,7 @@ if [ "${APP_ENV}" == "tugboat" ]; then fi # Start the dev server. Vets-website assets need to be in place prior to this build. -yarn start +# Need to start in the background so the script can exit. +yarn start &> /dev/null & +PID=$! +echo "Started next server with PID: $PID" From 9a3dabcba60525f5f07ccc01ef4672c769cf34e7 Mon Sep 17 00:00:00 2001 From: Alex Finnarn Date: Fri, 8 Mar 2024 11:20:48 -0500 Subject: [PATCH 15/25] move around where tugboat env vars are set --- .tugboat/config.yml | 8 ++++++++ scripts/next-build.sh | 12 ++++++++++++ scripts/next-start.sh | 12 ------------ 3 files changed, 20 insertions(+), 12 deletions(-) diff --git a/.tugboat/config.yml b/.tugboat/config.yml index b5caf1add9..0316d8ea61 100644 --- a/.tugboat/config.yml +++ b/.tugboat/config.yml @@ -253,6 +253,14 @@ 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 {} \+ + # 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 / + - echo "Setting up Tugboat environment variables for Next.js..." + - echo "NEXT_PUBLIC_DRUPAL_BASE_URL=https://cms-${TUGBOAT_SERVICE_TOKEN}.${TUGBOAT_SERVICE_CONFIG_DOMAIN}" >> ${ROOT}/next/envs/.env.tugboat + - echo "NEXT_IMAGE_DOMAIN=https://cms-${TUGBOAT_SERVICE_TOKEN}.${TUGBOAT_SERVICE_CONFIG_DOMAIN}" >> ${ROOT}/next/envs/.env.tugboat + - echo "DRUPAL_CLIENT_ID=${DRUPAL_CLIENT_ID}" >> ${ROOT}/next/envs/.env.tugboat + - echo "DRUPAL_CLIENT_SECRET=${DRUPAL_CLIENT_SECRET}" >> ${ROOT}/next/envs/.env.tugboat + # Build storybook and the frontends (web, next) in parallel - bash -lc 'time task --taskfile=tugboat.yml' diff --git a/scripts/next-build.sh b/scripts/next-build.sh index 549ef741e6..e26c84d736 100755 --- a/scripts/next-build.sh +++ b/scripts/next-build.sh @@ -17,4 +17,16 @@ source ~/.bashrc cd "${ROOT}/next" +# Set environment variables if on Tugboat. +if [ "${APP_ENV}" == "tugboat" ]; then + echo "Setting up Tugboat environment variables for Next.js..." + + # 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 / + echo "NEXT_PUBLIC_DRUPAL_BASE_URL=https://cms-${TUGBOAT_SERVICE_TOKEN}.${TUGBOAT_SERVICE_CONFIG_DOMAIN}" >> ${ROOT}/next/envs/.env.tugboat + echo "NEXT_IMAGE_DOMAIN=https://cms-${TUGBOAT_SERVICE_TOKEN}.${TUGBOAT_SERVICE_CONFIG_DOMAIN}" >> ${ROOT}/next/envs/.env.tugboat + echo "DRUPAL_CLIENT_ID=${DRUPAL_CLIENT_ID}" >> ${ROOT}/next/envs/.env.tugboat + echo "DRUPAL_CLIENT_SECRET=${DRUPAL_CLIENT_SECRET}" >> ${ROOT}/next/envs/.env.tugboat +fi + yarn build:preview diff --git a/scripts/next-start.sh b/scripts/next-start.sh index 6e9c3f6203..535c156e42 100755 --- a/scripts/next-start.sh +++ b/scripts/next-start.sh @@ -26,18 +26,6 @@ for pid in ${NEXT_SERVER_PIDS}; do kill $pid done -# Set environment variables if on Tugboat. -if [ "${APP_ENV}" == "tugboat" ]; then - echo "Setting up Tugboat environment variables for Next.js..." - - # 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 / - echo "NEXT_PUBLIC_DRUPAL_BASE_URL=https://cms-${TUGBOAT_SERVICE_TOKEN}.${TUGBOAT_SERVICE_CONFIG_DOMAIN}" >> ${ROOT}/next/envs/.env.tugboat - echo "NEXT_IMAGE_DOMAIN=https://cms-${TUGBOAT_SERVICE_TOKEN}.${TUGBOAT_SERVICE_CONFIG_DOMAIN}" >> ${ROOT}/next/envs/.env.tugboat - echo "DRUPAL_CLIENT_ID=${DRUPAL_CLIENT_ID}" >> ${ROOT}/next/envs/.env.tugboat - echo "DRUPAL_CLIENT_SECRET=${DRUPAL_CLIENT_SECRET}" >> ${ROOT}/next/envs/.env.tugboat -fi - # Start the dev server. Vets-website assets need to be in place prior to this build. # Need to start in the background so the script can exit. yarn start &> /dev/null & From b0b28084d57739f9829804a1176278957e63831e Mon Sep 17 00:00:00 2001 From: Alex Finnarn Date: Fri, 8 Mar 2024 15:53:02 -0500 Subject: [PATCH 16/25] misspelled the damn root variable; see if can debug faster without two steps --- .tugboat/config.yml | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/.tugboat/config.yml b/.tugboat/config.yml index 0316d8ea61..5c073e63c2 100644 --- a/.tugboat/config.yml +++ b/.tugboat/config.yml @@ -169,9 +169,9 @@ services: - bash -lc 'composer va:theme:compile' - bash -lc 'composer va:web:install' - - curl --remote-name https://dsva-vagov-prod-cms-backup-sanitized.s3-us-gov-west-1.amazonaws.com/files/cms-prod-files-latest.tgz - - tar --extract --gunzip --file cms-prod-files-latest.tgz --directory "${DOCROOT}/sites/default/files/" - - rm cms-prod-files-latest.tgz +# - curl --remote-name https://dsva-vagov-prod-cms-backup-sanitized.s3-us-gov-west-1.amazonaws.com/files/cms-prod-files-latest.tgz +# - tar --extract --gunzip --file cms-prod-files-latest.tgz --directory "${DOCROOT}/sites/default/files/" +# - rm cms-prod-files-latest.tgz # Set file permissions such that Drupal will not complain - chgrp -R www-data "${DOCROOT}/sites/default/files" @@ -244,7 +244,7 @@ services: online: # We only want tests running on PRs, not branches like the base preview build of main. - - if [ "$TUGBOAT_PREVIEW_TYPE" = "pullrequest" ]; then bash -lc 'time task --taskfile=tests.yml'; fi +# - if [ "$TUGBOAT_PREVIEW_TYPE" = "pullrequest" ]; then bash -lc 'time task --taskfile=tests.yml'; fi # Set file permissions so web based build calls work. This must run after all web builds are done in tests. - chown -R www-data:www-data "${DOCROOT}/vendor/va-gov/content-build" @@ -256,10 +256,10 @@ 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 / - echo "Setting up Tugboat environment variables for Next.js..." - - echo "NEXT_PUBLIC_DRUPAL_BASE_URL=https://cms-${TUGBOAT_SERVICE_TOKEN}.${TUGBOAT_SERVICE_CONFIG_DOMAIN}" >> ${ROOT}/next/envs/.env.tugboat - - echo "NEXT_IMAGE_DOMAIN=https://cms-${TUGBOAT_SERVICE_TOKEN}.${TUGBOAT_SERVICE_CONFIG_DOMAIN}" >> ${ROOT}/next/envs/.env.tugboat - - echo "DRUPAL_CLIENT_ID=${DRUPAL_CLIENT_ID}" >> ${ROOT}/next/envs/.env.tugboat - - echo "DRUPAL_CLIENT_SECRET=${DRUPAL_CLIENT_SECRET}" >> ${ROOT}/next/envs/.env.tugboat + - 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 + - echo "DRUPAL_CLIENT_SECRET=${DRUPAL_CLIENT_SECRET}" >> ${TUGBOAT_ROOT}/next/envs/.env.tugboat # Build storybook and the frontends (web, next) in parallel - bash -lc 'time task --taskfile=tugboat.yml' From c96a05434319c620db9361e59090619dce46dc21 Mon Sep 17 00:00:00 2001 From: Alex Finnarn Date: Fri, 8 Mar 2024 16:46:00 -0500 Subject: [PATCH 17/25] more debugging --- .tugboat/config.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.tugboat/config.yml b/.tugboat/config.yml index 5c073e63c2..ed2ee15038 100644 --- a/.tugboat/config.yml +++ b/.tugboat/config.yml @@ -174,9 +174,9 @@ services: # - rm cms-prod-files-latest.tgz # Set file permissions such that Drupal will not complain - - chgrp -R www-data "${DOCROOT}/sites/default/files" - - find "${DOCROOT}/sites/default/files" -type d -print0 | xargs -0 chmod 2775 - - find "${DOCROOT}/sites/default/files" -type f -print0 | xargs -0 chmod 0664 +# - chgrp -R www-data "${DOCROOT}/sites/default/files" +# - find "${DOCROOT}/sites/default/files" -type d -print0 | xargs -0 chmod 2775 +# - find "${DOCROOT}/sites/default/files" -type f -print0 | xargs -0 chmod 0664 # Commands that build the site. This is where you would add things # like feature reverts or any other drush commands required to From 4e032ac4e2bdf8c13c232aa812f1d06a49d67989 Mon Sep 17 00:00:00 2001 From: Alex Finnarn Date: Mon, 11 Mar 2024 11:03:16 -0400 Subject: [PATCH 18/25] make sure that the app env var is picked up --- scripts/next-build.sh | 2 +- scripts/next-start.sh | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/scripts/next-build.sh b/scripts/next-build.sh index e26c84d736..9cbbf974a9 100755 --- a/scripts/next-build.sh +++ b/scripts/next-build.sh @@ -29,4 +29,4 @@ if [ "${APP_ENV}" == "tugboat" ]; then echo "DRUPAL_CLIENT_SECRET=${DRUPAL_CLIENT_SECRET}" >> ${ROOT}/next/envs/.env.tugboat fi -yarn build:preview +APP_ENV=${APP_ENV} yarn build:preview diff --git a/scripts/next-start.sh b/scripts/next-start.sh index 535c156e42..005b9fab01 100755 --- a/scripts/next-start.sh +++ b/scripts/next-start.sh @@ -28,6 +28,6 @@ done # Start the dev server. Vets-website assets need to be in place prior to this build. # Need to start in the background so the script can exit. -yarn start &> /dev/null & +APP_ENV=${APP_ENV} yarn start &> /dev/null & PID=$! echo "Started next server with PID: $PID" From 733a03422c6d64ea89dd5c99922d1a3fb522e95d Mon Sep 17 00:00:00 2001 From: Alex Finnarn Date: Mon, 11 Mar 2024 13:37:17 -0400 Subject: [PATCH 19/25] take out the debugging now that I know the server starts --- .tugboat/config.yml | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/.tugboat/config.yml b/.tugboat/config.yml index ed2ee15038..54851c063a 100644 --- a/.tugboat/config.yml +++ b/.tugboat/config.yml @@ -169,14 +169,14 @@ services: - bash -lc 'composer va:theme:compile' - bash -lc 'composer va:web:install' -# - curl --remote-name https://dsva-vagov-prod-cms-backup-sanitized.s3-us-gov-west-1.amazonaws.com/files/cms-prod-files-latest.tgz -# - tar --extract --gunzip --file cms-prod-files-latest.tgz --directory "${DOCROOT}/sites/default/files/" -# - rm cms-prod-files-latest.tgz + - curl --remote-name https://dsva-vagov-prod-cms-backup-sanitized.s3-us-gov-west-1.amazonaws.com/files/cms-prod-files-latest.tgz + - tar --extract --gunzip --file cms-prod-files-latest.tgz --directory "${DOCROOT}/sites/default/files/" + - rm cms-prod-files-latest.tgz # Set file permissions such that Drupal will not complain -# - chgrp -R www-data "${DOCROOT}/sites/default/files" -# - find "${DOCROOT}/sites/default/files" -type d -print0 | xargs -0 chmod 2775 -# - find "${DOCROOT}/sites/default/files" -type f -print0 | xargs -0 chmod 0664 + - chgrp -R www-data "${DOCROOT}/sites/default/files" + - find "${DOCROOT}/sites/default/files" -type d -print0 | xargs -0 chmod 2775 + - find "${DOCROOT}/sites/default/files" -type f -print0 | xargs -0 chmod 0664 # Commands that build the site. This is where you would add things # like feature reverts or any other drush commands required to @@ -244,7 +244,7 @@ services: online: # We only want tests running on PRs, not branches like the base preview build of main. -# - if [ "$TUGBOAT_PREVIEW_TYPE" = "pullrequest" ]; then bash -lc 'time task --taskfile=tests.yml'; fi + - if [ "$TUGBOAT_PREVIEW_TYPE" = "pullrequest" ]; then bash -lc 'time task --taskfile=tests.yml'; fi # Set file permissions so web based build calls work. This must run after all web builds are done in tests. - chown -R www-data:www-data "${DOCROOT}/vendor/va-gov/content-build" From 225390f2ed02e436d84cf9d650058766321eee51 Mon Sep 17 00:00:00 2001 From: Alex Finnarn Date: Tue, 12 Mar 2024 09:03:05 -0400 Subject: [PATCH 20/25] try killing more process types --- scripts/next-start.sh | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/scripts/next-start.sh b/scripts/next-start.sh index 005b9fab01..73fb873ac3 100755 --- a/scripts/next-start.sh +++ b/scripts/next-start.sh @@ -17,10 +17,7 @@ source ~/.bashrc 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}') - -# In case we have multiple processes, loop through them. +NEXT_SERVER_PIDS=$(ps aux | grep -E '(\.\/scripts\/yarn\/start\.js|next start|next-router-worker)' | awk '{print $2}') for pid in ${NEXT_SERVER_PIDS}; do echo "Killing process ${pid}..." kill $pid @@ -28,6 +25,7 @@ done # Start the dev server. Vets-website assets need to be in place prior to this build. # Need to start in the background so the script can exit. +# @todo Will this work as a general script with this line? APP_ENV=${APP_ENV} yarn start &> /dev/null & PID=$! echo "Started next server with PID: $PID" From 8488432a0e142b873cada80adb5dfb351fd1817e Mon Sep 17 00:00:00 2001 From: Alex Finnarn Date: Tue, 12 Mar 2024 10:58:36 -0400 Subject: [PATCH 21/25] remove Tugboat steps to make build faster --- .tugboat/config.yml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.tugboat/config.yml b/.tugboat/config.yml index 54851c063a..5c073e63c2 100644 --- a/.tugboat/config.yml +++ b/.tugboat/config.yml @@ -169,9 +169,9 @@ services: - bash -lc 'composer va:theme:compile' - bash -lc 'composer va:web:install' - - curl --remote-name https://dsva-vagov-prod-cms-backup-sanitized.s3-us-gov-west-1.amazonaws.com/files/cms-prod-files-latest.tgz - - tar --extract --gunzip --file cms-prod-files-latest.tgz --directory "${DOCROOT}/sites/default/files/" - - rm cms-prod-files-latest.tgz +# - curl --remote-name https://dsva-vagov-prod-cms-backup-sanitized.s3-us-gov-west-1.amazonaws.com/files/cms-prod-files-latest.tgz +# - tar --extract --gunzip --file cms-prod-files-latest.tgz --directory "${DOCROOT}/sites/default/files/" +# - rm cms-prod-files-latest.tgz # Set file permissions such that Drupal will not complain - chgrp -R www-data "${DOCROOT}/sites/default/files" @@ -244,7 +244,7 @@ services: online: # We only want tests running on PRs, not branches like the base preview build of main. - - if [ "$TUGBOAT_PREVIEW_TYPE" = "pullrequest" ]; then bash -lc 'time task --taskfile=tests.yml'; fi +# - if [ "$TUGBOAT_PREVIEW_TYPE" = "pullrequest" ]; then bash -lc 'time task --taskfile=tests.yml'; fi # Set file permissions so web based build calls work. This must run after all web builds are done in tests. - chown -R www-data:www-data "${DOCROOT}/vendor/va-gov/content-build" From 60b8e70f5bdaec490d4de1c6b4070da25347d7a9 Mon Sep 17 00:00:00 2001 From: Alex Finnarn Date: Tue, 12 Mar 2024 11:43:20 -0400 Subject: [PATCH 22/25] debug --- .tugboat/config.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.tugboat/config.yml b/.tugboat/config.yml index 5c073e63c2..09012a172f 100644 --- a/.tugboat/config.yml +++ b/.tugboat/config.yml @@ -169,9 +169,9 @@ services: - bash -lc 'composer va:theme:compile' - bash -lc 'composer va:web:install' -# - curl --remote-name https://dsva-vagov-prod-cms-backup-sanitized.s3-us-gov-west-1.amazonaws.com/files/cms-prod-files-latest.tgz -# - tar --extract --gunzip --file cms-prod-files-latest.tgz --directory "${DOCROOT}/sites/default/files/" -# - rm cms-prod-files-latest.tgz + - curl --remote-name https://dsva-vagov-prod-cms-backup-sanitized.s3-us-gov-west-1.amazonaws.com/files/cms-prod-files-latest.tgz + - tar --extract --gunzip --file cms-prod-files-latest.tgz --directory "${DOCROOT}/sites/default/files/" + - rm cms-prod-files-latest.tgz # Set file permissions such that Drupal will not complain - chgrp -R www-data "${DOCROOT}/sites/default/files" From 241b7ab66eb3d6927a89a58927b850b9281c7fa3 Mon Sep 17 00:00:00 2001 From: Alex Finnarn Date: Wed, 13 Mar 2024 09:06:42 -0400 Subject: [PATCH 23/25] add env vars script and set to execute script files --- .tugboat/config.yml | 11 +++-------- scripts/next-build-frontend.sh | 0 scripts/next-set-tugboat-env-vars.sh | 9 +++++++++ scripts/queue_runner/next_queue_runner.sh | 0 4 files changed, 12 insertions(+), 8 deletions(-) mode change 100644 => 100755 scripts/next-build-frontend.sh create mode 100755 scripts/next-set-tugboat-env-vars.sh mode change 100644 => 100755 scripts/queue_runner/next_queue_runner.sh diff --git a/.tugboat/config.yml b/.tugboat/config.yml index 09012a172f..aafa977986 100644 --- a/.tugboat/config.yml +++ b/.tugboat/config.yml @@ -244,7 +244,7 @@ services: online: # We only want tests running on PRs, not branches like the base preview build of main. -# - if [ "$TUGBOAT_PREVIEW_TYPE" = "pullrequest" ]; then bash -lc 'time task --taskfile=tests.yml'; fi + - if [ "$TUGBOAT_PREVIEW_TYPE" = "pullrequest" ]; then bash -lc 'time task --taskfile=tests.yml'; fi # Set file permissions so web based build calls work. This must run after all web builds are done in tests. - chown -R www-data:www-data "${DOCROOT}/vendor/va-gov/content-build" @@ -253,13 +253,8 @@ 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 {} \+ - # 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 / - - echo "Setting up Tugboat environment variables for Next.js..." - - 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 - - echo "DRUPAL_CLIENT_SECRET=${DRUPAL_CLIENT_SECRET}" >> ${TUGBOAT_ROOT}/next/envs/.env.tugboat + # Put necessary env variables in place for next's Drupal Preview before building server + - ${TUGBOAT_ROOT}/scripts/next-set-tugboat-env-vars.sh # Build storybook and the frontends (web, next) in parallel - bash -lc 'time task --taskfile=tugboat.yml' diff --git a/scripts/next-build-frontend.sh b/scripts/next-build-frontend.sh old mode 100644 new mode 100755 diff --git a/scripts/next-set-tugboat-env-vars.sh b/scripts/next-set-tugboat-env-vars.sh new file mode 100755 index 0000000000..624eb93219 --- /dev/null +++ b/scripts/next-set-tugboat-env-vars.sh @@ -0,0 +1,9 @@ +#!/usr/bin/env bash + +# 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 / +echo "Setting up Tugboat environment variables for Next.js..." +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 +echo "DRUPAL_CLIENT_SECRET=${DRUPAL_CLIENT_SECRET}" >> ${TUGBOAT_ROOT}/next/envs/.env.tugboat diff --git a/scripts/queue_runner/next_queue_runner.sh b/scripts/queue_runner/next_queue_runner.sh old mode 100644 new mode 100755 From 1bd3741ffd4dc84f6ce2866ed6d5c34339ec7830 Mon Sep 17 00:00:00 2001 From: Alex Finnarn Date: Wed, 13 Mar 2024 09:12:46 -0400 Subject: [PATCH 24/25] DRY env vars --- scripts/next-build-frontend.sh | 17 +++++++++++++++-- scripts/next-build.sh | 13 ------------- scripts/next-start.sh | 1 - 3 files changed, 15 insertions(+), 16 deletions(-) diff --git a/scripts/next-build-frontend.sh b/scripts/next-build-frontend.sh index 3b0167b189..e4ba9cb709 100755 --- a/scripts/next-build-frontend.sh +++ b/scripts/next-build-frontend.sh @@ -3,6 +3,14 @@ # Exit if a command fails with a non-zero status code. set -ex +if [ -n "${IS_DDEV_PROJECT}" ]; then + APP_ENV="local" +elif [ -n "${TUGBOAT_ROOT}" ]; then + APP_ENV="tugboat" +else + APP_ENV="tugboat" +fi + # Find repo root -> $ROOT ROOT=${TUGBOAT_ROOT:-${DDEV_APPROOT:-unknown}} if [ "$ROOT" == "unknown" ]; then @@ -53,8 +61,8 @@ if [ "${next_build_version}" != "__default" ]; then pushd ${ROOT}/next # Reset the working directory to the last commit. - # This is necessary because we set some env vars in "next-start.sh" for Tugboat - # which prevents the checkout from working if the working directory is dirty. + # This is necessary because we set some env vars for Tugboat which prevents + # the checkout from working if the working directory is dirty. git reset --hard &>> ${logfile} if echo "${next_build_version}" | grep -qE '^[0-9]+$' > /dev/null; then @@ -66,6 +74,11 @@ if [ "${next_build_version}" != "__default" ]; then fi git checkout FETCH_HEAD &>> ${logfile} + if [ "${APP_ENV}" == "tugboat" ]; then + echo "Setting up Tugboat environment variables for Next.js..." + ${ROOT}/scripts/next-set-tugboat-env-vars.sh + fi + popd else echo "==> Using default next-build version" >> ${logfile} diff --git a/scripts/next-build.sh b/scripts/next-build.sh index 9cbbf974a9..fe9477ceed 100755 --- a/scripts/next-build.sh +++ b/scripts/next-build.sh @@ -16,17 +16,4 @@ export NVM_DIR="$HOME/.nvm" source ~/.bashrc cd "${ROOT}/next" - -# Set environment variables if on Tugboat. -if [ "${APP_ENV}" == "tugboat" ]; then - echo "Setting up Tugboat environment variables for Next.js..." - - # 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 / - echo "NEXT_PUBLIC_DRUPAL_BASE_URL=https://cms-${TUGBOAT_SERVICE_TOKEN}.${TUGBOAT_SERVICE_CONFIG_DOMAIN}" >> ${ROOT}/next/envs/.env.tugboat - echo "NEXT_IMAGE_DOMAIN=https://cms-${TUGBOAT_SERVICE_TOKEN}.${TUGBOAT_SERVICE_CONFIG_DOMAIN}" >> ${ROOT}/next/envs/.env.tugboat - echo "DRUPAL_CLIENT_ID=${DRUPAL_CLIENT_ID}" >> ${ROOT}/next/envs/.env.tugboat - echo "DRUPAL_CLIENT_SECRET=${DRUPAL_CLIENT_SECRET}" >> ${ROOT}/next/envs/.env.tugboat -fi - APP_ENV=${APP_ENV} yarn build:preview diff --git a/scripts/next-start.sh b/scripts/next-start.sh index 73fb873ac3..e5ba3c9aca 100755 --- a/scripts/next-start.sh +++ b/scripts/next-start.sh @@ -25,7 +25,6 @@ done # Start the dev server. Vets-website assets need to be in place prior to this build. # Need to start in the background so the script can exit. -# @todo Will this work as a general script with this line? APP_ENV=${APP_ENV} yarn start &> /dev/null & PID=$! echo "Started next server with PID: $PID" From acc1805cf1f8ed98d3098e633e2d5e6d09b81428 Mon Sep 17 00:00:00 2001 From: Tim Cosgrove Date: Wed, 18 Sep 2024 15:21:20 -0700 Subject: [PATCH 25/25] Update Next Build on Tugboat to use proper node version for all scripts. --- scripts/next-build.sh | 4 ++++ scripts/next-start.sh | 3 +++ 2 files changed, 7 insertions(+) diff --git a/scripts/next-build.sh b/scripts/next-build.sh index fe9477ceed..c7061c424a 100755 --- a/scripts/next-build.sh +++ b/scripts/next-build.sh @@ -16,4 +16,8 @@ export NVM_DIR="$HOME/.nvm" source ~/.bashrc cd "${ROOT}/next" + +nvm install 18.17.0 +nvm use 18.17.0 + APP_ENV=${APP_ENV} yarn build:preview diff --git a/scripts/next-start.sh b/scripts/next-start.sh index e5ba3c9aca..33d742f881 100755 --- a/scripts/next-start.sh +++ b/scripts/next-start.sh @@ -16,6 +16,9 @@ source ~/.bashrc cd ${ROOT}/next +nvm install 18.17.0 +nvm use 18.17.0 + # Kill any current running server. NEXT_SERVER_PIDS=$(ps aux | grep -E '(\.\/scripts\/yarn\/start\.js|next start|next-router-worker)' | awk '{print $2}') for pid in ${NEXT_SERVER_PIDS}; do