Compare commits

...

9 Commits
main ... dev

Author SHA1 Message Date
knoflook d2141167bd
don't build in compose
continuous-integration/drone/push Build is failing Details
2022-05-09 15:31:23 +02:00
knoflook f578de0ef6
get capacity from /proc/meminfo (via 3wordchant/capsul-flask) 2022-05-09 15:30:48 +02:00
knoflook cb8b605383
first working release
continuous-integration/drone/push Build is failing Details
2022-04-20 15:22:14 +02:00
knoflook a39cf380a4
update repo before install
continuous-integration/drone/push Build is failing Details
2022-04-20 14:58:20 +02:00
knoflook 775d6829e7
move apk to apt-get
continuous-integration/drone/push Build is failing Details
2022-04-20 14:57:28 +02:00
knoflook 3fbd1a36db
testing on debian based image
continuous-integration/drone Build is failing Details
2022-04-20 14:51:31 +02:00
knoflook 83596ea7bb
fix docker passwd
continuous-integration/drone/push Build is failing Details
2022-04-20 12:44:07 +02:00
knoflook 47b2a355cb
change drone config
continuous-integration/drone Build is failing Details
2022-04-20 11:35:25 +02:00
knoflook ea33ecd589
not working, numpy related failure 2022-04-20 11:06:38 +02:00
5 changed files with 90 additions and 6 deletions

13
.drone.yml Normal file
View File

@ -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}

32
Dockerfile Normal file
View File

@ -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

View File

@ -4,6 +4,7 @@ verify_ssl = true
name = "pypi"
[packages]
psycopg2 = "==2.8.5"
astroid = "==2.4.1"
blinker = "==1.4"
click = "==7.1.2"
@ -17,7 +18,6 @@ lazy-object-proxy = "==1.4.3"
MarkupSafe = "==1.1.1"
mccabe = "==0.6.1"
nanoid = "==2.0.0"
psycopg2 = "==2.8.5"
pylint = "==2.5.2"
six = "==1.14.0"
toml = "==0.10.0"

View File

@ -3,7 +3,7 @@
# check available RAM and IPv4s
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))"
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
fi
# 20GB
if [ "$ram_bytes_remainder" -le $((20 * 1024 * 1024 * 1024)) ]; then
# 0.25GB
if [ "$ram_bytes_remainder" -le $((1 * 1024 * 1024 * 1024 / 4)) ]; then
echo "VM is requesting more RAM than $(hostname -f) has available."
echo "Bytes requested: $ram_bytes_to_allocate"
echo "Bytes available: $ram_bytes_available"
@ -20,9 +20,12 @@ if [ "$ram_bytes_remainder" -le $((20 * 1024 * 1024 * 1024)) ]; then
fi
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"
exit 1
fi

36
docker-compose.yml Normal file
View File

@ -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: