Skip to content

Commit

Permalink
ISSUE #1
Browse files Browse the repository at this point in the history
* Add `microservice-python-deploy-kubernetes` template.
  • Loading branch information
Sergio García Prado committed Dec 13, 2021
1 parent 93b03a3 commit 7def6f7
Show file tree
Hide file tree
Showing 7 changed files with 93 additions and 0 deletions.
4 changes: 4 additions & 0 deletions .github/workflows/template-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ jobs:
- name: Build Microservice Python Deploy Docker Template
run: tar -czvf microservice-python-deploy-docker.tar.gz -C ${{ github.workspace }}/microservice/language/python/deploy/docker .

- name: Build Microservice Python Deploy Kubernetes Template
run: tar -czvf microservice-python-deploy-kubernetes.tar.gz -C ${{ github.workspace }}/microservice/language/python/deploy/kubernetes .

- name: Build Project Init Template
run: tar -czvf project-init.tar.gz -C ${{ github.workspace }}/project/init .

Expand All @@ -38,5 +41,6 @@ jobs:
microservice-python-package-manager-poetry.tar.gz
microservice-python-package-manager-pip.tar.gz
microservice-python-deploy-docker.tar.gz
microservice-python-deploy-kubernetes.tar.gz
project-init.tar.gz
4 changes: 4 additions & 0 deletions microservice/language/python/deploy/kubernetes/Makefile.jinja
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
build:
docker build --no-cache -t {{ project_name }}_{{ name }} -f deploy/Dockerfile .
docker tag {{ project_name }}_{{ name }}:latest {{ kubernetes_registry }}/{{ project_name }}_{{ name }}:{{ version }}
docker push {{ kubernetes_registry }}/{{ project_name }}_{{ name }}:{{ version }}
31 changes: 31 additions & 0 deletions microservice/language/python/deploy/kubernetes/copier.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
name:
type: str
help: What is the name of the microservice?
version:
type: str
help: What is the version of the microservice?
project_name:
type: str
help: What is the name of the project?
rest_port:
type: int
default: 8080
help: What is the rest's port?
kubernetes_config:
type: str
default: microservices-config
help: What is the kubernetes config?
kubernetes_registry:
type: str
help: What is the kubernetes registry?

_envops:
block_start_string: "{%"
block_end_string: "%}"
comment_start_string: "{#"
comment_end_string: "#}"
variable_start_string: "{{"
variable_end_string: "}}"
keep_trailing_newline: false

_templates_suffix: .jinja
17 changes: 17 additions & 0 deletions microservice/language/python/deploy/kubernetes/deploy/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
FROM ghcr.io/clariteia/minos-microservice:0.1.5 as development

COPY ./pyproject.toml ./poetry.lock ./
RUN poetry install --no-root
COPY . .
CMD ["poetry", "run", "microservice", "start"]

FROM development as build
RUN poetry export --without-hashes > req.txt && pip wheel -r req.txt --wheel-dir ./dist
RUN poetry build --format wheel

FROM python:3.9-slim as production
COPY --from=build /microservice/dist/ ./dist
RUN pip install --no-deps ./dist/*
COPY config.yml ./config.yml
ENTRYPOINT ["microservice"]
CMD ["start"]
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: {{ project_name }}-{{ name }}
namespace: {{ project_name }}
spec:
replicas: 1
selector:
matchLabels:
app.kubernetes.io/name: {{ project_name }}-{{ name }}
template:
metadata:
labels:
app.kubernetes.io/name: {{ project_name }}-{{ name }}
spec:
containers:
- name: {{ project_name }}-{{ name }}
image: {{ kubernetes_registry }}/{{ project_name }}-{{ name }}:{{ version }}
imagePullPolicy: "IfNotPresent"
ports:
- containerPort: {{ rest_port }}
envFrom:
- configMapRef:
name: {{ kubernetes_config }}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
apiVersion: v1
kind: Service
metadata:
name: {{ project_name }}-{{ name }}
namespace: {{ project_name }}
spec:
type: ClusterIP
ports:
- port: {{ rest_port }}
targetPort: {{ rest_port }}
selector:
app.kubernetes.io/name: {{ project_name }}-{{ name }}
1 change: 1 addition & 0 deletions microservice/language/python/skeleton/copier.yml
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ deploy:
help: What deploy system do you want to use?
choices:
docker: &docker_url "{{ template_root }}/microservice-python-deploy-docker.tar.gz"
kubernetes: "{{ template_root }}/microservice-python-deploy-kubernetes.tar.gz"
default: *docker_url

_envops:
Expand Down

0 comments on commit 7def6f7

Please sign in to comment.