Per region ENV variables

Hi again, I was wondering if there was anything like per region ENV varibles? I’d like to host the same app in two different locations (one in dallas, one in london) that would have separate env variables but under the same deployments, is this possible? or am i better off making 2 deploy workers in github for separate projects

Hi Robert, I had a similar issue to solve. I wanted to only run a set of jobs on my “primary” server in dfw but not on my other regions. The way I got this to work is to tap into the FLY_REGION env variable at deploy time. FLY_REGION is always set to the Fly region name that the server is deployed to. I also statically set a PRIMARY_REGION env in my environment file to indicate to the servers which region I consider my “primary”.

my config file:::

'server-region' => strtolower(env('FLY_REGION')),

'primary-region' => strtolower(env('PRIMARY_REGION')),

Then in my jobs definition, I just compare what region my server is deployed to and the PRIMARY_REGION to adjust what processing happens:::

$schedule->job(new UpdateCurrencyJob)->everyFourHours();

if (config('server-region') == config('primary-region')) {
    $schedule->command('airportdata:fetch --withping')->timezone('Australia/Sydney')->dailyAt('17:00');

    // Global Runways
    $schedule->command('runwaydata:update --withping')->timezone('Australia/Sydney')->dailyAt('17:10');

So you could do something like :::

if (env('FLY_REGION') == 'lhr') {

Cheers, Tom

1 Like

Thanks for the insight tom! I’ll give your option a whirl, appreciate the run down as well. I’m currently trying to achieve this with database details but I definitely think I can achieve it with how you did it.