A gateway/firewall task to be able to talk someone about the real job
Fibinger Ádám
2021-10-22 e3c5369dcc89531b88f7abe421f1bf1b6f69d223
Docs + Database Schema Migration for Doctrine
2 files added
94 ■■■■■ changed files
README.md 61 ●●●●● patch | view | raw | blame | history
migrations/Version20211022202051.php 33 ●●●●● patch | view | raw | blame | history
README.md
New file
@@ -0,0 +1,61 @@
# SecretServer
This is a submission for the Shoprenter's backend developer job.
Live version: https://secretserver.unr.hu/
## Minimum requirements
### Everywhere
- PHP 7.2.5 (tested with 7.4)
- composer
##### Locally
- [Symfony binary](https://symfony.com/download)
#### On a webserver
- A properly configured php 7+ and some VHost-config skills on your webserver of choice (It is on an Nginx + php-fpm on the live version)
### How to fire up the project
 Included a default .env file with a preconfigured Sqlite database and unless you have a production ready stuff, you should use this default.
If you want to use anything else, please consult the [Symfony Documentation](https://symfony.com/doc/current/configuration.html#configuring-environment-variables-in-env-files) about the correct configuration.
### Install
Checkout the repository and change dir (same for local and deployed):
```
git clone https://shr:yRmglFOqNMbwpnuhP5iy@git.unr.hu/r/shoprenter-secretserver.git secretserver.website.tld
cd secretserver.website.tld
```
This is gonna create an Sqlite DB (or anything else if you changed the config) with the correct schema (you can check the .env file about the details) in the project dir (`var/data.db`):
```
php bin/console doctrine:database:create
php bin/console doctrine:migrations:migrate
```
##### SELinux
In theory if you have good sysadmins, you have SELinux.
Tell them to add `httpd_sys_rw_content_t` type to the project var/* directory and you are good to go.
##### Im am alone in the dark and my desire to `setenforce 0` is high
_Never turn off_ SELinux if you have it, its easy: let the almighty SERuler know we have some stuff that should be R/W by the webserver (you have to be in the project directory):
```
semanage fcontext -a -t httpd_sys_rw_content_t "`pwd`/var(/.*)?"
```
At this point you have a proper type context enabled on the var files (if your OS has correctly configured context), but SELinux cannot see it yet, you have to "activate" it:
```
restorecon -R -v "`pwd`/var/"
```
You should see the context you modified on the files, the app is able to function now. This is a permanent change, it sticks (reloads) even after a restart.
### Run
The .env by default is in debug mode, so if something goes sideways, you should be able to see it.
#### Locally
Fire up this baby:
`symfony server:start`
### Deploy
Only god knows what you are using (Apache, Nginx, Windows Server), you can configure as a normal symfony project: https://symfony.com/doc/current/setup/web_server_configuration.html
migrations/Version20211022202051.php
New file
@@ -0,0 +1,33 @@
<?php
declare(strict_types=1);
namespace DoctrineMigrations;
use Doctrine\DBAL\Schema\Schema;
use Doctrine\Migrations\AbstractMigration;
/**
 * Auto-generated Migration: Please modify to your needs!
 */
final class Version20211022202051 extends AbstractMigration
{
    public function getDescription(): string
    {
        return '';
    }
    public function up(Schema $schema): void
    {
        // this up() migration is auto-generated, please modify it to your needs
        $this->addSql('CREATE TABLE secret (hash VARCHAR(255) NOT NULL, secret_text VARCHAR(255) NOT NULL, created_at DATETIME NOT NULL --(DC2Type:datetime_immutable)
        , expires_at DATETIME DEFAULT NULL --(DC2Type:datetime_immutable)
        , remaining_views INTEGER NOT NULL, PRIMARY KEY(hash))');
    }
    public function down(Schema $schema): void
    {
        // this down() migration is auto-generated, please modify it to your needs
        $this->addSql('DROP TABLE secret');
    }
}