diff --git a/.github/workflows/docker-image_dev_benste.yml b/.github/workflows/docker-image_dev_benste.yml index 1f5234e..a284edc 100644 --- a/.github/workflows/docker-image_dev_benste.yml +++ b/.github/workflows/docker-image_dev_benste.yml @@ -15,9 +15,27 @@ jobs: - name: Checkout code uses: actions/checkout@v3 + - name: Set up Python + uses: actions/setup-python@v4.6.1 + with: + python-version: 3.x + + - name: Install Poetry + run: | + pip install poetry + poetry config virtualenvs.create false # Skip creating a virtual environment + env: + POETRY_HOME: ${{ github.workspace }}/.poetry + + - name: Install project dependencies + run: | + poetry install + env: + POETRY_HOME: ${{ github.workspace }}/.poetry + - name: Version from Python run: echo "VERSION=$(python3 ./version.py)" >> $GITHUB_ENV - + - name: SHA_short run: echo "GITHUB_SHA_SHORT=$(echo $GITHUB_SHA | cut -c 1-6)" >> $GITHUB_ENV diff --git a/.github/workflows/docker-image_master.yml b/.github/workflows/docker-image_master.yml index 5121c45..c1804d5 100644 --- a/.github/workflows/docker-image_master.yml +++ b/.github/workflows/docker-image_master.yml @@ -19,6 +19,25 @@ jobs: - name: Checkout code uses: actions/checkout@v3 + + - name: Set up Python + uses: actions/setup-python@v4.6.1 + with: + python-version: 3.x + + - name: Install Poetry + run: | + pip install poetry + poetry config virtualenvs.create false # Skip creating a virtual environment + env: + POETRY_HOME: ${{ github.workspace }}/.poetry + + - name: Install project dependencies + run: | + poetry install + env: + POETRY_HOME: ${{ github.workspace }}/.poetry + - name: Version from Python run: echo "VVERSION=$(python3 ./version.py)" >> $GITHUB_ENV diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 33ed058..f4d0000 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -10,9 +10,6 @@ jobs: - name: Checkout code uses: actions/checkout@v3 - - name: Version from Python - run: echo "VERSION=$(python3 ./version.py)" >> $GITHUB_ENV - - name: Set up Python uses: actions/setup-python@v4.6.1 with: @@ -36,6 +33,9 @@ jobs: poetry build env: POETRY_HOME: ${{ github.workspace }}/.poetry + + - name: Version from Python + run: echo "VERSION=$(python3 ./version.py)" >> $GITHUB_ENV - name: Create Release uses: ncipollo/release-action@v1.12.0 diff --git a/.vscode/launch.json b/.vscode/launch.json index df7f907..93a59b4 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -6,7 +6,7 @@ "configurations": [ { "name": "ChurchWebHelper (local)", - "type": "python", + "type": "debugpy", "request": "launch", "module": "church_web_helper", "cwd": "${workspaceFolder}", @@ -16,7 +16,6 @@ "PYTHONUNBUFFERED": "1", "CT_DOMAIN": "https://elkw1610.krz.tools", "COMMUNI_SERVER": "https://api.communiapp.de/rest", - "VERSION": "VS Code Launch config w/o version" }, "args": [ "run", diff --git a/README.md b/README.md index 7a9e970..72d7c29 100644 --- a/README.md +++ b/README.md @@ -23,6 +23,13 @@ version.py is used to define the version number used by any automation 'Docker Compose Up' is using docker-compose.yml and will start a production server including the current version number 'Docker Compose Debug Up' composes a docker container for debugging also including the version number +### nice2know for debugging local docker containers +1. make sure /var/run/docker.sock has group "docker" with rw permissions and user is assigned to group docker +2. docker container IP != local IP - might wanna use the following commands to find the correct IP + - ```docker container list``` + - ```docker inspect -f '{{range.NetworkSettings.Networks}}{{.IPAddress}}{{end}} container_name_or_id``` +default could be http://172.18.0.2:5000 + ## tasks.json does trigger the docker-compose commands used for 2 launch configurations. This is also where the respective ENV vars can be changed. diff --git a/church_web_helper/app.py b/church_web_helper/app.py index 1903aab..3b58207 100644 --- a/church_web_helper/app.py +++ b/church_web_helper/app.py @@ -23,6 +23,8 @@ from dateutil.relativedelta import relativedelta import urllib +import toml + app = Flask(__name__) app.secret_key = os.urandom(16) @@ -40,6 +42,10 @@ if "VERSION" in os.environ.keys(): config["VERSION"] = os.environ["VERSION"] +else: + with open("pyproject.toml", "r") as f: + pyproject_data = toml.load(f) + config["VERSION"] = pyproject_data["tool"]["poetry"]["version"] app.config.update(config) locale.setlocale(locale.LC_TIME, "de_DE.UTF-8") @@ -54,15 +60,23 @@ def index(): @app.before_request def check_session(): - if request.endpoint != "login": - if "ct_api" not in session: - return redirect(url_for("login")) + """Session variable should contain ct_api and communi_api. + If not a redirect to respective login pages should be executed + """ + if request.endpoint != "login_ct" and request.endpoint != "login_communi": + #Check CT Login + if not session.get("ct_api"): + return redirect(url_for("login_ct")) elif not session["ct_api"].who_am_i(): - return redirect(url_for("login")) - - -@app.route("/login_churchtools", methods=["GET", "POST"]) -def login(): + return redirect(url_for("login_ct")) + #Check Communi Login + if not session.get("communi_api"): + return redirect(url_for("login_communi")) + elif not session["communi_api"].who_am_i(): + return redirect(url_for("login_communi")) + +@app.route("/ct/login", methods=["GET", "POST"]) +def login_ct(): """ Update login information for CT :return: @@ -91,7 +105,7 @@ def login(): ) -@app.route("/login_communi", methods=["GET", "POST"]) +@app.route("/communi/login", methods=["GET", "POST"]) def login_communi(): """ Update login information for Communi Login diff --git a/church_web_helper/templates/login_churchtools.html b/church_web_helper/templates/login_churchtools.html index 2711ace..2d1341a 100644 --- a/church_web_helper/templates/login_churchtools.html +++ b/church_web_helper/templates/login_churchtools.html @@ -14,7 +14,7 @@