Compare commits

14 Commits
v0.1 ... master

Author SHA1 Message Date
Andreas Balogh
10f298659e added env 2021-02-17 18:44:20 +01:00
Andreas Balogh
f2b5e89649 corrected cmd order 2021-02-16 21:39:58 +01:00
Andreas Balogh
40d707c397 corrected line removal 2021-02-16 21:38:50 +01:00
Andreas Balogh
10ebc09663 added buildback requirement 2021-02-16 16:23:54 +01:00
Andreas Balogh
954b9380f4 another try 2021-02-16 15:52:28 +01:00
Andreas Balogh
c1d80cabbd simplest flask server 2021-02-16 15:44:39 +01:00
Andreas Balogh
00a89222be changed mixed runner 2021-02-16 09:15:28 +01:00
Andreas Balogh
96a9449b53 using docker image 2021-02-15 23:29:54 +01:00
Andreas Balogh
f94c882b53 removed tags 2021-02-15 23:20:18 +01:00
Andreas Balogh
4508f0db92 retry ci 2021-02-15 23:17:51 +01:00
Andreas Balogh
be2d91aff8 minimal fileset 2021-02-15 23:07:10 +01:00
Andreas Balogh
c211a66b47 retry 2021-02-15 22:53:03 +01:00
Andreas Balogh
82665a7eb1 removed requirements 2021-02-15 22:29:56 +01:00
Andreas Balogh
ac568b2508 activate autodevops 2021-02-15 22:03:16 +01:00
21 changed files with 33 additions and 351 deletions

1
.gitignore vendored
View File

@@ -1,6 +1,7 @@
# eclipse
.project
.pydevproject
.settings/
# Byte-compiled / optimized / DLL files
__pycache__/

View File

@@ -1,59 +0,0 @@
build_zeo:
stage: build
tags:
- shell
- ubuntu
variables:
IMAGE_TAG: $CI_REGISTRY_IMAGE/zeo:$CI_COMMIT_REF_SLUG
RELEASE_TAG: $CI_REGISTRY_IMAGE/zeo:latest
script:
- cd src/zeo
- docker build -t $IMAGE_TAG .
- docker login -u $CI_REGISTRY_USER -p $CI_REGISTRY_PASSWORD $CI_REGISTRY
- docker push $IMAGE_TAG
build_flask:
stage: build
tags:
- shell
- ubuntu
variables:
IMAGE_TAG: $CI_REGISTRY_IMAGE/webui:$CI_COMMIT_REF_SLUG
RELEASE_TAG: $CI_REGISTRY_IMAGE/webui:latest
script:
- cd src/webui
- docker build -t $IMAGE_TAG .
- docker login -u $CI_REGISTRY_USER -p $CI_REGISTRY_PASSWORD $CI_REGISTRY
- docker push $IMAGE_TAG
build_tester:
stage: build
tags:
- shell
- ubuntu
script:
- echo "Build api image"
- export
# https://gitlab.com/gitlab-org/gitlab-runner/-/issues/26785
unit_test:
stage: test
services:
- name: $CI_REGISTRY_IMAGE/zeo:$CI_COMMIT_REF_SLUG
alias: zeo
- name: $CI_REGISTRY_IMAGE/webui:$CI_COMMIT_REF_SLUG
alias: webui
image:
name: $CI_REGISTRY_IMAGE/webui:$CI_COMMIT_REF_SLUG
entrypoint: [""]
tags:
- docker
- ubuntu
artifacts:
paths:
- var/
script:
- '[ -d var ] || mkdir var'
- cd var
- wget webui:5000 -o wget.log
- echo "Done."

View File

@@ -1,2 +0,0 @@
eclipse.preferences.version=1
encoding//src/webui/flaskr/zcm.py=utf8

6
Dockerfile Normal file
View File

@@ -0,0 +1,6 @@
FROM python:3.9-slim
COPY . .
RUN pip install -r requirements.txt
ENV FLASK_APP=flaskr/hello
EXPOSE 5000
ENTRYPOINT python3 -m flask run --host=0.0.0.0

View File

@@ -1,3 +1,3 @@
# scraper
# Kubernetes AutoDevOps example
Ripper worming through blogs for videos, images, text.
Example project to test gitlab CI, Docker, Kubernetes and AutoDevOps integration.

23
flaskr/hello.py Normal file
View File

@@ -0,0 +1,23 @@
# https://gitlab.com/gitlab-org/gitlab/-/issues/22684
# herokuish/AutoDevOps can't test some languages
# Internal error occurred: failed calling webhook "validate.nginx.ingress.kubernetes.io"
# https://stackoverflow.com/questions/61365202/nginx-ingress-service-ingress-nginx-controller-admission-not-found
# kubectl get -A ValidatingWebhookConfiguration
# kubectl delete -A ValidatingWebhookConfiguration ingress-nginx-admission
from flask import Flask
import os
app = Flask(__name__)
@app.route('/')
def hello():
return 'Hello world!\n'
@app.route('/env')
def env():
return "\n".join([f"{k}: {v}" for k,v in os.environ.items()])

View File

@@ -1 +1 @@
couchbase
Flask

View File

View File

@@ -1,43 +0,0 @@
#!python3
# Created Jul 24, 2020
# @author: andreas
""" Module: Main Template """
from argparse import ArgumentParser
import logging
import sys
import os
LOG = logging.getLogger(__name__)
def cli(argv=None):
# command line interface
if argv is None:
argv = sys.argv
LOG.info("%s %s", os.path.basename(argv[0]), " ".join(argv[1:]))
parser = ArgumentParser(description="Module Template")
parser.add_argument("--action", help="mock action verb")
parser.add_argument("--database", help="database connection")
parser.add_argument("--config_file", help="json filepath, not used by mock")
args = parser.parse_args(argv[1:])
argd = vars(args)
# arguments
for k, v in argd.items():
print(k, v)
# enviroment
for k, v in os.environ.items():
print(k, v)
# feature
LOG.info("Hello world!")
LOG.info("done")
return 0
if __name__ == "__main__":
logging.Formatter.default_time_format = '%H:%M:%S'
logging.Formatter.default_msec_format = '%s.%03d'
logging.basicConfig(level=logging.INFO,
format='%(asctime)s [%(process)i] %(levelname).4s %(module)s.%(funcName)s: %(message)s')
sys.exit(cli())

View File

@@ -1,43 +0,0 @@
#!python3
# Created Jul 24, 2020
# @author: andreas
""" Module: Main Template """
from argparse import ArgumentParser
import logging
import sys
import os
LOG = logging.getLogger(__name__)
def cli(argv=None):
# command line interface
if argv is None:
argv = sys.argv
LOG.info("%s %s", os.path.basename(argv[0]), " ".join(argv[1:]))
parser = ArgumentParser(description="Module Template")
parser.add_argument("--action", help="mock action verb")
parser.add_argument("--database", help="database connection")
parser.add_argument("--config_file", help="json filepath, not used by mock")
args = parser.parse_args(argv[1:])
argd = vars(args)
# arguments
for k, v in argd.items():
print(k, v)
# enviroment
for k, v in os.environ.items():
print(k, v)
# feature
LOG.info("Hello world!")
LOG.info("done")
return 0
if __name__ == "__main__":
logging.Formatter.default_time_format = '%H:%M:%S'
logging.Formatter.default_msec_format = '%s.%03d'
logging.basicConfig(level=logging.INFO,
format='%(asctime)s [%(process)i] %(levelname).4s %(module)s.%(funcName)s: %(message)s')
sys.exit(cli())

View File

@@ -1,5 +0,0 @@
#!python3
# Created Jul 25, 2020
# @author: andreas
print("Building package...")

View File

@@ -1,13 +0,0 @@
FROM python:3.9-slim
RUN apt-get update && apt-get install -y \
gcc \
wget \
&& rm -rf /var/lib/apt/lists/*
RUN pip install ZEO==5.2.1
RUN pip install flask
COPY . .
RUN chmod +x /tester.sh
RUN chmod +x /run.sh
ENV FLASK_APP=flaskr/zeo_db
EXPOSE 5000
ENTRYPOINT python3 -m flask run --host=0.0.0.0

View File

@@ -1,26 +0,0 @@
import time
from flask import Flask
import redis
app = Flask(__name__)
cache = redis.Redis(host='redis', port=6379)
def get_hit_count():
retries = 5
while True:
try:
return cache.incr('hits')
except redis.exceptions.ConnectionError as exc:
if retries == 0:
raise exc
retries -= 1
time.sleep(0.5)
@app.route('/')
def hello():
count = get_hit_count()
return 'Hello World! I have been seen {} times.\n'.format(count)

View File

@@ -1,94 +0,0 @@
# Copyright (c) 2016 Andreas
# See LICENSE for details.
""" ZODB context manager """
# from BTrees.IOBTree import IOBTree
# from BTrees.OOBTree import OOBTree
# from persistent import Persistent
# from persistent.list import PersistentList as PList
# from persistent.mapping import PersistentMapping as PDict
from ZEO.ClientStorage import ClientStorage
from ZODB import DB
from ZODB.FileStorage import FileStorage
class ZDatabase():
""" Provides a ZODB database context manager """
def __init__(self, uri, **kwargs):
self.storage = create_storage(uri)
self.db = DB(self.storage, **kwargs)
def __enter__(self):
return self.db
def __exit__(self, exc_type, exc_value, traceback):
self.db.close()
return False
class ZConnection():
""" Provides a ZODB connection with auto-abort (default).
Provides a tuple of connection and root object:
with ZConnection(db) as (cx, root):
root.one = "ok"
ZConnection implements a connection context manager.
Transaction context managers in contrast do auto-commit:
a) with db.transaction() as connection, or
b) with cx.transaction_manager as transaction, or
c) with transaction.manager as transaction (for the thread-local transaction manager)
See also http://www.zodb.org/en/latest/guide/transactions-and-threading.html
"""
def __init__(self, db, auto_commit=False, transaction_manager=None):
self.db = db
self.auto_commit = auto_commit
self.transaction_manager = transaction_manager
self.cx = None
def __enter__(self):
if self.transaction_manager:
self.cx = self.db.open(self.transaction_manager)
else:
self.cx = self.db.open()
return self.cx, self.cx.root()
def __exit__(self, exc_type, exc_value, traceback):
if self.auto_commit:
self.cx.transaction_manager.commit()
self.cx.close()
return False
def create_storage(uri):
""" supported URIs
file://e:/workspaces/zeo/bots.fs
zeo://localhost:8001
e:/workspaces/zeo/bots.fs
@see https://en.wikipedia.org/wiki/Uniform_Resource_Identifier
"""
if uri.startswith("file://"):
storage = FileStorage(uri[7:])
elif uri.startswith("zeo://"):
addr, port = uri[6:].split(":")
# addr_ = addr.encode("ASCII")
storage = ClientStorage((addr, int(port)))
else:
storage = FileStorage(uri)
return storage
def database(uri):
""" convenience function for single thread, return one connection from the pool """
storage = create_storage(uri)
db = DB(storage)
return db
def connection(db):
""" Convenience function for multi thread, returns
connection, transaction manager and root
"""
cx = db.open()
return cx, cx.root()

View File

@@ -1,27 +0,0 @@
from ZEO.ClientStorage import ClientStorage
from ZODB import DB
import socket
from flask import Flask
app = Flask(__name__)
ipv4 = socket.gethostbyname("zeo")
storage = ClientStorage((ipv4, 8100))
db = DB(storage)
cx = db.open()
def get_hit_count():
root = cx.root()
if "hits" not in root:
root['hits'] = 0
hits = root['hits']
root['hits'] = hits + 1
cx.transaction_manager.commit()
return hits
@app.route('/')
def hello():
count = get_hit_count()
return 'Hello World! I have been seen {} times.\n'.format(count)

View File

@@ -1,4 +0,0 @@
#!/bin/sh
export FLASK_APP=flaskr/zeo_db
exec python3 -m flask run --host=0.0.0.0

View File

@@ -1,2 +0,0 @@
mkdir var
wget webui:5000 -o var/index.html

View File

@@ -1,12 +0,0 @@
FROM python:3.9-slim
RUN apt-get update && apt-get install -y \
gcc \
&& rm -rf /var/lib/apt/lists/*
RUN pip install ZODB==5.6.0
RUN pip install ZEO==5.2.1
COPY ./zeo.conf /etc/zeo.conf
COPY ./run.sh /run.sh
RUN chmod +x /run.sh
VOLUME ["/var/zeo/fs", "/var/zeo/blobs"]
EXPOSE 8100
CMD /run.sh

View File

@@ -1,9 +0,0 @@
#!/bin/sh
# We need to add a empty Data.fs if it does not exist
# as zeo will not start without on.
if [ ! -f /var/zeo/fs/Data.fs ]; then
touch /var/zeo/fs/Data.fs
fi
exec /usr/local/bin/runzeo -a 8100 -C /etc/zeo.conf

View File

@@ -1,9 +0,0 @@
<zeo>
address 8100
read-only false
</zeo>
<filestorage>
path /var/zeo/fs/Data.fs
blob-dir /var/zeo/blobs
</filestorage>