Skip to content

Commit

Permalink
Merge pull request #419 from bakaphp/development
Browse files Browse the repository at this point in the history
  • Loading branch information
kaioken authored Jul 16, 2023
2 parents 66a4efe + e8e782c commit 6670224
Show file tree
Hide file tree
Showing 221 changed files with 7,475 additions and 1,689 deletions.
1 change: 1 addition & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ RABBITMQ_HOST=rabbitmq

#GRAPHQL CONFIGURATION
LIGHTHOUSE_CACHE_ENABLE=false
LIGHTHOUSE_SCHEMA_CACHE_ENABLE=false
LIGHTHOUSE_CACHE_VERSION=2

#SEACH CONFIGURATION
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/dependabot-auto-merge.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:

- name: Dependabot metadata
id: metadata
uses: dependabot/fetch-metadata@v1.4.0
uses: dependabot/fetch-metadata@v1.6.0
with:
github-token: "${{ secrets.GITHUB_TOKEN }}"

Expand Down
22 changes: 14 additions & 8 deletions .github/workflows/deploy-gcp.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,21 @@ jobs:
runs-on: ubuntu-latest
environment: ${{ github.ref_name }}
permissions:
id-token: write
contents: read
packages: write
steps:
- id: checkout
name: Checkout
uses: actions/checkout@v3

- id: auth
name: "Authenticate to Google Cloud"
uses: "google-github-actions/auth@v1"
- id: 'auth'
name: 'Authenticate to Google Cloud'
uses: 'google-github-actions/auth@v1'
with:
credentials_json: "${{ secrets.GOOGLE_CREDENTIALS }}"
token_format: 'access_token'
workload_identity_provider: "${{secrets.GCP_WORKLOAD_IDENTITY_PROVIDER}}"
service_account: "${{secrets.GCP_SERVICE_ACCOUNT}}"

- name: Login to Artifact Registry
uses: docker/login-action@v2
Expand All @@ -38,6 +40,7 @@ jobs:
uses: docker/build-push-action@v4
with:
push: true
file: ${{ github.ref_name }}.Dockerfile
tags: |
${{ secrets.GCP_IMAGE_TAG }}:${{ github.run_number }}
${{ secrets.GCP_IMAGE_TAG }}:latest
Expand All @@ -47,17 +50,20 @@ jobs:
environment: ${{ github.ref_name }}
needs: Build
permissions:
id-token: write
contents: read
packages: write
steps:
- name: Checkout repository
uses: actions/checkout@v3

- id: auth
name: "Authenticate to Google Cloud"
uses: "google-github-actions/auth@v1"
- id: 'auth'
name: 'Authenticate to Google Cloud'
uses: 'google-github-actions/auth@v1'
with:
credentials_json: "${{ secrets.GOOGLE_CREDENTIALS }}"
token_format: 'access_token'
workload_identity_provider: "${{secrets.GCP_WORKLOAD_IDENTITY_PROVIDER}}"
service_account: "${{secrets.GCP_SERVICE_ACCOUNT}}"

- name: 'Set up Cloud SDK'
uses: 'google-github-actions/setup-gcloud@v1'
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ jobs:
region: ${{ secrets.AWS_REGION }}
create_repo: true
tags: latest,${{ github.run_number }},
dockerfile: ${{ github.ref_name }}.Dockerfile

Deploy:
runs-on: ubuntu-latest
Expand Down
25 changes: 2 additions & 23 deletions .github/workflows/static-analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -104,29 +104,8 @@ jobs:
- name: Install Composer dependencies
run: composer install --prefer-dist --no-interaction --no-progress

- name: Run Migrations
run: php artisan migrate

- name: Run Inventory Migrations
run: php artisan migrate --path database/migrations/Inventory/ --database inventory

- name: Run Social Migrations
run: php artisan migrate --path database/migrations/Social/ --database social

- name: Run Guild Migrations
run: php artisan migrate --path database/migrations/Guild/ --database crm

- name: Run Seeders
run: php artisan db:seed

- name: Create Role Admin
run: php artisan kanvas:create-role Admin

- name: Create Role Users
run: php artisan kanvas:create-role Users

- name: Create Role Agents
run: php artisan kanvas:create-role Agents
- name: Setup Kanvas Ecosystem
run: php artisan kanvas:setup-ecosystem

- name: Execute type checking
run: vendor/bin/phpstan --configuration="phpstan.src.neon.dist" --xdebug
42 changes: 15 additions & 27 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,14 @@ jobs:
AWS_DEFAULT_REGION_CICD: ${{ secrets.AWS_DEFAULT_REGION_CICD }}
AWS_BUCKET_CICD: ${{ secrets.AWS_BUCKET_CICD }}
AWS_URL: ${{ secrets.AWS_URL }}
SCOUT_DRIVER: database
MODEL_CACHE_STORE: model
MODEL_CACHE_ENABLED: false
LIGHTHOUSE_CACHE_ENABLE: true
LIGHTHOUSE_CACHE_VERSION: 2
SCOUT_DRIVER: meilisearch
MEILISEARCH_HOST: http://localhost:7700
MEILISEARCH_KEY: masterKey
SCOUT_QUEUE: false
#APP_DEBUG: true
strategy:
fail-fast: false
Expand Down Expand Up @@ -73,6 +76,15 @@ jobs:
image: rabbitmq
ports:
- 5672:5672
meilisearch:
image: getmeili/meilisearch:latest
env:
MEILI_MASTER_KEY: masterKey
MEILI_NO_ANALYTICS: true
MEILI_ENV: development
MEILI_DB_PATH: data.ms
ports:
- 7700:7700
steps:
- uses: actions/checkout@v3

Expand Down Expand Up @@ -109,32 +121,8 @@ jobs:
- name: Install Composer dependencies
run: composer install --prefer-dist --no-interaction --no-progress

- name: Run Migrations
run: php artisan migrate

- name: Run Inventory Migrations
run: php artisan migrate --path database/migrations/Inventory/ --database inventory

- name: Run Social Migrations
run: php artisan migrate --path database/migrations/Social/ --database social

- name: Run Guild Migrations
run: php artisan migrate --path database/migrations/Guild/ --database crm

- name: Run Seeders
run: php artisan db:seed

- name: Create Role Admin
run: php artisan kanvas:create-role Admin

- name: Create Role Users
run: php artisan kanvas:create-role Users

- name: Create Role Agents
run: php artisan kanvas:create-role Agents

- name: Set filesystem configs
run: php artisan kanvas:filesystem-setup
- name: Setup Kanvas Ecosystem
run: php artisan kanvas:setup-ecosystem

- name: Run Tests
if: success()
Expand Down
21 changes: 21 additions & 0 deletions 1.x.Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
FROM mctekk/kanvasapp:8.2-alpine

# Set working directory
WORKDIR /app

# Add user for laravel application
RUN addgroup -g 1000 www
RUN adduser -u 1000 -s /bin/sh --disabled-password -G www www

# Copy code to /var/www
COPY --chown=www:www-data . /app

RUN composer install --no-dev --optimize-autoloader

# add root to www group
RUN chmod -R ug+w /app/storage

RUN cp docker/docker-php-ext-opcache-prod.ini /usr/local/etc/php/conf.d/docker-php-ext-opcache.ini
RUN cp docker/php.ini /usr/local/etc/php/conf.d/zx-app-config.ini

WORKDIR /var/www/html
13 changes: 9 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,17 @@ Todo:

3. Get inside the php container using ```docker exec -it php bash```.

4. Use the command ```php artisan migrate``` to migrate all kanvas migrations file.
4. Create 3 databases `inventory`, `social`, `crm`, update your .env with the connection info

5. Use the command ```php artisan db:seed --class=DatabaseSeeder``` to seed the database with an app, role and default system modules.
5. Check the .env and setup correctly the `REDIS` parameters and your database connections before running the setup-ecosystem

6. Generate app keys `php artisan key:generate`
6. Use the command ```php artisan kanvas:setup-ecosystem``` to run the kanvas setup

7. To check if the API is working just make a GET request to ```http://localhost:80/v1/``` and see if the response returns ```"Woot Kanvas"```
7. If you're presenting some errors after running the command from before, drop all the tables from the schema `kanvas_laravel` and run it again

8. Generate app keys `php artisan key:generate`

9. To check if the API is working just make a GET request to ```http://localhost:80/v1/``` and see if the response returns ```"Woot Kanvas"```

### Setup Inventory
1. php artisan migrate --path database/migrations/Inventory/ --database inventory
Expand Down Expand Up @@ -97,6 +101,7 @@ After doing all the steps above, you could run the project with Laravel Octane b

Use `--watch` in development allowing you to refresh modified files , this works assuming to have `npm install chokidar` installed in the project.
****

Note:
- To install Swoole you can use the command ```pecl install swoole```
- For production remove `--watch` from the command.
Expand Down
19 changes: 13 additions & 6 deletions app/Console/Commands/CreateRoleCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@

namespace App\Console\Commands;

use Bouncer;
use Illuminate\Console\Command;
use Kanvas\AccessControlList\Actions\CreateRoleAction;
use Kanvas\Apps\Models\Apps;

class CreateRoleCommand extends Command
{
Expand All @@ -14,7 +15,7 @@ class CreateRoleCommand extends Command
*
* @var string
*/
protected $signature = 'kanvas:create-role {name}';
protected $signature = 'kanvas:create-role {name} {app_id?}';

/**
* The console command description.
Expand All @@ -25,9 +26,15 @@ class CreateRoleCommand extends Command

public function handle(): void
{
$role = Bouncer::role()->firstOrCreate([
'name' => $this->argument('name'),
'title' => $this->argument('name'),
]);
$roleName = $this->argument('name');
$appId = $this->argument('app_id') ?? Apps::first()->getId();
$createRole = new CreateRoleAction(
$roleName,
$roleName,
Apps::getById($appId)
);
$createRole->execute();

$this->info('Role ' . $roleName . ' created successfully.');
}
}
6 changes: 6 additions & 0 deletions app/Console/Commands/GuildSetupCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use Illuminate\Console\Command;
use Kanvas\Apps\Models\Apps;
use Kanvas\Companies\Models\Companies;
use Kanvas\Guild\Support\Setup;
use Kanvas\Users\Models\Users;

class GuildSetupCommand extends Command
Expand Down Expand Up @@ -37,6 +38,11 @@ public function handle()
$user = Users::getById((int) $this->argument('user_id'));

//todo: add setup class
(new Setup(
$app,
$user,
$company
))->run();

$this->newLine();
$this->info('Guild setup for Company ' . $company->name . ' completed successful');
Expand Down
2 changes: 1 addition & 1 deletion app/Console/Commands/KanvasAppSetupCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class KanvasAppSetupCommand extends Command
*
* @var string
*/
protected $signature = 'kanvas:setup';
protected $signature = 'kanvas:app-create';

/**
* The console command description.
Expand Down
18 changes: 12 additions & 6 deletions app/Console/Commands/KanvasAppUserMigration.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use Kanvas\Apps\Models\Apps;
use Kanvas\Auth\Actions\RegisterUsersAppAction;
use Kanvas\Users\Models\UsersAssociatedApps;
use Throwable;

class KanvasAppUserMigration extends Command
{
Expand Down Expand Up @@ -35,13 +36,18 @@ public function handle()
$appUid = $this->argument('app_uuid');
$app = Apps::getByUuid($appUid);

$users = UsersAssociatedApps::fromApp($app)->notDeleted()->get();
$users = UsersAssociatedApps::fromApp($app)->notDeleted()->orderBy('users_id', 'desc')->get();
foreach ($users as $user) {
$userRegisterInApp = new RegisterUsersAppAction(
$user,
$app
);
$userRegisterInApp->execute($user->password);
try {
$userData = $user->user()->firstOrFail();
$userRegisterInApp = new RegisterUsersAppAction(
$userData,
$app
);
$userRegisterInApp->execute($userData->password);
} catch(Throwable $e) {
$this->error('Error creating user : ' . $user->user_id . ' ' . $e->getMessage());
}
}

return;
Expand Down
Loading

0 comments on commit 6670224

Please sign in to comment.