Skip to content

Commit

Permalink
chore: Forced config URL (#9735)
Browse files Browse the repository at this point in the history
  • Loading branch information
Yserz authored Sep 28, 2020
1 parent ddbda34 commit 43e2380
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 36 deletions.
50 changes: 16 additions & 34 deletions .copyconfigrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
const pkg = require('./package.json');
const appConfigPkg = require('./app-config/package.json');
const {execSync} = require('child_process');
require('dotenv').config();

/**
* Selects configuration based on current branch and tagged commits
Expand All @@ -31,48 +32,29 @@ const selectConfiguration = () => {
console.log(`Selecting configuration "${distribution}" (reason: custom distribution)`);
return distribution;
}
let currentBranch = '';
let currentTag = '';

try {
currentBranch = execSync('git rev-parse --abbrev-ref HEAD').toString().trim();
} catch (error) {}
try {
currentTag = execSync('git tag -l --points-at HEAD').toString().trim();
} catch (error) {}

switch (currentBranch) {
case 'dev': {
// On staging bump use production config
if (currentTag.includes('staging')) {
console.log(`Selecting configuration "master" (reason: branch "${currentBranch}" & tag "${currentTag}")`);
return 'master';
}
// When merging master back to dev with the last commit being a production release tag
// And for all other cases
console.log(`Selecting configuration "staging" (reason: branch "${currentBranch}")`);
return 'staging';
}
case 'master': {
// On production release use production config
if (currentTag.includes('production')) {
console.log(`Selecting configuration "master" (reason: branch "${currentBranch}" & tag "${currentTag}")`);
return 'master';
}
// When merging dev into master with the last commit being a staging bump tag
// And for all other cases
console.log(`Selecting configuration "staging" (reason: branch "${currentBranch}")`);
return 'staging';
}
default: {
console.log('Selecting configuration "staging" (reason: default)');
return 'staging';
}
if (currentTag.includes('staging') || currentTag.includes('production')) {
console.log(`Selecting configuration "master" (reason: tag "${currentTag}")`);
return 'master';
}

console.log('Selecting configuration "staging" (reason: default)');
return 'staging';
};

const configurationEntry = `wire-web-config-default-${selectConfiguration()}`;
const repositoryUrl = appConfigPkg.dependencies[configurationEntry];
let repositoryUrl;
const forcedConfigUrl = process.env.FORCED_CONFIG_URL;
if (forcedConfigUrl) {
console.log(`Selecting configuration "${forcedConfigUrl}" (reason: forced config URL)`);
repositoryUrl = forcedConfigUrl;
} else {
const configurationEntry = `wire-web-config-default-${selectConfiguration()}`;
repositoryUrl = appConfigPkg.dependencies[configurationEntry];
}

console.log('Repo URL', repositoryUrl);

Expand Down
6 changes: 4 additions & 2 deletions .env.localhost
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@

PORT="8081"

FORCED_CONFIG_URL="https://github.com/wireapp/wire-web-config-master"

APP_BASE="https://localhost:8081"
BACKEND_REST="https://prod-nginz-https.wire.com"
BACKEND_WS="wss://prod-nginz-ssl.wire.com"
#BACKEND_REST="https://staging-nginz-https.zinfra.io"
#BACKEND_WS="wss://staging-nginz-ssl.zinfra.io"
# BACKEND_REST="https://staging-nginz-https.zinfra.io"
# BACKEND_WS="wss://staging-nginz-ssl.zinfra.io"
CSP_EXTRA_CONNECT_SRC="http://localhost:32123, ws://localhost:32123, https://*.zinfra.io, https://*.wire.com, wss://*.zinfra.io, wss://prod-nginz-ssl.wire.com, https://wire.count.ly"
CSP_EXTRA_IMG_SRC="https://*.zinfra.io, https://*.wire.com"
CSP_EXTRA_SCRIPT_SRC="http://localhost:32123, https://*.zinfra.io, https://*.wire.com"
Expand Down

0 comments on commit 43e2380

Please sign in to comment.