Skip to content

Commit 7bd3d39

Browse files
committed
Version 1.3
1 parent 478f526 commit 7bd3d39

File tree

4 files changed

+69
-17
lines changed

4 files changed

+69
-17
lines changed

Dockerfile

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,14 @@ LABEL maintainer="[email protected]" \
99
django-localflavor-version="1.5.1" \
1010
mysql-python-version="1.2.5"
1111

12-
# Copies the apache conf python script
12+
# Copies the apache conf python script and shell script
1313

1414
COPY ./apache-site-conf.sh /bin/
15+
COPY ./apache-site-conf.py /bin/
1516

1617
# Arguments for Apache conf file builder script if not used, they will use default settings
18+
# Also it will only allow them if there is only one site directory if there
19+
# is more it will use default, and you will need to modify manually
1720
# SITE_SERVER_NAME = ServerName
1821
# SITE_SERVER_ADMIN = ServerAdmin
1922

@@ -24,7 +27,8 @@ ARG SITE_SERVER_ADMIN
2427

2528
WORKDIR /DjangoSites
2629

27-
RUN chmod 755 /bin/apache-site-conf.sh
30+
RUN chmod 755 /bin/apache-site-conf.sh \
31+
&& chmod 755 /bin/apache-site-conf.py
2832

2933
EXPOSE 80 443
3034

README.md

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
## Created By: Benjamin P. Trachtenberg
44

55
### Contact Information: [email protected]
6+
### If you have any questions e-mail me
67

78
### LinkedIn: [Ben Trachtenberg](https://www.linkedin.com/in/ben-trachtenberg-3a78496)
89
### Docker Hub: [Image](https://hub.docker.com/r/btr1975/apache-py2-django/)
@@ -28,11 +29,24 @@ This image is for Python Django Apps written in Python 2
2829
* MySQL-python: 1.2.5
2930
* apache-site-conf.py: 1.0.0.prod
3031

32+
### Image Versions in apache-py2-django:1.3
33+
34+
* Python: 2.7.12
35+
* Apache: 2.4.18 (Ubuntu) with mod_wsgi
36+
* Django: 1.11.2
37+
* Django-Localflavor: 1.5.1
38+
* MySQL-python: 1.2.5
39+
* apache-site-conf.py: 1.0.1.prod
40+
* apache-site-conf.sh: 1.0 prod
41+
3142
### Docker-Image Version Tags
3243
* latest
3344
* 1.1
3445
* 1.2
46+
* 1.3
3547

36-
#### -- Version News: apache-py2-django:1.2 --
37-
Added a Python script that builds the apache conf file
48+
#### -- Version News: apache-py2-django:1.3 --
49+
Updated Python script that builds the apache conf file
50+
Added a bash script that builds the apache conf file
51+
Both scripts do the same thing, so use whichever you want.
3852

apache-site-conf.py

Lines changed: 27 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,28 +6,30 @@
66
__credits__ = None
77
__license__ = 'The MIT License (MIT)'
88
__status__ = 'prod'
9-
__version_info__ = (1, 0, 0, __status__)
9+
__version_info__ = (1, 0, 1, __status__)
1010
__version__ = '.'.join(map(str, __version_info__))
1111
__maintainer__ = 'Benjamin P. Trachtenberg'
1212
__email__ = '[email protected]'
1313

1414

15-
def create_conf(folder_name):
15+
def create_conf(folder_name, dir_count):
1616
"""
1717
Function to create apache conf files for loaded sites
1818
Currently only non-SSL Sites
19-
:param folder_name: The folder name of the site
19+
:param
20+
folder_name: The folder name of the site
21+
dir_count: Count of dirs
2022
:return:
2123
"""
2224
temp_list = list()
2325
temp_list.append('<VirtualHost *:80>')
24-
if os.environ.get('SITE_SERVER_NAME'):
26+
if os.environ.get('SITE_SERVER_NAME') and dir_count == 1:
2527
temp_list.append(' ServerName %s' % (os.environ.get('SITE_SERVER_NAME'),))
2628

2729
else:
2830
temp_list.append(' # ServerName www.example.com')
2931

30-
if os.environ.get('SITE_SERVER_ADMIN'):
32+
if os.environ.get('SITE_SERVER_ADMIN') and dir_count == 1:
3133
temp_list.append(' ServerAdmin %s' % (os.environ.get('SITE_SERVER_ADMIN'),))
3234

3335
else:
@@ -99,7 +101,22 @@ def add_line_break(list_line):
99101

100102
site_to_enable = output_file(temp_list, folder_name)
101103

102-
sub.call('a2ensite %s' % (site_to_enable,), stderr=sub.STDOUT, shell=True)
104+
sub.call('a2ensite %s > /dev/null' % (site_to_enable,), stderr=sub.STDOUT, shell=True)
105+
106+
107+
def count_dir():
108+
"""
109+
Function to count how many dirs in a dir
110+
:return:
111+
An integer of how many dirs
112+
"""
113+
temp_list_count = list()
114+
115+
for item_name in os.listdir(os.getcwd()):
116+
if os.path.isdir(item_name):
117+
temp_list_count.append(item_name)
118+
119+
return len(temp_list_count)
103120

104121

105122
def main():
@@ -108,11 +125,13 @@ def main():
108125
:return: None
109126
110127
"""
128+
dir_count = count_dir()
129+
111130
for item_name in os.listdir(os.getcwd()):
112131
if os.path.isdir(item_name):
113-
create_conf(item_name)
132+
create_conf(item_name, dir_count)
114133

115-
sub.call('a2dissite 000-default.conf', stderr=sub.STDOUT, shell=True)
134+
sub.call('a2dissite 000-default.conf > /dev/null', stderr=sub.STDOUT, shell=True)
116135

117136

118137
main()

apache-site-conf.sh

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
#!/bin/bash
22

33
# This script is to build apache conf files for Django apps
4-
# Version: 1.0 Dev
4+
# Version: 1.0 Prod
55
# Author: Benjamin P. Trachtenberg
66
77

8-
apachedirname="/etc/apache2/sites-available"
8+
declare -r apachedirname="/etc/apache2/sites-available"
99
apacheconfname=""
10-
djangodirname="/DjangoSites"
10+
declare -r djangodirname="/DjangoSites"
1111

1212
# Check for DjangoSites Directory
1313
if [[ ! -d $djangodirname ]]; then
@@ -31,8 +31,23 @@ for directory in $(ls $djangodirname); do
3131
if [[ ! -f "$apachedirname/$apacheconfname" ]]; then
3232
echo "Creating apache config $apachedirname/$apacheconfname"
3333
echo "<VirtualHost *:80>" >> $apachedirname/$apacheconfname
34-
echo " # ServerName www.example.com" >> $apachedirname/$apacheconfname
35-
echo " ServerAdmin webmaster@localhost" >> $apachedirname/$apacheconfname
34+
35+
if [[ $(ls -d $djangodirname/*/ | wc -l) = 1 && $SITE_SERVER_NAME ]]; then
36+
echo " ServerName $SITE_SERVER_NAME" >> $apachedirname/$apacheconfname
37+
38+
else
39+
echo " # ServerName www.example.com" >> $apachedirname/$apacheconfname
40+
41+
fi
42+
43+
if [[ $(ls -d $djangodirname/*/ | wc -l) = 1 && $SITE_SERVER_ADMIN ]]; then
44+
echo " ServerAdmin $SITE_SERVER_ADMIN" >> $apachedirname/$apacheconfname
45+
46+
else
47+
echo " ServerAdmin webmaster@localhost" >> $apachedirname/$apacheconfname
48+
49+
fi
50+
3651
echo "" >> $apachedirname/$apacheconfname
3752
echo " Alias /media/ /DjangoSites/$directory/media/" >> $apachedirname/$apacheconfname
3853
echo "" >> $apachedirname/$apacheconfname

0 commit comments

Comments
 (0)