Skip to content

Commit

Permalink
Merge pull request #2 from Clariteia/0.0.1
Browse files Browse the repository at this point in the history
0.0.1
  • Loading branch information
Sergio García Prado authored Dec 30, 2021
2 parents f403579 + 846ca9e commit cdb46db
Show file tree
Hide file tree
Showing 117 changed files with 1,596 additions and 224 deletions.
16 changes: 6 additions & 10 deletions .github/workflows/template-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,13 @@ jobs:
- name: Check out repository code
uses: actions/checkout@v2

- name: Build Microservice Init Template
run: tar -czvf microservice-init.tar.gz -C ${{ github.workspace }}/microservice .
- name: Build Templates
run: sh ${{ github.workspace }}/build.sh

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

- name: Release
- name: Release Templates
uses: softprops/action-gh-release@v1
if: startsWith(github.ref, 'refs/tags/')
with:
files: |
microservice-init.tar.gz
project-init.tar.gz
prerelease: true
fail_on_unmatched_files: true
files: ${{ github.workspace }}/.build/*
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# Intellij IDEa / PyCharm / etc.
.idea
.run

# Build
.build
8 changes: 8 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
repos:
- repo: local
hooks:
- id: build
pass_filenames: false
entry: make build
name: Generate build
language: system
5 changes: 5 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
.PHONY: build

build:
rm -rf .build
sh build.sh
98 changes: 98 additions & 0 deletions build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
#!/bin/sh

set -e

ROOT_DIR=$(dirname "$0")
BUILD_DIR=$(dirname "$0")/.build

mkdir -p "$BUILD_DIR"

echo "Building Microservice Init Template..."
tar -czf "$BUILD_DIR/microservice-init.tar.gz" -C "$ROOT_DIR/microservice/init" .

echo "Building Microservice Python Init Template..."
tar -czf "$BUILD_DIR/microservice-python-init.tar.gz" -C "$ROOT_DIR/microservice/language/python/init" .

echo "Building Microservice Python Package Manager Poetry Template..."
tar -czf "$BUILD_DIR/microservice-python-package-manager-poetry.tar.gz" -C "$ROOT_DIR/microservice/language/python/package-manager/poetry" .

echo "Building Microservice Python Package Manager Pip Template..."
tar -czf "$BUILD_DIR/microservice-python-package-manager-pip.tar.gz" -C "$ROOT_DIR/microservice/language/python/package-manager/pip" .

echo "Building Microservice Python Deploy Docker Compose Template..."
tar -czf "$BUILD_DIR/microservice-python-deploy-docker-compose.tar.gz" -C "$ROOT_DIR/microservice/language/python/deploy/docker-compose" .

echo "Building Microservice Python Deploy Kubernetes Template..."
tar -czf "$BUILD_DIR/microservice-python-deploy-kubernetes.tar.gz" -C "$ROOT_DIR/microservice/language/python/deploy/kubernetes" .

echo "Building Project Init Template..."
tar -czf "$BUILD_DIR/project-init.tar.gz" -C "$ROOT_DIR/project/init" .

echo "Building Project API Gateway Minos Init Template..."
tar -czf "$BUILD_DIR/project-apigateway-minos-init.tar.gz" -C "$ROOT_DIR/project/apigateway/minos/init" .

echo "Building Project API Gateway Minos Deploy Docker Compose Template..."
tar -czf "$BUILD_DIR/project-apigateway-minos-deploy-docker-compose.tar.gz" -C "$ROOT_DIR/project/apigateway/minos/deploy/docker-compose" .

echo "Building Project API Gateway Minos Deploy Kubernetes Template..."
tar -czf "$BUILD_DIR/project-apigateway-minos-deploy-kubernetes.tar.gz" -C "$ROOT_DIR/project/apigateway/minos/deploy/kubernetes" .

echo "Building Project API Gateway Minos Deploy Remote Template..."
tar -czf "$BUILD_DIR/project-apigateway-minos-deploy-remote.tar.gz" -C "$ROOT_DIR/project/apigateway/minos/deploy/remote" .

echo "Building Project Broker Kafka Init Template..."
tar -czf "$BUILD_DIR/project-broker-kafka-init.tar.gz" -C "$ROOT_DIR/project/broker/kafka/init" .

echo "Building Project Broker Kafka Deploy Docker Compose Template..."
tar -czf "$BUILD_DIR/project-broker-kafka-deploy-docker-compose.tar.gz" -C "$ROOT_DIR/project/broker/kafka/deploy/docker-compose" .

echo "Building Project Broker Kafka Deploy Kubernetes Template..."
tar -czf "$BUILD_DIR/project-broker-kafka-deploy-kubernetes.tar.gz" -C "$ROOT_DIR/project/broker/kafka/deploy/kubernetes" .

echo "Building Project Broker Kafka Deploy Remote Template..."
tar -czf "$BUILD_DIR/project-broker-kafka-deploy-remote.tar.gz" -C "$ROOT_DIR/project/broker/kafka/deploy/remote" .

echo "Building Project Database Postgres Init Template..."
tar -czf "$BUILD_DIR/project-database-postgres-init.tar.gz" -C "$ROOT_DIR/project/database/postgres/init" .

echo "Building Project Database Postgres Deploy Docker Compose Template..."
tar -czf "$BUILD_DIR/project-database-postgres-deploy-docker-compose.tar.gz" -C "$ROOT_DIR/project/database/postgres/deploy/docker-compose" .

echo "Building Project Database Postgres Deploy Kubernetes Template..."
tar -czf "$BUILD_DIR/project-database-postgres-deploy-kubernetes.tar.gz" -C "$ROOT_DIR/project/database/postgres/deploy/kubernetes" .

echo "Building Project Database Postgres Deploy Remote Template..."
tar -czf "$BUILD_DIR/project-database-postgres-deploy-remote.tar.gz" -C "$ROOT_DIR/project/database/postgres/deploy/remote" .

echo "Building Project Database Redis Init Template..."
tar -czf "$BUILD_DIR/project-database-redis-init.tar.gz" -C "$ROOT_DIR/project/database/redis/init" .

echo "Building Project Database Redis Deploy Docker Compose Template..."
tar -czf "$BUILD_DIR/project-database-redis-deploy-docker-compose.tar.gz" -C "$ROOT_DIR/project/database/redis/deploy/docker-compose" .

echo "Building Project Database Redis Deploy Kubernetes Template..."
tar -czf "$BUILD_DIR/project-database-redis-deploy-kubernetes.tar.gz" -C "$ROOT_DIR/project/database/redis/deploy/kubernetes" .

echo "Building Project Database Redis Deploy Remote Template..."
tar -czf "$BUILD_DIR/project-database-redis-deploy-remote.tar.gz" -C "$ROOT_DIR/project/database/redis/deploy/remote" .

echo "Building Project Deploy Docker Compose Template..."
tar -czf "$BUILD_DIR/project-deploy-docker-compose.tar.gz" -C "$ROOT_DIR/project/deploy/docker-compose" .

echo "Building Project Discovery Minos Init Template..."
tar -czf "$BUILD_DIR/project-discovery-minos-init.tar.gz" -C "$ROOT_DIR/project/discovery/minos/init" .

echo "Building Project Discovery Minos Deploy Docker Compose Template..."
tar -czf "$BUILD_DIR/project-discovery-minos-deploy-docker-compose.tar.gz" -C "$ROOT_DIR/project/discovery/minos/deploy/docker-compose" .

echo "Building Project Discovery Minos Deploy Kubernetes Template..."
tar -czf "$BUILD_DIR/project-discovery-minos-deploy-kubernetes.tar.gz" -C "$ROOT_DIR/project/discovery/minos/deploy/kubernetes" .

echo "Building Project Discovery Minos Deploy Remote Template..."
tar -czf "$BUILD_DIR/project-discovery-minos-deploy-remote.tar.gz" -C "$ROOT_DIR/project/discovery/minos/deploy/remote" .

echo "Building Project Deploy Docker Compose Template..."
tar -czf "$BUILD_DIR/project-deploy-docker-compose.tar.gz" -C "$ROOT_DIR/project/deploy/docker-compose" .

echo "Building Project Deploy Kubernetes Template..."
tar -czf "$BUILD_DIR/project-deploy-kubernetes.tar.gz" -C "$ROOT_DIR/project/deploy/kubernetes" .
84 changes: 0 additions & 84 deletions microservice/copier.yml

This file was deleted.

4 changes: 4 additions & 0 deletions microservice/init/README.md.jinja
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# {{ name }} Microservice

## Description
{{ description }}
21 changes: 21 additions & 0 deletions microservice/init/copier.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
name:
type: str
help: What is the name of the microservice?
language:
type: str
link: true
help: What programming language do you want to use?
choices:
python: &python_url "{{ template_registry }}/microservice-python-init.tar.gz"
default: *python_url

_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
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
.venv
*.lmdb
dist/
dist/
10 changes: 10 additions & 0 deletions microservice/language/python/deploy/docker-compose/copier.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
_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
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM ghcr.io/clariteia/minos-microservice:0.1.5 as development
FROM ghcr.io/clariteia/minos-microservice:0.1.8 as development

COPY ./pyproject.toml ./poetry.lock ./
RUN poetry install --no-root
Expand All @@ -12,6 +12,6 @@ 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
COPY config.yml ./config.yml
ENTRYPOINT ["microservice"]
CMD ["start"]
3 changes: 3 additions & 0 deletions microservice/language/python/deploy/kubernetes/.dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.venv
*.lmdb
dist/
22 changes: 22 additions & 0 deletions microservice/language/python/deploy/kubernetes/Makefile.jinja
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
.PHONY: deploy

{% include (destination / "Makefile").as_posix() %}

deploy:
$(MAKE) deploy-image
$(MAKE) deploy-config

deploy-image:
docker build --pull -t microservice-{{ name }} -f deploy/Dockerfile .
docker tag microservice-{{ name }}:latest {{ kubernetes_registry }}/microservice-{{ name }}:{{ version }}
docker push {{ kubernetes_registry }}/microservice-{{ name }}:{{ version }}

deploy-config:
kubectl apply -f deploy/deployment.yaml
kubectl apply -f deploy/service.yaml

restart:
kubectl rollout restart --namespace={{ project_name }} deployment/microservice-{{ name }} > /dev/null

logs:
kubectl logs svc/microservice-{{ name }} --namespace={{ project_name }} --follow --tail 1000
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?
kubernetes_config:
type: str
default: microservice-config
help: What is the kubernetes config?
kubernetes_registry:
type: str
default: "localhost:5000"
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

_tasks:
- make -s deploy
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.8 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: microservice-{{ name }}
namespace: {{ project_name }}
spec:
replicas: 1
selector:
matchLabels:
app.kubernetes.io/name: microservice-{{ name }}
template:
metadata:
labels:
app.kubernetes.io/name: microservice-{{ name }}
spec:
containers:
- name: microservice-{{ name }}
image: {{ kubernetes_registry }}/microservice-{{ name }}:{{ version }}
imagePullPolicy: Always
ports:
- containerPort: 8080
envFrom:
- configMapRef:
name: {{ kubernetes_config }}
Loading

0 comments on commit cdb46db

Please sign in to comment.