The website of S.A. Proto.
The study association of BSc. Creative Technology and MSc. Interaction Technology.
Here you can find the people that have contributed to the code to this project. But, let's not forget the other members of the HYTTIOAOAc!
This README is tailored to using Docker in WSL2 (Ubuntu) on Windows using Laravel Sail. Laravel Sail also supports MacOS and Linux, however you may encounter issues with the installation instruction below when using a different operating system.
Before following the installation instructions, you need to have a working installation of WSL2, Docker and Git. You can install docker using the official instructions at docs.docker.com. JetBrains PhpStorm IDE is strongly recommended for development on this project, especially with the laravel plugin for proper code completion and reverences.
This website can be run locally through Docker by using Laravel Sail. For more information on using Laravel Sail check out their documentation.
First you need to clone the repository into a folder in WSL2.
git clone git@github.com:saproto/saproto.git
git clone https://github.com/saproto/saproto.git
After installing Docker and cloning the repository the following instructions can be run in the terminal in the source folder of the project.
Copy and rename .env.dev
to .env
.
cp .env.dev .env
After that, open the new .env
file and set the PERSONAL_PROTO_KEY
to your personal Proto key, which can be
found/generated on the bottom of your dashboard on the live Proto
website.
When first cloning the project you may not have a functional installation of the correct version of PHP or Composer. To install Laravel sail and its dependencies it is therefore necessary to spin up a temporary container.
docker run --rm \
-u "$(id -u):$(id -g)" \
-v $(pwd):/var/www/html \
-w /var/www/html \
laravelsail/php82-composer:latest \
composer install --ignore-platform-reqs --no-scripts
By default, Laravel Sail commands are invoked using the vendor/bin/sail
script. That is a lot of characters to type
every time you want to execute a command. So, instead you can create an alias. By adding the alias definition
to ~/.bash_aliases
(WSL2/Linux) or ~/.zshenv
(macOS) the alias will persist between terminal restarts.
The rest of these instruction will assume that you successfully added the sail
alias.
WSL2/Linux/macOS High Sierra or earlier:
echo "alias sail='[ -f sail ] && bash sail || bash vendor/bin/sail'" > ~/.bash_aliases
macOS Catalina or newer:
echo "alias sail='[ -f sail ] && bash sail || bash vendor/bin/sail'" > ~/.zshenv
sail up -d
sail composer install
sail artisan key:generate
sail artisan migrate --seed
To install the client-side dependencies you'll need to run sail npm install
to install all client-side dependencies.
To compile the project assets (JS/CSS) run sail npm run build
to compile once or sail npm run dev
to keep checking
for changes to scripts or stylesheets.
When adding a new library or client-side dependency through npm don't forget to require the scripts in application.js
and the stylesheet in vendor.scss
.
In some parts of the website we use websockets to update the page in real-time. For this we use a soketi server. This runs in a docker container in your sail setup.
For the frontend we use the Laravel Echo library to connect to the websocket server.
When you have finished the above setup the following port will be exposed on localhost.
8080
= Website8081
= PhpMyAdmin8082
= Mailhog
You can sign in with the same Proto username you use on the live website and the password given to you during the database seeding. This user will have full admin rights on the local website.
Due to the permission changes, Git might detect that all files have been changed. If this is the case,
run git config core.filemode false
to make git ignore the permission changes.
sail up -d
sail stop
sail shell
sail artisan migrate:fresh --seed
When your sail container is running, you can use Laravel Solo to run all the
commands you would normally in different
terminals. It will automatically start npm run dev
and tail the logs. Use the arrow keys to switch between the
different tabs, and press q
to exit.
The queue and schedule are not automatically run. To run these, switch to the tab and press 's'.
sail artisan solo
When writing code it is useful to have tools such as code completion and linting in an integrated development
environment (IDE). As mentioned before PHPStorm is the recommended IDE for this
project. To add additional code completion for Laravel you can run sail composer ide-helper
in the docker container to
let Laravel-IDE-Helper generate an _ide_helper.php
file which tells
PHPStorm what certain classes and function are, so it can perform proper code completion and show documentation.
Run sail composer fix
in the docker container to fix stylistic errors in your code
using PHP-CS-Fixer. This will also be done automatically when creating a
pull-request or pushing to a branch with an open pull-request.
Run sail composer rector
in the docker container to automatically upgrade your code
using Laravel-Rector to meet the rules set in rector.php.
This will also be done automatically when creating a
pull-request or pushing to a branch with an open pull-request.
There is also the option for static analysis of your code. Run sail composer analyse
in the docker container to
let Larastan find any potential bugs in your code.
Xdebug is activated in Laravel Sail to aid you while debugging the website. Xdebug enables breakpoints and step debugging which can easily be controlled from your IDE. For this to work, you will have to set up your IDE correctly.
PhpStorm for zero-configuration debugging. In case of zero-configuration debugging, you do not need to create any debug configuration. Instead, you open the starting page of your PHP application in the browser manually, and then activate the debugging engine from the browser, while PhpStorm listens to incoming debugger connections. For full instructions on how to use zero-configuration debugging, check out the PhpStorm documentation
Clockwork is a php dev tool in your browser. When running the website in debug mode you can access the clockwork debug page at localhost:8080/clockwork. The application has various debugging features such as timelines of runtime requests, database queries and client-metrics.
For testing we use Pest for basic tests and Dusk for browser tests. These tests should be run locally, but are also run on every PR in GitHub Actions.
If tests are failing, and it shows that all the tests using a database fail, you should run
sail artisan optimize:clear
first.
The Pest tests can be run with the following command:
sail test
.
If you do not need the output and want it to go faster you can use the --parallel
flag.
To make a new test you can use the following command:
sail artisan make:test {{TestName}}
.
To make a unit test you can use the following command:
sail artisan make:test {{TestName}} --unit
.
The dusk tests can be run with the following command:
sail dusk
.