Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat (470): Script commands for development operations #1549

Merged
merged 28 commits into from
Feb 1, 2022
Merged
Changes from 11 commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
a4c0c5a
Initial work done on command script
riatzukiza Jan 5, 2022
011ea0c
Added a few commands, not working
riatzukiza Jan 6, 2022
9fd24ea
added commands and shell header
msohanifr Jan 6, 2022
80aff15
resolve conflict with comments
riatzukiza Jan 6, 2022
99b1174
documented some functions, added several more
riatzukiza Jan 6, 2022
4975b7b
name space migration functions
riatzukiza Jan 7, 2022
882c81e
tweaked a few commands and added namespaces
riatzukiza Jan 14, 2022
aa2c966
add owasp commands
riatzukiza Jan 14, 2022
939d73f
Update commands.sh
riatzukiza Jan 19, 2022
5598602
Added an example
riatzukiza Jan 20, 2022
1580801
shortened some definitions to aliases and added a new shortcut function
riatzukiza Jan 20, 2022
d3e5624
corrected backend hard restart command
msohanifr Jan 20, 2022
4122b8e
corrected tdrs-backend-compose
msohanifr Jan 21, 2022
8a526c6
Merge branch 'build/854-npm-migration' into feat/470-commands
riatzukiza Jan 21, 2022
3ea13e6
succeed loudly for lint
riatzukiza Jan 21, 2022
6adf85c
use npm
riatzukiza Jan 21, 2022
7a2ab85
remove misleading comment
riatzukiza Jan 21, 2022
6803086
Added white space
riatzukiza Jan 21, 2022
3d6f0ef
Converted a few functions to aliases and add/update comments
riatzukiza Jan 21, 2022
b6ae5b2
comment tdrs function listing command
riatzukiza Jan 21, 2022
43d0644
confirmed owasp commands work
riatzukiza Jan 21, 2022
6e9a549
corrected lint
msohanifr Jan 21, 2022
7334010
Changed tdrs-start: to start backend first
msohanifr Jan 22, 2022
c3ee613
Changed tdrs-restart: to start backend first
msohanifr Jan 22, 2022
405bcff
Merge branch 'raft-tdp-main' into feat/470-commands
jorgegonzalez Jan 24, 2022
3af5d46
Merge branch 'raft-tdp-main' into feat/470-commands
jorgegonzalez Jan 24, 2022
3dd53bb
resolve conflicts
Jan 31, 2022
43fb840
Merge branch 'raft-tdp-main' into feat/470-commands
raftmsohani Jan 31, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
159 changes: 159 additions & 0 deletions commands.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,159 @@
#!/usr/bin/sh
# You will need to set this variable to match your local directory structure
# TDRS_HOME="$HOME/Where/Ever/You/Want/TANF-app"

# navigate terminal to tdrs home if $TDRS_HOME is set
alias cd-tdrs='cd "$TDRS_HOME"'

# navigate terminal to tdrs frontend if $TDRS_HOME is set
alias cd-tdrs-frontend='cd "$TDRS_HOME/tdrs-frontend"'

# navigate terminal to tdrs backend if $TDRS_HOME is set
alias cd-tdrs-backend='cd "$TDRS_HOME/tdrs-backend"'

# shortcut for applying all relavent compose files for local development
# I.E. `cd-tdrs-frontend && tdrs-compose-local up`
alias tdrs-compose-local='docker-compose -f docker-compose.yml -f docker-compose.local.yml'
riatzukiza marked this conversation as resolved.
Show resolved Hide resolved

# Stop tdrs backend entirely, then start it up again
alias tdrs-backend-hard-restart='tdrs-start-backend && tdrs-start-backend'
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the first command in here supposed to be tdrs-stop-backend?


# shortcut for running bash commands in backend container
alias tdrs-backend-exec='tdrs-backend-compose exec web /bin/bash'
riatzukiza marked this conversation as resolved.
Show resolved Hide resolved

# Open shell_plus for django backend inside of container
alias tdrs-django-shell='tdrs-backend-compose run --rm web bash -c "python manage.py shell_plus"'
riatzukiza marked this conversation as resolved.
Show resolved Hide resolved

# TDRS Frontend aliases

# start both the frontend and backend
alias tdrs-start='tdrs-start-frontend && tdrs-start-backend'

# Stop both the frontend and the backend
alias tdrs-stop='tdrs-stop-frontend && tdrs-stop-backend'

# Restart frontend and backend
alias tdrs-restart='tdrs-restart-frontend && tdrs-restart-backend'

andrew-jameson marked this conversation as resolved.
Show resolved Hide resolved
# start all backend containers
alias tdrs-start-backend='tdrs-compose-backend up -d'

# run npm install updating all dependencies and start the dev server
alias tdrs-start-frontend='tdrs-compose-frontend up -d'

# Stop all containers for the backend
alias tdrs-stop-backend='tdrs-compose-backend down'
# stop the frontend development server
alias tdrs-stop-frontend='tdrs-compose-frontend down'

# restart the frontends, mainly to rebuild dependencies
alias tdrs-restart-frontend='tdrs-compose-frontend restart'

# restart all containers for the backend
alias tdrs-restart-backend='tdrs-compose-backend restart'

# to restart just django, keeping the other containers intact.
alias restart-django='tdrs-compose-django restart web'
riatzukiza marked this conversation as resolved.
Show resolved Hide resolved

# run flake8 against backend source from inside of web container
alias tdrs-lint-backend='tdrs-compose-backend run --rm web bash -c "flake8 ."'

# short cut for running compose sub commands on backend
tdrs-compose-backend() {
cd-tdrs
cd tdrs-backend && tdrs-compose-local $@
cd ..
}

# short cut for running compose sub commands on backend
tdrs-compose-frontend() {
cd-tdrs
cd tdrs-frontend && tdrs-compose-local $@
cd ..
}


# Stop the backend if its running and rebuild the docker container for django
tdrs-rebuild-backend() {
cd-tdrs
tdrs-stop-backend
cd tdrs-backend && tdrs-compose-local up --build -d web
cd ..
}

# Run eslint against frontend source from frontend container
tdrs-lint-frontend() {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What do I need installed locally?

$ tdrs-lint-frontend
Creating network "tdrs-frontend_local" with driver "bridge"
node:internal/modules/cjs/loader:936
  throw err;
  ^

Error: Cannot find module '/home/node/app/bash'
    at Function.Module._resolveFilename (node:internal/modules/cjs/loader:933:15)
    at Function.Module._load (node:internal/modules/cjs/loader:778:27)
    at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:81:12)
    at node:internal/main/run_main_module:17:47 {
  code: 'MODULE_NOT_FOUND',
  requireStack: []
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was running the linter inside of the container when we usually weren't doing that.

cd-tdrs
yarn lint
cd ..
}

# Fix all automaticly fixable linting errors for the frontend
tdrs-fix-lint-frontend() {
cd-tdrs
eslint --fix ./src
cd ..
}

tdrs-npm-run() {
cd-tdrs
cd tdrs-frontend/ && npm run $1
cd ..
}

tdrs-run-jest() {
tdrs-yarn test
}


tdrs-run-jest-cov() {
tdrs-yarn test:cov
}

tdrs-run-pa11y() {
cd tdrs-frontend; mkdir pa11y-screenshots/; yarn test:accessibility
}

# tdrs-run-owasp() {}
riatzukiza marked this conversation as resolved.
Show resolved Hide resolved

tdrs-run-migrations() {
cd-tdrs
cd tdrs-backend/
docker-compose run web sh -c 'python manage.py migrate'
cd ..
}

tdrs-merge-migrations() {
cd-tdrs
cd tdrs-backend/
docker-compose run web sh -c 'python manage.py makemigrations --merge'
cd ..
}

tdrs-prune-all-docker-data() {
docker system prune -a
docker system prune --volumes
}

tdrs-run-pytest () {

cd-tdrs
cd tdrs-backend/

if [ "$#" -lt 1 ]; then
quoted_args=""
else
quoted_args="$(printf " %q" "${@}")"
fi
tdrs-compose-local run --rm web bash -c "./wait_for_services.sh && pytest ${quoted_args}"
cd ..
}
tdrs-run-backend-owasp() {
cd-tdrs
./scripts/zap-scanner.sh backend circle
}

tdrs-run-frontend-owasp() {
cd-tdrs
./scripts/zap-scanner.sh frontend circle
}
riatzukiza marked this conversation as resolved.
Show resolved Hide resolved