fix: only setup triton when composing

This commit is contained in:
Sérgio Ramos 2017-05-31 16:08:29 +01:00
parent b6c6139023
commit 2687690407

View File

@ -15,11 +15,13 @@ const NAMESPACE = 'quay.io/yldio';
const ROOT = path.join(__dirname, '..'); const ROOT = path.join(__dirname, '..');
const LOG = console.log; const LOG = console.log;
const createTritonProfile = async ({ SDC_ACCOUNT = '', SDC_KEY_ID = '' }) => { const createTritonProfile = async () => {
LOG( LOG(
`${figures.arrowRight} create triton profile SDC_ACCOUNT=${SDC_ACCOUNT.length} SDC_KEY_ID=${SDC_KEY_ID.length}` `${figures.arrowRight} create triton profile SDC_ACCOUNT=${SDC_ACCOUNT.length} SDC_KEY_ID=${SDC_KEY_ID.length}`
); );
const { SDC_ACCOUNT = '', SDC_KEY_ID = '' } = process.env;
const payload = JSON.stringify({ const payload = JSON.stringify({
url: 'https://eu-ams-1.api.joyent.com', url: 'https://eu-ams-1.api.joyent.com',
account: SDC_ACCOUNT, account: SDC_ACCOUNT,
@ -39,19 +41,21 @@ const createTritonProfile = async ({ SDC_ACCOUNT = '', SDC_KEY_ID = '' }) => {
}; };
const getEnv = async () => { const getEnv = async () => {
await createTritonProfile(process.env); await createTritonProfile();
const tritonEnv = await execa.stdout('triton', ['env']); const tritonEnv = await execa.stdout('triton', ['env']);
const dotEnv = tritonEnv.replace(/^export /gim, ''); const dotEnv = tritonEnv.replace(/^export /gim, '');
return Object.assign({}, process.env, parse(dotEnv)); return Object.assign({}, process.env, parse(dotEnv));
}; };
const login = ({ const login = async () => {
LOG(`${figures.arrowRight} login`);
const {
_DOCKER_LOGIN_USERNAME, _DOCKER_LOGIN_USERNAME,
_DOCKER_LOGIN_PASSWORD, _DOCKER_LOGIN_PASSWORD,
_DOCKER_REGISTRY _DOCKER_REGISTRY
}) => async () => { } = process.env;
LOG(`${figures.arrowRight} login`);
return execa( return execa(
'docker', 'docker',
[ [
@ -67,7 +71,9 @@ const login = ({
); );
}; };
const build = ({ CIRCLE_BRANCH }) => async () => { const build = async () => {
const { CIRCLE_BRANCH } = process.env;
LOG(`${figures.arrowRight} build`); LOG(`${figures.arrowRight} build`);
const dockerfiles = await globby(['packages/*/Dockerfile'], { const dockerfiles = await globby(['packages/*/Dockerfile'], {
@ -77,7 +83,7 @@ const build = ({ CIRCLE_BRANCH }) => async () => {
LOG(`${figures.arrowRight} build.dockerfiles`); LOG(`${figures.arrowRight} build.dockerfiles`);
LOG(JSON.stringify(dockerfiles, null, 2)); LOG(JSON.stringify(dockerfiles, null, 2));
return map(dockerfiles, async dockerfile => { const images = await map(dockerfiles, async dockerfile => {
const folder = path.resolve(ROOT, path.dirname(dockerfile)); const folder = path.resolve(ROOT, path.dirname(dockerfile));
const { name } = await readPkg(folder); const { name } = await readPkg(folder);
const tags = [`${name}:${CIRCLE_BRANCH}`, `${name}:latest`]; const tags = [`${name}:${CIRCLE_BRANCH}`, `${name}:latest`];
@ -99,21 +105,27 @@ const build = ({ CIRCLE_BRANCH }) => async () => {
} }
); );
LOG(`${figures.arrowRight} build.push ${NAMESPACE}/${name}`); return `${NAMESPACE}/${name}`;
return execa('docker', ['push', `${NAMESPACE}/${name}`], { });
await map(images, image => {
LOG(`${figures.arrowRight} build.push ${image}`);
return execa('docker', ['push', `${image}}`], {
stdio: 'inherit' stdio: 'inherit'
}); });
}); });
}; };
const logout = env => () => { const logout = () => {
LOG(`${figures.arrowRight} logout`); LOG(`${figures.arrowRight} logout`);
return execa('docker', ['logout'], { return execa('docker', ['logout'], {
stdio: 'inherit' stdio: 'inherit'
}); });
}; };
const deploy = env => () => { const deploy = async () => {
const env = await getEnv();
LOG(`${figures.arrowRight} deploy`); LOG(`${figures.arrowRight} deploy`);
return execa('docker-compose', ['up', '-d', '--build'], { return execa('docker-compose', ['up', '-d', '--build'], {
stdio: 'inherit', stdio: 'inherit',
@ -122,11 +134,10 @@ const deploy = env => () => {
}; };
const run = async () => { const run = async () => {
const env = await getEnv();
LOG(`${figures.arrowRight} .env`); LOG(`${figures.arrowRight} .env`);
LOG(JSON.stringify(Object.keys(env), null, 2)); LOG(JSON.stringify(Object.keys(process.env), null, 2));
return series([login(env), build(env), logout(env), deploy(env)]); return series([login, build, logout, deploy]);
}; };
LOG(`${figures.arrowRight} DEPLOY`); LOG(`${figures.arrowRight} DEPLOY`);