From 3f04917c98c7be3f73dde2d05a1149eed660cde5 Mon Sep 17 00:00:00 2001 From: Haitao Pan Date: Fri, 28 Mar 2025 19:37:41 +0800 Subject: [PATCH] merged: go-demo js-demo python python-demo rust-demo --- app/go-demo/.github/workflows/pipeline.yaml | 158 ----------------- app/go-demo/.gitmodules | 3 - app/python/FastAPI-APP/App.vue | 47 +++++ app/python/FastAPI-APP/Dockerfile | 6 + app/python/FastAPI-APP/Dockerfile.Vue3 | 15 ++ app/python/FastAPI-APP/app.py | 58 +++++++ app/python/FastAPI-APP/app/cache/redis.py | 5 + app/python/FastAPI-APP/app/db/mysql.py | 11 ++ app/python/FastAPI-APP/app/main.py | 6 + app/python/FastAPI-APP/app/messaging/kafka.py | 14 ++ app/python/FastAPI-APP/app/routes/main.py | 44 +++++ app/python/FastAPI-APP/deployment.yaml | 74 ++++++++ app/python/FastAPI-APP/redis-deployment.yaml | 31 ++++ app/python/FastAPI-APP/run.sh | 4 + app/python/FastAPI-APP/vu3-deployment.yaml | 32 ++++ app/python/FastAPI-MicroService/App.vue | 47 +++++ app/python/FastAPI-MicroService/Dockerfile | 6 + .../FastAPI-MicroService/Dockerfile.Vue3 | 15 ++ app/python/FastAPI-MicroService/app.py | 58 +++++++ .../FastAPI-MicroService/app/cache/redis.py | 5 + .../FastAPI-MicroService/app/db/mysql.py | 11 ++ app/python/FastAPI-MicroService/app/main.py | 11 ++ .../app/messaging/kafka.py | 14 ++ .../FastAPI-MicroService/app/routes/main.py | 31 ++++ .../FastAPI-MicroService/deployment.yaml | 74 ++++++++ .../redis-deployment.yaml | 31 ++++ app/python/FastAPI-MicroService/run.sh | 4 + .../FastAPI-MicroService/vu3-deployment.yaml | 32 ++++ app/python/LNMP-With-Cache/App.vue | 27 +++ app/python/LNMP-With-Cache/Dockerfile | 6 + app/python/LNMP-With-Cache/Dockerfile.Vue3 | 15 ++ app/python/LNMP-With-Cache/app.py | 20 +++ app/python/LNMP-With-Cache/deployment.yaml | 74 ++++++++ .../LNMP-With-Cache/redis-deployment.yaml | 31 ++++ app/python/LNMP-With-Cache/run.sh | 4 + .../LNMP-With-Cache/vu3-deployment.yaml | 32 ++++ app/python/LNMP-With-Kafaka/App.vue | 47 +++++ app/python/LNMP-With-Kafaka/Dockerfile | 6 + app/python/LNMP-With-Kafaka/Dockerfile.Vue3 | 15 ++ app/python/LNMP-With-Kafaka/app.py | 42 +++++ app/python/LNMP-With-Kafaka/deployment.yaml | 74 ++++++++ .../LNMP-With-Kafaka/redis-deployment.yaml | 31 ++++ app/python/LNMP-With-Kafaka/run.sh | 4 + .../LNMP-With-Kafaka/vu3-deployment.yaml | 32 ++++ app/python/LNMP/App.vue | 27 +++ app/python/LNMP/Dockerfile | 6 + app/python/LNMP/Dockerfile.Vue3 | 15 ++ app/python/LNMP/app.py | 20 +++ app/python/LNMP/deployment.yaml | 74 ++++++++ app/python/LNMP/run.sh | 4 + app/python/LNMP/vu3-deployment.yaml | 32 ++++ app/rust-demo/.github/workflows/pipeline.yaml | 159 ----------------- app/rust-demo/.gitignore | 160 ------------------ app/rust-demo/.gitmodules | 3 - 54 files changed, 1324 insertions(+), 483 deletions(-) delete mode 100644 app/go-demo/.github/workflows/pipeline.yaml delete mode 100644 app/go-demo/.gitmodules create mode 100644 app/python/FastAPI-APP/App.vue create mode 100644 app/python/FastAPI-APP/Dockerfile create mode 100644 app/python/FastAPI-APP/Dockerfile.Vue3 create mode 100644 app/python/FastAPI-APP/app.py create mode 100644 app/python/FastAPI-APP/app/cache/redis.py create mode 100644 app/python/FastAPI-APP/app/db/mysql.py create mode 100644 app/python/FastAPI-APP/app/main.py create mode 100644 app/python/FastAPI-APP/app/messaging/kafka.py create mode 100644 app/python/FastAPI-APP/app/routes/main.py create mode 100644 app/python/FastAPI-APP/deployment.yaml create mode 100644 app/python/FastAPI-APP/redis-deployment.yaml create mode 100644 app/python/FastAPI-APP/run.sh create mode 100644 app/python/FastAPI-APP/vu3-deployment.yaml create mode 100644 app/python/FastAPI-MicroService/App.vue create mode 100644 app/python/FastAPI-MicroService/Dockerfile create mode 100644 app/python/FastAPI-MicroService/Dockerfile.Vue3 create mode 100644 app/python/FastAPI-MicroService/app.py create mode 100644 app/python/FastAPI-MicroService/app/cache/redis.py create mode 100644 app/python/FastAPI-MicroService/app/db/mysql.py create mode 100644 app/python/FastAPI-MicroService/app/main.py create mode 100644 app/python/FastAPI-MicroService/app/messaging/kafka.py create mode 100644 app/python/FastAPI-MicroService/app/routes/main.py create mode 100644 app/python/FastAPI-MicroService/deployment.yaml create mode 100644 app/python/FastAPI-MicroService/redis-deployment.yaml create mode 100644 app/python/FastAPI-MicroService/run.sh create mode 100644 app/python/FastAPI-MicroService/vu3-deployment.yaml create mode 100644 app/python/LNMP-With-Cache/App.vue create mode 100644 app/python/LNMP-With-Cache/Dockerfile create mode 100644 app/python/LNMP-With-Cache/Dockerfile.Vue3 create mode 100644 app/python/LNMP-With-Cache/app.py create mode 100644 app/python/LNMP-With-Cache/deployment.yaml create mode 100644 app/python/LNMP-With-Cache/redis-deployment.yaml create mode 100644 app/python/LNMP-With-Cache/run.sh create mode 100644 app/python/LNMP-With-Cache/vu3-deployment.yaml create mode 100644 app/python/LNMP-With-Kafaka/App.vue create mode 100644 app/python/LNMP-With-Kafaka/Dockerfile create mode 100644 app/python/LNMP-With-Kafaka/Dockerfile.Vue3 create mode 100644 app/python/LNMP-With-Kafaka/app.py create mode 100644 app/python/LNMP-With-Kafaka/deployment.yaml create mode 100644 app/python/LNMP-With-Kafaka/redis-deployment.yaml create mode 100644 app/python/LNMP-With-Kafaka/run.sh create mode 100644 app/python/LNMP-With-Kafaka/vu3-deployment.yaml create mode 100644 app/python/LNMP/App.vue create mode 100644 app/python/LNMP/Dockerfile create mode 100644 app/python/LNMP/Dockerfile.Vue3 create mode 100644 app/python/LNMP/app.py create mode 100644 app/python/LNMP/deployment.yaml create mode 100644 app/python/LNMP/run.sh create mode 100644 app/python/LNMP/vu3-deployment.yaml delete mode 100644 app/rust-demo/.github/workflows/pipeline.yaml delete mode 100644 app/rust-demo/.gitignore delete mode 100644 app/rust-demo/.gitmodules diff --git a/app/go-demo/.github/workflows/pipeline.yaml b/app/go-demo/.github/workflows/pipeline.yaml deleted file mode 100644 index e057067e..00000000 --- a/app/go-demo/.github/workflows/pipeline.yaml +++ /dev/null @@ -1,158 +0,0 @@ -name: Build Test And Deploy - -on: - pull_request: - push: - paths: - - 'Dockerfile' - - '.github/workflows/pipieline.yaml' - workflow_dispatch: - branches: - - main - -env: - TZ: Asia/Shanghai - REPO: "artifact.onwalk.net" - IMAGE: base/${{ github.repository }} - TAG: ${{ github.sha }} - -jobs: - build: - runs-on: ubuntu-latest - - steps: - - uses: actions/checkout@v2 - - - name: Install dependencies - run: | - sudo apt-get update - sudo apt install -y golang-1.18 - - - name: Build - run: | - go mod tidy && go build && tar -czvpf example_pkg-0.1.0.tar.gz example_pkg - - - name: Upload binaries to release - uses: svenstaro/upload-release-action@v2 - with: - asset_name: example_pkg-0.1.0.tar.gz - file: example_pkg-0.1.0.tar.gz - tag: ${{ github.ref }} - overwrite: true - body: "Release v0.1.0" - - test: - runs-on: ubuntu-latest - - steps: - - uses: actions/checkout@v2 - - - name: Install dependencies - run: | - sudo apt-get update - sudo apt install -y golang-1.18 - - - name: Run tests - run: | - go mod tidy && go test -v - docker-image: - runs-on: ubuntu-latest - name: Build image - needs: - - build - - test - steps: - - uses: actions/checkout@master - - - name: 'Artifact: build && push image' - uses: aevea/action-kaniko@master - with: - registry: ${{ secrets.HELM_REPO_REGISTRY }} - username: ${{ secrets.HELM_REPO_USER }} - password: ${{ secrets.HELM_REPO_PASSWORD }} - path: './' - build_file: 'Dockerfile' - image: ${{ env.IMAGE }} - tag: ${{ env.TAG }} - cache: true - cache_registry: cache - - setup-k3s: - runs-on: ubuntu-latest - needs: - - docker-image - - steps: - - uses: actions/checkout@v3 - - - name: update submodule - run: | - sudo apt-get update && sudo apt-get install -y git && git submodule update --init --recursive - - - name: Setup K3S Cluster - working-directory: ./scripts - shell: bash - run: | - export ANSIBLE_HOST_KEY_CHECKING=False - sudo apt install jq ansible -y - - mkdir -pv ~/.ssh/ - cat > ~/.ssh/id_rsa << EOF - ${{ secrets.SSH_PRIVATE_KEY }} - EOF - sudo chmod 0400 ~/.ssh/id_rsa - md5sum ~/.ssh/id_rsa - - mkdir -pv hosts/ - cat > hosts/inventory << EOF - [master] - ${{ secrets.HOST_DOMAIN }} ansible_host=${{ secrets.HOST_IP }} - - [all:vars] - ansible_port=22 - ansible_ssh_user=${{ secrets.HOST_USER }} - ansible_ssh_private_key_file=~/.ssh/id_rsa - ansible_host_key_checking=False - ingress_ip=${{ secrets.HOST_IP }} - EOF - cat hosts/inventory - ansible-playbook -i hosts/inventory init_k3s_cluster -D - deploy-app: - runs-on: ubuntu-latest - needs: [setup-k3s] - - steps: - - uses: actions/checkout@v3 - - - name: update submodule - run: | - sudo apt-get update && sudo apt-get install -y git && git submodule update --init --recursive - - - name: Deploy - working-directory: ./scripts - shell: bash - run: | - export ANSIBLE_HOST_KEY_CHECKING=False - sudo apt install jq ansible -y - - mkdir -pv ~/.ssh/ - cat > ~/.ssh/id_rsa << EOF - ${{ secrets.SSH_PRIVATE_KEY }} - EOF - sudo chmod 0400 ~/.ssh/id_rsa - md5sum ~/.ssh/id_rsa - - mkdir -pv hosts/ - cat > hosts/inventory << EOF - [master] - ${{ secrets.HOST_DOMAIN }} ansible_host=${{ secrets.HOST_IP }} - - [all:vars] - ansible_port=22 - ansible_ssh_user=${{ secrets.HOST_USER }} - ansible_ssh_private_key_file=~/.ssh/id_rsa - ansible_host_key_checking=False - app_image=${{ env.REPO }}/${{ env.IMAGE }} - app_tag=${{ env.TAG }} - EOF - ansible-playbook -i hosts/inventory deploy_app -D diff --git a/app/go-demo/.gitmodules b/app/go-demo/.gitmodules deleted file mode 100644 index 70d8c5a8..00000000 --- a/app/go-demo/.gitmodules +++ /dev/null @@ -1,3 +0,0 @@ -[submodule "scripts"] - path = scripts - url = https://github.com/SvcDesignScaffolding/AnsibleScripts.git diff --git a/app/python/FastAPI-APP/App.vue b/app/python/FastAPI-APP/App.vue new file mode 100644 index 00000000..63a2779a --- /dev/null +++ b/app/python/FastAPI-APP/App.vue @@ -0,0 +1,47 @@ + + + diff --git a/app/python/FastAPI-APP/Dockerfile b/app/python/FastAPI-APP/Dockerfile new file mode 100644 index 00000000..48b1ce86 --- /dev/null +++ b/app/python/FastAPI-APP/Dockerfile @@ -0,0 +1,6 @@ +FROM python:3.7-alpine +WORKDIR /app +COPY . /app +RUN pip install fastapi uvicorn mysql-connector-python redis confluent-kafka +EXPOSE 80 +CMD ["uvicorn", "app:app", "--host", "0.0.0.0", "--port", "80"] diff --git a/app/python/FastAPI-APP/Dockerfile.Vue3 b/app/python/FastAPI-APP/Dockerfile.Vue3 new file mode 100644 index 00000000..641b5f2e --- /dev/null +++ b/app/python/FastAPI-APP/Dockerfile.Vue3 @@ -0,0 +1,15 @@ +# build stage +FROM node:lts-alpine as build-stage +WORKDIR /app +COPY package*.json ./ +RUN npm install +RUN npm install axios +COPY . . +RUN npm run build + +# production stage +FROM nginx:stable-alpine as production-stage +COPY --from=build-stage /app/dist /usr/share/nginx/html +EXPOSE 80 +CMD ["nginx", "-g", "daemon off;"] + diff --git a/app/python/FastAPI-APP/app.py b/app/python/FastAPI-APP/app.py new file mode 100644 index 00000000..4666db13 --- /dev/null +++ b/app/python/FastAPI-APP/app.py @@ -0,0 +1,58 @@ +from fastapi import FastAPI +from starlette.requests import Request +import mysql.connector +import redis +import json +from confluent_kafka import Producer, Consumer, KafkaError + +app = FastAPI() +cache = redis.Redis(host='redis-service', port=6379) + +# Kafka producer configuration +p = Producer({'bootstrap.servers': 'my-kafka-service:9092'}) + +# Kafka consumer configuration +c = Consumer({ + 'bootstrap.servers': 'my-kafka-service:9092', + 'group.id': 'mygroup', + 'auto.offset.reset': 'earliest' +}) +c.subscribe(['mytopic']) + +@app.get('/') +async def read_root(): + data = cache.get('mydata') + if data is not None: + return data + + db = mysql.connector.connect( + host="mysql-service", + user="username", + password="password", + database="mydb" + ) + cursor = db.cursor() + cursor.execute("SELECT * FROM your_table") + results = cursor.fetchall() + data = json.dumps(results) + + cache.set('mydata', data) + return data + +@app.post('/produce') +async def produce(request: Request): + data = await request.json() + p.produce('mytopic', json.dumps(data)) + return {'message': 'Message produced'} + +@app.get('/consume') +async def consume(): + msg = c.poll(1.0) + + if msg is None: + return {'message': 'No message'} + if msg.error(): + return {'error': str(msg.error())} + + data = json.loads(msg.value().decode('utf-8')) + return data diff --git a/app/python/FastAPI-APP/app/cache/redis.py b/app/python/FastAPI-APP/app/cache/redis.py new file mode 100644 index 00000000..79959cec --- /dev/null +++ b/app/python/FastAPI-APP/app/cache/redis.py @@ -0,0 +1,5 @@ +import redis + +def get_cache_connection(): + cache = redis.Redis(host='redis-service', port=6379) + return cache diff --git a/app/python/FastAPI-APP/app/db/mysql.py b/app/python/FastAPI-APP/app/db/mysql.py new file mode 100644 index 00000000..7779e3cd --- /dev/null +++ b/app/python/FastAPI-APP/app/db/mysql.py @@ -0,0 +1,11 @@ +import mysql.connector + +def get_db_connection(): + db = mysql.connector.connect( + host="mysql-service", + user="username", + password="password", + database="mydb" + ) + return db + diff --git a/app/python/FastAPI-APP/app/main.py b/app/python/FastAPI-APP/app/main.py new file mode 100644 index 00000000..1bda2f20 --- /dev/null +++ b/app/python/FastAPI-APP/app/main.py @@ -0,0 +1,6 @@ +from fastapi import FastAPI +from routes.main import router as main_router + +app = FastAPI() + +app.include_router(main_router) diff --git a/app/python/FastAPI-APP/app/messaging/kafka.py b/app/python/FastAPI-APP/app/messaging/kafka.py new file mode 100644 index 00000000..33b1e0f5 --- /dev/null +++ b/app/python/FastAPI-APP/app/messaging/kafka.py @@ -0,0 +1,14 @@ +from confluent_kafka import Producer, Consumer + +def get_kafka_producer(): + p = Producer({'bootstrap.servers': 'my-kafka-service:9092'}) + return p + +def get_kafka_consumer(): + c = Consumer({ + 'bootstrap.servers': 'my-kafka-service:9092', + 'group.id': 'mygroup', + 'auto.offset.reset': 'earliest' + }) + c.subscribe(['mytopic']) + return c diff --git a/app/python/FastAPI-APP/app/routes/main.py b/app/python/FastAPI-APP/app/routes/main.py new file mode 100644 index 00000000..ad73a3dd --- /dev/null +++ b/app/python/FastAPI-APP/app/routes/main.py @@ -0,0 +1,44 @@ +from fastapi import APIRouter, Request +from db.mysql import get_db_connection +from cache.redis import get_cache_connection +from messaging.kafka import get_kafka_producer, get_kafka_consumer +import json + +router = APIRouter() + +@router.get('/') +async def read_root(): + cache = get_cache_connection() + data = cache.get('mydata') + if data is not None: + return data + + db = get_db_connection() + cursor = db.cursor() + cursor.execute("SELECT * FROM your_table") + results = cursor.fetchall() + data = json.dumps(results) + + cache.set('mydata', data) + return data + +@router.post('/produce') +async def produce(request: Request): + data = await request.json() + p = get_kafka_producer() + p.produce('mytopic', json.dumps(data)) + return {'message': 'Message produced'} + +@router.get('/consume') +async def consume(): + c = get_kafka_consumer() + msg = c.poll(1.0) + + if msg is None: + return 'No message', 200 + if msg.error(): + return 'Error: {}'.format(msg.error()), 500 + + data = json.loads(msg.value().decode('utf-8')) + return json.dumps(data), 200 + diff --git a/app/python/FastAPI-APP/deployment.yaml b/app/python/FastAPI-APP/deployment.yaml new file mode 100644 index 00000000..c3795aa1 --- /dev/null +++ b/app/python/FastAPI-APP/deployment.yaml @@ -0,0 +1,74 @@ +apiVersion: apps/v1 +kind: Deployment +metadata: + name: mysql-deployment +spec: + replicas: 1 + selector: + matchLabels: + app: mysql + template: + metadata: + labels: + app: mysql + spec: + containers: + - name: mysql + image: mysql:5.7 + env: + - name: MYSQL_ROOT_PASSWORD + value: "password" + - name: MYSQL_DATABASE + value: "mydb" + - name: MYSQL_USER + value: "username" + - name: MYSQL_PASSWORD + value: "password" + ports: + - containerPort: 3306 +--- +apiVersion: v1 +kind: Service +metadata: + name: mysql-service +spec: + selector: + app: mysql + ports: + - protocol: TCP + port: 3306 + targetPort: 3306 +--- +apiVersion: apps/v1 +kind: Deployment +metadata: + name: app-deployment +spec: + replicas: 3 + selector: + matchLabels: + app: my-app + template: + metadata: + labels: + app: my-app + spec: + containers: + - name: my-app + image: your-repo/your-tag # replace with your Docker image name and tag + ports: + - containerPort: 80 +--- +apiVersion: v1 +kind: Service +metadata: + name: app-service +spec: + selector: + app: my-app + ports: + - protocol: TCP + port: 80 + targetPort: 80 + type: LoadBalancer + diff --git a/app/python/FastAPI-APP/redis-deployment.yaml b/app/python/FastAPI-APP/redis-deployment.yaml new file mode 100644 index 00000000..cb3f1de8 --- /dev/null +++ b/app/python/FastAPI-APP/redis-deployment.yaml @@ -0,0 +1,31 @@ +apiVersion: apps/v1 +kind: Deployment +metadata: + name: redis-deployment +spec: + replicas: 1 + selector: + matchLabels: + app: redis + template: + metadata: + labels: + app: redis + spec: + containers: + - name: redis + image: redis:latest + ports: + - containerPort: 6379 +--- +apiVersion: v1 +kind: Service +metadata: + name: redis-service +spec: + selector: + app: redis + ports: + - protocol: TCP + port: 6379 + targetPort: 6379 diff --git a/app/python/FastAPI-APP/run.sh b/app/python/FastAPI-APP/run.sh new file mode 100644 index 00000000..592912b0 --- /dev/null +++ b/app/python/FastAPI-APP/run.sh @@ -0,0 +1,4 @@ +kubectl apply -f mysql-deployment.yaml +kubectl apply -f mysql-service.yaml +kubectl apply -f app-deployment.yaml +kubectl apply -f app-service.yaml diff --git a/app/python/FastAPI-APP/vu3-deployment.yaml b/app/python/FastAPI-APP/vu3-deployment.yaml new file mode 100644 index 00000000..39faf4a4 --- /dev/null +++ b/app/python/FastAPI-APP/vu3-deployment.yaml @@ -0,0 +1,32 @@ +apiVersion: apps/v1 +kind: Deployment +metadata: + name: vue-deployment +spec: + replicas: 3 + selector: + matchLabels: + app: vue-app + template: + metadata: + labels: + app: vue-app + spec: + containers: + - name: vue-app + image: your-repo/your-tag # replace with your Docker image name and tag + ports: + - containerPort: 80 +--- +apiVersion: v1 +kind: Service +metadata: + name: vue-service +spec: + selector: + app: vue-app + ports: + - protocol: TCP + port: 80 + targetPort: 80 + type: LoadBalancer diff --git a/app/python/FastAPI-MicroService/App.vue b/app/python/FastAPI-MicroService/App.vue new file mode 100644 index 00000000..63a2779a --- /dev/null +++ b/app/python/FastAPI-MicroService/App.vue @@ -0,0 +1,47 @@ + + + diff --git a/app/python/FastAPI-MicroService/Dockerfile b/app/python/FastAPI-MicroService/Dockerfile new file mode 100644 index 00000000..85a8d952 --- /dev/null +++ b/app/python/FastAPI-MicroService/Dockerfile @@ -0,0 +1,6 @@ +FROM python:3.7-alpine +WORKDIR /app +COPY . /app +RUN pip install fastapi uvicorn mysql-connector-python redis confluent-kafka pip install bali-core grpclib +EXPOSE 80 +CMD ["uvicorn", "app:app", "--host", "0.0.0.0", "--port", "80"] diff --git a/app/python/FastAPI-MicroService/Dockerfile.Vue3 b/app/python/FastAPI-MicroService/Dockerfile.Vue3 new file mode 100644 index 00000000..641b5f2e --- /dev/null +++ b/app/python/FastAPI-MicroService/Dockerfile.Vue3 @@ -0,0 +1,15 @@ +# build stage +FROM node:lts-alpine as build-stage +WORKDIR /app +COPY package*.json ./ +RUN npm install +RUN npm install axios +COPY . . +RUN npm run build + +# production stage +FROM nginx:stable-alpine as production-stage +COPY --from=build-stage /app/dist /usr/share/nginx/html +EXPOSE 80 +CMD ["nginx", "-g", "daemon off;"] + diff --git a/app/python/FastAPI-MicroService/app.py b/app/python/FastAPI-MicroService/app.py new file mode 100644 index 00000000..4666db13 --- /dev/null +++ b/app/python/FastAPI-MicroService/app.py @@ -0,0 +1,58 @@ +from fastapi import FastAPI +from starlette.requests import Request +import mysql.connector +import redis +import json +from confluent_kafka import Producer, Consumer, KafkaError + +app = FastAPI() +cache = redis.Redis(host='redis-service', port=6379) + +# Kafka producer configuration +p = Producer({'bootstrap.servers': 'my-kafka-service:9092'}) + +# Kafka consumer configuration +c = Consumer({ + 'bootstrap.servers': 'my-kafka-service:9092', + 'group.id': 'mygroup', + 'auto.offset.reset': 'earliest' +}) +c.subscribe(['mytopic']) + +@app.get('/') +async def read_root(): + data = cache.get('mydata') + if data is not None: + return data + + db = mysql.connector.connect( + host="mysql-service", + user="username", + password="password", + database="mydb" + ) + cursor = db.cursor() + cursor.execute("SELECT * FROM your_table") + results = cursor.fetchall() + data = json.dumps(results) + + cache.set('mydata', data) + return data + +@app.post('/produce') +async def produce(request: Request): + data = await request.json() + p.produce('mytopic', json.dumps(data)) + return {'message': 'Message produced'} + +@app.get('/consume') +async def consume(): + msg = c.poll(1.0) + + if msg is None: + return {'message': 'No message'} + if msg.error(): + return {'error': str(msg.error())} + + data = json.loads(msg.value().decode('utf-8')) + return data diff --git a/app/python/FastAPI-MicroService/app/cache/redis.py b/app/python/FastAPI-MicroService/app/cache/redis.py new file mode 100644 index 00000000..79959cec --- /dev/null +++ b/app/python/FastAPI-MicroService/app/cache/redis.py @@ -0,0 +1,5 @@ +import redis + +def get_cache_connection(): + cache = redis.Redis(host='redis-service', port=6379) + return cache diff --git a/app/python/FastAPI-MicroService/app/db/mysql.py b/app/python/FastAPI-MicroService/app/db/mysql.py new file mode 100644 index 00000000..7779e3cd --- /dev/null +++ b/app/python/FastAPI-MicroService/app/db/mysql.py @@ -0,0 +1,11 @@ +import mysql.connector + +def get_db_connection(): + db = mysql.connector.connect( + host="mysql-service", + user="username", + password="password", + database="mydb" + ) + return db + diff --git a/app/python/FastAPI-MicroService/app/main.py b/app/python/FastAPI-MicroService/app/main.py new file mode 100644 index 00000000..29b1379f --- /dev/null +++ b/app/python/FastAPI-MicroService/app/main.py @@ -0,0 +1,11 @@ +from grpclib.server import Server +from routes.main import AppService + +async def main(): + server = Server([AppService()]) + await server.start('127.0.0.1', 50051) + print('Serving on localhost:50051') + +if __name__ == '__main__': + import asyncio + asyncio.run(main()) diff --git a/app/python/FastAPI-MicroService/app/messaging/kafka.py b/app/python/FastAPI-MicroService/app/messaging/kafka.py new file mode 100644 index 00000000..33b1e0f5 --- /dev/null +++ b/app/python/FastAPI-MicroService/app/messaging/kafka.py @@ -0,0 +1,14 @@ +from confluent_kafka import Producer, Consumer + +def get_kafka_producer(): + p = Producer({'bootstrap.servers': 'my-kafka-service:9092'}) + return p + +def get_kafka_consumer(): + c = Consumer({ + 'bootstrap.servers': 'my-kafka-service:9092', + 'group.id': 'mygroup', + 'auto.offset.reset': 'earliest' + }) + c.subscribe(['mytopic']) + return c diff --git a/app/python/FastAPI-MicroService/app/routes/main.py b/app/python/FastAPI-MicroService/app/routes/main.py new file mode 100644 index 00000000..fea875f2 --- /dev/null +++ b/app/python/FastAPI-MicroService/app/routes/main.py @@ -0,0 +1,31 @@ +from bali.core import Service +from db.mysql import get_db_connection +from cache.redis import get_cache_connection +from messaging.kafka import get_kafka_producer, get_kafka_consumer +from app_pb2 import ProduceRequest, ProduceResponse, ConsumeRequest, ConsumeResponse +from app_grpc import AppBase + +class AppService(AppBase, Service): + def __init__(self): + super().__init__() + self.producer = get_kafka_producer() + self.consumer = get_kafka_consumer() + self.cache = get_cache_connection() + self.db = get_db_connection() + + async def Produce(self, stream): + request = await stream.recv_message() + data = request.data + self.producer.produce('mytopic', data) + await stream.send_message(ProduceResponse(message='Message produced')) + + async def Consume(self, stream): + await stream.recv_message() + msg = self.consumer.poll(1.0) + if msg is None: + data = 'No message' + elif msg.error(): + data = 'Error: {}'.format(msg.error()) + else: + data = msg.value().decode('utf-8') + await stream.send_message(ConsumeResponse(data=data)) diff --git a/app/python/FastAPI-MicroService/deployment.yaml b/app/python/FastAPI-MicroService/deployment.yaml new file mode 100644 index 00000000..c3795aa1 --- /dev/null +++ b/app/python/FastAPI-MicroService/deployment.yaml @@ -0,0 +1,74 @@ +apiVersion: apps/v1 +kind: Deployment +metadata: + name: mysql-deployment +spec: + replicas: 1 + selector: + matchLabels: + app: mysql + template: + metadata: + labels: + app: mysql + spec: + containers: + - name: mysql + image: mysql:5.7 + env: + - name: MYSQL_ROOT_PASSWORD + value: "password" + - name: MYSQL_DATABASE + value: "mydb" + - name: MYSQL_USER + value: "username" + - name: MYSQL_PASSWORD + value: "password" + ports: + - containerPort: 3306 +--- +apiVersion: v1 +kind: Service +metadata: + name: mysql-service +spec: + selector: + app: mysql + ports: + - protocol: TCP + port: 3306 + targetPort: 3306 +--- +apiVersion: apps/v1 +kind: Deployment +metadata: + name: app-deployment +spec: + replicas: 3 + selector: + matchLabels: + app: my-app + template: + metadata: + labels: + app: my-app + spec: + containers: + - name: my-app + image: your-repo/your-tag # replace with your Docker image name and tag + ports: + - containerPort: 80 +--- +apiVersion: v1 +kind: Service +metadata: + name: app-service +spec: + selector: + app: my-app + ports: + - protocol: TCP + port: 80 + targetPort: 80 + type: LoadBalancer + diff --git a/app/python/FastAPI-MicroService/redis-deployment.yaml b/app/python/FastAPI-MicroService/redis-deployment.yaml new file mode 100644 index 00000000..cb3f1de8 --- /dev/null +++ b/app/python/FastAPI-MicroService/redis-deployment.yaml @@ -0,0 +1,31 @@ +apiVersion: apps/v1 +kind: Deployment +metadata: + name: redis-deployment +spec: + replicas: 1 + selector: + matchLabels: + app: redis + template: + metadata: + labels: + app: redis + spec: + containers: + - name: redis + image: redis:latest + ports: + - containerPort: 6379 +--- +apiVersion: v1 +kind: Service +metadata: + name: redis-service +spec: + selector: + app: redis + ports: + - protocol: TCP + port: 6379 + targetPort: 6379 diff --git a/app/python/FastAPI-MicroService/run.sh b/app/python/FastAPI-MicroService/run.sh new file mode 100644 index 00000000..592912b0 --- /dev/null +++ b/app/python/FastAPI-MicroService/run.sh @@ -0,0 +1,4 @@ +kubectl apply -f mysql-deployment.yaml +kubectl apply -f mysql-service.yaml +kubectl apply -f app-deployment.yaml +kubectl apply -f app-service.yaml diff --git a/app/python/FastAPI-MicroService/vu3-deployment.yaml b/app/python/FastAPI-MicroService/vu3-deployment.yaml new file mode 100644 index 00000000..39faf4a4 --- /dev/null +++ b/app/python/FastAPI-MicroService/vu3-deployment.yaml @@ -0,0 +1,32 @@ +apiVersion: apps/v1 +kind: Deployment +metadata: + name: vue-deployment +spec: + replicas: 3 + selector: + matchLabels: + app: vue-app + template: + metadata: + labels: + app: vue-app + spec: + containers: + - name: vue-app + image: your-repo/your-tag # replace with your Docker image name and tag + ports: + - containerPort: 80 +--- +apiVersion: v1 +kind: Service +metadata: + name: vue-service +spec: + selector: + app: vue-app + ports: + - protocol: TCP + port: 80 + targetPort: 80 + type: LoadBalancer diff --git a/app/python/LNMP-With-Cache/App.vue b/app/python/LNMP-With-Cache/App.vue new file mode 100644 index 00000000..d689fa40 --- /dev/null +++ b/app/python/LNMP-With-Cache/App.vue @@ -0,0 +1,27 @@ + + + diff --git a/app/python/LNMP-With-Cache/Dockerfile b/app/python/LNMP-With-Cache/Dockerfile new file mode 100644 index 00000000..36914550 --- /dev/null +++ b/app/python/LNMP-With-Cache/Dockerfile @@ -0,0 +1,6 @@ +FROM python:3.7-alpine +WORKDIR /app +COPY . /app +RUN pip install flask mysql-connector-python redis +EXPOSE 80 +CMD ["python", "app.py"] diff --git a/app/python/LNMP-With-Cache/Dockerfile.Vue3 b/app/python/LNMP-With-Cache/Dockerfile.Vue3 new file mode 100644 index 00000000..641b5f2e --- /dev/null +++ b/app/python/LNMP-With-Cache/Dockerfile.Vue3 @@ -0,0 +1,15 @@ +# build stage +FROM node:lts-alpine as build-stage +WORKDIR /app +COPY package*.json ./ +RUN npm install +RUN npm install axios +COPY . . +RUN npm run build + +# production stage +FROM nginx:stable-alpine as production-stage +COPY --from=build-stage /app/dist /usr/share/nginx/html +EXPOSE 80 +CMD ["nginx", "-g", "daemon off;"] + diff --git a/app/python/LNMP-With-Cache/app.py b/app/python/LNMP-With-Cache/app.py new file mode 100644 index 00000000..d16e67ff --- /dev/null +++ b/app/python/LNMP-With-Cache/app.py @@ -0,0 +1,20 @@ +from flask import Flask +import mysql.connector + +app = Flask(__name__) + +@app.route('/') +def hello_world(): + db = mysql.connector.connect( + host="mysql-service", # Kubernetes service name for your MySQL service + user="username", + password="password", + database="mydb" + ) + cursor = db.cursor() + cursor.execute("SELECT * FROM your_table") # Replace 'your_table' with your table name + results = cursor.fetchall() + return str(results) # Convert results to string to return as HTTP response + +if __name__ == '__main__': + app.run(host='0.0.0.0', port=80) diff --git a/app/python/LNMP-With-Cache/deployment.yaml b/app/python/LNMP-With-Cache/deployment.yaml new file mode 100644 index 00000000..c3795aa1 --- /dev/null +++ b/app/python/LNMP-With-Cache/deployment.yaml @@ -0,0 +1,74 @@ +apiVersion: apps/v1 +kind: Deployment +metadata: + name: mysql-deployment +spec: + replicas: 1 + selector: + matchLabels: + app: mysql + template: + metadata: + labels: + app: mysql + spec: + containers: + - name: mysql + image: mysql:5.7 + env: + - name: MYSQL_ROOT_PASSWORD + value: "password" + - name: MYSQL_DATABASE + value: "mydb" + - name: MYSQL_USER + value: "username" + - name: MYSQL_PASSWORD + value: "password" + ports: + - containerPort: 3306 +--- +apiVersion: v1 +kind: Service +metadata: + name: mysql-service +spec: + selector: + app: mysql + ports: + - protocol: TCP + port: 3306 + targetPort: 3306 +--- +apiVersion: apps/v1 +kind: Deployment +metadata: + name: app-deployment +spec: + replicas: 3 + selector: + matchLabels: + app: my-app + template: + metadata: + labels: + app: my-app + spec: + containers: + - name: my-app + image: your-repo/your-tag # replace with your Docker image name and tag + ports: + - containerPort: 80 +--- +apiVersion: v1 +kind: Service +metadata: + name: app-service +spec: + selector: + app: my-app + ports: + - protocol: TCP + port: 80 + targetPort: 80 + type: LoadBalancer + diff --git a/app/python/LNMP-With-Cache/redis-deployment.yaml b/app/python/LNMP-With-Cache/redis-deployment.yaml new file mode 100644 index 00000000..cb3f1de8 --- /dev/null +++ b/app/python/LNMP-With-Cache/redis-deployment.yaml @@ -0,0 +1,31 @@ +apiVersion: apps/v1 +kind: Deployment +metadata: + name: redis-deployment +spec: + replicas: 1 + selector: + matchLabels: + app: redis + template: + metadata: + labels: + app: redis + spec: + containers: + - name: redis + image: redis:latest + ports: + - containerPort: 6379 +--- +apiVersion: v1 +kind: Service +metadata: + name: redis-service +spec: + selector: + app: redis + ports: + - protocol: TCP + port: 6379 + targetPort: 6379 diff --git a/app/python/LNMP-With-Cache/run.sh b/app/python/LNMP-With-Cache/run.sh new file mode 100644 index 00000000..592912b0 --- /dev/null +++ b/app/python/LNMP-With-Cache/run.sh @@ -0,0 +1,4 @@ +kubectl apply -f mysql-deployment.yaml +kubectl apply -f mysql-service.yaml +kubectl apply -f app-deployment.yaml +kubectl apply -f app-service.yaml diff --git a/app/python/LNMP-With-Cache/vu3-deployment.yaml b/app/python/LNMP-With-Cache/vu3-deployment.yaml new file mode 100644 index 00000000..39faf4a4 --- /dev/null +++ b/app/python/LNMP-With-Cache/vu3-deployment.yaml @@ -0,0 +1,32 @@ +apiVersion: apps/v1 +kind: Deployment +metadata: + name: vue-deployment +spec: + replicas: 3 + selector: + matchLabels: + app: vue-app + template: + metadata: + labels: + app: vue-app + spec: + containers: + - name: vue-app + image: your-repo/your-tag # replace with your Docker image name and tag + ports: + - containerPort: 80 +--- +apiVersion: v1 +kind: Service +metadata: + name: vue-service +spec: + selector: + app: vue-app + ports: + - protocol: TCP + port: 80 + targetPort: 80 + type: LoadBalancer diff --git a/app/python/LNMP-With-Kafaka/App.vue b/app/python/LNMP-With-Kafaka/App.vue new file mode 100644 index 00000000..63a2779a --- /dev/null +++ b/app/python/LNMP-With-Kafaka/App.vue @@ -0,0 +1,47 @@ + + + diff --git a/app/python/LNMP-With-Kafaka/Dockerfile b/app/python/LNMP-With-Kafaka/Dockerfile new file mode 100644 index 00000000..6129805a --- /dev/null +++ b/app/python/LNMP-With-Kafaka/Dockerfile @@ -0,0 +1,6 @@ +FROM python:3.7-alpine +WORKDIR /app +COPY . /app +RUN pip install flask mysql-connector-python redis confluent-kafka +EXPOSE 80 +CMD ["python", "app.py"] diff --git a/app/python/LNMP-With-Kafaka/Dockerfile.Vue3 b/app/python/LNMP-With-Kafaka/Dockerfile.Vue3 new file mode 100644 index 00000000..641b5f2e --- /dev/null +++ b/app/python/LNMP-With-Kafaka/Dockerfile.Vue3 @@ -0,0 +1,15 @@ +# build stage +FROM node:lts-alpine as build-stage +WORKDIR /app +COPY package*.json ./ +RUN npm install +RUN npm install axios +COPY . . +RUN npm run build + +# production stage +FROM nginx:stable-alpine as production-stage +COPY --from=build-stage /app/dist /usr/share/nginx/html +EXPOSE 80 +CMD ["nginx", "-g", "daemon off;"] + diff --git a/app/python/LNMP-With-Kafaka/app.py b/app/python/LNMP-With-Kafaka/app.py new file mode 100644 index 00000000..4934fcf5 --- /dev/null +++ b/app/python/LNMP-With-Kafaka/app.py @@ -0,0 +1,42 @@ +from flask import Flask, request +import json +import redis +import mysql.connector +from confluent_kafka import Producer, Consumer, KafkaError + +app = Flask(__name__) +cache = redis.Redis(host='redis-service', port=6379) + +# Kafka producer configuration +p = Producer({'bootstrap.servers': 'my-kafka-service:9092'}) # replace 'my-kafka-service' with your Kafka service name + +# Kafka consumer configuration +c = Consumer({ + 'bootstrap.servers': 'my-kafka-service:9092', # replace 'my-kafka-service' with your Kafka service name + 'group.id': 'mygroup', + 'auto.offset.reset': 'earliest' +}) + +c.subscribe(['mytopic']) + +@app.route('/produce', methods=['POST']) +def produce(): + data = request.json + p.produce('mytopic', json.dumps(data)) + return 'Message produced' + +@app.route('/consume') +def consume(): + msg = c.poll(1.0) + + if msg is None: + return 'No message' + if msg.error(): + return 'Error: {}'.format(msg.error()) + + data = json.loads(msg.value().decode('utf-8')) + return data + +if __name__ == '__main__': + app.run(host='0.0.0.0', port=80) + diff --git a/app/python/LNMP-With-Kafaka/deployment.yaml b/app/python/LNMP-With-Kafaka/deployment.yaml new file mode 100644 index 00000000..c3795aa1 --- /dev/null +++ b/app/python/LNMP-With-Kafaka/deployment.yaml @@ -0,0 +1,74 @@ +apiVersion: apps/v1 +kind: Deployment +metadata: + name: mysql-deployment +spec: + replicas: 1 + selector: + matchLabels: + app: mysql + template: + metadata: + labels: + app: mysql + spec: + containers: + - name: mysql + image: mysql:5.7 + env: + - name: MYSQL_ROOT_PASSWORD + value: "password" + - name: MYSQL_DATABASE + value: "mydb" + - name: MYSQL_USER + value: "username" + - name: MYSQL_PASSWORD + value: "password" + ports: + - containerPort: 3306 +--- +apiVersion: v1 +kind: Service +metadata: + name: mysql-service +spec: + selector: + app: mysql + ports: + - protocol: TCP + port: 3306 + targetPort: 3306 +--- +apiVersion: apps/v1 +kind: Deployment +metadata: + name: app-deployment +spec: + replicas: 3 + selector: + matchLabels: + app: my-app + template: + metadata: + labels: + app: my-app + spec: + containers: + - name: my-app + image: your-repo/your-tag # replace with your Docker image name and tag + ports: + - containerPort: 80 +--- +apiVersion: v1 +kind: Service +metadata: + name: app-service +spec: + selector: + app: my-app + ports: + - protocol: TCP + port: 80 + targetPort: 80 + type: LoadBalancer + diff --git a/app/python/LNMP-With-Kafaka/redis-deployment.yaml b/app/python/LNMP-With-Kafaka/redis-deployment.yaml new file mode 100644 index 00000000..cb3f1de8 --- /dev/null +++ b/app/python/LNMP-With-Kafaka/redis-deployment.yaml @@ -0,0 +1,31 @@ +apiVersion: apps/v1 +kind: Deployment +metadata: + name: redis-deployment +spec: + replicas: 1 + selector: + matchLabels: + app: redis + template: + metadata: + labels: + app: redis + spec: + containers: + - name: redis + image: redis:latest + ports: + - containerPort: 6379 +--- +apiVersion: v1 +kind: Service +metadata: + name: redis-service +spec: + selector: + app: redis + ports: + - protocol: TCP + port: 6379 + targetPort: 6379 diff --git a/app/python/LNMP-With-Kafaka/run.sh b/app/python/LNMP-With-Kafaka/run.sh new file mode 100644 index 00000000..592912b0 --- /dev/null +++ b/app/python/LNMP-With-Kafaka/run.sh @@ -0,0 +1,4 @@ +kubectl apply -f mysql-deployment.yaml +kubectl apply -f mysql-service.yaml +kubectl apply -f app-deployment.yaml +kubectl apply -f app-service.yaml diff --git a/app/python/LNMP-With-Kafaka/vu3-deployment.yaml b/app/python/LNMP-With-Kafaka/vu3-deployment.yaml new file mode 100644 index 00000000..39faf4a4 --- /dev/null +++ b/app/python/LNMP-With-Kafaka/vu3-deployment.yaml @@ -0,0 +1,32 @@ +apiVersion: apps/v1 +kind: Deployment +metadata: + name: vue-deployment +spec: + replicas: 3 + selector: + matchLabels: + app: vue-app + template: + metadata: + labels: + app: vue-app + spec: + containers: + - name: vue-app + image: your-repo/your-tag # replace with your Docker image name and tag + ports: + - containerPort: 80 +--- +apiVersion: v1 +kind: Service +metadata: + name: vue-service +spec: + selector: + app: vue-app + ports: + - protocol: TCP + port: 80 + targetPort: 80 + type: LoadBalancer diff --git a/app/python/LNMP/App.vue b/app/python/LNMP/App.vue new file mode 100644 index 00000000..d689fa40 --- /dev/null +++ b/app/python/LNMP/App.vue @@ -0,0 +1,27 @@ + + + diff --git a/app/python/LNMP/Dockerfile b/app/python/LNMP/Dockerfile new file mode 100644 index 00000000..205600df --- /dev/null +++ b/app/python/LNMP/Dockerfile @@ -0,0 +1,6 @@ +FROM python:3.7-alpine +WORKDIR /app +COPY . /app +RUN pip install flask mysql-connector-python +EXPOSE 80 +CMD ["python", "app.py"] diff --git a/app/python/LNMP/Dockerfile.Vue3 b/app/python/LNMP/Dockerfile.Vue3 new file mode 100644 index 00000000..641b5f2e --- /dev/null +++ b/app/python/LNMP/Dockerfile.Vue3 @@ -0,0 +1,15 @@ +# build stage +FROM node:lts-alpine as build-stage +WORKDIR /app +COPY package*.json ./ +RUN npm install +RUN npm install axios +COPY . . +RUN npm run build + +# production stage +FROM nginx:stable-alpine as production-stage +COPY --from=build-stage /app/dist /usr/share/nginx/html +EXPOSE 80 +CMD ["nginx", "-g", "daemon off;"] + diff --git a/app/python/LNMP/app.py b/app/python/LNMP/app.py new file mode 100644 index 00000000..d16e67ff --- /dev/null +++ b/app/python/LNMP/app.py @@ -0,0 +1,20 @@ +from flask import Flask +import mysql.connector + +app = Flask(__name__) + +@app.route('/') +def hello_world(): + db = mysql.connector.connect( + host="mysql-service", # Kubernetes service name for your MySQL service + user="username", + password="password", + database="mydb" + ) + cursor = db.cursor() + cursor.execute("SELECT * FROM your_table") # Replace 'your_table' with your table name + results = cursor.fetchall() + return str(results) # Convert results to string to return as HTTP response + +if __name__ == '__main__': + app.run(host='0.0.0.0', port=80) diff --git a/app/python/LNMP/deployment.yaml b/app/python/LNMP/deployment.yaml new file mode 100644 index 00000000..c3795aa1 --- /dev/null +++ b/app/python/LNMP/deployment.yaml @@ -0,0 +1,74 @@ +apiVersion: apps/v1 +kind: Deployment +metadata: + name: mysql-deployment +spec: + replicas: 1 + selector: + matchLabels: + app: mysql + template: + metadata: + labels: + app: mysql + spec: + containers: + - name: mysql + image: mysql:5.7 + env: + - name: MYSQL_ROOT_PASSWORD + value: "password" + - name: MYSQL_DATABASE + value: "mydb" + - name: MYSQL_USER + value: "username" + - name: MYSQL_PASSWORD + value: "password" + ports: + - containerPort: 3306 +--- +apiVersion: v1 +kind: Service +metadata: + name: mysql-service +spec: + selector: + app: mysql + ports: + - protocol: TCP + port: 3306 + targetPort: 3306 +--- +apiVersion: apps/v1 +kind: Deployment +metadata: + name: app-deployment +spec: + replicas: 3 + selector: + matchLabels: + app: my-app + template: + metadata: + labels: + app: my-app + spec: + containers: + - name: my-app + image: your-repo/your-tag # replace with your Docker image name and tag + ports: + - containerPort: 80 +--- +apiVersion: v1 +kind: Service +metadata: + name: app-service +spec: + selector: + app: my-app + ports: + - protocol: TCP + port: 80 + targetPort: 80 + type: LoadBalancer + diff --git a/app/python/LNMP/run.sh b/app/python/LNMP/run.sh new file mode 100644 index 00000000..592912b0 --- /dev/null +++ b/app/python/LNMP/run.sh @@ -0,0 +1,4 @@ +kubectl apply -f mysql-deployment.yaml +kubectl apply -f mysql-service.yaml +kubectl apply -f app-deployment.yaml +kubectl apply -f app-service.yaml diff --git a/app/python/LNMP/vu3-deployment.yaml b/app/python/LNMP/vu3-deployment.yaml new file mode 100644 index 00000000..39faf4a4 --- /dev/null +++ b/app/python/LNMP/vu3-deployment.yaml @@ -0,0 +1,32 @@ +apiVersion: apps/v1 +kind: Deployment +metadata: + name: vue-deployment +spec: + replicas: 3 + selector: + matchLabels: + app: vue-app + template: + metadata: + labels: + app: vue-app + spec: + containers: + - name: vue-app + image: your-repo/your-tag # replace with your Docker image name and tag + ports: + - containerPort: 80 +--- +apiVersion: v1 +kind: Service +metadata: + name: vue-service +spec: + selector: + app: vue-app + ports: + - protocol: TCP + port: 80 + targetPort: 80 + type: LoadBalancer diff --git a/app/rust-demo/.github/workflows/pipeline.yaml b/app/rust-demo/.github/workflows/pipeline.yaml deleted file mode 100644 index b74f51f4..00000000 --- a/app/rust-demo/.github/workflows/pipeline.yaml +++ /dev/null @@ -1,159 +0,0 @@ -name: Build Test And Deploy - -on: - pull_request: - push: - paths: - - 'Dockerfile' - - '.github/workflows/pipieline.yaml' - workflow_dispatch: - branches: - - main - -env: - TZ: Asia/Shanghai - REPO: "artifact.onwalk.net" - IMAGE: base/${{ github.repository }} - TAG: ${{ github.sha }} - -jobs: - build: - runs-on: ubuntu-latest - - steps: - - uses: actions/checkout@v2 - - - name: Install dependencies - run: | - sudo apt update - sudo apt install -y rustc cargo - - - name: Build - run: | - cargo build --release - tar -czvpf my_rust_server-0.0.1.tar.gz target/release/my_rust_server - - - name: Upload binaries to release - uses: svenstaro/upload-release-action@v2 - with: - asset_name: my_rust_server-0.0.1.tar.gz - file: my_rust_server-0.0.1.tar.gz - tag: ${{ github.ref }} - overwrite: true - body: "Release v0.1.0" - - test: - runs-on: ubuntu-latest - - steps: - - uses: actions/checkout@v2 - - - name: Install dependencies - run: | - sudo apt update - sudo apt install -y rustc cargo - - - name: Run tests - run: | - echo "To do ..." - docker-image: - runs-on: ubuntu-latest - name: Build image - needs: - - build - - test - steps: - - uses: actions/checkout@master - - - name: 'Artifact: build && push debian-c-sysinfo image' - uses: aevea/action-kaniko@master - with: - registry: ${{ secrets.HELM_REPO_REGISTRY }} - username: ${{ secrets.HELM_REPO_USER }} - password: ${{ secrets.HELM_REPO_PASSWORD }} - path: './' - build_file: 'Dockerfile' - image: ${{ env.IMAGE }} - tag: ${{ env.TAG }} - cache: true - cache_registry: cache - - setup-k3s: - runs-on: ubuntu-latest - needs: - - docker-image - - steps: - - uses: actions/checkout@v3 - - - name: update submodule - run: | - sudo apt-get update && sudo apt-get install -y git && git submodule update --init --recursive - - - name: Setup K3S Cluster - working-directory: ./scripts - shell: bash - run: | - export ANSIBLE_HOST_KEY_CHECKING=False - sudo apt install jq ansible -y - - mkdir -pv ~/.ssh/ - cat > ~/.ssh/id_rsa << EOF - ${{ secrets.SSH_PRIVATE_KEY }} - EOF - sudo chmod 0400 ~/.ssh/id_rsa - md5sum ~/.ssh/id_rsa - - mkdir -pv hosts/ - cat > hosts/inventory << EOF - [master] - ${{ secrets.HOST_DOMAIN }} ansible_host=${{ secrets.HOST_IP }} - - [all:vars] - ansible_port=22 - ansible_ssh_user=${{ secrets.HOST_USER }} - ansible_ssh_private_key_file=~/.ssh/id_rsa - ansible_host_key_checking=False - ingress_ip=${{ secrets.HOST_IP }} - EOF - cat hosts/inventory - ansible-playbook -i hosts/inventory init_k3s_cluster -D - deploy-app: - runs-on: ubuntu-latest - needs: [setup-k3s] - - steps: - - uses: actions/checkout@v3 - - - name: update submodule - run: | - sudo apt-get update && sudo apt-get install -y git && git submodule update --init --recursive - - - name: Deploy - working-directory: ./scripts - shell: bash - run: | - export ANSIBLE_HOST_KEY_CHECKING=False - sudo apt install jq ansible -y - - mkdir -pv ~/.ssh/ - cat > ~/.ssh/id_rsa << EOF - ${{ secrets.SSH_PRIVATE_KEY }} - EOF - sudo chmod 0400 ~/.ssh/id_rsa - md5sum ~/.ssh/id_rsa - - mkdir -pv hosts/ - cat > hosts/inventory << EOF - [master] - ${{ secrets.HOST_DOMAIN }} ansible_host=${{ secrets.HOST_IP }} - - [all:vars] - ansible_port=22 - ansible_ssh_user=${{ secrets.HOST_USER }} - ansible_ssh_private_key_file=~/.ssh/id_rsa - ansible_host_key_checking=False - app_image=${{ env.REPO }}/${{ env.IMAGE }} - app_tag=${{ env.TAG }} - EOF - ansible-playbook -i hosts/inventory deploy_app -D diff --git a/app/rust-demo/.gitignore b/app/rust-demo/.gitignore deleted file mode 100644 index 68bc17f9..00000000 --- a/app/rust-demo/.gitignore +++ /dev/null @@ -1,160 +0,0 @@ -# Byte-compiled / optimized / DLL files -__pycache__/ -*.py[cod] -*$py.class - -# C extensions -*.so - -# Distribution / packaging -.Python -build/ -develop-eggs/ -dist/ -downloads/ -eggs/ -.eggs/ -lib/ -lib64/ -parts/ -sdist/ -var/ -wheels/ -share/python-wheels/ -*.egg-info/ -.installed.cfg -*.egg -MANIFEST - -# PyInstaller -# Usually these files are written by a python script from a template -# before PyInstaller builds the exe, so as to inject date/other infos into it. -*.manifest -*.spec - -# Installer logs -pip-log.txt -pip-delete-this-directory.txt - -# Unit test / coverage reports -htmlcov/ -.tox/ -.nox/ -.coverage -.coverage.* -.cache -nosetests.xml -coverage.xml -*.cover -*.py,cover -.hypothesis/ -.pytest_cache/ -cover/ - -# Translations -*.mo -*.pot - -# Django stuff: -*.log -local_settings.py -db.sqlite3 -db.sqlite3-journal - -# Flask stuff: -instance/ -.webassets-cache - -# Scrapy stuff: -.scrapy - -# Sphinx documentation -docs/_build/ - -# PyBuilder -.pybuilder/ -target/ - -# Jupyter Notebook -.ipynb_checkpoints - -# IPython -profile_default/ -ipython_config.py - -# pyenv -# For a library or package, you might want to ignore these files since the code is -# intended to run in multiple environments; otherwise, check them in: -# .python-version - -# pipenv -# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control. -# However, in case of collaboration, if having platform-specific dependencies or dependencies -# having no cross-platform support, pipenv may install dependencies that don't work, or not -# install all needed dependencies. -#Pipfile.lock - -# poetry -# Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control. -# This is especially recommended for binary packages to ensure reproducibility, and is more -# commonly ignored for libraries. -# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control -#poetry.lock - -# pdm -# Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control. -#pdm.lock -# pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it -# in version control. -# https://pdm.fming.dev/#use-with-ide -.pdm.toml - -# PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm -__pypackages__/ - -# Celery stuff -celerybeat-schedule -celerybeat.pid - -# SageMath parsed files -*.sage.py - -# Environments -.env -.venv -env/ -venv/ -ENV/ -env.bak/ -venv.bak/ - -# Spyder project settings -.spyderproject -.spyproject - -# Rope project settings -.ropeproject - -# mkdocs documentation -/site - -# mypy -.mypy_cache/ -.dmypy.json -dmypy.json - -# Pyre type checker -.pyre/ - -# pytype static type analyzer -.pytype/ - -# Cython debug symbols -cython_debug/ - -# PyCharm -# JetBrains specific template is maintained in a separate JetBrains.gitignore that can -# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore -# and can be added to the global gitignore or merged into this file. For a more nuclear -# option (not recommended) you can uncomment the following to ignore the entire idea folder. -#.idea/ diff --git a/app/rust-demo/.gitmodules b/app/rust-demo/.gitmodules deleted file mode 100644 index 70d8c5a8..00000000 --- a/app/rust-demo/.gitmodules +++ /dev/null @@ -1,3 +0,0 @@ -[submodule "scripts"] - path = scripts - url = https://github.com/SvcDesignScaffolding/AnsibleScripts.git