Skip to content

Commit a892c25

Browse files
committed
Initial commit
0 parents  commit a892c25

36 files changed

+1395
-0
lines changed

.github/workflows/rubocop.yml

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
name: Tests and Rubocop
2+
3+
on:
4+
pull_request:
5+
push:
6+
branches: [ main ]
7+
workflow_dispatch:
8+
9+
jobs:
10+
rake:
11+
runs-on: ubuntu-latest
12+
13+
steps:
14+
- uses: actions/checkout@v3
15+
- uses: ruby/setup-ruby@v1
16+
with:
17+
ruby-version: '3.0'
18+
bundler-cache: true
19+
- run: bundle exec rake

.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
*.gem
2+
/.vagrant/

.rubocop.yml

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
require: rubocop-rake
2+
3+
AllCops:
4+
NewCops: enable
5+
TargetRubyVersion: 2.7
6+
7+
Style/StringLiterals:
8+
Enabled: true
9+
EnforcedStyle: double_quotes
10+
11+
Style/StringLiteralsInInterpolation:
12+
Enabled: true
13+
EnforcedStyle: double_quotes
14+
15+
Style/FormatStringToken:
16+
Enabled: false
17+
18+
Layout/LineLength:
19+
Max: 120
20+
21+
Metrics/AbcSize:
22+
Max: 24
23+
24+
Metrics/MethodLength:
25+
Max: 25
26+
27+
Gemspec/RequireMFA:
28+
Enabled: false
29+
30+
Style/ClassVars:
31+
Enabled: false

Gemfile

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# frozen_string_literal: true
2+
3+
source "https://rubygems.org"
4+
gemspec

Gemfile.lock

+90
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
PATH
2+
remote: .
3+
specs:
4+
koch (0.1.5)
5+
diffy (~> 3.4)
6+
logger (~> 1.5)
7+
thor (~> 1.2)
8+
zeitwerk (~> 2.6)
9+
zlib (~> 1.1)
10+
11+
GEM
12+
remote: https://rubygems.org/
13+
specs:
14+
ast (2.4.2)
15+
coderay (1.1.3)
16+
diffy (3.4.2)
17+
ffi (1.15.5)
18+
formatador (1.1.0)
19+
guard (2.18.0)
20+
formatador (>= 0.2.4)
21+
listen (>= 2.7, < 4.0)
22+
lumberjack (>= 1.0.12, < 2.0)
23+
nenv (~> 0.1)
24+
notiffany (~> 0.0)
25+
pry (>= 0.13.0)
26+
shellany (~> 0.0)
27+
thor (>= 0.18.1)
28+
guard-compat (1.2.1)
29+
guard-minitest (2.4.6)
30+
guard-compat (~> 1.2)
31+
minitest (>= 3.0)
32+
json (2.6.3)
33+
listen (3.8.0)
34+
rb-fsevent (~> 0.10, >= 0.10.3)
35+
rb-inotify (~> 0.9, >= 0.9.10)
36+
logger (1.5.3)
37+
lumberjack (1.2.8)
38+
method_source (1.0.0)
39+
minitest (5.18.0)
40+
nenv (0.3.0)
41+
notiffany (0.1.3)
42+
nenv (~> 0.1)
43+
shellany (~> 0.0)
44+
parallel (1.22.1)
45+
parser (3.2.1.1)
46+
ast (~> 2.4.1)
47+
pry (0.14.2)
48+
coderay (~> 1.1)
49+
method_source (~> 1.0)
50+
rainbow (3.1.1)
51+
rake (13.0.6)
52+
rb-fsevent (0.11.2)
53+
rb-inotify (0.10.1)
54+
ffi (~> 1.0)
55+
regexp_parser (2.7.0)
56+
rexml (3.2.5)
57+
rubocop (1.48.1)
58+
json (~> 2.3)
59+
parallel (~> 1.10)
60+
parser (>= 3.2.0.0)
61+
rainbow (>= 2.2.2, < 4.0)
62+
regexp_parser (>= 1.8, < 3.0)
63+
rexml (>= 3.2.5, < 4.0)
64+
rubocop-ast (>= 1.26.0, < 2.0)
65+
ruby-progressbar (~> 1.7)
66+
unicode-display_width (>= 2.4.0, < 3.0)
67+
rubocop-ast (1.27.0)
68+
parser (>= 3.2.1.0)
69+
rubocop-rake (0.6.0)
70+
rubocop (~> 1.0)
71+
ruby-progressbar (1.13.0)
72+
shellany (0.0.1)
73+
thor (1.2.1)
74+
unicode-display_width (2.4.2)
75+
zeitwerk (2.6.7)
76+
zlib (1.1.0)
77+
78+
PLATFORMS
79+
x86_64-linux
80+
81+
DEPENDENCIES
82+
guard (~> 2.18)
83+
guard-minitest (~> 2.4)
84+
koch!
85+
rake (~> 13.0)
86+
rubocop (~> 1.48)
87+
rubocop-rake (~> 0.6)
88+
89+
BUNDLED WITH
90+
2.4.8

Guardfile

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# frozen_string_literal: true
2+
3+
guard :minitest do
4+
watch(%r{^test/(.*)?_test\.rb$})
5+
watch(%r{^lib/(.*/)?([^/]+)\.rb$}) { |m| "test/#{m[2]}_test.rb" }
6+
watch(%r{^test/test_helper\.rb$}) { "test" }
7+
watch(%r{^bin/koch$}) { "test" }
8+
end

LICENSE

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
Copyright 2023 Marius Nünnerich
2+
3+
Licensed under the Apache License, Version 2.0 (the "License");
4+
you may not use this file except in compliance with the License.
5+
You may obtain a copy of the License at
6+
7+
http://www.apache.org/licenses/LICENSE-2.0
8+
9+
Unless required by applicable law or agreed to in writing, software
10+
distributed under the License is distributed on an "AS IS" BASIS,
11+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
See the License for the specific language governing permissions and
13+
limitations under the License.

README.md

+50
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
# Koch
2+
3+
Koch is a tool to install software packages, change files and other things
4+
on a single machine. The changes are described in a file and are written in Ruby.
5+
6+
The file describing a machine should be versioned, that way you create a repeatable
7+
description of how a machine is set up, with history.
8+
9+
For an example of how this can look like, check out this [Rezeptfile](example/Rezeptfile)
10+
and the other files in the directory.
11+
12+
## Notice
13+
14+
THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
16+
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT
17+
18+
Fully **backup** any machine you run this on! This is alpha grade software and
19+
might cause havoc, esp when run with root privileges!
20+
I suggest you use Vagrant to try this out.
21+
22+
## Status
23+
24+
![Tests and Rubocop](https://github.com/marius/koch/actions/workflows/rubocop.yml/badge.svg)
25+
26+
## Philosophy
27+
28+
Koch's configuration files (Rezeptfiles) are just Ruby. All Koch does is provide
29+
a bunch of convenience functions. Feel free to use all the Ruby you want.
30+
31+
## Usage
32+
33+
```
34+
sudo apt -y install git
35+
sudo gem install koch
36+
git clone [email protected]:example/machine.git
37+
cd machine
38+
sudo koch
39+
```
40+
41+
## Supported platforms
42+
43+
- Ubuntu 22.04 (amd64)
44+
- Debian 11 (amd64)
45+
- End of list
46+
47+
## TODO
48+
49+
- [ ] Interactive mode, ask about each change
50+
- [ ] publish to rubygems

Rakefile

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# frozen_string_literal: true
2+
3+
require "bundler/gem_tasks"
4+
require "rake/testtask"
5+
6+
Rake::TestTask.new(:test) do |t|
7+
t.libs << "test"
8+
t.libs << "lib"
9+
t.test_files = FileList["test/**/*_test.rb"]
10+
end
11+
12+
require "rubocop/rake_task"
13+
14+
RuboCop::RakeTask.new
15+
16+
task default: %i[test rubocop]

Vagrantfile

+84
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
# frozen_string_literal: true
2+
3+
# -*- mode: ruby -*-
4+
# vi: set ft=ruby :
5+
6+
# All Vagrant configuration is done below. The "2" in Vagrant.configure
7+
# configures the configuration version (we support older styles for
8+
# backwards compatibility). Please don't change it unless you know what
9+
# you're doing.
10+
Vagrant.configure("2") do |config|
11+
# The most common configuration options are documented and commented below.
12+
# For a complete reference, please see the online documentation at
13+
# https://docs.vagrantup.com.
14+
15+
# Every Vagrant development environment requires a box. You can search for
16+
# boxes at https://vagrantcloud.com/search.
17+
# config.vm.box = "generic/ubuntu2204"
18+
19+
# Disable automatic box update checking. If you disable this, then
20+
# boxes will only be checked for updates when the user runs
21+
# `vagrant box outdated`. This is not recommended.
22+
# config.vm.box_check_update = false
23+
24+
# Create a forwarded port mapping which allows access to a specific port
25+
# within the machine from a port on the host machine. In the example below,
26+
# accessing "localhost:8080" will access port 80 on the guest machine.
27+
# NOTE: This will enable public access to the opened port
28+
# config.vm.network "forwarded_port", guest: 80, host: 8080
29+
30+
# Create a forwarded port mapping which allows access to a specific port
31+
# within the machine from a port on the host machine and only allow access
32+
# via 127.0.0.1 to disable public access
33+
# config.vm.network "forwarded_port", guest: 80, host: 8080, host_ip: "127.0.0.1"
34+
35+
# Create a private network, which allows host-only access to the machine
36+
# using a specific IP.
37+
# config.vm.network "private_network", ip: "192.168.33.10"
38+
39+
# Create a public network, which generally matched to bridged network.
40+
# Bridged networks make the machine appear as another physical device on
41+
# your network.
42+
# config.vm.network "public_network"
43+
44+
# Share an additional folder to the guest VM. The first argument is
45+
# the path on the host to the actual folder. The second argument is
46+
# the path on the guest to mount the folder. And the optional third
47+
# argument is a set of non-required options.
48+
config.vm.synced_folder ".", "/vagrant", nfs_version: 4, nfs_udp: false
49+
50+
# Provider-specific configuration so you can fine-tune various
51+
# backing providers for Vagrant. These expose provider-specific options.
52+
# Example for VirtualBox:
53+
#
54+
# config.vm.provider "virtualbox" do |vb|
55+
# # Display the VirtualBox GUI when booting the machine
56+
# vb.gui = true
57+
#
58+
# # Customize the amount of memory on the VM:
59+
# vb.memory = "1024"
60+
# end
61+
#
62+
# View the documentation for the provider you are using for more
63+
# information on available options.
64+
65+
# Enable provisioning with a shell script. Additional provisioners such as
66+
# Ansible, Chef, Docker, Puppet and Salt are also available. Please see the
67+
# documentation for more information about their specific syntax and use.
68+
require_relative "lib/koch/version"
69+
config.vm.provision "shell", inline: <<-SHELL
70+
export DEBIAN_FRONTEND=noninteractive
71+
apt update
72+
apt install -y build-essential zlib1g-dev ruby-dev
73+
gem install --no-document /vagrant/koch-#{Koch::VERSION}.gem
74+
printf -- "---\\nrestic:\\n password: test123\\n" >/etc/secrets.yaml
75+
SHELL
76+
77+
config.vm.define "ubuntu", primary: true do |ubuntu|
78+
ubuntu.vm.box = "generic/ubuntu2204"
79+
end
80+
81+
config.vm.define "debian" do |debian|
82+
debian.vm.box = "debian/bullseye64"
83+
end
84+
end

bin/koch

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
#!/usr/bin/env ruby
2+
# frozen_string_literal: true
3+
4+
require "thor"
5+
require_relative "../lib/koch"
6+
7+
# KochCLI is the glue between the commandline and the actual Koch implementation
8+
class KochCLI < Thor
9+
class_option :verbose, type: :boolean, aliases: "-v"
10+
class_option :"dry-run", type: :boolean, aliases: "-d", default: true
11+
12+
desc "apply", "Apply a Rezeptfile to the local machine"
13+
option :rezeptfile, aliases: "-f", default: "Rezeptfile"
14+
def apply
15+
logger.level = if options[:verbose]
16+
Logger::DEBUG
17+
else
18+
Logger::INFO
19+
end
20+
@@dry_run = options[:"dry-run"]
21+
r = Koch::Runner.new options[:rezeptfile]
22+
r.go
23+
end
24+
default_task :apply
25+
end
26+
27+
KochCLI.start(ARGV)

0 commit comments

Comments
 (0)