Skip to content

Commit 7658985

Browse files
committed
Local exec, strict mode, build
1 parent 25c6c5c commit 7658985

File tree

24 files changed

+510
-253
lines changed

24 files changed

+510
-253
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
cmake-*
22
build/
33
build-artifact/
4+
tmp

CHANGELOG

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
* Mon May 24 2021 Matiss Treinis <mrtreinis@gmail.com> - 1.1.4
2+
- Add "local" command for local execution context runner
3+
- Introduce strict mode
4+
- Switch EL 8 compatible build to use AlmaLinux 8
5+
- Add support for Fedora 35
6+
- Remove support for Ubuntu 19.10 (EOL)
7+
18
* Mon Oct 5 2020 Matiss Treinis <mrtreinis@gmail.com> - 1.1.3
29
- Fix build compatibility with libssh
310
- Fix OSX build

CMakeLists.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
cmake_minimum_required(VERSION 3.11.4)
22

33
# IMPORTANT: updating version might require update in package dependencies at the end of this file.
4-
set(KAFE_VERSION "1.1.3")
4+
set(KAFE_VERSION "1.1.4")
55
set(KAFE_SOVERSION "1.1")
66
set(KAFE_VERSION_INT 11)
77
set(KAFE_VERSION_DEP_NEXT_MAJOR "2.0.0")
@@ -73,7 +73,7 @@ set(CPACK_DEBIAN_CLI_PACKAGE_NAME "kafe-cli")
7373
set(CPACK_DEBIAN_LIBKAFE_PACKAGE_NAME "libkafe")
7474
set(CPACK_DEBIAN_LIBKAFE-DEV_PACKAGE_NAME "libkafe-dev")
7575
set(CPACK_DEBIAN_CLI_PACKAGE_DEPENDS "libkafe (>=${KAFE_VERSION}), libkafe (<<${KAFE_VERSION_DEP_NEXT_MAJOR}), libstdc++6, libc6, libgcc1, libc6")
76-
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")
76+
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")
7777
set(CPACK_DEBIAN_LIBKAFE-DEV_PACKAGE_DEPENDS "libkafe (=${KAFE_VERSION})")
7878

7979
set(CPACK_ARCHIVE_COMPONENT_INSTALL ON)

DOWNLOAD.md

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,16 @@ Binary package repositories for Kafe are generously hosted by [Cloudsmith](https
88
- [Debian 10](#debian-10)
99
- [Debian 11](#debian-11)
1010
- [Ubuntu 18.04](#ubuntu-1804)
11-
- [Ubuntu 19.10](#ubuntu-1910)
1211
- [Ubuntu 20.04](#ubuntu-2004)
1312
- [Ubuntu 20.10](#ubuntu-2010)
1413
- [Ubuntu 21.04](#ubuntu-2104)
15-
- [CentOS and RHEL 7](#centos-and-rhel-7)
16-
- [CentOS and RHEL 8](#centos-and-rhel-8)
14+
- [EL7](#el7)
15+
- [EL8](#el8)
1716
- [Fedora 31](#fedora-31)
1817
- [Fedora 32](#fedora-32)
1918
- [Fedora 33](#fedora-33)
2019
- [Fedora 34](#fedora-34)
20+
- [Fedora 35](#fedora-35)
2121
- [macOS](https://github.com/libkafe/homebrew-kafe)
2222

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

95-
#### Ubuntu 19.10
96-
97-
```shell script
98-
# Setup Kafe repository signing key
99-
apt-key adv --keyserver keyserver.ubuntu.com --recv AEE35447B5D3E4A69860622702F762CA6730E6A7
100-
# Setup repository
101-
echo 'deb https://dl.cloudsmith.io/public/kafe/libkafe/deb/ubuntu eoan main' | \
102-
tee /etc/apt/sources.list.d/kafe.list
103-
# Update APT package lists and install kafe-cli
104-
apt update && apt -y install kafe-cli
105-
# Print about
106-
kafe about
107-
```
108-
10995
#### Ubuntu 20.04
11096

11197
```shell script
@@ -148,7 +134,7 @@ apt update && apt -y install kafe-cli
148134
kafe about
149135
```
150136

151-
#### CentOS and RHEL 7
137+
#### EL7
152138

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

168-
#### CentOS and RHEL 8
154+
#### EL8
169155

170156
```shell script
171157
# Setup repository
@@ -176,6 +162,8 @@ dnf install -y kafe-cli
176162
kafe about
177163
```
178164

165+
**NOTE:** this build WILL work on all RHEL 8 forks and derivatives. It SHOULD work on CentOS Stream 8.
166+
179167
#### Fedora 31
180168

181169
```shell script
@@ -219,3 +207,15 @@ dnf install -y kafe-cli
219207
# Print about
220208
kafe about
221209
```
210+
211+
212+
#### Fedora 35
213+
214+
```shell script
215+
# Setup repository
216+
curl -1sLf 'https://dl.cloudsmith.io/public/kafe/libkafe/cfg/setup/bash.rpm.sh' | distro=fedora codename=35 bash
217+
# Install kafe-cli
218+
dnf install -y kafe-cli
219+
# Print about
220+
kafe about
221+
```

README.md

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,11 @@ See [available package downloads and repositories](DOWNLOAD.md).
88

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

11-
- **CentOS** and **RHEL** versions [7<sup>1</sup>](./DOWNLOAD.md#centos-and-rhel-7), [8](./DOWNLOAD.md#centos-and-rhel-8)
12-
- **Fedora** versions [31](./DOWNLOAD.md#fedora-31), [32](./DOWNLOAD.md#fedora-32), [33](./DOWNLOAD.md#fedora-33), [34](./DOWNLOAD.md#fedora-34)
13-
- **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)
11+
- **RHEL/EL** versions [7<sup>1</sup>](./DOWNLOAD.md#el7), [8](./DOWNLOAD.md#el8)
12+
- **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)
13+
- **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)
1414
- **Debian** versions [9](./DOWNLOAD.md#debian-9), [10](./DOWNLOAD.md#debian-10), [11](./DOWNLOAD.md#debian-11)
15-
- **macOS** versions 10.5 (Catalina), 11 (Big Sur) using [Homebrew vendor tap](https://github.com/libkafe/homebrew-kafe).
15+
- **macOS** versions 10.5 (Catalina), 11 (Big Sur) and newer, using [Homebrew vendor tap](https://github.com/libkafe/homebrew-kafe).
1616

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

177+
### Local tasks and local execution environment
178+
179+
From version 1.1.4, Kafe adds support for local scripting using `kafe local` command line interface.
180+
This is simply a shortcut that allows for writing local automation tasks, local scripts and similar directly in
181+
Kafe and allows Kafe to be used as build automation framework and local task runner.
182+
183+
**NOTE:** in local, APIs like `exec`, `shell` are simply aliased to `local_shell` and `local_exec`.
184+
177185
#### SSH and SSH authentication
178186

179187
Kafe is using SSH for remote command execution and file uploads. It will attempt to use SSH agent, any known local

build-dist-docker-clean.sh

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
#!/usr/bin/env bash
22

33
docker rmi kafe/centos:7-build
4-
docker rmi kafe/centos:8-build
4+
docker rmi kafe/almalinux:8-build
55
docker rmi kafe/debian:9-build
66
docker rmi kafe/debian:10-build
77
docker rmi kafe/debian:11-build
88
docker rmi kafe/ubuntu:1804-build
9-
docker rmi kafe/ubuntu:1910-build
109
docker rmi kafe/ubuntu:2004-build
1110
docker rmi kafe/ubuntu:2010-build
1211
docker rmi kafe/fedora:31-build
1312
docker rmi kafe/fedora:32-build
14-
docker rmi kafe/fedora:33-build
13+
docker rmi kafe/fedora:33-build
14+
docker rmi kafe/fedora:34-build
15+
docker rmi kafe/fedora:35-build

build-dist.sh

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ set -xe
66
rm -rf build/
77
rm -rf build-artifact/
88

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

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

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

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

75-
# Ubuntu 19.10
76-
if [[ "$(docker images -q "kafe/ubuntu:1910-build" 2> /dev/null)" == "" ]]; then
77-
docker build -t kafe/ubuntu:1910-build dist/ubuntu/1910
78-
fi
79-
80-
docker run -it --rm -v `pwd`:/kafe kafe/ubuntu:1910-build
81-
mkdir -p build-artifact/ubuntu-1910/
82-
cp build/ubuntu/1910/kafe-cli*.deb build-artifact/ubuntu-1910/
83-
cp build/ubuntu/1910/libkafe*.deb build-artifact/ubuntu-1910/
84-
for f in build-artifact/ubuntu-1910/*; do mv -v "$f" $(echo "$f" | sed "s/\.deb/\.ubu1910\.deb/"); done
85-
8675
# Ubuntu 20.04
8776
if [[ "$(docker images -q "kafe/ubuntu:2004-build" 2> /dev/null)" == "" ]]; then
8877
docker build -t kafe/ubuntu:2004-build dist/ubuntu/2004
@@ -159,3 +148,14 @@ mkdir -p build-artifact/fedora-34/
159148
cp build/fedora/34/kafe-cli-*.rpm build-artifact/fedora-34/
160149
cp build/fedora/34/libkafe-*.rpm build-artifact/fedora-34/
161150
for f in build-artifact/fedora-34/*; do mv -v "$f" $(echo "$f" | sed "s/\.rpm/\.f34\.rpm/"); done
151+
152+
# Fedora 35
153+
if [[ "$(docker images -q "kafe/fedora:35-build" 2> /dev/null)" == "" ]]; then
154+
docker build -t kafe/fedora:35-build dist/fedora/35
155+
fi
156+
157+
docker run -it --rm -v `pwd`:/kafe kafe/fedora:35-build
158+
mkdir -p build-artifact/fedora-35/
159+
cp build/fedora/35/kafe-cli-*.rpm build-artifact/fedora-35/
160+
cp build/fedora/35/libkafe-*.rpm build-artifact/fedora-35/
161+
for f in build-artifact/fedora-35/*; do mv -v "$f" $(echo "$f" | sed "s/\.rpm/\.f35\.rpm/"); done

cli/logger.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ namespace kafe {
166166
}
167167

168168
void Logger::on_stdout_line(string line) const {
169-
on_stdout_line("out", line);
169+
on_stdout_line("stdout", line);
170170
}
171171

172172
void Logger::on_stdout_line(string prefix, string line) const {
@@ -197,7 +197,7 @@ namespace kafe {
197197
}
198198

199199
void Logger::on_stderr_line(string line) const {
200-
on_stderr_line("err", line);
200+
on_stderr_line("stderr", line);
201201
}
202202

203203
void Logger::on_stderr_line(string prefix, string line) const {
@@ -212,7 +212,7 @@ namespace kafe {
212212
fprintf(
213213
stderr,
214214
"%s%s%s %s%s",
215-
IO_TTY_ANSI_COLOR_RED,
215+
IO_TTY_ANSI_COLOR_YELLOW,
216216
expand_prefix(prefix).c_str(),
217217
IO_TTY_ANSI_COLOR_RESET,
218218
context_to_s(get_context()).c_str(),
@@ -238,4 +238,4 @@ namespace kafe {
238238
LogLevel Logger::get_level() const {
239239
return get_env_log_level();
240240
}
241-
}
241+
}

cli/main.cpp

Lines changed: 53 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,18 @@ using namespace kafe;
3535
extern char** environ;
3636
#endif
3737

38+
void loadEnvMap(map<const string, const string> &envVals) {
39+
for (char **current = environ; *current; ++current) {
40+
const string envVal = string(*current);
41+
const ulong pos = envVal.find_first_of('=');
42+
pair<string, string> p = pair<string, string>(
43+
envVal.substr(0, pos),
44+
envVal.substr(pos + 1)
45+
);
46+
envVals.insert(p);
47+
}
48+
}
49+
3850
void print_usage() {
3951
fflush(stderr);
4052
fflush(stdout);
@@ -44,13 +56,15 @@ void print_usage() {
4456

4557
cout << "Usage: kafe <command> [arguments, ...]" << endl;
4658
cout << " kafe do <environment> <task,task,task,...>" << endl;
59+
cout << " kafe local <task,task,task,...>" << endl;
4760
cout << " kafe <help|--help>" << endl;
4861
cout << " kafe <version|--version> [--lib]" << endl;
4962
cout << " kafe <about|--about>" << endl;
5063

5164
cout << "\n";
5265

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

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

129-
map<const string, const string> envvals;
130-
for (char **current = environ; *current; ++current) {
131-
const string envl = string(*current);
132-
const int pos = envl.find_first_of('=');
133-
pair<string, string> p = pair<string, string>(
134-
envl.substr(0, pos),
135-
envl.substr(pos + 1)
136-
);
137-
envvals.insert(p);
138-
}
143+
map<const string, const string> envVals;
144+
loadEnvMap(envVals);
139145

140146
string environment = argv[2];
141147
string task_list_s = argv[3];
@@ -149,7 +155,41 @@ int main(int argc, char *argv[]) {
149155
try {
150156
auto project = Project("kafe.lua");
151157
auto logger = Logger();
152-
auto context = Context(envvals, environment, task_list_v, &logger);
158+
auto context = Context(envVals, environment, task_list_v, &logger);
159+
auto inventory = Inventory();
160+
project.execute(context, inventory, extra_args);
161+
} catch (RuntimeException &e) {
162+
cerr << e.what() << endl;
163+
return 1;
164+
}
165+
return 0;
166+
}
167+
168+
if (0 == strcmp("local", argv[1])) {
169+
if (3 > argc) {
170+
cerr << "Command expects at least one argument - "
171+
"a comma separated task list, and optionally - zero or more arguments "
172+
"to forward to the tasks being invoked.\n"
173+
"Example: kafe run task1,task2,task3 <arg, arg, arg>";
174+
print_usage();
175+
return 1;
176+
}
177+
178+
map<const string, const string> envVals;
179+
loadEnvMap(envVals);
180+
181+
string task_list_s = argv[2];
182+
vector<string> task_list_v = split_csv_arguments(task_list_s, ',');
183+
184+
vector<string> extra_args;
185+
for (int ii = 4; ii < argc; ++ii) {
186+
extra_args.emplace_back(argv[ii]);
187+
}
188+
189+
try {
190+
auto project = Project("kafe.lua");
191+
auto logger = Logger();
192+
auto context = Context(envVals, "", task_list_v, &logger);
153193
auto inventory = Inventory();
154194
project.execute(context, inventory, extra_args);
155195
} catch (RuntimeException &e) {

0 commit comments

Comments
 (0)