Просмотр исходного кода

Add script for fast deployment

tags/1.0^2
9seconds 6 лет назад
Родитель
Сommit
b6251608d9
3 измененных файлов: 74 добавлений и 7 удалений
  1. 16
    0
      README.md
  2. 2
    7
      config/config.go
  3. 56
    0
      run.sh

+ 16
- 0
README.md Просмотреть файл

144
 ee852380f362a09343efb4690c4e17862e676f6f676c652e636f6d
144
 ee852380f362a09343efb4690c4e17862e676f6f676c652e636f6d
145
 ```
145
 ```
146
 
146
 
147
+Or, if you prefer docker:
148
+
149
+```console
150
+$ docker run --rm nineseconds/mtg generate-secret tls -c bing.com
151
+eedf71035a8ed48a623d8e83e66aec4d0562696e672e636f6d
152
+```
153
+
147
 ## Antireplay cache
154
 ## Antireplay cache
148
 
155
 
149
 To prevent replay attacks, we have internal storage of first frames
156
 To prevent replay attacks, we have internal storage of first frames
215
 This tool will listen on port 3128 by default with the given secret.
222
 This tool will listen on port 3128 by default with the given secret.
216
 
223
 
217
 
224
 
225
+# oneliner to run this proxy
226
+
227
+Please ensure that docker is installed. After that just execute
228
+
229
+```console
230
+curl -sfL https:// | bash
231
+```
232
+
233
+
218
 # statsd integration
234
 # statsd integration
219
 
235
 
220
 mtg provides an integration with statsd, you can enable it with command
236
 mtg provides an integration with statsd, you can enable it with command

+ 2
- 7
config/config.go Просмотреть файл

174
 	}
174
 	}
175
 
175
 
176
 	if C.CloakHost != "" {
176
 	if C.CloakHost != "" {
177
-		addrs, err := net.LookupHost(C.CloakHost)
178
-		if err != nil {
179
-			return fmt.Errorf("cannot resolve address of %s host: %w", C.CloakHost, err)
180
-		}
181
-
182
-		if len(addrs) == 0 {
183
-			return fmt.Errorf("no known ip addresses for the host %s", C.CloakHost)
177
+		if _, err := net.LookupHost(C.CloakHost); err != nil {
178
+			zap.S().Warnw("Cannot resolve address of host", "hostname", C.CloakHost, "error", err)
184
 		}
179
 		}
185
 	}
180
 	}
186
 
181
 

+ 56
- 0
run.sh Просмотреть файл

1
+#!/bin/bash
2
+#
3
+# Configuration options (set by environment variables during script execution)
4
+#   - MTG_CONFIG    - directory where mtg stores its configuration
5
+#   - MTG_IMAGENAME - a name of the docker image to use
6
+#   - MTG_PORT      - which port of the host system should be used
7
+#   - MTG_CONTAINER - a name of the container to use
8
+#
9
+# Example:
10
+#   export MTG_CONFIG="$HOME/mtg_config"
11
+#   export MTG_IMAGENAME="nineseconds/mtg:latest"
12
+#   curl -sfL https://lalala | bash
13
+
14
+set -eu -o pipefail
15
+
16
+export XDG_CONFIG_HOME="${XDG_CONFIG_HOME:-$HOME/.config}"
17
+export MTG_CONFIG="${MTG_CONFIG:-$XDG_CONFIG_HOME/mtg}"
18
+
19
+mkdir -p "$MTG_CONFIG" || true
20
+
21
+MTG_SECRET="$MTG_CONFIG/secret"
22
+MTG_ENV="$MTG_CONFIG/env"
23
+
24
+if [ ! -f "$MTG_ENV" ]; then
25
+    MTG_IMAGENAME="${MTG_IMAGENAME:-nineseconds/mtg:latest}"
26
+    MTG_PORT="${MTG_PORT:-3128}"
27
+    MTG_CONTAINER="${MTG_CONTAINER:-mtg}"
28
+
29
+    echo "MTG_IMAGENAME=${MTG_IMAGENAME}" > "$MTG_ENV"
30
+    echo "MTG_PORT=${MTG_PORT}" >> "$MTG_ENV"
31
+    echo "MTG_CONTAINER=${MTG_CONTAINER}" >> "$MTG_ENV"
32
+fi
33
+
34
+set -a
35
+source "$MTG_ENV"
36
+set +a
37
+
38
+docker pull "$MTG_IMAGENAME"
39
+if [ ! -f "$MTG_SECRET" ]; then
40
+    docker run \
41
+            --rm \
42
+            "$MTG_IMAGENAME" \
43
+        generate-secret tls -c "$(openssl rand -hex 16).com" \
44
+    > "$MTG_SECRET"
45
+fi
46
+
47
+echo "Proxy secret is $(cat "$MTG_SECRET")"
48
+
49
+docker ps --filter "Name=$MTG_CONTAINER" -aq | xargs -r docker rm -fv
50
+docker run \
51
+        -d \
52
+        --restart=unless-stopped \
53
+        --name "$MTG_CONTAINER" \
54
+        --ulimit nofile=51200:51200 \
55
+        -p "$MTG_PORT:3128" \
56
+    "$MTG_IMAGENAME" run "$(cat "$MTG_SECRET")"

Загрузка…
Отмена
Сохранить