-
Notifications
You must be signed in to change notification settings - Fork 8
/
alias
executable file
·188 lines (173 loc) · 8.41 KB
/
alias
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
184
185
186
187
188
#!/usr/bin/zsh
rcpath="$HOME/go/src/github.com/kpango/dotfiles"
dockerrm(){
docker container stop $(docker container ls -aq)
docker ps -aq | xargs docker rm -f
docker container prune -f
docker images -aq | xargs docker rmi -f;
docker image prune -a -f
docker volume prune -f
docker network prune -f
docker system prune -a -f
}
alias dockerrm="dockerrm"
zsh_path="/usr/bin/zsh"
container_name="dev"
alias kpmove="cd $rcpath"
alias kpbuild="kpmove&&docker build --pull=true --file=$rcpath/Dockerfile -t kpango/dev:latest $rcpath"
devrun(){
port_range="8000-9300"
privileged=true
tz_path="/usr/share/zoneinfo/Japan"
font_dir="/System/Library/Fonts"
docker_daemon="$HOME/Library/Containers/com.docker.helper/Data/.docker/daemon.json"
docker_config="$HOME/Library/Containers/com.docker.helper/Data/.docker/config.json"
docker_sock="/var/run/docker.sock"
container_home="/home/kpango"
container_root="/root"
container_goroot="$container_home/go"
goroot="/usr/local/go"
image_name=kpango/dev:latest
case "$(uname -s)" in
Darwin)
echo 'Docker on macOS start'
# -e DISPLAY \
# -v /tmp/.X11-unix:/tmp/.X11-unix \
docker run \
--cap-add=ALL \
--name $container_name \
--restart always \
--privileged=$privileged \
--workdir $container_home \
-p $port_range:$port_range \
-v $HOME/.docker/daemon.json:$container_home/.docker/daemon.json \
-v $HOME/.gitconfig:$container_home/.gitconfig \
-v $HOME/.gnupg:$container_home/.gnupg \
-v $HOME/.kube:$container_home/.kube \
-v $HOME/.netrc:$container_home/.netrc \
-v $HOME/.ssh:$container_home/.ssh \
-v $HOME/.talos:$container_home/.talos \
-v $HOME/.tmux:$container_home/.tmux \
-v $HOME/.zsh_history:$container_home/.zsh_history \
-v $HOME/Documents:$container_home/Documents \
-v $HOME/Downloads:$container_home/Downloads \
-v $HOME/go/src:$container_goroot/src:cached \
-v $docker_config:/etc/docker/config.json \
-v $docker_daemon:/etc/docker/daemon.json \
-v $docker_sock:$docker_sock \
-v $font_dir:/usr/share/fonts:ro \
-v $rcpath/arch/limits.conf:/etc/security/limits.conf \
-v $rcpath/editorconfig:$container_home/.editorconfig \
-v $rcpath/gitattributes:$container_home/.gitattributes \
-v $rcpath/gitignore:$container_home/.gitignore \
-v $rcpath/network/sysctl.conf:/etc/sysctl.conf \
-v $rcpath/nvim/init.lua:$container_home/.config/nvim/init.lua \
-v $rcpath/nvim/lua:$container_home/.config/nvim/lua \
-v $rcpath/nvim/luacheckrc:$container_home/.config/nvim/luacheckrc \
-v $rcpath/sheldon.toml:$container_home/.config/sheldon/plugins.toml \
-v $rcpath/starship.toml:$container_home/.config/starship.toml \
-v $rcpath/tmux-kube:$container_home/.tmux-kube \
-v $rcpath/tmux.conf:$container_home/.tmux.conf \
-v $rcpath/vintrc.yaml:$container_home/.vintrc.yaml \
-v $rcpath/zshrc:$container_home/.zshrc \
-v $tz_path:/etc/localtime:ro \
-dit $image_name
;;
Linux)
echo 'Docker on Linux start'
# privileged=false
# privileged=false
font_dir="/usr/share/fonts"
tz_path="/etc/localtime"
docker_daemon="/etc/docker/daemon.json"
docker_config="/etc/docker/config.json"
resolve_config="/etc/resolv.conf"
resolve_dnsmasq_config="/etc/resolv.dnsmasq.conf"
# -e DISPLAY \
# -v /tmp/.X11-unix:/tmp/.X11-unix \
if type nvidia-smi >/dev/null 2>&1; then
gpu_option="--gpus=all"
fi
docker run \
--cap-add=ALL \
--name $container_name \
--privileged=$privileged \
--restart always \
--workdir $container_home \
--network=host \
--mount type=bind,source=$resolve_dnsmasq_config,destination=$resolve_config,readonly \
--add-host=host.docker.internal:host-gateway \
--memory=200G \
$gpu_option \
-u "$(id -u $USER):$(id -g $USER)" \
-v $HOME/.aws:$container_home/.aws \
-v $HOME/.config/gcloud:$container_home/.config/gcloud \
-v $HOME/.docker:$container_home/.docker \
-v $HOME/.docker:$container_root/.docker \
-v $HOME/.gnupg:$container_home/.gnupg \
-v $HOME/.gnupg:$container_root/.gnupg \
-v $HOME/.kube:$container_home/.kube \
-v $HOME/.netrc:$container_home/.netrc:ro \
-v $HOME/.password-store:$container_home/.password-store \
-v $HOME/.password-store:$container_root/.password-store \
-v $HOME/.ssh:$container_home/.ssh:ro \
-v $HOME/.talos:$container_home/.talos \
-v $HOME/.tig_history:$container_home/.tig_history \
-v $HOME/.tmux:$container_home/.tmux \
-v $HOME/.zsh_history:$container_home/.zsh_history:cached \
-v $HOME/Documents:$container_home/Documents \
-v $HOME/Downloads:$container_home/Downloads \
-v $HOME/go/src:$container_goroot/src \
-v $docker_config:$docker_config:ro,cached \
-v $docker_daemon:$docker_daemon:ro,cached \
-v $docker_sock:$docker_sock \
-v $font_dir:$font_dir \
-v $rcpath/arch/limits.conf:/etc/security/limits.conf:ro,cached \
-v $rcpath/editorconfig:$container_home/.editorconfig \
-v $rcpath/gitattributes:$container_home/.gitattributes \
-v $rcpath/gitconfig:$container_home/.gitconfig \
-v $rcpath/gitignore:$container_home/.gitignore \
-v $rcpath/go.env:$container_goroot/go.env:ro \
-v $rcpath/go.env:$goroot/go.env:ro \
-v $rcpath/network/sysctl.conf:/etc/sysctl.conf:ro,cached \
-v $rcpath/nvim/init.lua:$container_home/.config/nvim/init.lua \
-v $rcpath/nvim/lua:$container_home/.config/nvim/lua \
-v $rcpath/nvim/luacheckrc:$container_home/.config/nvim/luacheckrc \
-v $rcpath/sheldon.toml:$container_home/.config/sheldon/plugins.toml \
-v $rcpath/starship.toml:$container_home/.config/starship.toml \
-v $rcpath/tmux-kube:$container_home/.tmux-kube \
-v $rcpath/tmux.conf:$container_home/.tmux.conf \
-v $rcpath/vintrc.yaml:$container_home/.vintrc.yaml \
-v $rcpath/zshrc:$container_home/.zshrc:ro,cached \
-v $tz_path:/etc/localtime:ro,cached \
-v /etc/group:/etc/group:ro \
-v /etc/passwd:/etc/passwd:ro \
-v /etc/shadow:/etc/shadow:ro \
-v /mnt:/mnt \
-v /usr/lib/modules:/lib/modules:ro \
-dt $image_name
# -v /etc/sudoers.d:/etc/sudoers.d:ro \
# -v /etc/sudoers:/etc/sudoers:ro \
# -v $HOME/.config/TabNine/tabnine_config.json:$container_home/.config/TabNine/tabnine_config.json \
;;
CYGWIN*|MINGW32*|MSYS*)
echo 'MS Windows is not ready for this environment'
;;
*)
echo 'other OS'
;;
esac
}
alias devrun="devrun"
# alias devin="docker exec -it $container_name $zsh_path -c \"tmux -S /tmp/tmux.sock -q has-session && exec tmux -S /tmp/tmux.sock -2 attach-session -d || exec tmux -S /tmp/tmux.sock -2 new-session -n$USER -s$USER@$HOST\""
alias devin="docker exec -it $container_name $zsh_path"
devkill(){
docker update --restart=no $container_name \
&& docker container stop $(docker container ls -aq) \
&& docker container stop $(docker ps -a -q) \
&& docker ps -aq | xargs docker rm -f \
&& docker container prune -f
}
alias devkill="devkill"
alias devres="devkill && devrun"
alias devref="devkill && dockerrm && devrun"