Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
marius committed May 5, 2023
0 parents commit a892c25
Show file tree
Hide file tree
Showing 36 changed files with 1,395 additions and 0 deletions.
19 changes: 19 additions & 0 deletions .github/workflows/rubocop.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
name: Tests and Rubocop

on:
pull_request:
push:
branches: [ main ]
workflow_dispatch:

jobs:
rake:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
- uses: ruby/setup-ruby@v1
with:
ruby-version: '3.0'
bundler-cache: true
- run: bundle exec rake
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
*.gem
/.vagrant/
31 changes: 31 additions & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
require: rubocop-rake

AllCops:
NewCops: enable
TargetRubyVersion: 2.7

Style/StringLiterals:
Enabled: true
EnforcedStyle: double_quotes

Style/StringLiteralsInInterpolation:
Enabled: true
EnforcedStyle: double_quotes

Style/FormatStringToken:
Enabled: false

Layout/LineLength:
Max: 120

Metrics/AbcSize:
Max: 24

Metrics/MethodLength:
Max: 25

Gemspec/RequireMFA:
Enabled: false

Style/ClassVars:
Enabled: false
4 changes: 4 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# frozen_string_literal: true

source "https://rubygems.org"
gemspec
90 changes: 90 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
PATH
remote: .
specs:
koch (0.1.5)
diffy (~> 3.4)
logger (~> 1.5)
thor (~> 1.2)
zeitwerk (~> 2.6)
zlib (~> 1.1)

GEM
remote: https://rubygems.org/
specs:
ast (2.4.2)
coderay (1.1.3)
diffy (3.4.2)
ffi (1.15.5)
formatador (1.1.0)
guard (2.18.0)
formatador (>= 0.2.4)
listen (>= 2.7, < 4.0)
lumberjack (>= 1.0.12, < 2.0)
nenv (~> 0.1)
notiffany (~> 0.0)
pry (>= 0.13.0)
shellany (~> 0.0)
thor (>= 0.18.1)
guard-compat (1.2.1)
guard-minitest (2.4.6)
guard-compat (~> 1.2)
minitest (>= 3.0)
json (2.6.3)
listen (3.8.0)
rb-fsevent (~> 0.10, >= 0.10.3)
rb-inotify (~> 0.9, >= 0.9.10)
logger (1.5.3)
lumberjack (1.2.8)
method_source (1.0.0)
minitest (5.18.0)
nenv (0.3.0)
notiffany (0.1.3)
nenv (~> 0.1)
shellany (~> 0.0)
parallel (1.22.1)
parser (3.2.1.1)
ast (~> 2.4.1)
pry (0.14.2)
coderay (~> 1.1)
method_source (~> 1.0)
rainbow (3.1.1)
rake (13.0.6)
rb-fsevent (0.11.2)
rb-inotify (0.10.1)
ffi (~> 1.0)
regexp_parser (2.7.0)
rexml (3.2.5)
rubocop (1.48.1)
json (~> 2.3)
parallel (~> 1.10)
parser (>= 3.2.0.0)
rainbow (>= 2.2.2, < 4.0)
regexp_parser (>= 1.8, < 3.0)
rexml (>= 3.2.5, < 4.0)
rubocop-ast (>= 1.26.0, < 2.0)
ruby-progressbar (~> 1.7)
unicode-display_width (>= 2.4.0, < 3.0)
rubocop-ast (1.27.0)
parser (>= 3.2.1.0)
rubocop-rake (0.6.0)
rubocop (~> 1.0)
ruby-progressbar (1.13.0)
shellany (0.0.1)
thor (1.2.1)
unicode-display_width (2.4.2)
zeitwerk (2.6.7)
zlib (1.1.0)

PLATFORMS
x86_64-linux

DEPENDENCIES
guard (~> 2.18)
guard-minitest (~> 2.4)
koch!
rake (~> 13.0)
rubocop (~> 1.48)
rubocop-rake (~> 0.6)

BUNDLED WITH
2.4.8
8 changes: 8 additions & 0 deletions Guardfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# frozen_string_literal: true

guard :minitest do
watch(%r{^test/(.*)?_test\.rb$})
watch(%r{^lib/(.*/)?([^/]+)\.rb$}) { |m| "test/#{m[2]}_test.rb" }
watch(%r{^test/test_helper\.rb$}) { "test" }
watch(%r{^bin/koch$}) { "test" }
end
13 changes: 13 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
Copyright 2023 Marius Nünnerich

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
50 changes: 50 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
# Koch

Koch is a tool to install software packages, change files and other things
on a single machine. The changes are described in a file and are written in Ruby.

The file describing a machine should be versioned, that way you create a repeatable
description of how a machine is set up, with history.

For an example of how this can look like, check out this [Rezeptfile](example/Rezeptfile)
and the other files in the directory.

## Notice

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

Fully **backup** any machine you run this on! This is alpha grade software and
might cause havoc, esp when run with root privileges!
I suggest you use Vagrant to try this out.

## Status

![Tests and Rubocop](https://github.com/marius/koch/actions/workflows/rubocop.yml/badge.svg)

## Philosophy

Koch's configuration files (Rezeptfiles) are just Ruby. All Koch does is provide
a bunch of convenience functions. Feel free to use all the Ruby you want.

## Usage

```
sudo apt -y install git
sudo gem install koch
git clone git@github.com:example/machine.git
cd machine
sudo koch
```

## Supported platforms

- Ubuntu 22.04 (amd64)
- Debian 11 (amd64)
- End of list

## TODO

- [ ] Interactive mode, ask about each change
- [ ] publish to rubygems
16 changes: 16 additions & 0 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# frozen_string_literal: true

require "bundler/gem_tasks"
require "rake/testtask"

Rake::TestTask.new(:test) do |t|
t.libs << "test"
t.libs << "lib"
t.test_files = FileList["test/**/*_test.rb"]
end

require "rubocop/rake_task"

RuboCop::RakeTask.new

task default: %i[test rubocop]
84 changes: 84 additions & 0 deletions Vagrantfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
# frozen_string_literal: true

# -*- mode: ruby -*-
# vi: set ft=ruby :

# All Vagrant configuration is done below. The "2" in Vagrant.configure
# configures the configuration version (we support older styles for
# backwards compatibility). Please don't change it unless you know what
# you're doing.
Vagrant.configure("2") do |config|
# The most common configuration options are documented and commented below.
# For a complete reference, please see the online documentation at
# https://docs.vagrantup.com.

# Every Vagrant development environment requires a box. You can search for
# boxes at https://vagrantcloud.com/search.
# config.vm.box = "generic/ubuntu2204"

# Disable automatic box update checking. If you disable this, then
# boxes will only be checked for updates when the user runs
# `vagrant box outdated`. This is not recommended.
# config.vm.box_check_update = false

# Create a forwarded port mapping which allows access to a specific port
# within the machine from a port on the host machine. In the example below,
# accessing "localhost:8080" will access port 80 on the guest machine.
# NOTE: This will enable public access to the opened port
# config.vm.network "forwarded_port", guest: 80, host: 8080

# Create a forwarded port mapping which allows access to a specific port
# within the machine from a port on the host machine and only allow access
# via 127.0.0.1 to disable public access
# config.vm.network "forwarded_port", guest: 80, host: 8080, host_ip: "127.0.0.1"

# Create a private network, which allows host-only access to the machine
# using a specific IP.
# config.vm.network "private_network", ip: "192.168.33.10"

# Create a public network, which generally matched to bridged network.
# Bridged networks make the machine appear as another physical device on
# your network.
# config.vm.network "public_network"

# Share an additional folder to the guest VM. The first argument is
# the path on the host to the actual folder. The second argument is
# the path on the guest to mount the folder. And the optional third
# argument is a set of non-required options.
config.vm.synced_folder ".", "/vagrant", nfs_version: 4, nfs_udp: false

# Provider-specific configuration so you can fine-tune various
# backing providers for Vagrant. These expose provider-specific options.
# Example for VirtualBox:
#
# config.vm.provider "virtualbox" do |vb|
# # Display the VirtualBox GUI when booting the machine
# vb.gui = true
#
# # Customize the amount of memory on the VM:
# vb.memory = "1024"
# end
#
# View the documentation for the provider you are using for more
# information on available options.

# Enable provisioning with a shell script. Additional provisioners such as
# Ansible, Chef, Docker, Puppet and Salt are also available. Please see the
# documentation for more information about their specific syntax and use.
require_relative "lib/koch/version"
config.vm.provision "shell", inline: <<-SHELL
export DEBIAN_FRONTEND=noninteractive
apt update
apt install -y build-essential zlib1g-dev ruby-dev
gem install --no-document /vagrant/koch-#{Koch::VERSION}.gem
printf -- "---\\nrestic:\\n password: test123\\n" >/etc/secrets.yaml
SHELL

config.vm.define "ubuntu", primary: true do |ubuntu|
ubuntu.vm.box = "generic/ubuntu2204"
end

config.vm.define "debian" do |debian|
debian.vm.box = "debian/bullseye64"
end
end
27 changes: 27 additions & 0 deletions bin/koch
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#!/usr/bin/env ruby
# frozen_string_literal: true

require "thor"
require_relative "../lib/koch"

# KochCLI is the glue between the commandline and the actual Koch implementation
class KochCLI < Thor
class_option :verbose, type: :boolean, aliases: "-v"
class_option :"dry-run", type: :boolean, aliases: "-d", default: true

desc "apply", "Apply a Rezeptfile to the local machine"
option :rezeptfile, aliases: "-f", default: "Rezeptfile"
def apply
logger.level = if options[:verbose]
Logger::DEBUG
else
Logger::INFO
end
@@dry_run = options[:"dry-run"]
r = Koch::Runner.new options[:rezeptfile]
r.go
end
default_task :apply
end

KochCLI.start(ARGV)
Loading

0 comments on commit a892c25

Please sign in to comment.