Add docker support
Replaced secrets.py with docker environment variables. Set location as a default "./archive/" while inside docker container.
This commit is contained in:
parent
33680efa00
commit
3d3c76bfe9
25
Dockerfile
Normal file
25
Dockerfile
Normal file
@ -0,0 +1,25 @@
|
||||
FROM jrottenberg/ffmpeg:4.0-alpine
|
||||
|
||||
ENV PYTHONUNBUFFERED=1
|
||||
ENV DOCKER=1
|
||||
|
||||
RUN apk add build-base && apk add python3-dev
|
||||
|
||||
RUN echo "**** install Python ****" && \
|
||||
apk add --no-cache python3 && \
|
||||
if [ ! -e /usr/bin/python ]; then ln -sf python3 /usr/bin/python ; fi && \
|
||||
\
|
||||
echo "**** install pip ****" && \
|
||||
python3 -m ensurepip && \
|
||||
rm -r /usr/lib/python*/ensurepip && \
|
||||
pip3 install --no-cache --upgrade pip setuptools wheel && \
|
||||
if [ ! -e /usr/bin/pip ]; then ln -s pip3 /usr/bin/pip ; fi
|
||||
|
||||
|
||||
COPY requirements.txt /opt/app/requirements.txt
|
||||
WORKDIR /opt/app
|
||||
RUN pip install -r requirements.txt
|
||||
COPY . .
|
||||
|
||||
ENTRYPOINT ["python", "save.py"]
|
||||
CMD []
|
12
docker-compose.yml
Normal file
12
docker-compose.yml
Normal file
@ -0,0 +1,12 @@
|
||||
version: "3.2"
|
||||
services:
|
||||
reddit-save:
|
||||
build: .
|
||||
image: reddit-save:latest
|
||||
environment:
|
||||
REDDIT_USERNAME:
|
||||
REDDIT_PASSWORD:
|
||||
REDDIT_CLIENT_ID:
|
||||
REDDIT_SECRET:
|
||||
volumes:
|
||||
- "./archive:/opt/app/archive"
|
6
save.py
Executable file → Normal file
6
save.py
Executable file → Normal file
@ -9,10 +9,12 @@ from utilities import *
|
||||
# Get arguments
|
||||
parser = argparse.ArgumentParser(description="Save reddit posts to file.")
|
||||
parser.add_argument("mode", type=str, nargs=1, choices=["saved", "upvoted"], help="The file to convert.")
|
||||
parser.add_argument("location", type=str, nargs=1, help="The path to save to.")
|
||||
|
||||
if os.getenv("DOCKER", "0") != "1":
|
||||
parser.add_argument("location", type=str, nargs=1, help="The path to save to.")
|
||||
args = parser.parse_args()
|
||||
mode = args.mode[0]
|
||||
location = args.location[0]
|
||||
location = "./archive/" if os.getenv("DOCKER", "0") == "1" else args.location[0]
|
||||
|
||||
# Is location specified a directory?
|
||||
if not os.path.isdir(location):
|
||||
|
11
utilities.py
11
utilities.py
@ -5,8 +5,15 @@ from redvid import Downloader
|
||||
import youtube_dl
|
||||
import re
|
||||
from datetime import datetime
|
||||
from secrets import REDDIT_USERNAME, REDDIT_PASSWORD
|
||||
from secrets import REDDIT_CLIENT_ID, REDDIT_SECRET
|
||||
|
||||
try:
|
||||
from secrets import REDDIT_USERNAME, REDDIT_PASSWORD
|
||||
from secrets import REDDIT_CLIENT_ID, REDDIT_SECRET
|
||||
except ImportError:
|
||||
REDDIT_USERNAME = os.getenv("REDDIT_USERNAME")
|
||||
REDDIT_PASSWORD = os.getenv("REDDIT_PASSWORD")
|
||||
REDDIT_CLIENT_ID = os.getenv("REDDIT_CLIENT_ID")
|
||||
REDDIT_SECRET = os.getenv("REDDIT_SECRET")
|
||||
|
||||
IMAGE_EXTENSIONS = ["gif", "gifv", "jpg", "jpeg", "png"]
|
||||
VIDEO_EXTENSIONS = ["mp4"]
|
||||
|
Loading…
Reference in New Issue
Block a user