Compare commits
9 Commits
Author | SHA1 | Date |
---|---|---|
knoflook | d2141167bd | |
knoflook | f578de0ef6 | |
knoflook | cb8b605383 | |
knoflook | a39cf380a4 | |
knoflook | 775d6829e7 | |
knoflook | 3fbd1a36db | |
knoflook | 83596ea7bb | |
knoflook | 47b2a355cb | |
knoflook | ea33ecd589 |
|
@ -0,0 +1,13 @@
|
||||||
|
---
|
||||||
|
kind: pipeline
|
||||||
|
name: publish docker image
|
||||||
|
steps:
|
||||||
|
- name: build and publish
|
||||||
|
image: plugins/docker
|
||||||
|
settings:
|
||||||
|
username:
|
||||||
|
from_secret: docker_reg_username
|
||||||
|
password:
|
||||||
|
from_secret: docker_reg_passwd
|
||||||
|
repo: autonomiccooperative/capsul-flask
|
||||||
|
tags: ${DRONE_COMMIT_BRANCH}
|
|
@ -0,0 +1,32 @@
|
||||||
|
FROM python:3.8-slim as build
|
||||||
|
RUN apt-get update && apt-get install --no-install-recommends -y \
|
||||||
|
gcc \
|
||||||
|
gettext \
|
||||||
|
git \
|
||||||
|
libffi-dev \
|
||||||
|
# postgresql \
|
||||||
|
python3-dev \
|
||||||
|
libpq-dev
|
||||||
|
RUN mkdir -p /app/{code,venv}
|
||||||
|
WORKDIR /app/code
|
||||||
|
COPY Pipfile Pipfile.lock /app/code/
|
||||||
|
RUN python3 -m venv /app/venv
|
||||||
|
RUN pip install pipenv setuptools
|
||||||
|
ENV PATH="/app/venv/bin:$PATH" VIRTUAL_ENV="/app/venv"
|
||||||
|
RUN pip install wheel cppy
|
||||||
|
# Install dependencies into the virtual environment with Pipenv
|
||||||
|
RUN pipenv install --deploy --verbose
|
||||||
|
FROM python:3.8-slim
|
||||||
|
RUN apt-get update && apt-get install --no-install-recommends -y \
|
||||||
|
cloud-utils \
|
||||||
|
libpq5 \
|
||||||
|
libvirt-clients \
|
||||||
|
openssh-client \
|
||||||
|
virtinst
|
||||||
|
COPY . /app/code/
|
||||||
|
WORKDIR /app/code
|
||||||
|
COPY --from=build /app/venv /app/venv
|
||||||
|
ENV PATH="/app/venv/bin:$PATH" VIRTUAL_ENV="/app/venv"
|
||||||
|
CMD ["gunicorn", "--bind", "0.0.0.0:5000", "-k", "gevent", "--worker-connections", "1000", "app:app"]
|
||||||
|
VOLUME /app/code
|
||||||
|
EXPOSE 5000
|
2
Pipfile
2
Pipfile
|
@ -4,6 +4,7 @@ verify_ssl = true
|
||||||
name = "pypi"
|
name = "pypi"
|
||||||
|
|
||||||
[packages]
|
[packages]
|
||||||
|
psycopg2 = "==2.8.5"
|
||||||
astroid = "==2.4.1"
|
astroid = "==2.4.1"
|
||||||
blinker = "==1.4"
|
blinker = "==1.4"
|
||||||
click = "==7.1.2"
|
click = "==7.1.2"
|
||||||
|
@ -17,7 +18,6 @@ lazy-object-proxy = "==1.4.3"
|
||||||
MarkupSafe = "==1.1.1"
|
MarkupSafe = "==1.1.1"
|
||||||
mccabe = "==0.6.1"
|
mccabe = "==0.6.1"
|
||||||
nanoid = "==2.0.0"
|
nanoid = "==2.0.0"
|
||||||
psycopg2 = "==2.8.5"
|
|
||||||
pylint = "==2.5.2"
|
pylint = "==2.5.2"
|
||||||
six = "==1.14.0"
|
six = "==1.14.0"
|
||||||
toml = "==0.10.0"
|
toml = "==0.10.0"
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
# check available RAM and IPv4s
|
# check available RAM and IPv4s
|
||||||
|
|
||||||
ram_bytes_to_allocate="$1"
|
ram_bytes_to_allocate="$1"
|
||||||
ram_bytes_available=$(grep -E "^(size|memory_available_bytes)" /proc/spl/kstat/zfs/arcstats | awk '{sum+=$3} END {printf "%.0f", sum}')
|
ram_bytes_available="$(($(grep Available /proc/meminfo | grep -o '[0-9]*') * 1024))"
|
||||||
ram_bytes_remainder="$((ram_bytes_available - ram_bytes_to_allocate))"
|
ram_bytes_remainder="$((ram_bytes_available - ram_bytes_to_allocate))"
|
||||||
|
|
||||||
if echo "$ram_bytes_to_allocate" | grep -vqE "^[0-9]+$"; then
|
if echo "$ram_bytes_to_allocate" | grep -vqE "^[0-9]+$"; then
|
||||||
|
@ -11,8 +11,8 @@ if echo "$ram_bytes_to_allocate" | grep -vqE "^[0-9]+$"; then
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# 20GB
|
# 0.25GB
|
||||||
if [ "$ram_bytes_remainder" -le $((20 * 1024 * 1024 * 1024)) ]; then
|
if [ "$ram_bytes_remainder" -le $((1 * 1024 * 1024 * 1024 / 4)) ]; then
|
||||||
echo "VM is requesting more RAM than $(hostname -f) has available."
|
echo "VM is requesting more RAM than $(hostname -f) has available."
|
||||||
echo "Bytes requested: $ram_bytes_to_allocate"
|
echo "Bytes requested: $ram_bytes_to_allocate"
|
||||||
echo "Bytes available: $ram_bytes_available"
|
echo "Bytes available: $ram_bytes_available"
|
||||||
|
@ -20,9 +20,12 @@ if [ "$ram_bytes_remainder" -le $((20 * 1024 * 1024 * 1024)) ]; then
|
||||||
fi
|
fi
|
||||||
|
|
||||||
ipv4_limit=61
|
ipv4_limit=61
|
||||||
total_addresses_used=$(virsh net-dhcp-leases public2 | grep -E '.+' | tail -n +3 | wc -l)
|
used_ips=$(grep ip-add "/var/lib/libvirt/dnsmasq/virbr3.status" | cut -d '"' -f 4)
|
||||||
|
reserved_ips=$(cat "/var/lib/libvirt/dnsmasq/public3.hostsfile" | cut -d ',' -f 2)
|
||||||
|
total_addresses_used=$(printf "$used_ips\n$reserved_ips" | sort | uniq | wc -l)
|
||||||
|
ipv4_count=$(printf "$total_addresses_used")
|
||||||
|
|
||||||
if [ "$total_addresses_used" -ge "$ipv4_limit" ]; then
|
if [ "$ipv4_count" -ge "$ipv4_limit" ]; then
|
||||||
echo "IPv4 address limit reached"
|
echo "IPv4 address limit reached"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
|
@ -0,0 +1,36 @@
|
||||||
|
---
|
||||||
|
version: "3.6"
|
||||||
|
|
||||||
|
services:
|
||||||
|
app:
|
||||||
|
image: kn0fl00k/capsul:latest
|
||||||
|
# build: .
|
||||||
|
volumes:
|
||||||
|
- "./:/app/code"
|
||||||
|
- "../tank:/tank"
|
||||||
|
# - "/var/run/libvirt/libvirt-sock:/var/run/libvirt/libvirt-sock"
|
||||||
|
depends_on:
|
||||||
|
- db
|
||||||
|
ports:
|
||||||
|
- "5000:5000"
|
||||||
|
environment:
|
||||||
|
- "POSTGRES_CONNECTION_PARAMETERS=host=db port=5432 user=capsul password=capsul dbname=capsul"
|
||||||
|
- SPOKE_MODEL=shell-scripts
|
||||||
|
#- FLASK_DEBUG=1
|
||||||
|
- BASE_URL=http://localhost:5000
|
||||||
|
- ADMIN_PANEL_ALLOW_EMAIL_ADDRESSES=3wc.capsul@doesthisthing.work
|
||||||
|
- VIRSH_DEFAULT_CONNECT_URI=qemu:///system
|
||||||
|
# The image uses gunicorn by default, let's override it with Flask's
|
||||||
|
# built-in development server
|
||||||
|
command: ["flask", "run", "-h", "0.0.0.0", "-p", "5000"]
|
||||||
|
db:
|
||||||
|
image: "postgres:14-alpine"
|
||||||
|
volumes:
|
||||||
|
- "postgres:/var/lib/postgresql/data"
|
||||||
|
environment:
|
||||||
|
POSTGRES_USER: capsul
|
||||||
|
POSTGRES_PASSWORD: capsul
|
||||||
|
POSTGRES_DB: capsul
|
||||||
|
|
||||||
|
volumes:
|
||||||
|
postgres:
|
Loading…
Reference in New Issue