Skip to content

Commit 36e063f

Browse files
authored
release: v1.2-3 (#200)
2 parents 90758c0 + f6475b3 commit 36e063f

File tree

25 files changed

+286
-134
lines changed

25 files changed

+286
-134
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,5 @@ local/*.hash
99

1010
# git add --force '**/*.local*'
1111

12-
*.local.caddy
12+
*.local.*
13+
!.*.local.*

base/default.yml

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,16 @@
44
gather_facts: no
55
vars:
66
os: "{{ OS | default('local:vztmpl/debian-13-standard_13.1-1_amd64.tar.zst') }}"
7-
key_dir: "{{ KEYS_DIR | default('/share/.ssh') }}"
7+
share_dir: "{{ SHARE | default('/share') }}"
8+
cert_dir: "{{ share_dir }}/.cert"
9+
key_dir: "{{ share_dir }}/.ssh"
810
tasks:
911

10-
- name: Ensure key directory
12+
- name: Ensure directories
1113
file:
1214
path: "{{ key_dir }}"
1315
state: directory
16+
loop: ["{{ share_dir }}", "{{ cert_dir }}", "{{ key_dir }}"]
1417

1518
- name: Generate container key on host
1619
community.crypto.openssh_keypair:

base/roles/base/files/profile.sh

Lines changed: 48 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,6 @@ alias .....='cd ../../../..'
77

88
# General
99

10-
alias l='ls -lhA --group-directories-first'
11-
alias grep='grep --color=auto'
12-
alias mdir='mkdir -pv'
13-
14-
alias df='df -h'
15-
alias free='free -h'
16-
alias du='du -h'
17-
18-
alias journal='journalctl -xef --output=short-iso --no-pager'
19-
alias ports='ss -tulpn'
20-
alias proc='ps aux | grep -v grep | grep -i'
2110
alias redo='sudo "$(fc -ln -1)"'
2211

2312
# Development
@@ -54,8 +43,6 @@ backport() {
5443

5544
# Functions
5645

57-
cdir() { mkdir "$1" && cd "$1"; }
58-
5946
extract () {
6047
if [ -f "$1" ] ; then
6148
case "$1" in
@@ -66,18 +53,60 @@ extract () {
6653
*.tar) tar xvf "$1" ;;
6754
*.tgz) tar xvzf "$1" ;;
6855
*.zip) unzip "$1" ;;
69-
*) echo "'$1' failed" ;;
7056
esac
71-
else
72-
echo "'$1' no valid file"
7357
fi
7458
}
7559

60+
exe() {
61+
docker exec -it "$(docker ps -qf name=$1)" /bin/bash
62+
}
63+
64+
c() {
65+
[ -z "$1" ] && { cd; return; }
66+
[ -d "$1" ] && { cd "$1"; return; } ||
67+
[ -f "$1" ] && file -b "$1" | grep -q -e "text" -e "empty" && { cat "$1"; return; } ||
68+
file "$1"
69+
}
70+
71+
d() {
72+
mkdir -pv "$1" && cd "$1";
73+
}
74+
75+
f() {
76+
case "$1" in
77+
/*) grep --color=auto -rni "$1" . ;;
78+
*) find . -iname "*${1:1}*" ;;
79+
esac
80+
}
81+
82+
l() {
83+
command ls -lAhF --color=auto "$@";
84+
}
85+
86+
j() {
87+
journalctl -xe --no-pager -u "$1" || journalctl -xe --no-pager
88+
}
89+
90+
p() {
91+
[ -z "$1" ] && { ps aux; return $?; }
92+
local search
93+
search="[${1:0:1}]${1:1}"
94+
ps aux | grep --color=auto "$search"
95+
}
96+
97+
s() {
98+
[ -z "$1" ] && { cd /etc/systemd/system; return $?; }
99+
case "$1" in start|stop|restart|reload|enable|disable|status|is-active|is-enabled|is-failed|mask|unmask|daemon-reload|reset-failed| \
100+
cat|show|edit|list-units|list-unit-files|list-dependencies|list-jobs)
101+
command systemctl "$@"; return $?;;
102+
esac
103+
systemctl cat "$1" && echo && systemctl status --no-pager "$1"
104+
}
105+
76106
package() {
77107
local project
78108
project=$(basename "$PWD")
79-
local out="${project}-packaged.txt"
80-
109+
local out="${project}.txt"
81110
rm -f -- "$out"
82111

83112
if [ -d .git ]; then
@@ -88,7 +117,7 @@ package() {
88117

89118
while IFS= read -r file; do
90119
if file --mime-type --brief "$file" | grep -q '^text/'; then
91-
printf "# Filename: %s\n\n" "$file"
120+
printf "# %s\n\n" "$file"
92121
sed '' "$file"
93122
printf "\n---\n\n"
94123
fi

base/roles/base/tasks/main.yml

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
- name: Base container configuration
22
block:
3-
- name: Set key directory
3+
- name: Set shared directories
44
set_fact:
5-
key_dir: "{{ KEYS_DIR | default('/share/.ssh') }}"
5+
cert_dir: "{{ share_dir }}/.certs"
6+
key_dir: "{{ share_dir }}/.ssh"
67

78
- name: Update system
89
apt:
@@ -53,6 +54,8 @@
5354
extra:
5455
- { path: "/app", state: "directory", mode: "0755", owner: "app", group: "config" }
5556
- { path: "/app/.ssh", state: "directory", mode: "0711", owner: "app", group: "config" }
57+
- { path: "{{ key_dir }}", state: "directory", mode: "0711", owner: "app", group: "config" }
58+
- { path: "{{ cert_dir }}", state: "directory", mode: "0711", owner: "app", group: "config" }
5659

5760
- name: Container accessibility
5861
import_tasks: access.yml

base/roles/base/vars/main.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ default_packages:
22
- sudo
33
- locales
44
- curl
5+
- jq
56
- unzip
67
- vim
78

@@ -11,5 +12,7 @@ default_users:
1112
- { name: "app", groups: ["config"], create_home: false, home: "/app" }
1213
- { name: "config", groups: ["config", "root", "sudo"], create_home: false, home: "/app" }
1314

15+
share_dir: "/share"
16+
1417
ssh_users:
1518
- config

config.env

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
IP="192.168.178.254"
2-
ID="254"
2+
ID="100"
33
CORES="4"
44
MEMORY="6144"
55
SWAP="1024"

config/attributes/default.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
default['title'] = "Proxmox-GitOps"
22
default['online'] = "https://github.com/stevius10/Proxmox-GitOps"
3-
default['version'] = "v1.2-2"
3+
default['version'] = "v1.2-3"
44

55
default['id'] = ENV['ID']
66
default['host'] = (default['ip'] = ENV['IP'].to_s.presence || "127.0.0.1")

config/libraries/common.rb

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
require_relative 'default'
2+
13
module Common
24

35
# General
@@ -33,14 +35,10 @@ def self.daemon(ctx, name)
3335
end
3436
end
3537

36-
def self.application(ctx, name, user: nil, group: nil,
38+
def self.application(ctx, name, user: Default.user(ctx).to_s, group: Default.group(ctx).to_s,
3739
exec: nil, cwd: nil, unit: {}, actions: [:enable, :start], subscribe: nil, reload: 'systemd_reload',
3840
restart: 'on-failure', restart_delay: 10, restart_limit: 10, restart_max: 600,
3941
verify: true, verify_timeout: 60, verify_interval: 5, verify_cmd: "systemctl is-active --quiet #{name}")
40-
user ||= Default.user(ctx)
41-
group ||= Default.group(ctx)
42-
user = user.to_s
43-
group = group.to_s
4442

4543
if exec
4644
daemon(ctx, reload)
@@ -69,7 +67,7 @@ def self.application(ctx, name, user: nil, group: nil,
6967

7068
# Mask default application service
7169
conflicts = %Q(systemctl list-unit-files '*#{File.basename(exec.split.first)}*.service' --no-legend | awk '$2!="masked" {print $1}')
72-
Ctx.dsl(ctx).execute "mask_conflicts_#{name}" do
70+
Ctx.dsl(ctx).execute "application_mask_#{name}" do
7371
command "#{conflicts} | xargs -r -IUNIT sh -c 'systemctl stop UNIT && systemctl mask UNIT'"
7472
only_if conflicts
7573
returns [0, 123] # already masked returns '123'
@@ -81,15 +79,22 @@ def self.application(ctx, name, user: nil, group: nil,
8179
group 'root'
8280
mode '0664'
8381
content unit_content
82+
notifies :run, "execute[application_reset_#{name}]", :immediately
8483
notifies :run, "execute[#{reload}]", :immediately
8584
notifies :restart, "service[#{name}]", :delayed
8685
end
8786

8887
end
8988

89+
Ctx.dsl(ctx).execute "application_reset_#{name}" do
90+
command "systemctl reset-failed #{name}.service"
91+
only_if "systemctl is-failed --quiet #{name}.service"
92+
action :nothing
93+
end
94+
9095
if actions.include?(:force_restart)
91-
Ctx.dsl(ctx).execute "force_restart_#{name}" do
92-
command "systemctl reset-failed #{name}; systemctl stop #{name} || true && sleep 1 && systemctl start #{name}"
96+
Ctx.dsl(ctx).execute "application_restart_#{name}" do
97+
command "systemctl stop #{name} || true && sleep 1 && systemctl start #{name}"
9398
action :run
9499
end
95100
else
@@ -107,11 +112,12 @@ def self.application(ctx, name, user: nil, group: nil,
107112
(is_active = Mixlib::ShellOut.new(verify_cmd)).run_command
108113
is_active.exitstatus.zero? ? (ok = true; break) : (sleep verify_interval)
109114
end
110-
Logs.error!("service '#{name}' failed health check") unless ok
115+
raise (Logs.debug("service '#{name}' failed health check", [
116+
Mixlib::ShellOut.new("systemctl status #{name} --no-pager").run_command.stdout.strip,
117+
Mixlib::ShellOut.new("journalctl -u #{name} --no-pager").run_command.stdout.strip,
118+
], level: :error)) unless ok
111119
end
112-
action :nothing
113-
subscribes :run, "service[#{name}]", :delayed if verify
114-
subscribes :run, "file[/etc/systemd/system/#{name}.service]", :delayed if verify
120+
only_if { verify }
115121
end
116122
end
117123

config/recipes/git.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@
99
mode '0644'
1010
variables(host: node['host'], app_user: node['app']['user'] , ssh_user: node['app']['config'],
1111
app_dir: node['git']['dir']['app'], home_dir: node['git']['dir']['home'],
12-
http_port: node['git']['port']['http'], ssh_port: node['git']['port']['ssh'] )
12+
http_port: node['git']['port']['http'], ssh_port: node['git']['port']['ssh'],
13+
org_main: node['git']['org']['main'])
1314
action :create_if_missing
1415
end
1516

config/recipes/repo/push.rb

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,18 +12,16 @@
1212
if ! git ls-remote origin refs/for/release | grep -q "$(git rev-parse HEAD)"; then
1313
if { [ "#{repository}" != "./" ] && [ "#{is_bootstrap}" = "false" ]; } || \
1414
{ [ "#{repository}" = "./" ] && [ "#{is_bootstrap}" = "true" ]; }; then
15-
git push origin HEAD:refs/for/release \
16-
-o topic="release" \
17-
-o title="Release Pull Request" \
18-
-o description="Created automatically for deployment." \
19-
-o force-push
15+
git push origin HEAD:refs/for/release -o topic="release" -o title="Release Pull Request" \
16+
-o description="Created automatically for deployment." -o force-push
2017
fi
18+
git push -u origin HEAD:snapshot
2119
fi
2220
fi
2321
EOH
2422
end
2523

26-
execute "repo_#{name_repo}_push_snapshot" do
24+
execute "repo_#{name_repo}_push_rollback" do
2725
command <<-EOH
2826
cp -r #{path_destination}/.git #{path_working}
2927
cd #{path_working} && git checkout -b #{node['git']['branch']['rollback']} && git add -A
@@ -32,6 +30,6 @@
3230
EOH
3331
cwd path_destination
3432
user node['app']['user']
35-
only_if { Logs.info("[#{repository} (#{name_repo})]: snapshot commit")
33+
only_if { Logs.info("[#{repository} (#{name_repo})]: rollback commit")
3634
node.run_state["#{name_repo}_repo_exists"] }
3735
end

0 commit comments

Comments
 (0)