Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve Docker support #15

Open
wants to merge 12 commits into
base: main
Choose a base branch
from
8 changes: 8 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
.git
**/__pycache__/
/**/config.json5
/**/log.txt
/.idea/
/**/*.iml
/**/record.db
/logs
5 changes: 3 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,15 @@ services:
- docker

before_install:
- docker pull mcr.microsoft.com/playwright/python:v1.23.0-focal
- docker pull mcr.microsoft.com/playwright/python:focal

install:
- echo "do not do anything"

script:
- export APP_VERSION=$(python3 -c "from version import *; print(VERSION)")
- docker build --rm -t lupohan44/games_hub:latest -t lupohan44/games_hub:v${APP_VERSION} .
- docker buildx create --use
- docker buildx build --platform=linux/amd64,linux/arm64 -t lupohan44/games_hub:latest -t lupohan44/games_hub:v${APP_VERSION} .

after_success:
- if [ "$TRAVIS_PULL_REQUEST" == "false" ]; then
Expand Down
33 changes: 26 additions & 7 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,9 +1,28 @@
FROM mcr.microsoft.com/playwright/python:v1.23.0-focal
FROM mcr.microsoft.com/playwright/python:focal as build-deps

# Reduce the size of the image
RUN cd home && git clone https://github.com/lupohan44/GamesHub
RUN cd /home/GamesHub && pip3 install -r requirements.txt
# Need to re-install webkit after reduce the size of the image
RUN python3 -m playwright install webkit firefox chromium
RUN apt-get update \
&& apt-get --no-install-recommends install -y python3-dev python3-pip build-essential \
&& ln -s /usr/bin/pip3 /usr/bin/pip3.8 \
&& rm -rf /var/lib/apt/lists/*

WORKDIR /tmp/python_requirements

COPY ./requirements.txt .
COPY plugins plugins

RUN find . -name 'requirements.txt' -exec bash -c "pip3 install --user --no-cache-dir -r {}" \; \
&& python3 -m playwright install webkit firefox chromium

FROM mcr.microsoft.com/playwright/python:focal

COPY --from=build-deps /root/.local /root/.local


ENV GAMESHUB_SRC_DIR=/src
WORKDIR /src
COPY . .

WORKDIR /config

ENTRYPOINT ["python", "/src/app.py"]

ENTRYPOINT cd /home/wd && python3 /home/GamesHub/app.py
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ Provide a framework to develop plugins to scrap games from different websites an
```
3. Run with docker
```shell
docker pull lupohan44/games_hub:latest && docker run -v $GAMES_HUB_FOLDER_NAME:/home/wd --rm lupohan44/games_hub:latest
docker pull lupohan44/games_hub:latest && docker run -v $GAMES_HUB_FOLDER_NAME:/config --rm lupohan44/games_hub:latest
```
All changes by script inside docker will be permanently save to this folder.
Each enabled official plugin should create a folder in ```{WORKING_DIR}/plugins/{PLUGIN_PACKAGE_NAME}``` to store runtime files and configs
Expand Down
8 changes: 4 additions & 4 deletions app.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,19 +106,19 @@ def main(argv):
check_update()
if len(enabled_plugins) == 0:
raise Exception(NO_PLUGINS_ENABLE_ERROR_MSG)
if not os.path.exists('plugins'):
if not os.path.exists(os.path.join(GAMESHUB_SRC_DIR, 'plugins')):
raise Exception(NO_PLUGINS_FOLDER_ERROR_MSG)
# try to enable plugins
folders_under_plugins = []
for dirs in os.listdir("plugins"):
if os.path.isdir(os.path.join("plugins", dirs)):
for dirs in os.listdir(os.path.join(GAMESHUB_SRC_DIR, "plugins")):
if os.path.isdir(os.path.join(GAMESHUB_SRC_DIR, "plugins", dirs)):
folders_under_plugins.append(dirs)
if len(folders_under_plugins) == 0:
raise Exception(PLUGINS_FOLDER_EMPTY_ERROR_MSG)
enabled_plugins_folders = []
for plugin_name in enabled_plugins:
if plugin_name in folders_under_plugins:
enabled_plugins_folders.append(os.path.join("plugins", plugin_name))
enabled_plugins_folders.append(os.path.join(GAMESHUB_SRC_DIR, "plugins", plugin_name))
if len(enabled_plugins_folders) == 0:
raise Exception(NO_PLUGINS_ENABLE_ERROR_MSG)
total_plugin_count = 0
Expand Down
8 changes: 8 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
version: '3'
services:
gameshub:
image: lupohan44/games_hub:latest
build: .
restart: on-failure
volumes:
- ./gameshub-conf/:/config
3 changes: 3 additions & 0 deletions games_hub/static.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
import logging
import os


'''Static Variables'''
PROJECT_NAME = "GamesHub"
GITHUB_URL = "https://github.com/lupohan44/GamesHub"
GITHUB_VERSION_URL = "https://raw.githubusercontent.com/lupohan44/GamesHub/main/version.py"
GITHUB_MIRROR_VERSION_URL = "https://ghproxy.com/" + GITHUB_VERSION_URL
CONFIG_PATH = "config.json5"
GAMESHUB_SRC_DIR = os.environ.get('GAMESHUB_SRC_DIR', '.')

# log format
LOG_FORMAT = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s')
Expand Down