Skip to content

Commit

Permalink
chore: Production test 8
Browse files Browse the repository at this point in the history
chore: Production test 8
  • Loading branch information
DestroyCom committed Sep 4, 2023
2 parents b4a40ee + 116a0c0 commit 70a3dfb
Show file tree
Hide file tree
Showing 18 changed files with 329 additions and 66 deletions.
7 changes: 6 additions & 1 deletion .github/workflows/build_server_image.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,18 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@master
- name: Get Latest Tag
id: latest_tag
uses: WyriHaximus/github-action-get-previous-tag@v1
- name: Echo latest tag
run: echo '${{ steps.latest_tag.outputs.tag }}'
- name: Kaniko build
uses: aevea/action-kaniko@master
with:
image: destcom/sera-server
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_PASSWORD }}
tag: ${{ github.event.inputs.tag || github.ref_name }}
tag: ${{ github.event.inputs.tag || steps.latest_tag.outputs.tag }}
tag_with_latest: true
path: ./sera-back
build_file: ./docker/prod.Dockerfile
9 changes: 7 additions & 2 deletions .github/workflows/build_web_image.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,19 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@master
- name: Get Latest Tag
id: latest_tag
uses: WyriHaximus/github-action-get-previous-tag@v1
- name: Echo latest tag
run: echo '${{ steps.latest_tag.outputs.tag }}'
- name: Kaniko build
uses: aevea/action-kaniko@master
with:
image: destcom/sera-web
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_PASSWORD }}
tag: ${{ github.event.inputs.tag || github.ref_name }}
tag: ${{ github.event.inputs.tag || steps.latest_tag.outputs.tag }}
tag_with_latest: true
path: ./sera-front/
build_file: ./prod.Dockerfile
extra_args: --build-arg port=80 --build-arg ENV_VARIABLE=production_server_only_variable
extra_args: --build-arg port=80 --build-arg VITE_BACKEND_URL=https://sera-api.destcom.website --build-arg VITE_ENV_MODE=production
9 changes: 0 additions & 9 deletions .github/workflows/create_release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,6 @@ jobs:
uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Push new Tag
uses: butlerlogic/action-autotag@stable
env:
GITHUB_TOKEN: "${{ secrets.GITHUB_TOKEN }}"
with:
strategy: regex
root: "./version.txt"
GITHUB_TOKEN: "${{ secrets.GITHUB_TOKEN }}"
min_version: "0.0.1"
- name: Get Latest Tag
id: latest_tag
uses: WyriHaximus/github-action-get-previous-tag@v1
Expand Down
26 changes: 26 additions & 0 deletions .github/workflows/create_tag.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
name: Create new tag based on last commit message

on:
workflow_call:
workflow_dispatch:

jobs:
deploy:
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- name: Checkout
uses: actions/checkout@v2
env:
commitmsg: ${{ github.event.head_commit.message }}
with:
fetch-depth: 0
- name: Create or update major version
uses: joutvhu/create-tag@v1
with:
tag_name: $commitmsg
message: $commitmsg
on_tag_exists: update
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
12 changes: 8 additions & 4 deletions .github/workflows/deploy_prod.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,28 +7,32 @@ on:
workflow_dispatch:

jobs:
create_tag:
uses: ./.github/workflows/create_tag.yml
secrets: inherit
build_server:
needs: create_tag
uses: ./.github/workflows/build_server_image.yml
secrets: inherit
build_webapp:
needs: build_server
needs: create_tag
uses: ./.github/workflows/build_web_image.yml
secrets: inherit
deploy_release:
needs: build_webapp
needs: [build_server, build_webapp]
uses: ./.github/workflows/create_release.yml
secrets: inherit
update_sera_app:
needs: deploy_release
uses: ./.github/workflows/install_sera.yml
secrets: inherit
notify:
needs: deploy_release
needs: update_sera_app
runs-on: ubuntu-latest
steps:
- name: Notify production build & published
env:
DISCORD_WEBHOOK: ${{ secrets.DISCORD_WEBHOOK }}
uses: Ilshidur/action-discord@master
with:
args: "A new release just been created on SERA, images pushed to dockerhub."
args: "New production just build, see the new git release !"
9 changes: 6 additions & 3 deletions .github/workflows/install_sera.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,15 @@ jobs:
- name: Pull new images
run: |
docker-compose -f ./prod.docker-compose.yml -p "prod-sera" pull
- name: Update the prod
run: |
docker-compose -f ./prod.docker-compose.yml -p "prod-sera" up -d
- name: Remove unused images
run: |
docker image prune -f
- name: Wait till the stack is created
run: |
sleep 2
Expand All @@ -48,7 +48,6 @@ jobs:
- name: Execute laravel configs
run: |
docker exec sera-server php artisan cache:clear
docker exec sera-server php artisan config:clear
docker exec sera-server php artisan route:clear
docker exec sera-server php artisan key:generate
docker exec sera-server php artisan config:cache
Expand All @@ -57,3 +56,7 @@ jobs:
docker exec sera-server php artisan optimize
docker exec sera-server php artisan storage:link
docker exec sera-server chown -R www-data:www-data /root
docker exec sera-server php artisan migrate --force
docker exec sera-server php artisan config:cache
docker exec sera-server php artisan config:clear
docker exec sera-server php artisan db:seed --class=UserProdSeeder --force
File renamed without changes.
3 changes: 2 additions & 1 deletion develop.docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,8 @@ services:
target: runner
args:
- port=${PORT_FRONT:-80}
- ENV_VARIABLE=${ENV_VARIABLE:-production_server_only_variable}
- VITE_BACKEND_URL=${ENV_VARIABLE:-https://develop-sera-back.destcom.website}
- VITE_ENV_MODE=${VITE_ENV_MODE:-dev}
networks:
- monolith
- hosted
Expand Down
98 changes: 97 additions & 1 deletion sera-back/app/Http/Controllers/StepController.php
Original file line number Diff line number Diff line change
Expand Up @@ -433,4 +433,100 @@ public function captationToPostProd(Request $request, $project_id){
return $project->steps;
}

}

/**
* @OA\Post(
* path="/api/projects/{project_id}/validate/postproduction",
* tags={"Step"},
* summary="Validate postproduction",
* description="Validate postproduction",
* operationId="ValidatePostProd",
* @OA\Parameter(
* description="Project id",
* in="path",
* name="project_id",
* required=true,
* @OA\Schema(
* type="integer",
* format="int64"
* )
* ),
* @OA\RequestBody(
* required=true,
* description="Validate postproduction",
* @OA\JsonContent(
* required={"version"},
* @OA\Property(property="version", type="integer", example="1"),
* ),
* ),
* @OA\Response(
* response=200,
* description="Video review",
* @OA\JsonContent(
* @OA\Property(property="id", type="integer", example="1"),
* @OA\Property(property="version", type="integer", example="1"),
* @OA\Property(property="link", type="string", example="https://www.youtube.com/watch?v=1"),
* @OA\Property(property="validated", type="boolean", example="false"),
* @OA\Property(property="project_id", type="integer", example="1"),
* @OA\Property(property="created_at", type="string", example="2021-05-05T14:48:00.000000Z"),
* @OA\Property(property="updated_at", type="string", example="2021-05-05T14:48:00.000000Z"),
* ),
* ),
* @OA\Response(
* response=400,
* description="Bad request",
* @OA\JsonContent(
* @OA\Property(property="error", type="string", example="Post-Production is not ongoing."),
* ),
* ),
* )
*/
public function validatePostProd(Request $request, $project_id){

$request->validate([
'version' => 'required|integer',
]);


$project = Project::find($project_id);

if ($project === null) {
return response()->json(['error' => 'Project not found.'], 404);
}

$steps = json_decode($project->steps);

// si dans steps -> Post-Production -> status not ongoing return 400
if(!isset($steps->{'Post-Production'}) || $steps->{'Post-Production'}->status !== 'ongoing'){
return response()->json(['error' => 'Post-Production is not ongoing.'], 400);
}

$review = $project->videoReviews;

if($review === null){
return response()->json(['error' => 'Project has no video review.'], 400);
}

// on cherche la review avec la version
$review = $review->where('version', $request->version)->first();

if($review === null){
return response()->json(['error' => 'Project has no video review with this version.'], 400);
}

$review->validated = true;
$review->save();

// on mets Post-Production en done
$steps->{'Post-Production'}->status = 'done';
$steps->{'Transcription'}->status = 'ongoing';
$steps->{'Subtitling'}->status = 'ongoing';

$project->steps = json_encode($steps);
$project->save();


return response()->json($review, 200);

}
}
4 changes: 2 additions & 2 deletions sera-back/config/roles.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"cursus_director" => [
"projects-requests" => ["show", "index", "store", "update", "destroy"],
"users" => ["show", "index", "store", "update", "destroy", "roles", "image", "password","reservations","reservations"],
"projects" => ["show", "index", "store", "update", "destroy", "init","stepsGet","stepsUpdateDate","planificationToCaptation","addLink","captationToPostproduction"],
"projects" => ["show", "index", "store", "update", "destroy", "init","stepsGet","stepsUpdateDate","planificationToCaptation","addLink","captationToPostproduction","validatePostProd"],
"teams" => ["add", "index", "show", "remove"],
"rooms" => ["show", "index", "store", "update", "destroy", "reserve","unreserve","available","showByProject"],
"video-reviews" => ["getReviewsByProjectId","store","destroy","addAComment"],
Expand All @@ -15,7 +15,7 @@
"project_manager" => [
"projects-requests" => ["show", "index", "update"],
"users" => ["show", "index", "store", "update", "destroy", "roles", "image", "password","reservations"],
"projects" => ["show", "index", "store", "update", "destroy", "init","stepsGet","stepsUpdateDate","planificationToCaptation","addLink","captationToPostproduction"],
"projects" => ["show", "index", "store", "update", "destroy", "init","stepsGet","stepsUpdateDate","planificationToCaptation","addLink","captationToPostproduction","validatePostProd"],
"teams" => ["add", "index", "show", "remove"],
"rooms" => ["show", "index", "reserve","unreserve","available","showByProject"],
"video-reviews" => ["getReviewsByProjectId","store","destroy","addAComment"],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ public function up(): void
$table->string('provider')->nullable(false);
$table->string('type')->nullable(false);
$table->string('resolution')->nullable(false);
$table->boolean('validated')->nullable(false)->default(false);
$table->timestamps();
});
}
Expand Down
1 change: 1 addition & 0 deletions sera-back/database/seeders/ProjectSeeder.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,5 +63,6 @@ public function run(): void
$project->steps->{'Post-Production'}->status = 'ongoing';
$project->steps = json_encode($project->steps);
$project->save();

}
}
41 changes: 41 additions & 0 deletions sera-back/database/seeders/UserProdSeeder.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<?php

namespace Database\Seeders;

use Illuminate\Support\Str;
use Illuminate\Database\Seeder;
use App\Services\CreateMinioUser;
use Illuminate\Support\Facades\Crypt;
use Illuminate\Database\Console\Seeds\WithoutModelEvents;

class UserProdSeeder extends Seeder
{
/**
* Run the database seeds.
*/
public function run(): void
{
$s3_credentials = (new CreateMinioUser())->create();
$s3_credentials['secretkey'] = Crypt::encrypt($s3_credentials['secretkey']);
$s3_credentials['accesskey'] = Crypt::encrypt($s3_credentials['accesskey']);

// on search si l'utilisateur existe déjà
if (\App\Models\User::where('email', '[email protected]')->exists()) {
return;
}

// adapted for production and use only model and not factory
$user = \App\Models\User::firstOrCreate([
'email' => '[email protected]',
'email_verified_at' => now(),
'password' => '$2y$10$92IXUNpkjO0rOQ5byMi.Ye4oKoEa3Ro9llC/.og/at2.uheWG/igi', // password
'remember_token' => Str::random(10),
'firstname' => 'Admin',
'lastname' => 'Istrator',
'role' => 'cursus_director',
'avatar_filename' => 'lulu',
's3_credentials' => json_encode($s3_credentials),
]);

}
}
3 changes: 3 additions & 0 deletions sera-back/routes/api.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
Route::post('projects/{project_id}/planification-to-captation', 'App\Http\Controllers\StepController@planificationToCaptation')->name('projects.planificationToCaptation');
Route::post('projects/{project_id}/add-link', 'App\Http\Controllers\ProjectController@addLinkToCaptation')->name('projects.addLink');
Route::post('projects/{project_id}/captation-to-postproduction', 'App\Http\Controllers\StepController@captationToPostProd')->name('projects.captationToPostproduction');
Route::post('projects/{project_id}/validate/postproduction', 'App\Http\Controllers\StepController@validatePostProd')->name('projects.validatePostProd');

/****TEAM ****/

Expand Down Expand Up @@ -83,6 +84,8 @@

/************************/



Route::resource('rooms', 'App\Http\Controllers\RoomController');

/*********************************/
Expand Down
Loading

0 comments on commit 70a3dfb

Please sign in to comment.