diff options
-rw-r--r-- | src/blogc-github-lambda/lambda_function.py | 28 | ||||
-rw-r--r-- | src/blogc-make/ctx.c | 7 | ||||
-rw-r--r-- | src/blogc-make/exec.c | 9 |
3 files changed, 36 insertions, 8 deletions
diff --git a/src/blogc-github-lambda/lambda_function.py b/src/blogc-github-lambda/lambda_function.py index 44f1bc9..b845285 100644 --- a/src/blogc-github-lambda/lambda_function.py +++ b/src/blogc-github-lambda/lambda_function.py @@ -142,16 +142,30 @@ def lambda_handler(event, context): if payload['ref'] == 'refs/heads/master': debug = 'DEBUG' in os.environ - stream = None if debug else subprocess.PIPE + + env = os.environ.copy() + env['BLOGC'] = os.path.join(cwd, 'blogc') + env['OUTPUT_DIR'] = '_build_lambda' rootdir = get_tarball(payload['repository']['full_name']) - rv = subprocess.call(['make', '-C', rootdir, - 'BLOGC=%s' % os.path.join(cwd, 'blogc'), - 'OUTPUT_DIR=_build'], - stdout=stream, stderr=stream) + settings_file = os.path.join(rootdir, 'settings.ini') + + if os.path.isfile(settings_file): + # deploy using blogc-make + args = [os.path.join(cwd, 'blogc'), '-m', '-f', settings_file, + 'all'] + if debug: + args.append('-V') + rv = subprocess.call(args, env=env) + else: + # fallback to using make. please note that this will break if + # amazon removes gnu make from lambda images + stream = None if debug else subprocess.PIPE + rv = subprocess.call(['make', '-C', rootdir], env=env, + stdout=stream, stderr=stream) if rv != 0: - raise RuntimeError('Failed to run make') + raise RuntimeError('Failed to run the build tool.') - sync_s3(os.path.join(rootdir, '_build'), + sync_s3(os.path.join(rootdir, env['OUTPUT_DIR']), payload['repository']['name'], os.path.join(rootdir, 's3.json')) diff --git a/src/blogc-make/ctx.c b/src/blogc-make/ctx.c index 8c9cc9a..7b8dfca 100644 --- a/src/blogc-make/ctx.c +++ b/src/blogc-make/ctx.c @@ -81,6 +81,13 @@ bm_ctx_new(const char *settings_file, bc_error_t **err) } free(content); + // fix output_dir, if forced from environment variable + const char *output_dir_env = getenv("OUTPUT_DIR"); + if (output_dir_env != NULL) { + bc_trie_insert(settings->settings, "output_dir", + bc_strdup(output_dir_env)); + } + char *atom_template = bm_atom_deploy(settings, err); if (*err != NULL) { return NULL; diff --git a/src/blogc-make/exec.c b/src/blogc-make/exec.c index 75b7c00..8b961e7 100644 --- a/src/blogc-make/exec.c +++ b/src/blogc-make/exec.c @@ -183,7 +183,14 @@ bm_exec_build_blogc_cmd(bm_settings_t *settings, bc_trie_t *variables, free(tmp); } - bc_string_append(rv, "blogc"); + // use blogc binary from environment, if provided + const char *blogc_bin = getenv("BLOGC"); + if (blogc_bin != NULL) { + bc_string_append(rv, blogc_bin); + } + else { + bc_string_append(rv, "blogc"); + } if (settings != NULL) { bc_trie_foreach(settings->env, |