From 9f871cc50c45c21d4a209b59f84a57be873ff891 Mon Sep 17 00:00:00 2001 From: Liam Date: Sat, 13 Jan 2024 19:51:28 +0000 Subject: [PATCH] 7 --- .dockerignore | 27 ++++++++++++++++ .gitea/workflows/publish.yml | 61 ++++++++++++++++++++++++++++++++++++ .gitignore | 1 + .vscode/launch.json | 19 +++++++++++ .vscode/tasks.json | 24 ++++++++++++++ Dockerfile | 19 +++++++++++ README.md | 9 ++++++ requirements.txt | 13 ++++++++ manage.py => src/manage.py | 10 ++++-- 9 files changed, 180 insertions(+), 3 deletions(-) create mode 100644 .dockerignore create mode 100644 .gitea/workflows/publish.yml create mode 100644 .vscode/launch.json create mode 100644 .vscode/tasks.json create mode 100644 Dockerfile create mode 100644 requirements.txt rename manage.py => src/manage.py (92%) diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..e0cc78f --- /dev/null +++ b/.dockerignore @@ -0,0 +1,27 @@ +**/__pycache__ +**/.venv +**/.classpath +**/.dockerignore +**/.env +**/.git +**/.gitignore +**/.project +**/.settings +**/.toolstarget +**/.vs +**/.vscode +**/*.*proj.user +**/*.dbmdl +**/*.jfm +**/bin +**/charts +**/docker-compose* +**/compose* +**/Dockerfile* +**/node_modules +**/npm-debug.log +**/obj +**/secrets.dev.yaml +**/values.dev.yaml +LICENSE +README.md diff --git a/.gitea/workflows/publish.yml b/.gitea/workflows/publish.yml new file mode 100644 index 0000000..469b6db --- /dev/null +++ b/.gitea/workflows/publish.yml @@ -0,0 +1,61 @@ +name: Publish Docker Image + +on: + push: + branches: + - "master" + +jobs: + docker: + runs-on: ubuntu-22.04 + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Restore Docker Cache + uses: actions/cache@v3 + id: docker-cache + with: + path: /usr/bin/docker + key: ${{ runner.os }}-docker + + - name: Install Docker (if not cached) + if: steps.docker-cache.outputs.cache-hit != 'true' + run: | + wget -q -O /tmp/docker.tgz https://download.docker.com/linux/static/stable/x86_64/docker-20.10.23.tgz \ + && tar --extract --file /tmp/docker.tgz --directory /usr/bin --strip-components 1 --no-same-owner docker/docker \ + && rm -rf /tmp/* && + echo "Done" + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + + - name: Login to Repo + uses: docker/login-action@v3 + with: + username: ${{ secrets.REPO_USERNAME }} + password: ${{ secrets.REPO_TOKEN }} + + - name: Restore Docker Build Cache + uses: actions/cache@v3 + id: build-cache + with: + path: /tmp/.buildx-cache + key: ${{ runner.os }}-buildx + + - name: Build and Push (Latest) + uses: docker/build-push-action@v5 + with: + push: true + context: . + tags: fascinated/traefik-helper:latest + cache-from: type=local,src=/tmp/.buildx-cache + cache-to: type=local,dest=/tmp/.buildx-cache + + - name: Save Docker Build Cache + if: steps.build-cache.outputs.cache-hit != 'true' + run: | + mkdir -p /tmp/.buildx-cache + cp -r /tmp/.buildx-cache/. /tmp/.buildx-cache-new + rm -rf /tmp/.buildx-cache + mv /tmp/.buildx-cache-new /tmp/.buildx-cache diff --git a/.gitignore b/.gitignore index 75094e7..2dd7105 100644 --- a/.gitignore +++ b/.gitignore @@ -174,3 +174,4 @@ cython_debug/ # Built Visual Studio Code Extensions *.vsix +config.yml \ No newline at end of file diff --git a/.vscode/launch.json b/.vscode/launch.json new file mode 100644 index 0000000..695cdc1 --- /dev/null +++ b/.vscode/launch.json @@ -0,0 +1,19 @@ +{ + "configurations": [ + { + "name": "Docker: Python - General", + "type": "docker", + "request": "launch", + "preLaunchTask": "docker-run: debug", + "python": { + "pathMappings": [ + { + "localRoot": "${workspaceFolder}", + "remoteRoot": "/app" + } + ], + "projectType": "general" + } + } + ] +} diff --git a/.vscode/tasks.json b/.vscode/tasks.json new file mode 100644 index 0000000..c47c364 --- /dev/null +++ b/.vscode/tasks.json @@ -0,0 +1,24 @@ +{ + "version": "2.0.0", + "tasks": [ + { + "type": "docker-build", + "label": "docker-build", + "platform": "python", + "dockerBuild": { + "tag": "traefikhelper:latest", + "dockerfile": "${workspaceFolder}/Dockerfile", + "context": "${workspaceFolder}", + "pull": true + } + }, + { + "type": "docker-run", + "label": "docker-run: debug", + "dependsOn": ["docker-build"], + "python": { + "file": "manage.py" + } + } + ] +} diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..1f45ede --- /dev/null +++ b/Dockerfile @@ -0,0 +1,19 @@ +# For more information, please refer to https://aka.ms/vscode-docker-python +FROM python:3.10-slim + +# Keeps Python from generating .pyc files in the container +ENV PYTHONDONTWRITEBYTECODE=1 + +# Turns off buffering for easier container logging +ENV PYTHONUNBUFFERED=1 + +# Install pip requirements +COPY requirements.txt . +RUN python -m pip install -r requirements.txt + +WORKDIR /app +COPY . /app + +ENV CONFIG_FILE_PATH=/app/config.yml + +CMD ["python", "src/manage.py"] diff --git a/README.md b/README.md index 3b83982..fcf249b 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,11 @@ # traefik-helper +This is a helper container for traefik. It can add, remove and update services. + +## Usage + +DO NOT CHANGE: `/home/config.yml` + +```bash +docker run --rm -v /var/run/docker.sock:/var/run/docker.sock -v /home/traefik/data/config.tml:/home/config.yml fascinateed/traefik-helper:latest +``` diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..1dd77c5 --- /dev/null +++ b/requirements.txt @@ -0,0 +1,13 @@ +# To ensure app dependencies are ported from your virtual environment/host machine into your container, run 'pip freeze > requirements.txt' in the terminal to overwrite this file +awscli==1.32.2 +botocore==1.34.2 +colorama==0.4.4 +docutils==0.16 +jmespath==1.0.1 +pyasn1==0.5.1 +python-dateutil==2.8.2 +PyYAML==6.0.1 +rsa==4.7.2 +s3transfer==0.9.0 +six==1.16.0 +urllib3==2.0.7 \ No newline at end of file diff --git a/manage.py b/src/manage.py similarity index 92% rename from manage.py rename to src/manage.py index 5251518..71ed070 100644 --- a/manage.py +++ b/src/manage.py @@ -1,10 +1,14 @@ import sys import subprocess import yaml +import os # Variables -baseDir = "/home/traefik/" -configFile = baseDir + "data/config.yml" +configFile = "./config.yml" + +# Are we running in a Docker container? +if os.environ.get("CONFIG_FILE"): + configFile = os.environ.get("CONFIG_FILE") # DO NOT TOUCH commands = ["add", "remove", "list"] @@ -31,7 +35,7 @@ def restartTraefik(): print("Restarting Traefik...") # Restart Traefik in the base directory - subprocess.run(["docker", "compose", "restart", "traefik"], cwd=baseDir) + subprocess.run(["docker", "restart", "traefik"]) def addDomain(name, domain, serviceHost): # Check if name already exists