Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ README.md
.phpunit.result.cache
.styleci.yml
/docker/
!docker/php-fpm.d/www.conf

phpunit.xml
/tests/
Expand Down
17 changes: 10 additions & 7 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ on:
pull_request:
branches:
- production
workflow_dispatch:

env:
IMAGE_NAME: "lumen-actions-sandbox"
Expand All @@ -23,13 +24,12 @@ jobs:

steps:
- uses: actions/checkout@v2
with:
php-version: '7.4'
tools: pecl
- name: Set PHP version to 7.4
run: sudo update-alternatives --set php /usr/bin/php7.4
- name: Copy .env
run: php -r "file_exists('.env') || copy('.env.example', '.env');"
- name: Install Dependencies
run: composer install --no-interaction --no-scripts --no-progress --prefer-dist
run: composer install --no-interaction --no-scripts --no-progress --prefer-dist --classmap-authoritative
- name: Directory Permissions
run: mkdir -p storage bootstrap/cache && chmod -R 777 storage bootstrap/cache
- name: Execute tests (Unit and Feature tests) via PHPUnit
Expand All @@ -40,14 +40,17 @@ jobs:
run: |
echo "::set-env name=IMAGE_NAME::$IMAGE_NAME_PRODUCTION"

- name: Create version.json
run: |
php artisan deploy:version ${{ github.run_number }} ${{ github.head_ref }} >storage/versions.json

- name: Build the Docker image
run: |
php artisan version ${{ github.run_number }} ${{ github.head_ref }} >storage/version.env
docker build . --file docker/Dockerfile \
--tag "$IMAGE_NAME":"$GITHUB_RUN_NUMBER" \
--tag "$REPO_ROOT"/"$GCP_PROJECT"/"$IMAGE_NAME":"$GITHUB_RUN_NUMBER"

- uses: GoogleCloudPlatform/github-actions/setup-gcloud@master
- uses: google-github-actions/setup-gcloud@master
with:
service_account_key: ${{ secrets.GCP_KEY }}
# Configure docker to use the gcloud command-line tool as a credential helper
Expand All @@ -72,7 +75,7 @@ jobs:
run: |
echo "::set-env name=GCP_PROJECT::$GCP_PROJECT_PRODUCTION"

- uses: GoogleCloudPlatform/github-actions/setup-gcloud@master
- uses: google-github-actions/setup-gcloud@master
with:
service_account_key: ${{ secrets.GCP_KEY }}

Expand Down
4 changes: 4 additions & 0 deletions .github/workflows/env.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ jobs:

steps:
- uses: actions/checkout@v2
- name: Set PHP version to 7.4
run: sudo update-alternatives --set php /usr/bin/php7.4
- name: Environment
run: |
echo github.event: ${{ github.event }}
Expand All @@ -31,3 +33,5 @@ jobs:
echo github.head_ref: ${{ github.head_ref }}
echo github.base_ref: ${{ github.base_ref }}
env
php -version
update-alternatives --list php
23 changes: 16 additions & 7 deletions app/Console/Commands/VersionCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@ class VersionCommand extends Command
*
* @var string
*/
protected $signature = 'version {run_number?} {ref?}';
protected $signature = 'deploy:version {run_number?} {ref?}';

/**
* The console command description.
*
* @var string
*/
protected $description = 'Read and print a .Net Approvals file';
protected $description = 'Create a versions file';

/**
* Create a new command instance.
Expand Down Expand Up @@ -47,10 +47,19 @@ public function handle()
);

$hash = exec("git rev-parse --short HEAD");
$this->info("MAJOR = 1");
$this->info("MINOR = 0");
$this->info("PATCH = $run_number");
$this->info("SHORT_HASH = $hash");
$this->info("BRANCH = " . $branch);
$date = exec("git show -s --format=%ci {$hash}");

$versions = [
'groupvitals-ccb' => [
'major' => 1,
'minor' => 0,
'patch' => $run_number,
'branch' => $branch,
'hash' => $hash,
'date' => $date
],
'lumen' => 'v6.3.5'
];
echo json_encode($versions, JSON_PRETTY_PRINT);
}
}
3 changes: 2 additions & 1 deletion app/Console/Kernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace App\Console;

use App\Console\Commands\VersionCommand;
use Illuminate\Console\Scheduling\Schedule;
use Laravel\Lumen\Console\Kernel as ConsoleKernel;

Expand All @@ -13,7 +14,7 @@ class Kernel extends ConsoleKernel
* @var array
*/
protected $commands = [
\App\Console\Commands\VersionCommand::class
VersionCommand::class
];

/**
Expand Down
52 changes: 37 additions & 15 deletions app/Http/Controllers/StatusController.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@

namespace App\Http\Controllers;

use \Illuminate\Support\Env;
use Illuminate\Support\Str;

class StatusController extends Controller
{

private $logger;
/**
* StatusController constructor.
*/
Expand All @@ -15,18 +15,40 @@ public function __construct()
}

public function index() {
$dotenv = \Dotenv\Dotenv::create('/usr/local/gv-ccb', '.version');
$version = $dotenv->load();

return response()->json(
[
'app' => "{$version['MAJOR']}.{$version['MINOR']}.{$version['PATCH']}-{$version['SHORT_HASH']}",
'mysql' => '5.7',
'lumen' => '6.0',
'version' => $version,
'env' => getenv(),
'Env' => Env::getVariables()
]
);
$lumen_version = "v6.0";
try {
$versions_json = json_decode(
file_get_contents(storage_path('versions.json'))
);
if (filled($versions_json->{'groupvitals-ccb'})) {
$ccb_version = $versions_json->{'groupvitals-ccb'};
$version = filled($ccb_version) ?
"{$ccb_version->major}.{$ccb_version->minor}.{$ccb_version->patch}" : "";
if (filled($ccb_version->branch) && !Str::endsWith($ccb_version->branch, 'production')) {
$version = "${version}-" . Str::slug($ccb_version->branch, '_');
}
if (filled($ccb_version->hash)) {
$version = "${version}-{$ccb_version->hash}";
}
if(filled($ccb_version->date)) {
$version .= " on {$ccb_version->date}";
}
}
if(filled($versions_json->lumen)) {
$lumen_version = $versions_json->lumen;
}
} catch (\Exception $exception) {
$this->logger->error("Could not load version.json: {$exception->getMessage()}");
$version = "unknown";
}
$status = [
env('APP_NAME') => $version,
'lumen' => $lumen_version,
'mysql' => '5.7.25-google-log', // TODO read from DB::connection()...
];
if (env('APP_DEBUG', false)) {
$status['Environment'] = $_ENV;
}
return response()->json($status);
}
}
5 changes: 5 additions & 0 deletions docs/_config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
theme: jekyll-theme-slate

title: Lumen, GH-Actions and GCP Sandbox
description: A place to experiment with and learn about Lumen, Github Actions and Google Cloud Platform.

Loading