first try

This commit is contained in:
Michael Grote 2023-07-19 20:46:20 +02:00
commit 5b1bb4e0bf
5 changed files with 178 additions and 0 deletions

54
.drone.yml Normal file
View file

@ -0,0 +1,54 @@
---
kind: pipeline
type: docker
name: linting
steps:
- name: gitleaks
image: plugins/gitleaks
settings:
path: .
when:
event:
exclude:
- tag
- name: hadolint
image: hadolint/hadolint:latest-debian
commands:
- hadolint Dockerfile
---
kind: pipeline
type: docker
name: selfhosted
depends_on: # bezieht sich auf linting pipeline
- linting
steps:
- name: docker_build_and_push_selfhosted
image: plugins/docker
settings:
dockerfile: Dockerfile
repo: registry.mgrote.net/oxidized-selfmade
registry: registry.mgrote.net
tags:
- ${DRONE_COMMIT_SHA:0:8}
- ${DRONE_COMMIT_BRANCH}
- latest
when:
event:
exclude:
- pull_request
- tag
- name: docker_build_and_push_selfhosted_tag
image: plugins/docker
settings:
dockerfile: Dockerfile
repo: registry.mgrote.net/oxidized-selfmade
registry: registry.mgrote.net
tags:
- ${DRONE_TAG}
when:
event:
- tag

16
Dockerfile Normal file
View file

@ -0,0 +1,16 @@
FROM ubuntu:latest
# Install necessary packages
RUN apt-get update && apt-get install -y openssh-client git
# Copy the script into the container
COPY app.sh /app/app.sh
# Set the working directory
WORKDIR /app
# Make the script executable
RUN chmod +x app.sh
# Set the entrypoint to execute the script
ENTRYPOINT ["/app/app.sh"]

43
README.md Normal file
View file

@ -0,0 +1,43 @@
# python-api-server
a small flask-application for storing and downloading stuff like small binaries
## Variables
- ``MAX_CONTENT_LENGTH``: maximal Filesize in MB; defaults to 5MB
- ``UPLOAD_DIRECTORY``: where to store the uploaded files; should be mapped to a volume; defaults to "/uploads"
- ``AUTH_TOKEN``: token used for authenticating
## Example Docker-Compose
```yaml
version: '3'
services:
python-api-server:
container_name: httpd-api
image: quotengrote/python-api-server:v2
ports:
- "5040:5000"
volumes:
- uploads:/uploads
environment:
# FLASK_DEBUG: 1 # for debugging
# FLASK_APP: app # for debugging
MAX_CONTENT_LENGTH: 10
UPLOAD_DIRECTORY: /uploads
AUTH_TOKEN: myuploadtoken
ENABLE_WEBSERVER: true # if enabled a list of files can be viewed in a webbrowser (see screenshot)
volumes:
uploads:
```
### ENABLE_WEBSERVER Screenshot
![](./assets/screenshot_webui.png)
## API-Endpoints
- see [Flasgger](https://github.com/flasgger/flasgger): ``http://<host>:5040/apidocs/``

52
app.sh Normal file
View file

@ -0,0 +1,52 @@
#!/bin/bash
# RouterOS devices SSH connection settings
DEVICE_CONFIGS="$DEVICE_CONFIGS" # Comma-separated list of device configurations in the format: "device,username,/path/to/ssh/key"
# Git repository settings
GIT_REPO_URL="$GIT_REPO_URL" # Git repository SSH URL
GIT_USERNAME="$GIT_USERNAME" # Git username for SSH authentication
GIT_SSH_KEY="$GIT_SSH_KEY" # Git SSH private key path (mounted in Docker container)
GIT_REPO_PATH="/app/config_repo" # Directory where the Git repository is cloned in the Docker container
# Function to export RouterOS configuration
export_routeros_config() {
local device="$1"
local username="$2"
local ssh_key="$3"
ssh -i "$ssh_key" "$username"@"$device" /export > "/app/${device}_config_export.txt"
}
# Function to commit and push the configuration to the Git repository
commit_and_push_to_git() {
cd "$GIT_REPO_PATH"
git config --global user.email "$GIT_USERNAME"
git config --global user.name "$GIT_USERNAME"
git add .
git commit -m "Update configuration $(date +%Y-%m-%d)"
git push origin master
}
# Main script
IFS=',' read -r -a devices <<< "$DEVICE_CONFIGS"
for device_config in "${devices[@]}"; do
IFS=' ' read -r -a config <<< "$device_config"
device="${config[0]}"
username="${config[1]}"
ssh_key="${config[2]}"
export_routeros_config "$device" "$username" "$ssh_key"
done
cd "$GIT_REPO_PATH"
if [ -d "$GIT_REPO_PATH" ]; then
git pull origin master
else
git clone "$GIT_REPO_URL" "$GIT_REPO_PATH"
fi
commit_and_push_to_git

13
docker-compose.yml Normal file
View file

@ -0,0 +1,13 @@
version: "3"
services:
routeros-config-export:
image: registry.mgrote.net/oxidized-selfmade:latest
environment:
- DEVICE_CONFIGS=device1,username1,/path/to/ssh/key1 device2,username2,/path/to/ssh/key2
- GIT_REPO_URL=your_git_repo_ssh_url
- GIT_USERNAME=your_git_username
- GIT_SSH_KEY=/app/your_git_ssh_key_file
volumes:
- /path/to/your_git_ssh_key_file:/app/your_git_ssh_key_file:ro
# Add any other volumes or configurations needed