Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
rootmos committed Oct 28, 2023
0 parents commit 510c0c2
Show file tree
Hide file tree
Showing 32 changed files with 2,485 additions and 0 deletions.
124 changes: 124 additions & 0 deletions .github/workflows/tests.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
name: Run tests
on:
push:
branches:
- main

jobs:
sanity-example:
runs-on: ubuntu-latest
steps:
- name: Check out repository code
uses: actions/checkout@v4

- name: The example's specification is clean
run: scripts/is-clean example/openbsd.toml

sanity-script:
runs-on: ubuntu-latest
container:
image: alpine:3.18.4
steps:
- name: Install essentials
run: apk add python3

- name: Check out repository code
uses: actions/checkout@v4

- name: Script is footloose and fancy-free
run: scripts/load_module.py openbsd

base:
needs:
- sanity-script
strategy:
matrix:
version: [ 7.3, 7.4 ]
arch: [ amd64, i386 ]
runs-on: ubuntu-latest
container:
image: alpine:3.18.4
env:
OPENBSD_CACHE: /tmp/cache
WORKDIR: /${{github.job}}-${{github.run_id}}-${{github.run_number}}-${{github.run_attempt}}
steps:
- name: Install essentials
run: apk add bash python3 tar

- name: Check out repository code
uses: actions/checkout@v4

- name: Install dependencies
run: ./openbsd deps --install --arch=${{ matrix.arch }}

- name: Cache OpenBSD files
id: cache-openbsd
uses: actions/cache@v3
with:
path: ${{ env.OPENBSD_CACHE }}
key: openbsd-${{ matrix.version }}-${{ matrix.arch }}-${{ github.job }}
restore-keys: |
openbsd-${{ matrix.version }}-${{ matrix.arch }}-${{ github.job }}
openbsd-${{ matrix.version }}-${{ matrix.arch }}
openbsd-${{ matrix.version }}
openbsd
- name: Run test
run: tests/base -v ${{ matrix.version }} -a ${{ matrix.arch }}

- name: Keep artifacts
uses: actions/upload-artifact@v3
if: always()
with:
name: ${{ github.job }}-${{ matrix.version }}-${{ matrix.arch }}-${{github.run_id}}-${{github.run_number}}-${{github.run_attempt}}
retention-days: 3
path: /${{github.job}}-${{github.run_id}}-${{github.run_number}}-${{github.run_attempt}}/**/*

example:
needs:
- base
- sanity-script
- sanity-example
strategy:
matrix:
version: [ 7.4 ]
arch: [ amd64 ]
runs-on: ubuntu-latest
env:
OPENBSD_CACHE: /tmp/cache
WORKDIR: /${{github.job}}-${{github.run_id}}-${{github.run_number}}-${{github.run_attempt}}
container:
image: alpine:3.18.4

steps:
- name: Install essentials
run: apk add bash python3 tar

- name: Check out repository code
uses: actions/checkout@v4

- name: Install dependencies
run: ./openbsd deps --install --arch=${{ matrix.arch }}

- name: Cache OpenBSD files
id: cache-openbsd
uses: actions/cache@v3
with:
path: ${{ env.OPENBSD_CACHE }}
key: openbsd-${{ matrix.version }}-${{ matrix.arch }}-${{ github.job }}
restore-keys: |
openbsd-${{ matrix.version }}-${{ matrix.arch }}-${{ github.job }}
openbsd-${{ matrix.version }}-${{ matrix.arch }}
openbsd-${{ matrix.version }}
openbsd
- name: Run test
run: tests/example -v ${{ matrix.version }} -a ${{ matrix.arch }}

- name: Keep artifacts
uses: actions/upload-artifact@v3
if: always()
with:
name: ${{ github.job }}-${{ matrix.version }}-${{ matrix.arch }}-${{github.run_id}}-${{github.run_number}}-${{github.run_attempt}}
retention-days: 3
path: /${{github.job}}-${{github.run_id}}-${{github.run_number}}-${{github.run_attempt}}/**/*
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
.cache
__pycache__

workdir
10 changes: 10 additions & 0 deletions example/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
ROOT := $(shell dirname $(realpath $(firstword $(MAKEFILE_LIST))))
SCRIPTS ?= $(ROOT)/../scripts

INTERCALATE ?= $(SCRIPTS)/intercalate

.PHONY: spec
spec: openbsd.toml

openbsd.toml: $(wildcard parts/*.toml) | $(INTERCALATE)
$(INTERCALATE) $@ $^
62 changes: 62 additions & 0 deletions example/openbsd.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
version = "7.4"
arch = "amd64"

[base]
hostname = "foo"
disk.size = 4096
sets = [ "man", "game", "comp" ]
network.interface = "xnf0"

[site]
pkgs = [ "awscli" ]
timeout = 1800

[[site.patch.doas.files]]
lines = [ "permit nopass :wheel" ]
mode = 0o400
dst = "/etc/doas.conf"

[[site.patch.ntpd.files]]
dst = "/etc/ntpd.conf"
lines = [
"server 169.254.169.123 weight 2", # https://aws.amazon.com/blogs/aws/keeping-time-with-amazon-time-sync-service/
"servers pool.ntp.org",
"sensor *",
"constraints from openbsd.org",
]

[site.patch.nginx]
pkg = "nginx"
service = "nginx"

[[site.patch.nginx.files]]
src = "site/index.html"
dst = "/var/www/htdocs/index.html"

[[site.patch.nginx.files]]
src = "site/nginx.conf"
dst = "/etc/nginx/nginx.conf"

[site.patch.echoip]
pkgs = [ "go" ]
services = [ "echoip" ]
install = "site/echoip/install"

[[site.patch.echoip.files]]
src = "site/echoip/service"
mode = 0o755
dst = "/etc/rc.d/echoip"

[[run.hostfwd.tcp]]
hport = 8000
gport = 80

[aws.ami]
name_template = "foo-%OS-%VERSION-%SALT"
snapshot.s3.bucket = "rootmos-infra-artifacts"
snapshot.s3.key_template = "uploads/foo-%TIMESTAMP-%SALT.img"
vmimport_role = "arn:aws:iam::676237474471:role/infra-vmimport"

[aws.ami.terraform]
local = "image"
output = "terraform/openbsd.tf"
2 changes: 2 additions & 0 deletions example/parts/00.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
version = "7.4"
arch = "amd64"
5 changes: 5 additions & 0 deletions example/parts/10.base.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
[base]
hostname = "foo"
disk.size = 4096
sets = [ "man", "game", "comp" ]
network.interface = "xnf0"
3 changes: 3 additions & 0 deletions example/parts/20.site.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[site]
pkgs = [ "awscli" ]
timeout = 1800
4 changes: 4 additions & 0 deletions example/parts/21.site.patch.doas.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[[site.patch.doas.files]]
lines = [ "permit nopass :wheel" ]
mode = 0o400
dst = "/etc/doas.conf"
8 changes: 8 additions & 0 deletions example/parts/22.site.patch.ntpd.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
[[site.patch.ntpd.files]]
dst = "/etc/ntpd.conf"
lines = [
"server 169.254.169.123 weight 2", # https://aws.amazon.com/blogs/aws/keeping-time-with-amazon-time-sync-service/
"servers pool.ntp.org",
"sensor *",
"constraints from openbsd.org",
]
11 changes: 11 additions & 0 deletions example/parts/23.site.patch.nginx.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
[site.patch.nginx]
pkg = "nginx"
service = "nginx"

[[site.patch.nginx.files]]
src = "site/index.html"
dst = "/var/www/htdocs/index.html"

[[site.patch.nginx.files]]
src = "site/nginx.conf"
dst = "/etc/nginx/nginx.conf"
9 changes: 9 additions & 0 deletions example/parts/24.site.patch.echoip.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
[site.patch.echoip]
pkgs = [ "go" ]
services = [ "echoip" ]
install = "site/echoip/install"

[[site.patch.echoip.files]]
src = "site/echoip/service"
mode = 0o755
dst = "/etc/rc.d/echoip"
3 changes: 3 additions & 0 deletions example/parts/30.run.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[[run.hostfwd.tcp]]
hport = 8000
gport = 80
5 changes: 5 additions & 0 deletions example/parts/40.aws.ami.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
[aws.ami]
name_template = "foo-%OS-%VERSION-%SALT"
snapshot.s3.bucket = "rootmos-infra-artifacts"
snapshot.s3.key_template = "uploads/foo-%TIMESTAMP-%SALT.img"
vmimport_role = "arn:aws:iam::676237474471:role/infra-vmimport"
3 changes: 3 additions & 0 deletions example/parts/41.aws.terraform.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[aws.ami.terraform]
local = "image"
output = "terraform/openbsd.tf"
6 changes: 6 additions & 0 deletions example/site/echoip/install
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/bin/sh

set -o errexit

export GOPATH=$(pwd) GOCACHE=/tmp/go
go install -v github.com/mpolden/echoip/...@d84665c
13 changes: 13 additions & 0 deletions example/site/echoip/service
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#!/bin/ksh

BASE=/usr/patch/echoip

daemon="$BASE/bin/echoip"
daemon_user=nobody
TEMPLATE_DIR=$(find "$BASE/pkg/mod/github.com/mpolden" -name html -type d)
daemon_flags="-l :9000 -H X-Real-IP -r -p -t $TEMPLATE_DIR"
rc_bg=YES

. /etc/rc.d/rc.subr

rc_cmd $1
1 change: 1 addition & 0 deletions example/site/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<html><head></head><body>hello</body></html>
23 changes: 23 additions & 0 deletions example/site/nginx.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
user www;
worker_processes 1;

events {
worker_connections 800;
}

http {
server {
listen 80;
server_name localhost;

root /var/www/htdocs;
index index.html;
rewrite ^/$ /index.html;

location ^~/ip/ {
proxy_pass http://127.0.0.1:9000/;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header Host $http_host;
}
}
}
1 change: 1 addition & 0 deletions example/terraform/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.terraform
25 changes: 25 additions & 0 deletions example/terraform/.terraform.lock.hcl

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

40 changes: 40 additions & 0 deletions example/terraform/app.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
resource "aws_instance" "app" {
ami = local.image
instance_type = "t2.nano"

security_groups = [ aws_security_group.sg.name ]

tags = {
Name = "foo"
GitRepo = var.git-repo
}
}

resource "aws_security_group" "sg" {
name = "${var.prefix}sg"

ingress {
protocol = "tcp"
from_port = 22
to_port = 22
cidr_blocks = ["0.0.0.0/0"]
}

ingress {
protocol = "tcp"
from_port = 80
to_port = 80
cidr_blocks = ["0.0.0.0/0"]
}

egress {
protocol = "-1"
from_port = 0
to_port = 0
cidr_blocks = ["0.0.0.0/0"]
}

tags = {
GitRepo = var.git-repo
}
}
Loading

0 comments on commit 510c0c2

Please sign in to comment.