deployer-buddy

custom deployment trigger scripts

Usage no npm install needed!

<script type="module">
  import deployerBuddy from 'https://cdn.skypack.dev/deployer-buddy';
</script>

README

Deployer Buddy

Some custom NodeJS scripts to trigger deployments from within CI workflows against our deployer.

getAuthToken

Get refresh tokens for a machine to machine authentication flow using refresh tokens and credentials, build for auth0.

import {getAuthToken} from 'cloud-buddy/getAuthToken'

const auth = async () => {
    const token = await getAuthToken(AUTH0_ID, AUTH0_SECRET, AUTH0_AUDIENCE, AUTH0_ISSUER + '/oauth/token', undefined)
    if(token.scope !== 'developer') {
        return Promise.reject('Action needs user scope `developer`')
    }
}

runDeploy

Execute a chain of deployment scripts, supplying a central configuration, aggregating the payload for further consume.

import path from 'path'
import fs from 'fs'
import {runDeploy} from 'cloud-buddy/runDeploy'

const prepareDeployment = async (deployment) => {
    const {
        config: {
            rootDir,
            // is `true` for `envConfig.GIT_BRANCH === 'master'` or `process.env.NODE_ENV === 'production'`
            isProd,
            AUTH_GCE,
        }
    } = deployment
    try {
        // CI config generation from env variables
        fs.writeFileSync(path.join(rootDir, '_auth-google.json'), AUTH_GCE)
    } catch(e) {
        // not fetching `e`, as may have secret values
        // console.log(e)
        throw new Error('couldn\'t write the config files!')
    }
    return deployment
}

const deployments = [
    prepareDeployment,
]

const rootDir = __dirname

// root terraform env. dirs
const rootDirs = {
    manage: '_ci/deployer',
}

runDeploy(
    deployments,
    {
        rootDir, rootDirs,
        // the root `envConfig` is merged into the payload `config` - enforcing that it is never overwritten
        envConfig: {
            GIT_BRANCH: 'master',
            AUTH_GCE: process.env.AUTH_GCE,
        },
    },
).then().catch()

License

MIT License

Copyright (c) 2021 Michael Becker

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.