- Clone the repo & open it in your IDE
- Copy
.env.exampleto.envand set a secure value forDB_PASSWORD - Generate an SSH commit-signing key at
~/.ssh/git_signing(and~/.ssh/git_signing.pub) - Tell GitHub about that key by following these steps
- Tell Git to sign commits using that key (omit
--globalif you only want to do so for this repo)foo@bar:~/DamSecure$ git config --global gpg.format ssh foo@bar:~/DamSecure$ git config --global user.signingkey ~/.ssh/gitsigning.pub foo@bar:~/DamSecure$ git config --global commit.gpgsign true
- Perform the following step for your dev environment of choice:
- If using VS Code and local dev containers, install the Dev Containers extension and reopen the project in the configured dev container
- If editing locally and running the dev server via Docker Compose, run
docker compose up --build --watch- Other commands (e.g. ones that require
php) will need to be prefixed withdocker compose exec -it apache_php- Created/modified files will need to be copied back to your local repository
(in order to be committed to version control) via
docker compose cp apache_php:/app/path/to/file ./path/to/filewherepath/to/fileis replaced with the filepath to copy
- Created/modified files will need to be copied back to your local repository
(in order to be committed to version control) via
- Other commands (e.g. ones that require
- Run
php artisan key:generate - Start developing!
Important
OSU's servers run PHP as a dedicated user that is not part of the user or group for this
project's files. To ensure that PHP can access all files to execute code and render
pages, all accessed files need the permissions 0o664 and all directories need the
permissions 0o775. For simplicity, you can add the
scripts/allow.sh script as a pre-commit hook to ensure all
committed files have the correct permissions:
foo@bar:~/DamSecure$ cp ./scripts/allow.sh ./.git/hooks/pre-commitTo deploy a DamSecure update to OSU's servers, follow these steps:
- Ensure all updates are merged to the
mainbranch of this repository - SSH into OSU's server and
cdto the directory where DamSecure's source lives - Run
git pullto get the latest changes - Run
bash scripts/allow.shto ensure all files have the necessary permissions for PHP to load them - Run
php artisan migrateto apply any database changes
This project is built on Laravel to simplify development. Before making changes, check out their directory structure and architecture concepts documentation.
Laravel routes are used to determine what code to execute when a given HTTP request is made.
- All routes for the web app should be placed in
/routes/web.php. These routes' handlers can access the currently-logged in user (based on the request's cookies) via theauth()->user()method. - All routes for the user-facing API should be placed in
/routes/api.php. These routes' handlers can access the project that the request is for via theauth()->user()method. This is still called user because Laravel's personal access tokens feature has been adapted to authenticate projects instead of users. This design decision was made because DamSecure is intended for group projects, where it makes more sense for the team to have 1 API token for the project, rather than require each member to generate their own (what does it mean for the group's IoT thermometer to authenticate as John Doe, anyway?).
Every change should be thoroughly tested. Integration tests are preferred since most of
this app's behavior involves visiting pages and making API calls, with little complex
backend logic. This makes integration tests more efficient than unit tests for ensuring
proper functionality. Integration tests live in /tests/Feature and
can be created with php artisan make:test <TestName> (where <TestName> is e.g.
UserTest).
Complex logic should be placed in a class in /app/Services and
should be unit tested. Unit tests live in [/tests/Unit](./tests/Unit/) and can be created with php artisan make:test --unit(whereis e.g.DataServiceTest.php`).
For more details on testing, check out Laravel's testing documentation.
All tests can be run with php artisan test. Tests should always be run before
creating a PR and new logic should always be tested.
The database for DamSecure is "version-controlled" via Laravel database migrations. To make changes to the database schema, follow these steps to create and apply a migration:
- Run
php artisan make:migration <migration_name>where<migration_name>is replaced with a short name for the changes being made (e.g.create_download_table) - Open the new file in
/database/migrations - Replace the
up()method's implementation with one that makes all needed changes to the database - Replace the
down()method's implementation with one that undoes all changes to the database- Ideally,
up()anddown()should be implemented such that runningup(); down();is non-destructive for data currently in the database
- Ideally,
- Run
php artisan migrateto apply the changes to your dev database - Update the model classes to match the new schema and fix any QueryBuilder calls this breaks
- Update the test factory classes and test seed script to match the new schema
- Commit the modified files
To apply these changes to the production database, run php artisan migrate --force from
the production PHP server after pulling the latest version of the code to that server.