Skip to content

Commit c797058

Browse files
author
=
committed
docker env fixes to make development simpler
1 parent a9a578e commit c797058

10 files changed

+45
-60
lines changed

.env.example

+6-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
DEBUG='False'
1+
DEBUG='False' # True for development
2+
NGINX_IMAGE='lscr.io/linuxserver/swag' # leave unset for development
3+
NGINX_CONF='./nginx.prod.conf' # leave unset for development
24
SECRET_KEY='secret'
35
DATABASE_PASSWORD='secret'
46
DATABASE_ROOT_PASSWORD="secret"
@@ -17,4 +19,6 @@ REDIS_PASSWORD='secret'
1719
GOOGLE_ADSENSE_ID='ca-pub-abcde'
1820
RECAPTCHA_PUBLIC_KEY='secret'
1921
RECAPTCHA_PRIVATE_KEY='secret'
20-
GOOGLE_OAUTH_LINK="secret.apps.googleusercontent.com"
22+
GOOGLE_OAUTH_LINK="secret.apps.googleusercontent.com"
23+
HTTP_PORT="80"
24+
SSL_PORT="443"

.gitignore

+3-1
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,6 @@ set_env.sh
55
fishauctions/customsettings.py
66
media/
77
auctions/templates/ads.txt
8-
swag/
8+
swag/
9+
mediafiles/
10+
staticfiles/

Dockerfile

+3-6
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ RUN pip install --upgrade pip pip-tools
2525
COPY . /usr/src/app/
2626

2727
# generate an updated requirements.txt file with the latest versions of all packages
28-
#RUN pip-compile requirements.in --upgrade # fixme
28+
RUN pip-compile requirements.in --upgrade
2929

3030
# install python dependencies
3131
# COPY ./requirements.txt . # no need to copy this, we just generated it
@@ -76,13 +76,10 @@ RUN touch /var/log/cron.log
7676
COPY --from=builder /usr/src/app/wheels /wheels
7777
COPY --from=builder /usr/src/app/requirements.txt .
7878
RUN pip install --upgrade pip
79-
# keep docker image smaller
80-
#RUN pip install --no-cache /wheels/*
81-
# faster
82-
RUN pip install /wheels/*
79+
RUN pip install --no-cache /wheels/*
8380
RUN pip install mysql-connector-python
8481

85-
COPY . $APP_HOME
82+
#COPY . $APP_HOME
8683

8784
# chown all the files to the app user
8885
RUN chown -R app:app $APP_HOME

auctions/templates/promo.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ <h2 class="text-right"><span class='text-info'>Completely free.</span></h2>
137137
</div>
138138
</div>
139139
<h5>This site provides all the tools you need to run traditional, in-person auctions. Or, run your auctions online without the need to reserve an auction hall or pay an auctioneer.</h5><h4 class="text-right">No paperwork. No math. Simple enough to use on your phone.</h4>
140-
<div><h3>Click below to learn more about:</h3>
140+
<div><h3>aaClick below to learn more about:</h3>
141141
<ul class="nav nav-pills">
142142
<li class="nav-item">
143143
<a class="nav-link " data-toggle="tab" href="#runAuction">Online auctions</a>

docker-compose.prod.yaml

-21
This file was deleted.

docker-compose.yaml

+18-11
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,12 @@ services:
22
web:
33
build: .
44
volumes:
5+
- .:/home/app/web
56
- static_volume:/home/app/web/staticfiles
67
- media_volume:/home/app/web/mediafiles
7-
ports:
8-
- 8000:8000
9-
#expose:
10-
# - 8000
8+
expose:
9+
- 8000
1110
env_file: .env
12-
# this will override whatever is set in the .env
13-
environment:
14-
- DEBUG=True
1511
depends_on:
1612
- db
1713
restart: always
@@ -40,21 +36,32 @@ services:
4036
restart: always
4137
command: redis-server --requirepass ${REDIS_PASSWORD-unsecure}
4238

43-
# this server will get overridden in production - see docker-compose.prod.yaml
4439
nginx:
45-
image: nginx:latest
40+
image: ${NGINX_IMAGE-nginx}:latest # default setting is for development, use lscr.io/linuxserver/swag for production
4641
volumes:
47-
- ./nginx.dev.conf:/etc/nginx/nginx.conf:ro
42+
- ${NGINX_CONF-./nginx.dev.conf}:/etc/nginx/nginx.conf:ro
43+
- ./swag:/config
4844
- ./nginx_fishauctions.conf:/etc/nginx/nginx_fishauctions.conf:ro
45+
- static_volume:/home/app/web/staticfiles:ro
46+
- media_volume:/home/app/web/mediafiles:ro
4947
ports:
5048
- ${HTTP_PORT-80}:80
49+
- ${SSL_PORT-443}:443 # this is only used in production
5150
restart: always
5251
depends_on:
5352
- web
53+
cap_add:
54+
- NET_ADMIN
55+
environment: # none of these get used in development
56+
- PUID=${PUID-1000}
57+
- PGID=${PGID-1000}
58+
- TZ=Etc/UTC
59+
- URL=${SITE_DOMAIN}
60+
- VALIDATION=http
61+
- EMAIL=${ADMIN_EMAIL}
5462

5563
volumes:
5664
redis_data:
57-
driver: local
5865
mariadb_data:
5966
static_volume:
6067
media_volume:

entrypoint.sh

+1-2
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,7 @@ python manage.py collectstatic --no-input > /dev/null 2>&1
3030

3131
if [ "${DEBUG}" = "True" ]; then
3232
echo Starting in development mode, cron jobs must be run manually
33-
uvicorn fishauctions.asgi:application --reload --port 8000 --log-config=./uvicorn_log_config.yml
34-
#python manage.py runserver 0.0.0.0:8000
33+
exec uvicorn fishauctions.asgi:application --host 0.0.0.0 --port 8000 --reload --reload-include '*.py' --reload-include '*.html' --reload-include '*.js'
3534
else
3635
echo Starting fishauctions in production mode
3736
cron -f & # run cron in the foreground, but & allows the script to continue

nginx.dev.conf

+2-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@ http {
99
'$status $body_bytes_sent "$http_referer" '
1010
'"$http_user_agent" "$http_x_forwarded_for"';
1111

12-
access_log /var/log/nginx/access.log main;
12+
access_log off;
13+
#access_log /var/log/nginx/access.log main;
1314
error_log /var/log/nginx/error.log warn;
1415

1516
sendfile on;

readme.md

+11-2
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,19 @@ git clone https://github.com/iragm/fishauctions
3333
docker compose build
3434
docker compose up
3535
```
36-
You should now be able to access a development site at 127.0.0.1
36+
You should now be able to access a development site at 127.0.0.1 (Note: don't use port 8000)
3737

3838
#### ENV
39-
Development-friendly default values are set for most of the environment, but you may wish to use existing databases or specify secure passwords. Simply rename the `.env.example` file to `.env`, edit it as needed, and you should be good to go.
39+
Development-friendly default values are set for most of the environment, but you may wish to use existing databases or specify secure passwords. Simply rename the `.env.example` file to `.env`, edit it as needed (making sure to remove the lines used for production), and you should be good to go.
40+
41+
This file doesn't document everything, but it has the most common settings. For example, if you use port 80 for something else, you could serve up the development site on a different port by editing your .env file to have the line HTTP_PORT=81
42+
43+
#### Production environment differences
44+
At this time, I'm only aware of one production deployment, but since this is open source, you're welcome to spin up your own competing website.
45+
46+
In keeping with 12 Factor, all configuration is done from the .env file and the rest of the environment is kept extremely similar, but:
47+
- Production uses SWAG to add a cert, dev uses plain old Nginx to serve just http content.
48+
- Production uses Gunicorn with a Uvicorn worker process, development uses Uvicorn with a --reload flag (this is configured in entrypoint.sh)
4049

4150
#### Cron jobs
4251
Some cron jobs are used to manage models - these run automatically if you're in production (debug=False), but will need to be run manually in development. These can be found in the crontab file in the same folder as this readme.

uvicorn_log_config.yml

-13
This file was deleted.

0 commit comments

Comments
 (0)