Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(remote-sync): Enable remote syncing based on an API response #1506

Merged
merged 2 commits into from
Sep 21, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
19 changes: 19 additions & 0 deletions build/ApiRsyncPlugin.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
const { execSync } = require('child_process');

function ApiRsyncPlugin(source, destination) {
this.source = source;
this.destination = destination;
}

/* eslint-disable no-console */
ApiRsyncPlugin.prototype.apply = function rsync(compiler) {
compiler.plugin('done', () => {
console.log('');
console.log(`🔄 🔄 🔄 Rsync starting for ${this.source} 🔄 🔄 🔄`);
execSync(`rsync -avz -e "ssh -p 8022 -o ConnectTimeout=3" ${this.source} ${this.destination}`, {
stdio: [0, 1, 2],
});
});
};

module.exports = ApiRsyncPlugin;
19 changes: 19 additions & 0 deletions build/webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,25 @@ const isDev = NODE_ENV === 'dev';
const isProd = NODE_ENV === 'production';

const fs = require('fs');
const get = require('lodash/get');
const path = require('path');
const locales = require('@box/languages');
const OptimizeCssAssetsPlugin = require('optimize-css-assets-webpack-plugin');
const UglifyJsPlugin = require('uglifyjs-webpack-plugin');

const { execSync } = require('child_process');
const commonConfig = require('./webpack.common.config');
const RsyncPlugin = require('./RsyncPlugin');
const ApiRsyncPlugin = require('./ApiRsyncPlugin');
const version = isProd ? require('../package.json').version : 'dev';

let rsyncLocation = '';
let rsyncApiLocation = null;
if (fs.existsSync('build/rsync.json')) {
/* eslint-disable */
const rsyncConf = require('./rsync.json');
rsyncLocation = rsyncConf.location;
rsyncApiLocation = rsyncConf.apiLocation;
/* eslint-enable */
}

Expand Down Expand Up @@ -78,6 +83,20 @@ function updateConfig(conf, language, index) {
if (rsyncLocation) {
config.plugins.push(new RsyncPlugin('dist/.', rsyncLocation));
}

if (rsyncApiLocation) {
TylerGauntlett marked this conversation as resolved.
Show resolved Hide resolved
const serverResponse = execSync(
`curl -sk -H "Content-Type: application/json" --connect-timeout 1 ${rsyncApiLocation.url}`,
)
.toString()
.replace('\n', '');

const json = JSON.parse(serverResponse);

const destination = `${rsyncApiLocation.user}@${get(json, rsyncApiLocation.ip)}:${rsyncApiLocation.path}`;

config.plugins.push(new ApiRsyncPlugin('dist/.', destination));
}
}

if (isProd) {
Expand Down