Commit ed055626 authored by Nane Kratzke's avatar Nane Kratzke
Browse files

first build+deploy check

parent 9e83cb02
stages:
- prepare
- deploy
- teardown
variables:
image: "transit/kubectl-plus:v1.19.4"
labeling:
stage: prepare
script:
- NS=$(kubectl config view --output 'jsonpath={..namespace}')
- kubectl label ns $NS istio-injection=enabled --overwrite
secrets:
stage: prepare
script:
- kubectl delete secret gitlab-registry-credentials || true
- "kubectl create secret docker-registry gitlab-registry-credentials \
--docker-server=$CI_REGISTRY \
--docker-username=image-registry \
--docker-password=$REGISTRY_READ_TOKEN \
"
space-container:
stage: prepare
image:
name: gcr.io/kaniko-project/executor:debug
entrypoint: [""]
only:
changes:
- .gitlab-ci.yml
- space/*
- space/*/*
script:
- mkdir -p /kaniko/.docker
- echo "{\"auths\":{\"$CI_REGISTRY\":{\"username\":\"$CI_REGISTRY_USER\",\"password\":\"$CI_REGISTRY_PASSWORD\"}}}" > /kaniko/.docker/config.json
- cd space
- /kaniko/executor --context . --destination $CI_REGISTRY_IMAGE/space:latest
space-services:
stage: deploy
script:
- ROLE=data mo deploy/space-dep.yaml | kubectl apply -f -
- ROLE=astros mo deploy/space-dep.yaml | kubectl apply -f -
- ROLE=position mo deploy/space-dep.yaml | kubectl apply -f -
- ROLE=data mo deploy/space-svc.yaml | kubectl apply -f -
- ROLE=astros mo deploy/space-svc.yaml | kubectl apply -f -
- ROLE=position mo deploy/space-svc.yaml | kubectl apply -f -
shutdown:
stage: teardown
when: manual
script:
- NS=$(kubectl config view --output 'jsonpath={..namespace}')
- kubectl label ns $NS istio-injection=disabled --overwrite
- ROLE=data mo deploy/space-dep.yaml | kubectl delete -f -
- ROLE=astros mo deploy/space-dep.yaml | kubectl delete -f -
- ROLE=position mo deploy/space-dep.yaml | kubectl delete -f -
- ROLE=data mo deploy/space-svc.yaml | kubectl delete -f -
- ROLE=astros mo deploy/space-svc.yaml | kubectl delete -f -
- ROLE=position mo deploy/space-svc.yaml | kubectl delete -f -
\ No newline at end of file
FROM python:3.9-alpine
COPY . /app/
WORKDIR /app
RUN pip3 install -r requirements.txt
EXPOSE 80
ENTRYPOINT ["python3", "-u", "service.py"]
\ No newline at end of file
apiVersion: apps/v1
kind: Deployment
metadata:
name: space-deployment
labels:
app: {{ ROLE }}
spec:
replicas: 1
selector:
matchLabels:
app: {{ ROLE }}
template:
metadata:
labels:
app: {{ ROLE }}
spec:
imagePullSecrets:
- name: gitlab-registry-credentials
containers:
- name: space
image: git.mylab.th-luebeck.de:4181/cloud-native/lab-traffic-mgmt/space:latest
imagePullPolicy: Always
resources:
requests:
cpu: "50m"
ports:
- containerPort: 80
env:
- name: ROLE
value: "{{ ROLE }}"
---
apiVersion: v1
kind: Service
metadata:
name: {{ROLE}}-svc
labels:
app: {{ROLE}}
spec:
selector:
app: {{ROLE}}
ports:
- protocol: TCP
port: 80
targetPort: 80
\ No newline at end of file
flask
requests
\ No newline at end of file
from flask import Flask, redirect, request, jsonify
import requests
import os
import socket
import json
# A very boring and basic space-service to demonstrate
# content-based traffic management.
role = os.environ.get('ROLE', 'data')
astro_svc = os.environ.get("ASTRO_SVC", "astros")
position_svc = os.environ.get("POSITION_SVC", "position")
app = Flask(__name__)
@app.route('/')
def index():
if role == "astros":
return redirect('/astros')
if role == "position":
return redirect('/position')
if role == "data":
return redirect('/data')
return "Bad config", 500
def load_url(url, headers):
h = { "User-Agent": headers['User-Agent'] }
return json.loads(requests.get(url, headers=h, allow_redirects=True).content)
@app.route('/data')
def data():
h = request.headers
return jsonify({
'from': socket.gethostname(),
'astros': load_url(astro_svc, request.headers),
'position': load_url(position_svc, request.headers)
})
@app.route('/astros')
def astros():
return jsonify({
'from': socket.socket.gethostname(),
'data': load_url("http://api.open-notify.org/astros.json", request.headers)
})
@app.route('/position')
def position():
return jsonify({
'from': socket.socket.gethostname(),
'data': load_url("http://api.open-notify.org/iss-now.json", request.headers)
})
app.run(host="0.0.0.0", port=80)
\ No newline at end of file
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment