Skip to content

Commit

Permalink
Prepared kubernetes deployment (#14)
Browse files Browse the repository at this point in the history
* Added DO load balancer annotations
* Added basic health check API
* Better settings
* Pick version at build from tags
  • Loading branch information
kopsha authored Feb 25, 2024
1 parent cb9fb04 commit 867e5e4
Show file tree
Hide file tree
Showing 10 changed files with 68 additions and 35 deletions.
1 change: 1 addition & 0 deletions .github/workflows/release-package.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ jobs:
with:
context: .
push: true
build-args: VERSION=${{ steps.meta.outputs.tags }}
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=local,src=/tmp/.buildx-cache
Expand Down
12 changes: 7 additions & 5 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,11 @@ RUN apt update && apt install --yes \
locales \
locales-all \
entr \
git \
wkhtmltopdf \
&& rm -rf /var/lib/apt/lists/*

# prepare application folder
RUN mkdir -p /app/src \
&& mkdir -p /app/shared
RUN mkdir -p /app/src

# install python dependencies
WORKDIR /app
Expand All @@ -29,8 +27,12 @@ COPY ./src /app/src

EXPOSE 8000
ENV SERVICE_PORT=8000

ARG VERSION=local # override at build
ENV VERSION=${VERSION}

CMD ["start"]

VOLUME [ "/app/src" ]
VOLUME [ "/app/shared" ]
VOLUME [ "/app/htmlcov/" ]
VOLUME [ "/app/data/db.sqlite3" ]

18 changes: 0 additions & 18 deletions argo-application.yaml

This file was deleted.

39 changes: 35 additions & 4 deletions deploy/service.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,43 @@ apiVersion: v1
kind: Service
metadata:
name: micro-invoicer
annotations:
service.beta.kubernetes.io/do-loadbalancer-name: "micro-invoicer"
service.beta.kubernetes.io/do-loadbalancer-protocol: "http"
service.beta.kubernetes.io/do-loadbalancer-tls-ports: "443"
service.beta.kubernetes.io/do-loadbalancer-redirect-http-to-https: "true"
service.beta.kubernetes.io/do-loadbalancer-enable-proxy-protocol: "true"
service.beta.kubernetes.io/do-loadbalancer-enable-backend-keepalive: "true"

# TODO: template ?
# service.beta.kubernetes.io/do-loadbalancer-certificate-id: "1234-5678-9012-3456"
service.beta.kubernetes.io/do-loadbalancer-hostname: "micro-invoicer.fibonet.ro"
service.beta.kubernetes.io/do-loadbalancer-disable-lets-encrypt-dns-records: "false"

# Just in case
# service.beta.kubernetes.io/do-loadbalancer-sticky-sessions-type: "cookies"
# service.beta.kubernetes.io/do-loadbalancer-sticky-sessions-cookie-name: "example"
# service.beta.kubernetes.io/do-loadbalancer-sticky-sessions-cookie-ttl: "60"

service.beta.kubernetes.io/do-loadbalancer-healthcheck-port: "8000"
service.beta.kubernetes.io/do-loadbalancer-healthcheck-protocol: "http"
service.beta.kubernetes.io/do-loadbalancer-healthcheck-path: "/healthy"
service.beta.kubernetes.io/do-loadbalancer-healthcheck-check-interval-seconds: "8"
service.beta.kubernetes.io/do-loadbalancer-healthcheck-response-timeout-seconds: "5"
service.beta.kubernetes.io/do-loadbalancer-healthcheck-unhealthy-threshold: "3"
service.beta.kubernetes.io/do-loadbalancer-healthcheck-healthy-threshold: "5"

spec:
type: LoadBalancer
selector:
app: micro-invoicer
ports:
- protocol: TCP
port: 80
targetPort: 8000
type: LoadBalancer
- name: http
protocol: TCP
port: 80
targetPort: 8000
- name: https
protocol: TCP
port: 443
targetPort: 8000

6 changes: 5 additions & 1 deletion docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,12 @@ version: "3"

services:
micro-invoicer:
build: ./
build: .
ports:
- 8000:8000
volumes:
- ./src:/app/src
- ./data/db.sqlite3:/app/data/db.sqlite3
environment:
- DEBUG=on

1 change: 0 additions & 1 deletion src/microinvoicer/micro_timesheet.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@ def previous_month():


def create_random_tasks(activity, how_many, hours):

names = pick_task_names(flavor=activity["flavor"], count=how_many)
durations = split_duration(duration=hours, count=how_many)
dates = compute_start_dates(activity["start_date"], durations)
Expand Down
4 changes: 1 addition & 3 deletions src/microinvoicer/views.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
"""How about now."""
from datetime import date, timedelta, datetime
from datetime import date, timedelta
from django.http import FileResponse
from django.urls import reverse_lazy
from django.views.generic import TemplateView
Expand Down Expand Up @@ -59,7 +58,6 @@ def get_context_data(self, **kwargs):


class ReportView(LoginRequiredMixin, TemplateView):

template_name = "report.html"

def get_context_data(self, **kwargs):
Expand Down
12 changes: 12 additions & 0 deletions src/microtools/healthy.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
from django.http import JsonResponse
from django.conf import settings


def health_check(request):
response = dict(
status="healthy",
version=settings.VERSION,
debug=settings.DEBUG,
message="Service is up and running",
)
return JsonResponse(response, status=200)
8 changes: 5 additions & 3 deletions src/microtools/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@
"""
import os

TRUEISH = {"true", "True", "yes", "1", "on"}
DEBUG = os.environ.get("DEBUG", "False") in TRUEISH

DEBUG = False
ALLOWED_HOSTS = ["micro.fibonet.ro"]
ALLOWED_HOSTS = os.environ.get("ALLOWED_HOSTS", "localhost").split(",")
VERSION = os.environ.get("VERSION", "develop")

BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))

Expand Down Expand Up @@ -53,7 +55,7 @@
DATABASES = {
"default": {
"ENGINE": "django.db.backends.sqlite3",
"NAME": os.path.join(BASE_DIR, "db.sqlite3"),
"NAME": os.path.join("/", "app", "data", "db.sqlite3"),
}
}

Expand Down
2 changes: 2 additions & 0 deletions src/microtools/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,11 @@
"""
from django.contrib import admin
from django.urls import include, path
from .healthy import health_check


urlpatterns = [
path("healthy/", health_check, name="healthy"),
path("admin/", admin.site.urls),
path("", include("microinvoicer.urls")),
]

0 comments on commit 867e5e4

Please sign in to comment.