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 8 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
174 changes: 174 additions & 0 deletions commands.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,174 @@
#!/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
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 start-tdrs='tdrs-start-frontend && tdrs-start-backend'

# Stop both the frontend and the backend
alias stop-tdrs='tdrs-stop-frontend && tdrs-stop-backend'
riatzukiza marked this conversation as resolved.
Show resolved Hide resolved

# 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
tdrs-start-backend() {
cd-tdrs
cd tdrs-backend && tdrs-compose-local up -d
cd ..
}

# run npm install updating all dependencies and start the dev server
tdrs-start-frontend() {
cd-tdrs
cd tdrs-frontend && tdrs-compose-local up -d
cd ..
}

# Stop all containers for the backend
tdrs-stop-backend() {
cd-tdrs
cd tdrs-backend && tdrs-compose-local down
cd ..
}
# stop the frontend development server
tdrs-stop-frontend() {
cd-tdrs
cd tdrs-frontend && tdrs-compose-local down
cd ..
}

# restart the frontends, mainly to rebuild dependencies
tdrs-restart-frontend() {
cd-tdrs
cd tdrs-frontend && tdrs-compose-local restart
cd ..
}

# restart all containers for the backend
tdrs-restart-backend() {
cd-tdrs
cd tdrs-backend && tdrs-compose-local restart
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 ..
}

# to restart just django, keeping the other containers intact.
restart-django() {
cd-tdrs
cd tdrs-backend && docker-compose restart web
cd ..
}

# run flake8 against backend source from inside of web container
tdrs-lint-backend() {
cd-tdrs
cd tdrs-backend/ && tdrs-compose-local run --rm web bash -c 'flake8 .'
riatzukiza marked this conversation as resolved.
Show resolved Hide resolved
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
cd tdrs-frontend/ && tdrs-compose-local run --rm tdp-frontend bash -c 'yarn lint'
riatzukiza marked this conversation as resolved.
Show resolved Hide resolved
cd ..
}

# Fix all automaticly fixable linting errors for the frontend
tdrs-fix-lint-frontend() {
cd-tdrs
cd tdrs-frontend/ && tdrs-compose-local run --rm tdp-frontend bash -c 'eslint --fix ./src'
cd ..
}

tdrs-yarn() {
cd-tdrs
cd tdrs-frontend/ && yarn $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