Skip to content

Commit

Permalink
[FIX] deploy script (#823)
Browse files Browse the repository at this point in the history
* modify staging

* update workflow script

* check previous commit

* check for changes differently

* remove unshallow

* handle passing variable outside of ssh

* remove dashes

* use correct container for checking database

* call container
  • Loading branch information
jdkent authored Sep 19, 2024
1 parent 9883e7b commit ac12969
Showing 1 changed file with 44 additions and 22 deletions.
66 changes: 44 additions & 22 deletions .github/workflows/deploy-to-staging.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,59 +19,81 @@ jobs:
with:
ssh-private-key: ${{ secrets.SSH_PRIVATE_KEY }}

- name: Add remote SSH server to known hosts
run: |
ssh-keyscan -H deepdream.psy.utexas.edu >> ~/.ssh/known_hosts
- name: Force sync staging branch to remote server
run: |
ssh jdkent@deepdream.psy.utexas.edu 'cd /var/www/neurostore && git fetch origin && git reset --hard origin/staging && git clean -fd'
ssh git@deepdream.psy.utexas.edu '
cd /var/www/neurostore &&
git fetch origin && # Fetch full history
git fetch --all && # Fetch all branches and their histories
git reset --hard origin/staging &&
git clean -fd
'
- name: Detect changes in specific directories
- name: Detect changes in specific directories from the previous commit
id: changes
run: |
git fetch origin staging
changes_in_store=$(git diff --name-only origin/staging HEAD | grep '^store/' || echo "")
changes_in_compose=$(git diff --name-only origin/staging HEAD | grep '^compose/' || echo "")
changes_in_frontend=$(git diff --name-only origin/staging HEAD | grep '^compose/neurosynth-frontend/' || echo "")
# Capture the output of the SSH session and process it locally
ssh_output=$(ssh git@deepdream.psy.utexas.edu '
cd /var/www/neurostore &&
git fetch origin &&
git log -n 2 &&
changes_in_store=$(git diff --name-only HEAD~1 -- | grep "^store/" || echo "") &&
changes_in_compose=$(git diff --name-only HEAD~1 -- | grep "^compose/" || echo "") &&
changes_in_frontend=$(git diff --name-only HEAD~1 -- | grep "^compose/neurosynth-frontend/" || echo "") &&
# Print results for local parsing
echo "store:$changes_in_store" &&
echo "compose:$changes_in_compose" &&
echo "frontend:$changes_in_frontend"
')
echo "::set-output name=store::$changes_in_store"
echo "::set-output name=compose::$changes_in_compose"
echo "::set-output name=frontend::$changes_in_frontend"
# Parse the results locally and set outputs
echo "$ssh_output" | while IFS=':' read -r key value; do
if [ -n "$value" ]; then
echo "$key=$value" >> $GITHUB_OUTPUT
fi
done
- name: Run Docker commands in store directory if changes detected
if: ${{ steps.changes.outputs.store }}
run: |
ssh jdkent@deepdream.psy.utexas.edu '
ssh git@deepdream.psy.utexas.edu '
cd /var/www/neurostore/store &&
docker compose down &&
docker compose build &&
docker compose up -d
# Wait for PostgreSQL to be ready
until docker-compose exec store pg_isready; do sleep 5; done
until docker compose exec store_pgsql pg_isready; do sleep 5; done
docker-compose exec store flask db migrate
docker-compose exec store flask db upgrade
docker compose exec store flask db migrate
docker compose exec store flask db upgrade
'
- name: Run Docker commands in compose directory if changes detected
if: ${{ steps.changes.outputs.compose && !steps.changes.outputs.frontend }}
if: ${{ steps.changes.outputs.compose }}
run: |
ssh jdkent@deepdream.psy.utexas.edu '
ssh git@deepdream.psy.utexas.edu '
cd /var/www/neurostore/compose &&
docker compose down &&
docker compose build &&
docker compose up -d
# Wait for PostgreSQL to be ready
until docker-compose exec compose pg_isready; do sleep 5; done
until docker compose exec compose_pgsql pg_isready; do sleep 5; done
docker-compose exec compose flask db migrate
docker-compose exec compose flask db upgrade
docker compose exec compose flask db migrate
docker compose exec compose flask db upgrade
'
- name: Skip Docker commands and run frontend build if only frontend changes detected
if: ${{ steps.changes.outputs.frontend }}
run: |
ssh jdkent@deepdream.psy.utexas.edu '
cd /var/www/neurostore/compose/neurosynth-frontend &&
npm install &&
npm run build:staging
ssh git@deepdream.psy.utexas.edu '
cd /var/www/neurostore/compose &&
docker compose exec -T compose bash -c "cd /compose/neurosynth-frontend/ && npm install && npm run build:staging"
'

0 comments on commit ac12969

Please sign in to comment.