Skip to content

Commit

Permalink
simpler build trigger within form submission
Browse files Browse the repository at this point in the history
  • Loading branch information
alexfinnarn committed Feb 6, 2024
1 parent 868f7d8 commit 80d968c
Show file tree
Hide file tree
Showing 4 changed files with 85 additions and 23 deletions.
5 changes: 5 additions & 0 deletions .tugboat/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,11 @@ 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

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"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public static function create(ContainerInterface $container) {
return new static(
$container->get('va_gov_content_release.request'),
$container->get('va_gov_content_release.reporter'),
$container->get('va_gov_build_trigger.next_release_state_manager'),
$container->get('va_gov_build_trigger.release_state_manager'),
$container->get('va_gov_content_release.frontend_version'),
$container->get('plugin.manager.block')
);
Expand Down Expand Up @@ -98,7 +98,7 @@ public function buildForm(array $form, FormStateInterface $form_state) {
$form['build_request']['title'] = [
'#type' => 'item',
'#prefix' => '<h2>',
'#markup' => $this->t('Request a content release'),
'#markup' => $this->t('Request a next-build content release'),
'#suffix' => '</h2>',
];

Expand Down Expand Up @@ -156,7 +156,51 @@ public function buildForm(array $form, FormStateInterface $form_state) {
],
];

$form['content_release_status_block'] = $this->getContentReleaseStatusBlock();
// Add container for the next build link form field.
$form['next_build_link'] = [
'#type' => 'container',
'#attributes' => [
'style' => 'background-color: #f2f2f2; padding: 20px; border: 1px solid #ccc;',
],
];

// Add title for the next build link container.
$form['next_build_link']['title'] = [
'#type' => 'item',
'#prefix' => '<strong>',
'#markup' => $this->t('Next Build Status:'),
'#suffix' => '</strong>',
];

// Check for the existence of the .next-build.txt.
$file = 'public://.next-buildlock';
$file_path = \Drupal::service('file_system')->realpath($file);
if (file_exists($file_path)) {
$form['build_request']['next_build_selection']['#disabled'] = TRUE;
$form['build_request']['next_build_git_ref']['#disabled'] = TRUE;

// Also disable the vets-website selection and git ref fields.
$form['build_request']['vets_website_selection']['#disabled'] = TRUE;
$form['build_request']['vets_website_git_ref']['#disabled'] = TRUE;

// Add a link to the .next-build.txt file.
$form['next_build_link']['link'] = [
'#markup' => $this->t(
'Build is in progress and the running log file can be viewed at: <a href=":file_path">:file_path</a>.',
[
':file_path' => '/sites/default/files/next-build.txt',
]),
];

// Display the content release submit button.
$form['build_request']['actions']['submit']['#disabled'] = TRUE;
}
else {
// Add message that the build is not in progress.
$form['next_build_link']['link'] = [
'#markup' => $this->t('Build is not in progress.'),
];
}

return $form;
}
Expand Down Expand Up @@ -184,7 +228,21 @@ protected function getContentReleaseStatusBlock() {
public function submitForm(array &$form, FormStateInterface $form_state) {
$this->submitFormForFrontend(Frontend::NextBuild, $form_state);
$this->submitFormForFrontend(Frontend::VetsWebsite, $form_state);
parent::submitForm($form, $form_state);

// Check if "public://.next-buildlock" file exists.
$file = 'public://.next-buildlock';
$file_path = \Drupal::service('file_system')->realpath($file);
if (file_exists($file_path)) {
// Set message to inform user that the build is in progress.
$this->messenger()
->addMessage($this->t('The build is in progress. Please wait for the build to complete.'));
}
else {
// Write the file to trigger the build.
$file = 'public://.next-buildrequest';
file_put_contents($file, 'build me Seymour!');
$this->messenger()->addMessage($this->t('Build lock file set.'));
}
}

/**
Expand Down
32 changes: 13 additions & 19 deletions scripts/next-build-frontend.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,25 +19,21 @@ fi
# For convenience.
cd $reporoot

# Make sure that we're ready to start a build.
releasestate=$(drush va-gov:content-release:get-state | grep -c 'dispatched')
if [ "$releasestate" -ne 1 ]; then
echo "[!] Build hasn't been requested by the site. Aborting!"
exit 1
fi
# 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 "${reporoot}/.next-buildlock" ]; then
if [ -f "${filesdir}/.next-buildlock" ]; then
echo "[!] There is already a build in progress. Aborting!"
exit 1
fi
touch ${reporoot}/.next-buildlock
touch ${filesdir}/.next-buildlock

# Make sure we clean up the build lock file if an error occurs or the build is killed.
trap "rm -f ${reporoot}/.next-buildlock" INT TERM EXIT
trap "rm -f ${filesdir}/.next-buildlock && rm -f ${filesdir}/.next-buildrequest" INT TERM EXIT

# Just because the path is really long:
logfile="${reporoot}/docroot/sites/default/files/next-build.txt"
logfile="${filesdir}/next-build.txt"

# The currently selected version of content-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)
Expand All @@ -54,16 +50,14 @@ date >> ${logfile}
echo "next-build version: ${next_build_version}" >> ${logfile}
echo "vets-website version: ${vets_website_version}" >> ${logfile}

exit 1

# Tell the frontend (and the user) that we're starting.
drush va-gov:content-release:advance-state 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}
#echo "==> Resetting VA repos to default versions" >> ${logfile}
#rm -rf ${reporoot}/docroot/vendor/va-gov
#composer install --no-scripts &>> ${logfile}

# Get the requested content-build version
if [ "${next_build_version}" != "__default" ]; then
Expand Down Expand Up @@ -105,13 +99,13 @@ fi

# Run the build.
echo "==> Starting build" >> ${logfile}
drush va-gov:content-release:advance-state inprogress
#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
#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
Expand Down
5 changes: 5 additions & 0 deletions scripts/queue_runner/next_queue_runner.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/bin/bash -l

cd "${TUGBOAT_ROOT}"
[ -f "./docroot/sites/default/files/.next-buildrequest" ] && ./scripts/next-build-frontend.sh
sleep 10s

0 comments on commit 80d968c

Please sign in to comment.