main: Added docker for the master server
All checks were successful
Build Docker / Build Master (push) Successful in 1m9s
All checks were successful
Build Docker / Build Master (push) Successful in 1m9s
This commit is contained in:
parent
aed9fea0f1
commit
14ee680583
29
.gitea/workflows/build.yml
Normal file
29
.gitea/workflows/build.yml
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
name: Build Docker
|
||||||
|
run-name: Build Docker Images
|
||||||
|
on: [push]
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
Build Master:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- name: Checkout
|
||||||
|
uses: actions/checkout@v2
|
||||||
|
- name: Install Docker
|
||||||
|
run : |
|
||||||
|
apt-get install ca-certificates curl gnupg
|
||||||
|
install -m 0755 -d /etc/apt/keyrings
|
||||||
|
curl -fsSL https://download.docker.com/linux/debian/gpg | gpg --dearmor -o /etc/apt/keyrings/docker.gpg
|
||||||
|
chmod a+r /etc/apt/keyrings/docker.gpg
|
||||||
|
echo "deb [arch="$(dpkg --print-architecture)" signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/debian "$(. /etc/os-release && echo "$VERSION_CODENAME")" stable" | tee /etc/apt/sources.list.d/docker.list > /dev/null
|
||||||
|
apt-get update
|
||||||
|
apt-get install docker-ce-cli -y
|
||||||
|
- name: Build Docker image
|
||||||
|
run : |
|
||||||
|
cd master
|
||||||
|
echo "${{ secrets.DOCKERGIT_TOKEN }}" | docker login git.woodburn.au -u nathanwoodburn --password-stdin
|
||||||
|
tag_num=$(git rev-parse --short HEAD)
|
||||||
|
docker build -t hnshosting-master:$tag_num .
|
||||||
|
docker tag hnshosting-master:$tag_num git.woodburn.au/nathanwoodburn/hnshosting-master:$tag_num
|
||||||
|
docker push git.woodburn.au/nathanwoodburn/hnshosting-master:$tag_num
|
||||||
|
docker tag hnshosting-master:$tag_num git.woodburn.au/nathanwoodburn/hnshosting-master:latest
|
||||||
|
docker push git.woodburn.au/nathanwoodburn/hnshosting-master:latest
|
14
README.md
14
README.md
@ -7,14 +7,20 @@ This is done to make it easier to manage multiple wordpress sites on multiple se
|
|||||||
|
|
||||||
## Master server install
|
## Master server install
|
||||||
|
|
||||||
Install prerequisites:
|
Docker is the easiest way to install the master server.
|
||||||
|
|
||||||
```
|
```
|
||||||
chmod +x install.sh
|
docker run -d -p 5000:5000 -e LICENCE-API=your-api-key -e WORKER_KEY=your-api-key --name hnshosting-master git.woodburn.au/nathanwoodburn/hnshosting-master:latest -v ./data:/data
|
||||||
./install.sh
|
|
||||||
```
|
```
|
||||||
|
You can also mount a docker volume to /data to store the files instead of mounting a host directory.
|
||||||
|
|
||||||
This will create the service to run the master server.
|
Alternatively you can install it manually.
|
||||||
|
Set your .env file.
|
||||||
|
```
|
||||||
|
cd master
|
||||||
|
python3 -m pip install -r requirements.txt
|
||||||
|
python3 main.py
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
## Worker server install
|
## Worker server install
|
||||||
|
29
master/Dockerfile
Normal file
29
master/Dockerfile
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
FROM --platform=$BUILDPLATFORM python:3.10-alpine AS builder
|
||||||
|
|
||||||
|
WORKDIR /app
|
||||||
|
|
||||||
|
COPY requirements.txt /app
|
||||||
|
RUN --mount=type=cache,target=/root/.cache/pip \
|
||||||
|
pip3 install -r requirements.txt
|
||||||
|
|
||||||
|
COPY . /app
|
||||||
|
|
||||||
|
# Add mount point for data volume
|
||||||
|
VOLUME /data
|
||||||
|
|
||||||
|
ENTRYPOINT ["python3"]
|
||||||
|
CMD ["main.py"]
|
||||||
|
|
||||||
|
FROM builder as dev-envs
|
||||||
|
|
||||||
|
# RUN <<EOF
|
||||||
|
# apk update
|
||||||
|
# apk add git
|
||||||
|
# EOF
|
||||||
|
|
||||||
|
# RUN <<EOF
|
||||||
|
# addgroup -S docker
|
||||||
|
# adduser -S --shell /bin/bash --ingroup docker vscode
|
||||||
|
# EOF
|
||||||
|
# # install Docker tools (cli, buildx, compose)
|
||||||
|
# COPY --from=gloursdocker/docker / /
|
@ -20,7 +20,7 @@ def add_license():
|
|||||||
licence_key = os.urandom(16).hex()
|
licence_key = os.urandom(16).hex()
|
||||||
|
|
||||||
# Add license key to file
|
# Add license key to file
|
||||||
key_file = open('licence_key.txt', 'a')
|
key_file = open('/data/licence_key.txt', 'a')
|
||||||
key_file.write(licence_key + '\n')
|
key_file.write(licence_key + '\n')
|
||||||
key_file.close()
|
key_file.close()
|
||||||
|
|
||||||
@ -38,7 +38,7 @@ def new_site():
|
|||||||
return jsonify({'error': 'Invalid API key or domain', 'success': 'false'})
|
return jsonify({'error': 'Invalid API key or domain', 'success': 'false'})
|
||||||
|
|
||||||
# Check if API key is a valid site key
|
# Check if API key is a valid site key
|
||||||
if api_key not in open('licence_key.txt', 'r').read():
|
if api_key not in open('/data/licence_key.txt', 'r').read():
|
||||||
return jsonify({'error': 'Invalid API key', 'success': 'false'})
|
return jsonify({'error': 'Invalid API key', 'success': 'false'})
|
||||||
|
|
||||||
# Check if domain already exists
|
# Check if domain already exists
|
||||||
@ -53,7 +53,7 @@ def new_site():
|
|||||||
# Check if worker file exists
|
# Check if worker file exists
|
||||||
workers = None
|
workers = None
|
||||||
try:
|
try:
|
||||||
worker_file = open('workers.txt', 'r')
|
worker_file = open('/data/workers.txt', 'r')
|
||||||
workers = worker_file.readlines()
|
workers = worker_file.readlines()
|
||||||
worker_file.close()
|
worker_file.close()
|
||||||
except FileNotFoundError:
|
except FileNotFoundError:
|
||||||
@ -74,15 +74,15 @@ def new_site():
|
|||||||
|
|
||||||
|
|
||||||
# Add domain to file
|
# Add domain to file
|
||||||
sites_file = open('sites.txt', 'a')
|
sites_file = open('/data/sites.txt', 'a')
|
||||||
sites_file.write(domain + ':' + worker.split(':')[0] + '\n')
|
sites_file.write(domain + ':' + worker.split(':')[0] + '\n')
|
||||||
sites_file.close()
|
sites_file.close()
|
||||||
|
|
||||||
# Use key
|
# Use key
|
||||||
key_file = open('licence_key.txt', 'r')
|
key_file = open('/data/licence_key.txt', 'r')
|
||||||
lines = key_file.readlines()
|
lines = key_file.readlines()
|
||||||
key_file.close()
|
key_file.close()
|
||||||
key_file = open('licence_key.txt', 'w')
|
key_file = open('/data/licence_key.txt', 'w')
|
||||||
for line in lines:
|
for line in lines:
|
||||||
if line.strip("\n") != api_key:
|
if line.strip("\n") != api_key:
|
||||||
key_file.write(line)
|
key_file.write(line)
|
||||||
@ -108,11 +108,11 @@ def add_worker():
|
|||||||
|
|
||||||
# Check worker file
|
# Check worker file
|
||||||
try:
|
try:
|
||||||
workers_file = open('workers.txt', 'r')
|
workers_file = open('/data/workers.txt', 'r')
|
||||||
except FileNotFoundError:
|
except FileNotFoundError:
|
||||||
workers_file = open('workers.txt', 'w')
|
workers_file = open('/data/workers.txt', 'w')
|
||||||
workers_file.close()
|
workers_file.close()
|
||||||
workers_file = open('workers.txt', 'r')
|
workers_file = open('/data/workers.txt', 'r')
|
||||||
|
|
||||||
# Check if worker already exists
|
# Check if worker already exists
|
||||||
if worker in workers_file.read():
|
if worker in workers_file.read():
|
||||||
@ -121,7 +121,7 @@ def add_worker():
|
|||||||
workers_file.close()
|
workers_file.close()
|
||||||
|
|
||||||
# Add worker to file
|
# Add worker to file
|
||||||
workers_file = open('workers.txt', 'a')
|
workers_file = open('/data/workers.txt', 'a')
|
||||||
workers_file.write(worker + ":" + worker_IP + '\n')
|
workers_file.write(worker + ":" + worker_IP + '\n')
|
||||||
workers_file.close()
|
workers_file.close()
|
||||||
|
|
||||||
@ -136,11 +136,11 @@ def add_worker():
|
|||||||
def get_sites_count():
|
def get_sites_count():
|
||||||
# If file doesn't exist, create it
|
# If file doesn't exist, create it
|
||||||
try:
|
try:
|
||||||
sites_file = open('sites.txt', 'r')
|
sites_file = open('/data/sites.txt', 'r')
|
||||||
except FileNotFoundError:
|
except FileNotFoundError:
|
||||||
sites_file = open('sites.txt', 'w')
|
sites_file = open('/data/sites.txt', 'w')
|
||||||
sites_file.close()
|
sites_file.close()
|
||||||
sites_file = open('sites.txt', 'r')
|
sites_file = open('/data/sites.txt', 'r')
|
||||||
num=len(sites_file.readlines())
|
num=len(sites_file.readlines())
|
||||||
sites_file.close()
|
sites_file.close()
|
||||||
# Return number of lines in file
|
# Return number of lines in file
|
||||||
@ -149,11 +149,11 @@ def get_sites_count():
|
|||||||
def site_exists(domain):
|
def site_exists(domain):
|
||||||
# If file doesn't exist, create it
|
# If file doesn't exist, create it
|
||||||
try:
|
try:
|
||||||
sites_file = open('sites.txt', 'r')
|
sites_file = open('/data/sites.txt', 'r')
|
||||||
except FileNotFoundError:
|
except FileNotFoundError:
|
||||||
sites_file = open('sites.txt', 'w')
|
sites_file = open('/data/sites.txt', 'w')
|
||||||
sites_file.close()
|
sites_file.close()
|
||||||
sites_file = open('sites.txt', 'r')
|
sites_file = open('/data/sites.txt', 'r')
|
||||||
|
|
||||||
contains_site = False
|
contains_site = False
|
||||||
for line in sites_file.readlines():
|
for line in sites_file.readlines():
|
||||||
@ -167,11 +167,11 @@ def site_exists(domain):
|
|||||||
def site_worker(domain):
|
def site_worker(domain):
|
||||||
# If file doesn't exist, create it
|
# If file doesn't exist, create it
|
||||||
try:
|
try:
|
||||||
sites_file = open('sites.txt', 'r')
|
sites_file = open('/data/sites.txt', 'r')
|
||||||
except FileNotFoundError:
|
except FileNotFoundError:
|
||||||
sites_file = open('sites.txt', 'w')
|
sites_file = open('/data/sites.txt', 'w')
|
||||||
sites_file.close()
|
sites_file.close()
|
||||||
sites_file = open('sites.txt', 'r')
|
sites_file = open('/data/sites.txt', 'r')
|
||||||
|
|
||||||
worker = None
|
worker = None
|
||||||
for line in sites_file.readlines():
|
for line in sites_file.readlines():
|
||||||
|
Loading…
Reference in New Issue
Block a user