Skip to content

Commit

Permalink
Local exec, strict mode, build
Browse files Browse the repository at this point in the history
  • Loading branch information
Addvilz committed May 24, 2021
1 parent 25c6c5c commit 7658985
Show file tree
Hide file tree
Showing 24 changed files with 510 additions and 253 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
cmake-*
build/
build-artifact/
tmp
7 changes: 7 additions & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
* Mon May 24 2021 Matiss Treinis <mrtreinis@gmail.com> - 1.1.4
- Add "local" command for local execution context runner
- Introduce strict mode
- Switch EL 8 compatible build to use AlmaLinux 8
- Add support for Fedora 35
- Remove support for Ubuntu 19.10 (EOL)

* Mon Oct 5 2020 Matiss Treinis <mrtreinis@gmail.com> - 1.1.3
- Fix build compatibility with libssh
- Fix OSX build
Expand Down
4 changes: 2 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
cmake_minimum_required(VERSION 3.11.4)

# IMPORTANT: updating version might require update in package dependencies at the end of this file.
set(KAFE_VERSION "1.1.3")
set(KAFE_VERSION "1.1.4")
set(KAFE_SOVERSION "1.1")
set(KAFE_VERSION_INT 11)
set(KAFE_VERSION_DEP_NEXT_MAJOR "2.0.0")
Expand Down Expand Up @@ -73,7 +73,7 @@ set(CPACK_DEBIAN_CLI_PACKAGE_NAME "kafe-cli")
set(CPACK_DEBIAN_LIBKAFE_PACKAGE_NAME "libkafe")
set(CPACK_DEBIAN_LIBKAFE-DEV_PACKAGE_NAME "libkafe-dev")
set(CPACK_DEBIAN_CLI_PACKAGE_DEPENDS "libkafe (>=${KAFE_VERSION}), libkafe (<<${KAFE_VERSION_DEP_NEXT_MAJOR}), libstdc++6, libc6, libgcc1, libc6")
set(CPACK_DEBIAN_LIBKAFE_PACKAGE_DEPENDS "libstdc++6, libc6, libgcc1, libc6, liblua5.3-0, libssh-4 (>=0.7.0), libarchive13, libcurl3 | libcurl4, libgit2-24 | libgit2-26 | libgit2-27 | libgit2-28")
set(CPACK_DEBIAN_LIBKAFE_PACKAGE_DEPENDS "libstdc++6, libc6, libgcc1, libc6, liblua5.3-0, libssh-4 (>=0.7.0), libarchive13, libcurl3 | libcurl4, libgit2-24 | libgit2-26 | libgit2-27 | libgit2-28 | libgit2-1.1")
set(CPACK_DEBIAN_LIBKAFE-DEV_PACKAGE_DEPENDS "libkafe (=${KAFE_VERSION})")

set(CPACK_ARCHIVE_COMPONENT_INSTALL ON)
Expand Down
38 changes: 19 additions & 19 deletions DOWNLOAD.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,16 @@ Binary package repositories for Kafe are generously hosted by [Cloudsmith](https
- [Debian 10](#debian-10)
- [Debian 11](#debian-11)
- [Ubuntu 18.04](#ubuntu-1804)
- [Ubuntu 19.10](#ubuntu-1910)
- [Ubuntu 20.04](#ubuntu-2004)
- [Ubuntu 20.10](#ubuntu-2010)
- [Ubuntu 21.04](#ubuntu-2104)
- [CentOS and RHEL 7](#centos-and-rhel-7)
- [CentOS and RHEL 8](#centos-and-rhel-8)
- [EL7](#el7)
- [EL8](#el8)
- [Fedora 31](#fedora-31)
- [Fedora 32](#fedora-32)
- [Fedora 33](#fedora-33)
- [Fedora 34](#fedora-34)
- [Fedora 35](#fedora-35)
- [macOS](https://github.com/libkafe/homebrew-kafe)

See [releases](https://github.com/libkafe/kafe/releases) for all available downloads and historic versions,
Expand Down Expand Up @@ -92,20 +92,6 @@ apt update && apt -y install kafe-cli
kafe about
```

#### Ubuntu 19.10

```shell script
# Setup Kafe repository signing key
apt-key adv --keyserver keyserver.ubuntu.com --recv AEE35447B5D3E4A69860622702F762CA6730E6A7
# Setup repository
echo 'deb https://dl.cloudsmith.io/public/kafe/libkafe/deb/ubuntu eoan main' | \
tee /etc/apt/sources.list.d/kafe.list
# Update APT package lists and install kafe-cli
apt update && apt -y install kafe-cli
# Print about
kafe about
```

#### Ubuntu 20.04

```shell script
Expand Down Expand Up @@ -148,7 +134,7 @@ apt update && apt -y install kafe-cli
kafe about
```

#### CentOS and RHEL 7
#### EL7

**IMPORTANT:** Kafe requires Lua version 5.3, a dependency not available in EL7 by default. You can either
build the package yourself or use [Cheese](http://www.nosuchhost.net/~cheese/fedora/packages/epel-7/x86_64/cheese-release.html)
Expand All @@ -165,7 +151,7 @@ yum -y install kafe-cli
kafe about
```

#### CentOS and RHEL 8
#### EL8

```shell script
# Setup repository
Expand All @@ -176,6 +162,8 @@ dnf install -y kafe-cli
kafe about
```

**NOTE:** this build WILL work on all RHEL 8 forks and derivatives. It SHOULD work on CentOS Stream 8.

#### Fedora 31

```shell script
Expand Down Expand Up @@ -219,3 +207,15 @@ dnf install -y kafe-cli
# Print about
kafe about
```


#### Fedora 35

```shell script
# Setup repository
curl -1sLf 'https://dl.cloudsmith.io/public/kafe/libkafe/cfg/setup/bash.rpm.sh' | distro=fedora codename=35 bash
# Install kafe-cli
dnf install -y kafe-cli
# Print about
kafe about
```
16 changes: 12 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ See [available package downloads and repositories](DOWNLOAD.md).

You can easily install and use libkafe on following operating systems:

- **CentOS** and **RHEL** versions [7<sup>1</sup>](./DOWNLOAD.md#centos-and-rhel-7), [8](./DOWNLOAD.md#centos-and-rhel-8)
- **Fedora** versions [31](./DOWNLOAD.md#fedora-31), [32](./DOWNLOAD.md#fedora-32), [33](./DOWNLOAD.md#fedora-33), [34](./DOWNLOAD.md#fedora-34)
- **Ubuntu** versions [18.04](./DOWNLOAD.md#ubuntu-1804), [19.10](./DOWNLOAD.md#ubuntu-1910), [20.04](./DOWNLOAD.md#ubuntu-2004), [20.10](./DOWNLOAD.md#ubuntu-2010), [21.04](./DOWNLOAD.md#ubuntu-2104)
- **RHEL/EL** versions [7<sup>1</sup>](./DOWNLOAD.md#el7), [8](./DOWNLOAD.md#el8)
- **Fedora** versions [31](./DOWNLOAD.md#fedora-31), [32](./DOWNLOAD.md#fedora-32), [33](./DOWNLOAD.md#fedora-33), [34](./DOWNLOAD.md#fedora-34), [35](./DOWNLOAD.md#fedora-35)
- **Ubuntu** versions [18.04](./DOWNLOAD.md#ubuntu-1804), [20.04](./DOWNLOAD.md#ubuntu-2004), [20.10](./DOWNLOAD.md#ubuntu-2010), [21.04](./DOWNLOAD.md#ubuntu-2104)
- **Debian** versions [9](./DOWNLOAD.md#debian-9), [10](./DOWNLOAD.md#debian-10), [11](./DOWNLOAD.md#debian-11)
- **macOS** versions 10.5 (Catalina), 11 (Big Sur) using [Homebrew vendor tap](https://github.com/libkafe/homebrew-kafe).
- **macOS** versions 10.5 (Catalina), 11 (Big Sur) and newer, using [Homebrew vendor tap](https://github.com/libkafe/homebrew-kafe).

<sup>1</sup> - EL7 does not ship with Lua 5.3. We currently use
[Cheese](http://www.nosuchhost.net/~cheese/fedora/packages/epel-7/x86_64/cheese-release.html) repository
Expand Down Expand Up @@ -174,6 +174,14 @@ execute following Kafe CLI command:
When executed, Kafe CLI will look for a file named `kafe.lua` in the current working direcory. This
file will be interpreted and requested tasks from it will be executed against all relevant remote servers.

### Local tasks and local execution environment

From version 1.1.4, Kafe adds support for local scripting using `kafe local` command line interface.
This is simply a shortcut that allows for writing local automation tasks, local scripts and similar directly in
Kafe and allows Kafe to be used as build automation framework and local task runner.

**NOTE:** in local, APIs like `exec`, `shell` are simply aliased to `local_shell` and `local_exec`.

#### SSH and SSH authentication

Kafe is using SSH for remote command execution and file uploads. It will attempt to use SSH agent, any known local
Expand Down
7 changes: 4 additions & 3 deletions build-dist-docker-clean.sh
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
#!/usr/bin/env bash

docker rmi kafe/centos:7-build
docker rmi kafe/centos:8-build
docker rmi kafe/almalinux:8-build
docker rmi kafe/debian:9-build
docker rmi kafe/debian:10-build
docker rmi kafe/debian:11-build
docker rmi kafe/ubuntu:1804-build
docker rmi kafe/ubuntu:1910-build
docker rmi kafe/ubuntu:2004-build
docker rmi kafe/ubuntu:2010-build
docker rmi kafe/fedora:31-build
docker rmi kafe/fedora:32-build
docker rmi kafe/fedora:33-build
docker rmi kafe/fedora:33-build
docker rmi kafe/fedora:34-build
docker rmi kafe/fedora:35-build
40 changes: 20 additions & 20 deletions build-dist.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ set -xe
rm -rf build/
rm -rf build-artifact/

# CentOS 7
# EL7
if [[ "$(docker images -q "kafe/centos:7-build" 2> /dev/null)" == "" ]]; then
docker build -t kafe/centos:7-build dist/centos/7
fi
Expand All @@ -17,16 +17,16 @@ cp build/centos/7/kafe-cli-*.rpm build-artifact/centos-7/
cp build/centos/7/libkafe-*.rpm build-artifact/centos-7/
for f in build-artifact/centos-7/*; do mv -v "$f" $(echo "$f" | sed "s/\.rpm/\.el7\.rpm/"); done

# CentOS 8
if [[ "$(docker images -q "kafe/centos:8-build" 2> /dev/null)" == "" ]]; then
docker build -t kafe/centos:8-build dist/centos/8
# EL 8
if [[ "$(docker images -q "kafe/almalinux:8-build" 2> /dev/null)" == "" ]]; then
docker build -t kafe/almalinux:8-build dist/almalinux/8
fi

docker run -it --rm -v `pwd`:/kafe kafe/centos:8-build
mkdir -p build-artifact/centos-8/
cp build/centos/8/kafe-cli-*.rpm build-artifact/centos-8/
cp build/centos/8/libkafe-*.rpm build-artifact/centos-8/
for f in build-artifact/centos-8/*; do mv -v "$f" $(echo "$f" | sed "s/\.rpm/\.el8\.rpm/"); done
docker run -it --rm -v `pwd`:/kafe kafe/almalinux:8-build
mkdir -p build-artifact/almalinux-8/
cp build/almalinux/8/kafe-cli-*.rpm build-artifact/almalinux-8/
cp build/almalinux/8/libkafe-*.rpm build-artifact/almalinux-8/
for f in build-artifact/almalinux-8/*; do mv -v "$f" $(echo "$f" | sed "s/\.rpm/\.el8\.rpm/"); done

# Debian 9
if [[ "$(docker images -q "kafe/debian:9-build" 2> /dev/null)" == "" ]]; then
Expand Down Expand Up @@ -72,17 +72,6 @@ cp build/ubuntu/1804/kafe-cli*.deb build-artifact/ubuntu-1804/
cp build/ubuntu/1804/libkafe*.deb build-artifact/ubuntu-1804/
for f in build-artifact/ubuntu-1804/*; do mv -v "$f" $(echo "$f" | sed "s/\.deb/\.ubu1804\.deb/"); done

# Ubuntu 19.10
if [[ "$(docker images -q "kafe/ubuntu:1910-build" 2> /dev/null)" == "" ]]; then
docker build -t kafe/ubuntu:1910-build dist/ubuntu/1910
fi

docker run -it --rm -v `pwd`:/kafe kafe/ubuntu:1910-build
mkdir -p build-artifact/ubuntu-1910/
cp build/ubuntu/1910/kafe-cli*.deb build-artifact/ubuntu-1910/
cp build/ubuntu/1910/libkafe*.deb build-artifact/ubuntu-1910/
for f in build-artifact/ubuntu-1910/*; do mv -v "$f" $(echo "$f" | sed "s/\.deb/\.ubu1910\.deb/"); done

# Ubuntu 20.04
if [[ "$(docker images -q "kafe/ubuntu:2004-build" 2> /dev/null)" == "" ]]; then
docker build -t kafe/ubuntu:2004-build dist/ubuntu/2004
Expand Down Expand Up @@ -159,3 +148,14 @@ mkdir -p build-artifact/fedora-34/
cp build/fedora/34/kafe-cli-*.rpm build-artifact/fedora-34/
cp build/fedora/34/libkafe-*.rpm build-artifact/fedora-34/
for f in build-artifact/fedora-34/*; do mv -v "$f" $(echo "$f" | sed "s/\.rpm/\.f34\.rpm/"); done

# Fedora 35
if [[ "$(docker images -q "kafe/fedora:35-build" 2> /dev/null)" == "" ]]; then
docker build -t kafe/fedora:35-build dist/fedora/35
fi

docker run -it --rm -v `pwd`:/kafe kafe/fedora:35-build
mkdir -p build-artifact/fedora-35/
cp build/fedora/35/kafe-cli-*.rpm build-artifact/fedora-35/
cp build/fedora/35/libkafe-*.rpm build-artifact/fedora-35/
for f in build-artifact/fedora-35/*; do mv -v "$f" $(echo "$f" | sed "s/\.rpm/\.f35\.rpm/"); done
8 changes: 4 additions & 4 deletions cli/logger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ namespace kafe {
}

void Logger::on_stdout_line(string line) const {
on_stdout_line("out", line);
on_stdout_line("stdout", line);
}

void Logger::on_stdout_line(string prefix, string line) const {
Expand Down Expand Up @@ -197,7 +197,7 @@ namespace kafe {
}

void Logger::on_stderr_line(string line) const {
on_stderr_line("err", line);
on_stderr_line("stderr", line);
}

void Logger::on_stderr_line(string prefix, string line) const {
Expand All @@ -212,7 +212,7 @@ namespace kafe {
fprintf(
stderr,
"%s%s%s %s%s",
IO_TTY_ANSI_COLOR_RED,
IO_TTY_ANSI_COLOR_YELLOW,
expand_prefix(prefix).c_str(),
IO_TTY_ANSI_COLOR_RESET,
context_to_s(get_context()).c_str(),
Expand All @@ -238,4 +238,4 @@ namespace kafe {
LogLevel Logger::get_level() const {
return get_env_log_level();
}
}
}
66 changes: 53 additions & 13 deletions cli/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,18 @@ using namespace kafe;
extern char** environ;
#endif

void loadEnvMap(map<const string, const string> &envVals) {
for (char **current = environ; *current; ++current) {
const string envVal = string(*current);
const ulong pos = envVal.find_first_of('=');
pair<string, string> p = pair<string, string>(
envVal.substr(0, pos),
envVal.substr(pos + 1)
);
envVals.insert(p);
}
}

void print_usage() {
fflush(stderr);
fflush(stdout);
Expand All @@ -44,13 +56,15 @@ void print_usage() {

cout << "Usage: kafe <command> [arguments, ...]" << endl;
cout << " kafe do <environment> <task,task,task,...>" << endl;
cout << " kafe local <task,task,task,...>" << endl;
cout << " kafe <help|--help>" << endl;
cout << " kafe <version|--version> [--lib]" << endl;
cout << " kafe <about|--about>" << endl;

cout << "\n";

cout << " kafe do: execute tasks from project file with given environment." << endl;
cout << " kafe local: execute tasks from project file on localhost." << endl;
cout << " kafe help: display this help." << endl;
cout << " kafe version: display KAFE program version and exit. Optionally,"
" show libkafe version used if argument --lib is set." << endl;
Expand Down Expand Up @@ -118,24 +132,16 @@ int main(int argc, char *argv[]) {

if (0 == strcmp("do", argv[1])) {
if (4 > argc) {
cerr << "Command expects exactly at least two arguments - environment name and "
"a comma separated task list with any number of arbitrary arguments "
cerr << "Command expects at least two arguments - environment name and "
"a comma separated task list, and optionally - zero or more of arguments "
"to forward to the tasks being invoked.\n"
"Example: kafe do staging task1,task2,task3 <arg, arg, arg>";
print_usage();
return 1;
}

map<const string, const string> envvals;
for (char **current = environ; *current; ++current) {
const string envl = string(*current);
const int pos = envl.find_first_of('=');
pair<string, string> p = pair<string, string>(
envl.substr(0, pos),
envl.substr(pos + 1)
);
envvals.insert(p);
}
map<const string, const string> envVals;
loadEnvMap(envVals);

string environment = argv[2];
string task_list_s = argv[3];
Expand All @@ -149,7 +155,41 @@ int main(int argc, char *argv[]) {
try {
auto project = Project("kafe.lua");
auto logger = Logger();
auto context = Context(envvals, environment, task_list_v, &logger);
auto context = Context(envVals, environment, task_list_v, &logger);
auto inventory = Inventory();
project.execute(context, inventory, extra_args);
} catch (RuntimeException &e) {
cerr << e.what() << endl;
return 1;
}
return 0;
}

if (0 == strcmp("local", argv[1])) {
if (3 > argc) {
cerr << "Command expects at least one argument - "
"a comma separated task list, and optionally - zero or more arguments "
"to forward to the tasks being invoked.\n"
"Example: kafe run task1,task2,task3 <arg, arg, arg>";
print_usage();
return 1;
}

map<const string, const string> envVals;
loadEnvMap(envVals);

string task_list_s = argv[2];
vector<string> task_list_v = split_csv_arguments(task_list_s, ',');

vector<string> extra_args;
for (int ii = 4; ii < argc; ++ii) {
extra_args.emplace_back(argv[ii]);
}

try {
auto project = Project("kafe.lua");
auto logger = Logger();
auto context = Context(envVals, "", task_list_v, &logger);
auto inventory = Inventory();
project.execute(context, inventory, extra_args);
} catch (RuntimeException &e) {
Expand Down
Loading

0 comments on commit 7658985

Please sign in to comment.