drop mysql and redis and use sqlite for Vito itself to optimize the resources

This commit is contained in:
Saeed Vaziry 2024-02-25 17:16:11 +01:00
parent 44d8364a52
commit 470274279b
14 changed files with 53 additions and 190 deletions

View File

@ -4,26 +4,7 @@ APP_KEY=
APP_DEBUG=true APP_DEBUG=true
APP_URL=http://vito.test APP_URL=http://vito.test
LOG_CHANNEL=stack
LOG_LEVEL=debug
DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=vito
DB_USERNAME=root
DB_PASSWORD=
BROADCAST_DRIVER=null
CACHE_DRIVER=file
FILESYSTEM_DRIVER=local FILESYSTEM_DRIVER=local
QUEUE_CONNECTION=default
SESSION_DRIVER=database
SESSION_LIFETIME=120
REDIS_HOST=127.0.0.1
REDIS_PASSWORD=null
REDIS_PORT=6379
MAIL_MAILER=smtp MAIL_MAILER=smtp
MAIL_HOST= MAIL_HOST=
@ -33,6 +14,3 @@ MAIL_PASSWORD=null
MAIL_ENCRYPTION=null MAIL_ENCRYPTION=null
MAIL_FROM_ADDRESS=null MAIL_FROM_ADDRESS=null
MAIL_FROM_NAME="${APP_NAME}" MAIL_FROM_NAME="${APP_NAME}"
SSH_PUBLIC_KEY_NAME=ssh-public.key
SSH_PRIVATE_KEY_NAME=ssh-private.pem

View File

@ -1,29 +1,9 @@
APP_NAME=Vito APP_NAME=Vito
APP_ENV=production APP_ENV=production
APP_KEY= APP_KEY=
APP_DEBUG=false APP_URL=http://vito.test
APP_URL=
LOG_CHANNEL=stack
LOG_LEVEL=debug
DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=
DB_USERNAME=
DB_PASSWORD=
BROADCAST_DRIVER=null
CACHE_DRIVER=file
FILESYSTEM_DRIVER=local FILESYSTEM_DRIVER=local
QUEUE_CONNECTION=default
SESSION_DRIVER=database
SESSION_LIFETIME=120
REDIS_HOST=127.0.0.1
REDIS_PASSWORD=null
REDIS_PORT=6379
MAIL_MAILER=smtp MAIL_MAILER=smtp
MAIL_HOST= MAIL_HOST=
@ -33,6 +13,3 @@ MAIL_PASSWORD=null
MAIL_ENCRYPTION=null MAIL_ENCRYPTION=null
MAIL_FROM_ADDRESS=null MAIL_FROM_ADDRESS=null
MAIL_FROM_NAME="${APP_NAME}" MAIL_FROM_NAME="${APP_NAME}"
SSH_PUBLIC_KEY_NAME=ssh-public.key
SSH_PRIVATE_KEY_NAME=ssh-private.pem

View File

@ -1,27 +0,0 @@
APP_NAME=Vito
APP_ENV=local
APP_KEY=base64:d9kZW60V4lFEw2SPn6UiJ0cfi04v80EWP0GZ6kzoxNg=
APP_DEBUG=true
APP_URL=http://localhost:2080
LOG_CHANNEL=stack
LOG_LEVEL=debug
DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=vito_test
DB_USERNAME=root
DB_PASSWORD=
BROADCAST_DRIVER=null
CACHE_DRIVER=array
FILESYSTEM_DRIVER=local
QUEUE_CONNECTION=database
SESSION_DRIVER=array
SESSION_LIFETIME=120
MAIL_MAILER=array
SSH_PUBLIC_KEY_NAME=ssh-public.key
SSH_PRIVATE_KEY_NAME=ssh-private.pem

View File

@ -1,10 +1,7 @@
name: code-style name: code-style
on: on:
push:
pull_request: pull_request:
schedule:
- cron: '0 0 * * *'
jobs: jobs:
code-style: code-style:

View File

@ -2,26 +2,14 @@ name: tests
on: on:
push: push:
branches:
- 1.x
pull_request: pull_request:
schedule:
- cron: '0 0 * * *'
jobs: jobs:
tests: tests:
runs-on: ubuntu-22.04 runs-on: ubuntu-22.04
services:
mysql:
image: mysql
env:
MYSQL_DATABASE: test_db
MYSQL_USER: user
MYSQL_PASSWORD: password
MYSQL_ROOT_PASSWORD: rootpassword
ports:
- 3306:3306
options: --health-cmd="mysqladmin ping" --health-interval=10s --health-timeout=5s --health-retries=3
strategy: strategy:
fail-fast: true fail-fast: true
matrix: matrix:
@ -49,8 +37,3 @@ jobs:
- name: Run test suite - name: Run test suite
run: php artisan test run: php artisan test
env:
DB_HOST: 127.0.0.1
DB_DATABASE: test_db
DB_USERNAME: user
DB_PASSWORD: password

View File

@ -4,9 +4,6 @@ WORKDIR /var/www/html
ENV DEBIAN_FRONTEND noninteractive ENV DEBIAN_FRONTEND noninteractive
RUN echo "mysql-server mysql-server/root_password password password" | debconf-set-selections
RUN echo "mysql-server mysql-server/root_password_again password password" | debconf-set-selections
# upgrade # upgrade
RUN apt clean && apt update && apt update && apt upgrade -y && apt autoremove -y RUN apt clean && apt update && apt update && apt upgrade -y && apt autoremove -y
@ -22,23 +19,13 @@ RUN apt update \
python2 dnsutils librsvg2-bin fswatch wget \ python2 dnsutils librsvg2-bin fswatch wget \
&& add-apt-repository ppa:ondrej/php -y \ && add-apt-repository ppa:ondrej/php -y \
&& apt update \ && apt update \
&& apt install -y php8.1 php8.1-fpm php8.1-mbstring php8.1-mysql php8.1-mcrypt php8.1-gd php8.1-xml \ && apt install -y php8.1 php8.1-fpm php8.1-mbstring php8.1-mcrypt php8.1-gd php8.1-xml \
php8.1-curl php8.1-gettext php8.1-zip php8.1-bcmath php8.1-soap php8.1-redis php8.1-curl php8.1-gettext php8.1-zip php8.1-bcmath php8.1-soap php8.1-redis
COPY docker/standalone/php.ini /etc/php/8.1/cli/conf.d/99-vito.ini COPY docker/standalone/php.ini /etc/php/8.1/cli/conf.d/99-vito.ini
# composer # composer
RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer
# mysql
RUN wget -c https://dev.mysql.com/get/mysql-apt-config_0.8.22-1_all.deb \
&& mkdir -p /etc/apt/keyrings \
&& apt clean \
&& apt update \
&& dpkg -i mysql-apt-config_0.8.22-1_all.deb \
&& apt install mysql-server -y
RUN service mysql stop
# app # app
COPY . /var/www/html COPY . /var/www/html
RUN rm -rf /var/www/html/vendor RUN rm -rf /var/www/html/vendor
@ -60,6 +47,6 @@ COPY docker/standalone/supervisord.conf /etc/supervisor/conf.d/supervisord.conf
COPY docker/standalone/start.sh /start.sh COPY docker/standalone/start.sh /start.sh
RUN chmod +x /start.sh RUN chmod +x /start.sh
EXPOSE 80 3306 EXPOSE 80
CMD ["/start.sh"] CMD ["/start.sh"]

View File

@ -15,7 +15,7 @@
| |
*/ */
'default' => env('DB_CONNECTION', 'mysql'), 'default' => env('DB_CONNECTION', 'sqlite'),
/* /*
|-------------------------------------------------------------------------- |--------------------------------------------------------------------------
@ -37,8 +37,7 @@
'sqlite' => [ 'sqlite' => [
'driver' => 'sqlite', 'driver' => 'sqlite',
'url' => env('DATABASE_URL'), 'database' => storage_path(env('DB_DATABASE', 'database.sqlite')),
'database' => env('DB_DATABASE', database_path('database.sqlite')),
'prefix' => '', 'prefix' => '',
'foreign_key_constraints' => env('DB_FOREIGN_KEYS', true), 'foreign_key_constraints' => env('DB_FOREIGN_KEYS', true),
], ],

View File

@ -15,7 +15,7 @@ public function up(): void
$table->string('protocol'); $table->string('protocol');
$table->integer('port'); $table->integer('port');
$table->ipAddress('source')->default('0.0.0.0'); $table->ipAddress('source')->default('0.0.0.0');
$table->tinyInteger('mask')->default(0); $table->string('mask')->nullable();
$table->text('note')->nullable(); $table->text('note')->nullable();
$table->string('status')->default('creating'); $table->string('status')->default('creating');
$table->timestamps(); $table->timestamps();

View File

@ -7,7 +7,9 @@
{ {
public function up(): void public function up(): void
{ {
DB::statement('ALTER TABLE firewall_rules MODIFY mask varchar(10) null'); if (DB::getDriverName() === 'mysql') {
DB::statement('ALTER TABLE firewall_rules MODIFY mask varchar(10) null');
}
} }
public function down(): void public function down(): void

View File

@ -8,19 +8,7 @@ PASSWORD=${PASSWORD:-"password"}
# Check if the flag file does not exist, indicating a first run # Check if the flag file does not exist, indicating a first run
if [ ! -f "$INIT_FLAG" ]; then if [ ! -f "$INIT_FLAG" ]; then
echo "First run of the container. Initializing MySQL..." echo "Initializing..."
# Start MySQL temporarily
service mysql start
# Wait for MySQL to start up completely (may need to adjust the sleep duration)
sleep 3
# Create Database
mysql -u root -p`echo password` -e "CREATE DATABASE IF NOT EXISTS vito CHARACTER SET utf8 COLLATE utf8_general_ci;"
# Change Password
mysql -u root -p`echo password` -e "ALTER USER 'root'@'localhost' IDENTIFIED BY '$DB_PASSWORD'; FLUSH PRIVILEGES;"
# Generate SSH keys # Generate SSH keys
openssl genpkey -algorithm RSA -out /var/www/html/storage/ssh-private.pem openssl genpkey -algorithm RSA -out /var/www/html/storage/ssh-private.pem
@ -31,8 +19,6 @@ if [ ! -f "$INIT_FLAG" ]; then
touch "$INIT_FLAG" touch "$INIT_FLAG"
fi fi
service mysql start
service php8.1-fpm start service php8.1-fpm start
service nginx start service nginx start

View File

@ -100,14 +100,11 @@ if ! echo "${V_NGINX_CONFIG}" | tee /etc/nginx/nginx.conf; then
fi fi
service nginx start service nginx start
# redis
apt install redis-server -y
# php # php
export V_PHP_VERSION="8.1" export V_PHP_VERSION="8.1"
add-apt-repository ppa:ondrej/php -y add-apt-repository ppa:ondrej/php -y
apt update apt update
apt install -y php${V_PHP_VERSION} php${V_PHP_VERSION}-fpm php${V_PHP_VERSION}-mbstring php${V_PHP_VERSION}-mysql php${V_PHP_VERSION}-mcrypt php${V_PHP_VERSION}-gd php${V_PHP_VERSION}-xml php${V_PHP_VERSION}-curl php${V_PHP_VERSION}-gettext php${V_PHP_VERSION}-zip php${V_PHP_VERSION}-bcmath php${V_PHP_VERSION}-soap php${V_PHP_VERSION}-redis apt install -y php${V_PHP_VERSION} php${V_PHP_VERSION}-fpm php${V_PHP_VERSION}-mbstring php${V_PHP_VERSION}-mcrypt php${V_PHP_VERSION}-gd php${V_PHP_VERSION}-xml php${V_PHP_VERSION}-curl php${V_PHP_VERSION}-gettext php${V_PHP_VERSION}-zip php${V_PHP_VERSION}-bcmath php${V_PHP_VERSION}-soap php${V_PHP_VERSION}-redis
if ! sed -i "s/www-data/${V_USERNAME}/g" /etc/php/${V_PHP_VERSION}/fpm/pool.d/www.conf; then if ! sed -i "s/www-data/${V_USERNAME}/g" /etc/php/${V_PHP_VERSION}/fpm/pool.d/www.conf; then
echo 'Error installing PHP' && exit 1 echo 'Error installing PHP' && exit 1
fi fi
@ -120,23 +117,6 @@ service php${V_PHP_VERSION}-fpm restart
curl -sS https://getcomposer.org/installer -o composer-setup.php curl -sS https://getcomposer.org/installer -o composer-setup.php
php composer-setup.php --install-dir=/usr/local/bin --filename=composer php composer-setup.php --install-dir=/usr/local/bin --filename=composer
# database
export V_MARIADB_VERSION="10.3"
export V_DB_USER="vito"
export V_DB_NAME="vito"
export V_DB_PASS=$(openssl rand -base64 12)
wget -c https://dev.mysql.com/get/mysql-apt-config_0.8.22-1_all.deb
dpkg -i mysql-apt-config_0.8.22-1_all.deb
apt update
apt install mysql-server -y
service mysql enable
service mysql start
mysql -e "CREATE DATABASE IF NOT EXISTS ${V_DB_NAME} CHARACTER SET utf8 COLLATE utf8_general_ci"
mysql -e "CREATE USER IF NOT EXISTS '${V_DB_USER}'@'localhost' IDENTIFIED BY '${V_DB_PASS}'"
mysql -e "FLUSH PRIVILEGES"
mysql -e "GRANT ALL PRIVILEGES ON ${V_DB_NAME}.* TO '${V_DB_USER}'@'localhost'"
mysql -e "FLUSH PRIVILEGES"
# setup website # setup website
export V_SSL=${V_SSL:-1} export V_SSL=${V_SSL:-1}
export COMPOSER_ALLOW_SUPERUSER=1 export COMPOSER_ALLOW_SUPERUSER=1
@ -196,9 +176,6 @@ else
export V_URL="http://${V_DOMAIN}" export V_URL="http://${V_DOMAIN}"
fi fi
sed -i "s|APP_URL=.*|APP_URL=${V_URL}|" /home/${V_USERNAME}/${V_DOMAIN}/.env sed -i "s|APP_URL=.*|APP_URL=${V_URL}|" /home/${V_USERNAME}/${V_DOMAIN}/.env
sed -i "s|DB_DATABASE=.*|DB_DATABASE=${V_DB_NAME}|" /home/${V_USERNAME}/${V_DOMAIN}/.env
sed -i "s|DB_USERNAME=.*|DB_USERNAME=${V_DB_USER}|" /home/${V_USERNAME}/${V_DOMAIN}/.env
sed -i "s|DB_PASSWORD=.*|DB_PASSWORD=${V_DB_PASS}|" /home/${V_USERNAME}/${V_DOMAIN}/.env
php artisan key:generate php artisan key:generate
php artisan storage:link php artisan storage:link
php artisan migrate --force php artisan migrate --force
@ -249,9 +226,6 @@ php artisan icons:cache
echo "🎉 Congratulations!" echo "🎉 Congratulations!"
echo "✅ SSH User: ${V_USERNAME}" echo "✅ SSH User: ${V_USERNAME}"
echo "✅ SSH Password: ${V_PASSWORD}" echo "✅ SSH Password: ${V_PASSWORD}"
echo "✅ DB Name: ${V_DB_NAME}"
echo "✅ DB Username: ${V_DB_USER}"
echo "✅ DB Password: ${V_DB_PASS}"
echo "✅ Admin Email: ${V_ADMIN_EMAIL}" echo "✅ Admin Email: ${V_ADMIN_EMAIL}"
echo "✅ Admin Password: ${V_ADMIN_PASSWORD}" echo "✅ Admin Password: ${V_ADMIN_PASSWORD}"
echo "✅ URL: http://${V_DOMAIN}" echo "✅ URL: http://${V_DOMAIN}"

View File

@ -11,12 +11,12 @@
<coverage/> <coverage/>
<php> <php>
<env name="APP_ENV" value="testing"/> <env name="APP_ENV" value="testing"/>
<env name="APP_KEY" value="base64:d9kZW60V4lFEw2SPn6UiJ0cfi04v80EWP0GZ6kzoxNg="/>
<env name="DB_DATABASE" value="database-test.sqlite"/>
<env name="BCRYPT_ROUNDS" value="4"/> <env name="BCRYPT_ROUNDS" value="4"/>
<env name="CACHE_DRIVER" value="array"/> <env name="CACHE_DRIVER" value="array"/>
<env name="MAIL_MAILER" value="array"/> <env name="MAIL_MAILER" value="array"/>
<env name="QUEUE_CONNECTION" value="database"/> <env name="QUEUE_CONNECTION" value="database"/>
<env name="SESSION_DRIVER" value="array"/>
<env name="TELESCOPE_ENABLED" value="false"/>
</php> </php>
<source> <source>
<include> <include>

View File

@ -27,13 +27,13 @@ public function test_add_email_channel(): void
->call('add') ->call('add')
->assertSuccessful(); ->assertSuccessful();
$this->assertDatabaseHas('notification_channels', [ /** @var \App\Models\NotificationChannel $channel */
'provider' => NotificationChannel::EMAIL, $channel = \App\Models\NotificationChannel::query()
'data' => cast_to_json([ ->where('provider', NotificationChannel::EMAIL)
'email' => 'email@example.com', ->first();
]),
'connected' => 1, $this->assertEquals('email@example.com', $channel->data['email']);
]); $this->assertTrue($channel->connected);
} }
public function test_add_slack_channel(): void public function test_add_slack_channel(): void
@ -49,13 +49,13 @@ public function test_add_slack_channel(): void
->call('add') ->call('add')
->assertSuccessful(); ->assertSuccessful();
$this->assertDatabaseHas('notification_channels', [ /** @var \App\Models\NotificationChannel $channel */
'provider' => NotificationChannel::SLACK, $channel = \App\Models\NotificationChannel::query()
'data' => cast_to_json([ ->where('provider', NotificationChannel::SLACK)
'webhook_url' => 'https://hooks.slack.com/services/123/token', ->first();
]),
'connected' => 1, $this->assertEquals('https://hooks.slack.com/services/123/token', $channel->data['webhook_url']);
]); $this->assertTrue($channel->connected);
} }
public function test_add_discord_channel(): void public function test_add_discord_channel(): void
@ -71,15 +71,18 @@ public function test_add_discord_channel(): void
->call('add') ->call('add')
->assertSuccessful(); ->assertSuccessful();
$this->assertDatabaseHas('notification_channels', [ /** @var \App\Models\NotificationChannel $channel */
'provider' => NotificationChannel::DISCORD, $channel = \App\Models\NotificationChannel::query()
'data' => cast_to_json([ ->where('provider', NotificationChannel::DISCORD)
'webhook_url' => 'https://discord.com/api/webhooks/123/token', ->first();
]),
'connected' => 1, $this->assertEquals('https://discord.com/api/webhooks/123/token', $channel->data['webhook_url']);
]); $this->assertTrue($channel->connected);
} }
/*
* @TODO fix json comparison
*/
public function test_add_telegram_channel(): void public function test_add_telegram_channel(): void
{ {
$this->actingAs($this->user); $this->actingAs($this->user);
@ -94,14 +97,14 @@ public function test_add_telegram_channel(): void
->call('add') ->call('add')
->assertSuccessful(); ->assertSuccessful();
$this->assertDatabaseHas('notification_channels', [ /** @var \App\Models\NotificationChannel $channel */
'provider' => NotificationChannel::TELEGRAM, $channel = \App\Models\NotificationChannel::query()
'data' => cast_to_json([ ->where('provider', NotificationChannel::TELEGRAM)
'chat_id' => '123', ->first();
'bot_token' => 'token',
]), $this->assertEquals('123', $channel->data['chat_id']);
'connected' => 1, $this->assertEquals('token', $channel->data['bot_token']);
]); $this->assertTrue($channel->connected);
} }
public function test_see_channels_list(): void public function test_see_channels_list(): void

View File

@ -28,7 +28,9 @@ public function test_see_server_keys()
'public_key' => 'public-key-content', 'public_key' => 'public-key-content',
]); ]);
$this->server->sshKeys()->attach($sshKey); $this->server->sshKeys()->attach($sshKey, [
'status' => SshKeyStatus::ADDED,
]);
Livewire::test(ServerKeysList::class, ['server' => $this->server]) Livewire::test(ServerKeysList::class, ['server' => $this->server])
->assertSeeText('My first key'); ->assertSeeText('My first key');
@ -46,7 +48,9 @@ public function test_delete_ssh_key()
'public_key' => 'public-key-content', 'public_key' => 'public-key-content',
]); ]);
$this->server->sshKeys()->attach($sshKey); $this->server->sshKeys()->attach($sshKey, [
'status' => SshKeyStatus::ADDED,
]);
Livewire::test(ServerKeysList::class, ['server' => $this->server]) Livewire::test(ServerKeysList::class, ['server' => $this->server])
->set('deleteId', $sshKey->id) ->set('deleteId', $sshKey->id)