Skip to content

Commit

Permalink
feat: add fortrabbit configuration (#617)
Browse files Browse the repository at this point in the history
  • Loading branch information
asbiin committed Mar 14, 2021
1 parent 9e04c87 commit 4dda54d
Show file tree
Hide file tree
Showing 3 changed files with 126 additions and 1 deletion.
61 changes: 61 additions & 0 deletions .github/workflows/build-assets.yml
Original file line number Diff line number Diff line change
Expand Up @@ -100,3 +100,64 @@ jobs:
echo "::error::Resources are not up to date. Please rebuild with: 'yarn run lint:all' and 'yarn run prod'."
exit -1
fi
- name: Store assets
uses: actions/upload-artifact@v2
with:
name: assets
path: |
public/mix-manifest.json
public/js
public/css
public/fonts
######################
# Deploy on fortrabbit
######################
deploy:
runs-on: ubuntu-latest
name: Deploy
needs: build
if: github.event_name != 'pull_request'

environment: fortrabbit

steps:
- name: Checkout repository
uses: actions/checkout@v2
with:
fetch-depth: 0

- uses: webfactory/ssh-agent@v0.5.0
with:
ssh-private-key: ${{ secrets.SSH_PRIVATE_KEY }}

- name: Download assets
uses: actions/download-artifact@v2
with:
name: assets
path: public

- name: Configure Git
run: |
git config user.email $GIT_EMAIL
git config user.name $GIT_USERNAME
env:
GIT_EMAIL: ${{ secrets.GIT_EMAIL }}
GIT_USERNAME: ${{ secrets.GIT_USERNAME }}

- name: Commit everything
run: |
git add -A --force public
git commit -m "Build $($CURRENT_DATE_TIME)"
env:
CURRENT_DATE_TIME: "date +%Y-%m-%d:%H-%M"

- name: Deploy
run: |
git push --force $REPO_URL
env:
# This avoids a failure when the client does not know the SSH Host already
GIT_SSH_COMMAND: "ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no"
REPO_URL: ${{ secrets.REPO_URL }}
51 changes: 50 additions & 1 deletion config/cache.php
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
<?php

use Illuminate\Support\Arr;
use Illuminate\Support\Str;

return [
$config = [

/*
|--------------------------------------------------------------------------
Expand Down Expand Up @@ -104,3 +105,51 @@
'prefix' => env('CACHE_PREFIX', Str::slug(env('APP_NAME', 'laravel'), '_').'_cache'),

];

// on fortrabbit: construct credentials from App secrets
if (getenv('APP_SECRETS')) {
$secrets = json_decode(file_get_contents(getenv('APP_SECRETS')), true);
$servers = [[
'host' => $secrets['MEMCACHE']['HOST1'],
'port' => $secrets['MEMCACHE']['PORT1'],
'weight' => 100,
]];
if ($secrets['MEMCACHE']['COUNT'] > 1) {
$servers []= [
'host' => $secrets['MEMCACHE']['HOST2'],
'port' => $secrets['MEMCACHE']['PORT2'],
'weight' => 100,
];
}
Arr::set($config, 'stores.memcached.servers', $servers);
}

if (extension_loaded('memcached')) {
$timeout_ms = 50;
$options = [
// Assure that dead servers are properly removed and ...
\Memcached::OPT_REMOVE_FAILED_SERVERS => true,

// ... retried after a short while (here: 2 seconds)
\Memcached::OPT_RETRY_TIMEOUT => 2,

// KETAMA must be enabled so that replication can be used
\Memcached::OPT_LIBKETAMA_COMPATIBLE => true,

// Replicate the data, write it to both memcached servers
\Memcached::OPT_NUMBER_OF_REPLICAS => 1,

// Those values assure that a dead (due to increased latency or
// really unresponsive) memcached server is dropped fast
\Memcached::OPT_POLL_TIMEOUT => $timeout_ms, // milliseconds
\Memcached::OPT_SEND_TIMEOUT => $timeout_ms * 1000, // microseconds
\Memcached::OPT_RECV_TIMEOUT => $timeout_ms * 1000, // microseconds
\Memcached::OPT_CONNECT_TIMEOUT => $timeout_ms, // milliseconds

// Further performance tuning
\Memcached::OPT_NO_BLOCK => true,
];
Arr::set($config, 'stores.memcached.options', $options);
}

return $config;
15 changes: 15 additions & 0 deletions fortrabbit.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# differentiate from the deployment files
version: 2

# optional Composer settings
composer:
# Resolves to the --no-dev parameter
no-dev: true

# called after Composer runs
post: artisan setup --force -vvv

# list of sustained folders in ~/htdocs. If not given, then it defaults to the "vendor" folder
sustained:
- storage
- vendor

0 comments on commit 4dda54d

Please sign in to comment.