Skip to content

Commit

Permalink
Refactored installation
Browse files Browse the repository at this point in the history
  • Loading branch information
VampireAotD committed Jul 31, 2024
1 parent a210a82 commit 6e7ffb3
Show file tree
Hide file tree
Showing 23 changed files with 195 additions and 191 deletions.
27 changes: 21 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,26 +21,33 @@ To fully use **Anilibrary** you can also use one or all services that are relate
different sites.
2. [`ELK`](https://github.com/VampireAotD/anilibrary-elk) - service that is used for advanced logging and search.
3. [`Monitoring`](https://github.com/VampireAotD/anilibrary-monitoring) - service for collecting different metrics and
traces from all Anilibrary services.
traces from all **Anilibrary** services.
4. [`gRPC`](https://github.com/VampireAotD/anilibrary-grpc) - service that is used for communication using gRPC,
generates client and server implementations for different languages.

---

## Build and deployment

Before you start to work with **Anilibrary**, you need to fill all required environment variables which will be located
in `.env` and `src/.env`. To acquire them, you can use script **install.sh** or launch it by using:
Before you start to work with **Anilibrary**, you need to create `.env` file in the project root:

```sh
make install
cp ./.env.example ./.env
```

and `.env` file in the `src` directory:

```sh
cp ./src/.env.example ./src/.env
```

After that you must fill up all required environment variables.

### Variables

#### For containers

This variables will be located in **.env** and are required for container to run properly.
This variables will be located in project root `.env` file and are required for containers to run properly.

| Variable | Default Value | Description |
|--------------------------|---------------|----------------------------------------------------------------------|
Expand Down Expand Up @@ -72,6 +79,14 @@ services.
| `SCRAPER_URL` | Url for **scraper microservice**. |
| `LOGSTASH_ADDRESS` | Url for **Logstash** receiver. |

### Launching

After filling up all environment variables you can proceed installation of **Anilibrary** by using:

```sh
make install
```

---

## Testing
Expand Down Expand Up @@ -121,7 +136,7 @@ To make life easier and automatically run all this commands for you before commi
## Logs

As mentioned before, **Anilibrary** has its own [ELK stack](https://github.com/VampireAotD/anilibrary-elk), so logs from
it or **Nginx** can be send to **Logstash**, and be visualised in **Kibana**. To send **Nginx** logs to **Logstash**,
it or **Nginx** can be sent to **Logstash**, and be visualised in **Kibana**. To send **Nginx** logs to **Logstash**,
you need to set `NGINX_LOGS_TO_LOGSTASH`variable to `true` in `.env` and specify `LOGSTASH_URL` for **Nginx** container
in `compose.yml`, like this:

Expand Down
59 changes: 19 additions & 40 deletions scripts/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@
set -eu
set -o pipefail

function info {
echo "$1"
}

function log {
echo "[+] $1"
}
Expand All @@ -11,52 +15,27 @@ function err {
echo "[x] Error: $1"
}

function set_compose_bin {
if which docker-compose >/dev/null 2>&1; then
echo docker-compose
return 0
elif docker compose version >/dev/null 2>&1; then
echo docker compose
return 0
else
echo "Couldn't find any version of docker compose"
return 1
fi
}

compose=$(set_compose_bin) || {
err "$compose"
exit 1
}

echo '⠿ Installing Anilibrary'

log 'Creating .env file with values from .env.example in root'
if [ ! -f ./.env ]; then
cp ./.env.example ./.env
fi

log 'Creating Laravel .env file with values from .env.example in src'
if [ ! -f ./src/.env ]; then
cp ./src/.env.example ./src/.env
fi
info 'Installing Anilibrary'

log 'Building images'
$compose up -d --build
docker compose build

log 'Installing frontend dependencies'
$compose exec app pnpm install --frozen-lockfile

log 'Installing Composer packages'
$compose exec app composer install
log 'Installing dependencies'
docker compose run -d --name anilibrary-dependencies app
docker compose exec app composer install
docker compose exec app pnpm install --frozen-lockfile

log 'Generating Laravel app key'
$compose exec app ./artisan key:generate
docker compose exec app ./artisan key:generate

log 'Launching containers'
docker rm -f anilibrary-dependencies
docker compose up -d

log 'Creating database'
$compose exec app ./artisan migrate --seed
log 'Running migrations'
docker compose exec app ./artisan migrate --seed

log 'Resolving owner'
$compose exec app ./artisan setup:create-owner
docker compose exec app ./artisan setup:create-owner

echo 'Anilibrary has been successfully installed!'
info 'Anilibrary has been successfully installed!'
4 changes: 2 additions & 2 deletions src/.env.example
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ LOG_DEPRECATIONS_CHANNEL=null
LOG_LEVEL=debug

DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_HOST=database
DB_PORT=3306
DB_DATABASE=laravel
DB_USERNAME=root
Expand All @@ -47,7 +47,7 @@ CACHE_PREFIX=
MEMCACHED_HOST=127.0.0.1

REDIS_CLIENT=phpredis
REDIS_HOST=127.0.0.1
REDIS_HOST=redis
REDIS_PASSWORD=null
REDIS_PORT=6379

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ trait IndexConfiguration
protected function getIndexSettings(): array
{
return [
'index' => [
'index' => [
'max_ngram_diff' => 10,
],
'analysis' => [
'filter' => [
'filter' => [
'english_stemmer' => [
'type' => 'stemmer',
'language' => 'english',
Expand All @@ -22,15 +22,15 @@ protected function getIndexSettings(): array
'type' => 'stemmer',
'language' => 'russian',
],
'english_stop' => [
'english_stop' => [
'type' => 'stop',
'language' => '_english_',
],
'russian_stop' => [
'russian_stop' => [
'type' => 'stop',
'language' => '_russian_',
],
'autocomplete' => [
'autocomplete' => [
'type' => 'ngram',
'min_gram' => 3,
'max_gram' => 8,
Expand All @@ -42,8 +42,8 @@ protected function getIndexSettings(): array
'char_filter' => [
'html_strip',
],
'tokenizer' => 'standard',
'filter' => [
'tokenizer' => 'standard',
'filter' => [
'lowercase',
'english_stemmer',
'english_stop',
Expand All @@ -61,27 +61,27 @@ protected function getIndexMappings(): array
{
return [
'properties' => [
'title' => [
'title' => [
'type' => 'text',
'analyzer' => 'anime_analyzer',
],
'status' => [
'status' => [
'type' => 'keyword',
],
'rating' => [
'rating' => [
'type' => 'keyword',
],
'episodes' => [
'episodes' => [
'type' => 'keyword',
],
'urls.url' => [
'urls.url' => [
'type' => 'keyword',
],
'synonyms.synonym' => [
'synonyms.synonym' => [
'type' => 'text',
'analyzer' => 'anime_analyzer',
],
'genres.name' => [
'genres.name' => [
'type' => 'text',
'analyzer' => 'anime_analyzer',
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public function resolve(CallbackDataDTO $dto): string
$callback = sprintf('command=%s', $dto->queryType->value);

return match (true) {
$dto instanceof ViewAnimeCallbackDataDTO => sprintf(
$dto instanceof ViewAnimeCallbackDataDTO => sprintf(
'%s&animeId=%s',
$callback,
$this->encoderService->encodeId($dto->animeId)
Expand Down
2 changes: 1 addition & 1 deletion src/app/Http/Middleware/HandleInertiaRequests.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public function share(Request $request): array
{
return [
...parent::share($request),
'auth' => [
'auth' => [
'user' => $request->user()?->load(['roles:name', 'telegramUser:user_id,username']),
],
'flash' => [
Expand Down
8 changes: 4 additions & 4 deletions src/app/Http/Requests/Anime/UpdateRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,10 @@ public function rules(): array
'string',
Rule::unique(AnimeSynonym::class, 'name')->ignore($animeId, 'anime_id'),
],
'voice_acting' => 'nullable|array',
'voice_acting.*' => 'uuid|exists:voice_acting,id',
'genres' => 'nullable|array',
'genres.*' => 'uuid|exists:genres,id',
'voice_acting' => 'nullable|array',
'voice_acting.*' => 'uuid|exists:voice_acting,id',
'genres' => 'nullable|array',
'genres.*' => 'uuid|exists:genres,id',
];
}
}
4 changes: 2 additions & 2 deletions src/app/Services/Elasticsearch/Index/AnimeIndexService.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ public function multiMatchSearch(string $term): array
'body' => [
'query' => [
'multi_match' => [
'query' => $term,
'fields' => [
'query' => $term,
'fields' => [
'title^8',
'status',
'rating',
Expand Down
20 changes: 10 additions & 10 deletions src/config/broadcasting.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,11 @@
'connections' => [

'reverb' => [
'driver' => 'reverb',
'key' => env('REVERB_APP_KEY'),
'secret' => env('REVERB_APP_SECRET'),
'app_id' => env('REVERB_APP_ID'),
'options' => [
'driver' => 'reverb',
'key' => env('REVERB_APP_KEY'),
'secret' => env('REVERB_APP_SECRET'),
'app_id' => env('REVERB_APP_ID'),
'options' => [
'host' => env('REVERB_HOST'),
'port' => env('REVERB_PORT', 443),
'scheme' => env('REVERB_SCHEME', 'https'),
Expand All @@ -48,11 +48,11 @@
],

'pusher' => [
'driver' => 'pusher',
'key' => env('PUSHER_APP_KEY'),
'secret' => env('PUSHER_APP_SECRET'),
'app_id' => env('PUSHER_APP_ID'),
'options' => [
'driver' => 'pusher',
'key' => env('PUSHER_APP_KEY'),
'secret' => env('PUSHER_APP_SECRET'),
'app_id' => env('PUSHER_APP_ID'),
'options' => [
'cluster' => env('PUSHER_APP_CLUSTER'),
'host' => env('PUSHER_HOST') ?: 'api-' . env('PUSHER_APP_CLUSTER', 'mt1') . '.pusher.com',
'port' => env('PUSHER_PORT', 443),
Expand Down
4 changes: 2 additions & 2 deletions src/config/cache.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,10 @@
env('MEMCACHED_USERNAME'),
env('MEMCACHED_PASSWORD'),
],
'options' => [
'options' => [
// Memcached::OPT_CONNECT_TIMEOUT => 2000,
],
'servers' => [
'servers' => [
[
'host' => env('MEMCACHED_HOST', '127.0.0.1'),
'port' => env('MEMCACHED_PORT', 11211),
Expand Down
10 changes: 5 additions & 5 deletions src/config/cloudinary.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
| URL that used for uploading media files to Cloudinary.
|
*/
'cloud_url' => env('CLOUDINARY_URL'),
'cloud_url' => env('CLOUDINARY_URL'),

/*
|--------------------------------------------------------------------------
Expand All @@ -40,7 +40,7 @@
| Upload preset From Cloudinary dashboard.
|
*/
'upload_preset' => env('CLOUDINARY_UPLOAD_PRESET'),
'upload_preset' => env('CLOUDINARY_UPLOAD_PRESET'),

/*
|--------------------------------------------------------------------------
Expand All @@ -50,7 +50,7 @@
| Route to get `cloud_image_url` from Blade Upload Widget.
|
*/
'upload_route' => env('CLOUDINARY_UPLOAD_ROUTE'),
'upload_route' => env('CLOUDINARY_UPLOAD_ROUTE'),

/*
|--------------------------------------------------------------------------
Expand All @@ -60,7 +60,7 @@
| Controller action to get `cloud_image_url` from Blade Upload Widget.
|
*/
'upload_action' => env('CLOUDINARY_UPLOAD_ACTION'),
'upload_action' => env('CLOUDINARY_UPLOAD_ACTION'),

/*
|--------------------------------------------------------------------------
Expand All @@ -81,5 +81,5 @@
| Default image url that will be used when no image is provided.
|
*/
'default_image' => env('CLOUDINARY_DEFAULT_IMAGE', ''),
'default_image' => env('CLOUDINARY_DEFAULT_IMAGE', ''),
];
Loading

0 comments on commit 6e7ffb3

Please sign in to comment.