Skip to content

Commit

Permalink
Merge pull request #77 from PrestaShop/develop
Browse files Browse the repository at this point in the history
MEP 2023-11-08
  • Loading branch information
Progi1984 authored Nov 8, 2023
2 parents 5b7126d + a0e9d49 commit 6cb7cb1
Show file tree
Hide file tree
Showing 12 changed files with 231 additions and 22 deletions.
36 changes: 36 additions & 0 deletions .github/workflows/cd-prestabulle-clean.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
name: APIQANIGHTLY PRESTABULLE CLEANING

on:
pull_request:
types: [closed]
branches:
- develop

env:
LABELS: ${{toJSON(github.event.pull_request.labels)}}

jobs:
apiqanightly_prestabulle:
name: apiqanightly Cleaning Prestabulle
runs-on: ubuntu-latest
timeout-minutes: 25
if: contains(github.event.pull_request.labels.*.name, 'prestabulle1') ||
contains(github.event.pull_request.labels.*.name, 'prestabulle2') ||
contains(github.event.pull_request.labels.*.name, 'prestabulle3')

steps:
- name: Checkout the repository 🎁
uses: actions/checkout@v3

- name: Setting up the Bulle variable for later 💬
run: echo "BULLE=$BULLE$(echo $LABELS > labels.json && cat labels.json | jq -r '.[]|.name'|grep prestabulle)" >> $GITHUB_OUTPUT
id: get_bulle

- name: Trigger clean prestabulle
uses: aurelien-baudet/workflow-dispatch@v2
with:
workflow: prestabulle-clean.yml
repo: PrestaShopCorp/qanightlyresults-cd
inputs: '{ "project": "api-nightly", "bulle": "${{ steps.get_bulle.outputs.BULLE }}"}'
token: ${{ secrets.TERRAFORM_ACCESS_TOKEN }}
ref: 'refs/heads/main'
38 changes: 38 additions & 0 deletions .github/workflows/integration-cd.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
name: Integration CD for QAnightly

on:
pull_request:
types: [opened, reopened, synchronize, labeled]

env:
LABELS: ${{toJSON(github.event.pull_request.labels)}}

jobs:
integration_deployment:
name: Deploy (integration)
runs-on: ubuntu-latest
environment: integration
if: contains(github.event.pull_request.labels.*.name, 'prestabulle1') ||
contains(github.event.pull_request.labels.*.name, 'prestabulle2') ||
contains(github.event.pull_request.labels.*.name, 'prestabulle3')

steps:
- name: Checkout the repository 🎁
uses: actions/checkout@v3

- name: Setting up the Bulle variable for later 💬
run: echo "BULLE=$BULLE$(echo $LABELS > labels.json && cat labels.json | jq -r '.[]|.name'|grep prestabulle)" >> $GITHUB_OUTPUT
id: get_bulle

- name: Get branch name
id: branch
uses: tj-actions/[email protected]

- name: Trigger CI / CD
uses: aurelien-baudet/workflow-dispatch@v2
with:
workflow: integration-cd.yml
repo: PrestaShopCorp/qanightlyresults-cd
inputs: '{ "branch": "${{ steps.branch.outputs.current_branch }}", "bulle": "${{ steps.get_bulle.outputs.BULLE }}", "project": "api-nightly", "repository": "PrestaShop/QANightlyResults"}'
token: ${{ secrets.TERRAFORM_ACCESS_TOKEN }}
ref: 'refs/heads/main'
30 changes: 30 additions & 0 deletions .github/workflows/preproduction-cd.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
name: preprod CD for QAnightly

on:
push:
branches:
- develop

jobs:
preprod_deployment:
name: Deploy (preprod)
runs-on: ubuntu-latest
environment: preproduction
concurrency: preprod-cd

steps:
- name: Checkout the repository 🎁
uses: actions/checkout@v3

- name: Get branch name
id: branch
uses: tj-actions/[email protected]

- name: Trigger CI / CD
uses: aurelien-baudet/workflow-dispatch@v2
with:
workflow: preproduction-cd.yml
repo: PrestaShopCorp/qanightlyresults-cd
inputs: '{ "branch": "${{ steps.branch.outputs.current_branch }}", "project": "api-nightly", "repository": "PrestaShop/QANightlyResults"}'
token: ${{ secrets.TERRAFORM_ACCESS_TOKEN }}
ref: 'refs/heads/main'
29 changes: 29 additions & 0 deletions .github/workflows/production-cd.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
name: production CD for QAnightly

on:
release:
types: [released]

jobs:
production_deployment:
name: Deploy (production)
runs-on: ubuntu-latest
environment: production
concurrency: production-cd

steps:
- name: Checkout the repository 🎁
uses: actions/checkout@v3

- name: Get branch name
id: branch
uses: tj-actions/[email protected]

- name: Trigger CI / CD
uses: aurelien-baudet/workflow-dispatch@v2
with:
workflow: production-cd.yml
repo: PrestaShopCorp/qanightlyresults-cd
inputs: '{ "branch": "${{ steps.branch.outputs.current_branch }}", "project": "api-nightly", "repository": "PrestaShop/QANightlyResults"}'
token: ${{ secrets.TERRAFORM_ACCESS_TOKEN }}
ref: 'refs/heads/main'
29 changes: 26 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,21 @@
FROM php:7.1-apache
FROM php:7.2-apache as builder

RUN apt-get update && \
apt-get install -y \
git \
zip

WORKDIR "/var/www/html/"

RUN curl --insecure https://getcomposer.org/composer.phar -o /usr/bin/composer && chmod +x /usr/bin/composer

COPY . /var/www/html

RUN composer update && \
composer install


FROM php:7.2-apache

RUN apt-get update && \
apt-get install -y \
Expand All @@ -7,16 +24,22 @@ RUN apt-get update && \
libfreetype6-dev \
libjpeg62-turbo-dev \
libpng-dev && \
openssl && \
apt-get clean && \
rm -rf /var/lib/apt/lists/*

RUN docker-php-ext-install pdo_mysql gd mysqli && \
docker-php-ext-enable pdo_mysql gd mysqli && \
docker-php-source delete

COPY . /var/www/html
COPY --from=0 /var/www/html/ /var/www/html/
RUN mv /var/www/html/vhost.conf /etc/apache2/sites-enabled/000-default.conf && \
mkdir -p /var/www/html/application/files/ && \
chown -R www-data:www-data /var/www/html && \
a2enmod rewrite
a2enmod rewrite && \
a2enmod ssl && \
a2enmod proxy_http && \
a2enmod headers

RUN sed -i 's/^max_execution_time = .*/max_execution_time = 300/' /usr/local/etc/php/php.ini-production && \
mv "$PHP_INI_DIR/php.ini-production" "$PHP_INI_DIR/php.ini"
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# QANightlyResults

QANightlyResults is an Slim Framewok app, acting as a backend (via a JSON API) to handle
QANightlyResults is a Slim Framework app, acting as a backend (via a JSON API) to handle
and browse tests reports records.

You can use any frontend app you want to consume this API. We use a [Vue app](https://github.com/PrestaShop/nightly-board).
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"ext-json": "*",
"ext-simplexml": "*",
"slim/slim": "4.*",
"slim/psr7": "^0.6.0",
"slim/psr7": "^1.0.0",
"php-di/slim-bridge": "^3.0",
"illuminate/database": "^6.8"
},
Expand Down
9 changes: 9 additions & 0 deletions dbUpgrade.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#!/bin/bash

echo "Launching DB upgrade php script..."

/usr/local/bin/php src/Upgrade/upgrade.php

exitCode=$?

echo "Script ended with this exit code: $exitCode"
46 changes: 46 additions & 0 deletions src/Controller/HealthCheckController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<?php

declare(strict_types=1);

namespace App\Controller;

use Illuminate\Database\Capsule\Manager;
use Illuminate\Database\QueryException;
use Slim\Psr7\Request;
use Slim\Psr7\Response;

class HealthCheckController extends BaseController
{
/**
* Display data for a badge in GitHub
*
* @param Request $request
* @param Response $response
*
* @return Response
*/
public function check(Request $request, Response $response): Response
{
$data = [
'database' => true,
'gcp' => true,
];

// Check database
try {
Manager::table('settings')->first();
} catch (QueryException $e) {
$data['database'] = false;
}

// Check GCP
$gcpCall = file_get_contents(QANB_GCPURL);
if (!$gcpCall) {
$data['gcp'] = false;
}

$response->getBody()->write(json_encode($data));

return $response->withHeader('Content-Type', 'application/json');
}
}
4 changes: 2 additions & 2 deletions src/Controller/ReportController.php
Original file line number Diff line number Diff line change
Expand Up @@ -700,7 +700,7 @@ private function loopThrough(int $executionId, stdClass $suite, ?int $parentSuit
if (isset($test->context)) {
try {
$identifier_data = json_decode($test->context);
$identifier = $identifier_data->value;
$identifier = is_array($identifier_data) ? $identifier_data[0]->value : $identifier_data->value;
} catch (Exception $e) {
}
}
Expand Down Expand Up @@ -768,7 +768,7 @@ private function loopThroughSuite(int $executionId, stdClass $suite, ?int $paren
if (isset($test->context)) {
try {
$identifier_data = json_decode($test->context);
$identifier = $identifier_data->value;
$identifier = is_array($identifier_data) ? $identifier_data[0]->value : $identifier_data->value;
} catch (Exception $e) {
// Don't care if it fails
}
Expand Down
4 changes: 4 additions & 0 deletions src/routes.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use App\Controller\DataController;
use App\Controller\GraphController;
use App\Controller\HealthCheckController;
use App\Controller\ReportController;
use Slim\App;
use Slim\Psr7\Request;
Expand Down Expand Up @@ -36,4 +37,7 @@ function loadRoutes(App $app): void
//data routes
$app->get('/data/badge', [DataController::class, 'badge']);
$app->get('/data/badge/svg', [DataController::class, 'svg']);

// healthcheck
$app->get('/healthcheck', [HealthCheckController::class, 'check']);
}
24 changes: 9 additions & 15 deletions vhost.conf
Original file line number Diff line number Diff line change
@@ -1,21 +1,15 @@
<VirtualHost *:80>
DocumentRoot "/var/www/html/PROJECT/public"
ServerName api.domain.com
ServerAdmin [email protected]
ServerName api-nightly.prestashop.com
ServerAlias integration-api-nightly.prestashop.com
DocumentRoot "/var/www/html/public/"

<Directory "/var/www/html/PROJECT/public/">
Header set Access-Control-Allow-Origin "*"

<Directory "/var/www/html/public/">
Options FollowSymLinks Indexes MultiViews
AllowOverride All
# replace the * by the full URL of your front eg. "https://www.domain.com"
Header set Access-Control-Allow-Origin "*"
# "testing" or "staging" to see errors
SetEnv QANB_ENV "production"
SetEnv QANB_DB_HOST "localhost"
SetEnv QANB_DB_USERNAME "root"
SetEnv QANB_DB_PASSWORD ""
SetEnv QANB_DB_NAME "qanightlyresults"
# replace "token" by your token value eg. "gfs5hkomhgSJh2sfhgs7Qdsv0"
SetEnv QANB_TOKEN "token"
SetEnv QANB_GCPURL "https://storage.googleapis.com/prestashop-core-nightly/"
SetEnv CI_ENV "production"
Require all granted
</Directory>
</VirtualHost>
</VirtualHost>

0 comments on commit 6cb7cb1

Please sign in to comment.