File tree Expand file tree Collapse file tree 4 files changed +44
-2
lines changed Expand file tree Collapse file tree 4 files changed +44
-2
lines changed Original file line number Diff line number Diff line change 2
2
FROM nginx:latest
3
3
4
4
# Install inotify-tools for file monitoring
5
- RUN apt-get update && apt-get install -y inotify-tools
5
+ RUN apt-get update && apt-get install -y inotify-tools python3
6
6
7
7
# Copy the initial routes.trp file
8
8
COPY routes.trp /etc/nginx/routes.trp
Original file line number Diff line number Diff line change 1
-
Original file line number Diff line number Diff line change
1
+ import os .path
2
+
3
+ formated = []
4
+ file_name = "routes.trp"
5
+
6
+ if not file_name .endswith (".trp" ):
7
+ file_name = file_name + ".trp"
8
+
9
+ if not os .path .isfile (file_name ):
10
+ print ("File not found: " + file_name + ". Creating..." )
11
+ f = open (file_name , "w+" )
12
+ f .write ("" )
13
+ f .close ()
14
+ print ("File created: " + file_name )
15
+
16
+ if not os .path .getsize (file_name ):
17
+ print ("File is empty: " + file_name )
18
+
19
+ with open (file_name , "r+" ) as f :
20
+ print ("File found: " + file_name + ". Validating..." )
21
+ content = f .readlines ()
22
+
23
+ if not content :
24
+ print ("File is empty: " + file_name + ". Nothing to validate" )
25
+
26
+ for line in content :
27
+ print ("Validating line: " + line )
28
+ if str (line ).strip () == '' :
29
+ print ("Skipping empty line" )
30
+ continue
31
+
32
+ if " => " in line :
33
+ print ("Appending line: " + line )
34
+ formated .append (line )
35
+
36
+ if not formated :
37
+ print ("No lines to write to file: " + file_name )
38
+ exit (0 )
39
+
40
+ print ("Writing to file: " + file_name )
41
+ with open (file_name , "w+" ) as f :
42
+ f .writelines (formated )
Original file line number Diff line number Diff line change @@ -65,5 +65,6 @@ generate_config
65
65
echo " Monitoring routes.trp for changes..."
66
66
while inotifywait -e modify /etc/nginx/routes.trp; do
67
67
echo " routes.trp has been modified. Regenerating Nginx configuration..."
68
+ python3 ./url_validate_and_trim.py
68
69
generate_config
69
70
done
You can’t perform that action at this time.
0 commit comments