This repository has been archived by the owner on Jun 11, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Taskfile.yaml
executable file
·183 lines (167 loc) · 6.65 KB
/
Taskfile.yaml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
---
# yaml-language-server: $schema=https://taskfile.dev/schema.json
version: "3"
env:
SOPS_AGE_KEY_FILE: '{{.ROOT_DIR}}/age.key'
vars:
# renovate: datasource=github-releases depName=getsops/sops
SOPS_VERSION: v3.8.1
# renovate: datasource=github-releases depName=fastfetch-cli/fastfetch
FASTFETCH_VERSION: 2.15.0
includes:
app: ./apps
nut: ./nut
x-preconditions:
- ¬-root
msg: must not be run as root
sh: '[[ $LOGNAME != "root" ]]'
- &container-service-not-found
msg: container service '{{.container}}' not found
sh: test -f /var/opt/{{.container}}/docker-compose.yml
- &container-not-found
msg: container '{{.container}}' not found
sh: docker inspect {{.container}}
- &container-file-not-found
msg: file 'apps/{{.container}}/docker-compose.yml' not found
sh: test -f {{.ROOT_DIR}}/apps/{{.container}}/docker-compose.yml
- &container-directory-not-found
msg: directory 'apps/{{.container}}/data' not found
sh: test -d {{.ROOT_DIR}}/apps/{{.container}}/data
tasks:
default:
cmd: task -l
silent: true
deps:
desc: Install System Deps
cmds:
- sudo install -m 0755 -d /etc/apt/keyrings
- sudo curl -fsSL https://download.docker.com/linux/debian/gpg -o /etc/apt/keyrings/docker.asc
- sudo chmod a+r /etc/apt/keyrings/docker.asc
- echo "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.asc] https://download.docker.com/linux/debian $(. /etc/os-release && echo "$VERSION_CODENAME") stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
- sudo apt update; sudo apt upgrade -y; sudo apt full-upgrade -y; sudo apt autoclean; sudo apt autoremove -y
- sudo apt install -y age dnsutils direnv expect fish fzf gh git gron htop btop moreutils nano net-tools netcat-traditional nmap rsync tcpdump telnet tree wget yq zoxide docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin
- wget https://github.com/getsops/sops/releases/download/{{.SOPS_VERSION}}/sops_{{.SOPS_VERSION | replace "v" ""}}_arm64.deb
- wget https://github.com/fastfetch-cli/fastfetch/releases/download/{{.FASTFETCH_VERSION}}/fastfetch-linux-aarch64.deb
- sudo apt install -y ./sops_{{.SOPS_VERSION | replace "v" ""}}_arm64.deb
- sudo apt install -y ./fastfetch-linux-aarch64.deb
- sudo rm sops_{{.SOPS_VERSION | replace "v" ""}}_arm64.deb
- sudo rm fastfetch-linux-aarch64.deb
- sudo install -d -o $(logname) -g $(logname) -m 755 /var/opt
preconditions:
- *not-root
start-*:
desc: Start a container service
cmds:
- task: reload-{{.container}}
- docker compose -f /var/opt/{{.container}}/docker-compose.yml up -d
- sudo docker ps --all --filter name={{.container}} --format "{{ `{{.Names}} - {{.Image}} - {{.Status}}` }}"
vars:
container: '{{index .MATCH 0}}'
preconditions:
- *not-root
stop-*:
desc: Stop a container service
cmd: docker compose -f /var/opt/{{.container}}/docker-compose.yml down
vars:
container: '{{index .MATCH 0}}'
preconditions:
- *not-root
- *container-service-not-found
restart-*:
desc: Restart a container service
cmds:
- task: reload-{{.container}}
- docker compose -f /var/opt/{{.container}}/docker-compose.yml restart
- sudo docker ps --all --filter name={{.container}} --format "{{ `{{.Names}} - {{.Image}} - {{.Status}}` }}"
vars:
container: '{{index .MATCH 0}}'
preconditions:
- *not-root
- *container-service-not-found
status-*:
desc: Status of a container service
cmd: docker compose -f /var/opt/{{.container}}/docker-compose.yml ps
vars:
container: '{{index .MATCH 0}}'
preconditions:
- *not-root
- *container-service-not-found
reload-*:
desc: Reload a container service
cmds:
# - sudo rsync -rv {{.ROOT_DIR}}/apps/{{.container}}/docker-compose.yml /var/opt/{{.container}}/
# - sudo rsync -rv --mkpath --delete {{.ROOT_DIR}}/apps/{{.container}}/data/{{- if eq .CLI_FORCE false }}config/{{ end }} /var/opt/{{.container}}{{- if eq .CLI_FORCE false }}/config{{ end }}
- sudo rsync -rv {{.ROOT_DIR}}/apps/{{.container}}/ /var/opt/{{.container}}/
- sudo --preserve-env bash -c "find /var/opt/{{.container}} -type f -name "*.sops.*" -print0 | xargs -0 -I {} sops --config {{.ROOT_DIR}}/.sops.yaml --decrypt --in-place {}"
sources:
- '{{.ROOT_DIR}}/apps/{{.container}}/docker-compose.yml'
- '{{.ROOT_DIR}}/apps/{{.container}}/data/config/**/**'
generates:
- /var/opt/{{.container}}/docker-compose.yml
- /var/opt/{{.container}}/config/**/**
label: reload-{{.container}}
preconditions:
- *not-root
- *container-file-not-found
- *container-directory-not-found
vars:
container: '{{index .MATCH 0}}'
remove-*:
desc: Remove a container service
prompt: Remove the '{{.container}}' container ... continue?
cmds:
- task: stop-{{.container}}
- sudo rm -rf /var/opt/{{.container}}
vars:
container: '{{index .MATCH 0}}'
preconditions:
- *not-root
logs-*:
desc: Tail logs of a container
cmd: sudo docker logs -f {{.container}}
vars:
container: '{{index .MATCH 0}}'
preconditions:
- *not-root
- *container-not-found
list:
desc: List all containers
cmd: docker ps --all --format '{{ `{{.Names}}\t{{.Status}}\t{{.Networks}}` }}' | sort | column -s$'\t' -t
preconditions:
- *not-root
dotfiles:
desc: Setup dotfiles
cmds:
- | # Nano
git -C ~/.nano pull || git clone https://github.com/galenguyer/nano-syntax-highlighting ~/.nano
- | # Direnv
mkdir -p /home/$LOGNAME/.config/direnv && \
tee /home/$LOGNAME/.config/direnv/direnv.toml > /dev/null <<EOF
[whitelist]
prefix = [ "~/git/home-service" ]
EOF
- | # Fish Hooks
tee /home/$LOGNAME/.config/fish/conf.d/hooks.fish > /dev/null <<EOF
if status is-interactive
if type -q direnv
direnv hook fish | source
end
if type -q starship
starship init fish | source
end
if type -q zoxide
zoxide init fish | source
end
end
EOF
- | # Fish Greeting
tee /home/$LOGNAME/.config/fish/conf.d/fish_greeting.fish > /dev/null <<EOF
function fish_greeting
fastfetch
end
EOF
- | # Fish Completions
curl -fsSL -o /home/$LOGNAME/.config/fish/completions/task.fish \
https://raw.githubusercontent.com/go-task/task/main/completion/fish/task.fish
preconditions:
- *not-root