This commit is contained in:
parent
51ff9abe4c
commit
fce4f86987
6 changed files with 191 additions and 0 deletions
78
.drone.yml
Normal file
78
.drone.yml
Normal file
|
@ -0,0 +1,78 @@
|
|||
---
|
||||
kind: pipeline
|
||||
name: build
|
||||
|
||||
steps:
|
||||
- name: build image
|
||||
image: plugins/docker
|
||||
settings:
|
||||
repo: kleph/quake3-status
|
||||
tags: ${DRONE_COMMIT_SHA:0:8}
|
||||
username:
|
||||
from_secret: dockerhub_username
|
||||
password:
|
||||
from_secret: dockerhub_password
|
||||
when:
|
||||
event:
|
||||
exclude:
|
||||
- pull_request
|
||||
|
||||
---
|
||||
deploy_commands_alias:
|
||||
- &deploy_commands
|
||||
commands:
|
||||
- sed "s/__LEVEL__/$${LEVEL}/g" kube/q3-status-deployment.yaml > kube/q3-status-deployment-$${LEVEL}.yaml
|
||||
- sed "s/__NAMESPACE__/$${NAMESPACE}/g" kube/q3-status-deployment-$${LEVEL}.yaml > kube/q3-status-deployment-$${NAMESPACE}-$${LEVEL}.yaml
|
||||
- sed "s/__IMAGE_TAG__/$${IMAGE_TAG}/g" kube/q3-status-deployment-$${NAMESPACE}-$${LEVEL}.yaml > kube/q3-status-deployment-$${NAMESPACE}-$${LEVEL}2.yaml
|
||||
- cat kube/q3-status-deployment-$${NAMESPACE}-$${LEVEL}2.yaml
|
||||
- echo "applying"
|
||||
- kubectl apply -f kube/q3-status-deployment-$${NAMESPACE}-$${LEVEL}2.yaml --namespace=q3
|
||||
- echo "== post deploy ($${LEVEL}) status:"
|
||||
- kubectl get deployments --namespace=q3
|
||||
- kubectl get pods --namespace=q3
|
||||
|
||||
kind: pipeline
|
||||
name: deploy
|
||||
|
||||
steps:
|
||||
- name: deploy staging
|
||||
image: sinlead/drone-kubectl
|
||||
settings:
|
||||
kubernetes_server:
|
||||
from_secret: kubectl_uri
|
||||
kubernetes_cert:
|
||||
from_secret: kubectl_cert
|
||||
kubernetes_token:
|
||||
from_secret: kubectl_token
|
||||
environment:
|
||||
IMAGE_TAG: ${DRONE_COMMIT_SHA:0:8}
|
||||
NAMESPACE: q3
|
||||
LEVEL: staging
|
||||
<<: *deploy_commands
|
||||
when:
|
||||
branch:
|
||||
exclude:
|
||||
- master
|
||||
|
||||
- name: deploy live
|
||||
image: sinlead/drone-kubectl
|
||||
settings:
|
||||
kubernetes_server:
|
||||
from_secret: kubectl_uri
|
||||
kubernetes_cert:
|
||||
from_secret: kubectl_cert
|
||||
kubernetes_token:
|
||||
from_secret: kubectl_token
|
||||
environment:
|
||||
IMAGE_TAG: ${DRONE_COMMIT_SHA:0:8}
|
||||
NAMESPACE: q3
|
||||
LEVEL: live
|
||||
<<: *deploy_commands
|
||||
when:
|
||||
branch:
|
||||
include:
|
||||
- master
|
||||
|
||||
depends_on:
|
||||
- build
|
||||
|
9
Dockerfile
Normal file
9
Dockerfile
Normal file
|
@ -0,0 +1,9 @@
|
|||
FROM python:2-slim
|
||||
|
||||
RUN pip install flask
|
||||
COPY /quake3_status.py /quake3_status.py
|
||||
COPY /pyquake3.py /pyquake3.py
|
||||
EXPOSE 5000
|
||||
|
||||
CMD ["python", "/quake3_status.py"]
|
||||
|
31
kube/q3-serviceaccount-deploy.yaml
Normal file
31
kube/q3-serviceaccount-deploy.yaml
Normal file
|
@ -0,0 +1,31 @@
|
|||
---
|
||||
apiVersion: v1
|
||||
kind: ServiceAccount
|
||||
metadata:
|
||||
name: q3-deploy
|
||||
namespace: q3
|
||||
|
||||
---
|
||||
apiVersion: rbac.authorization.k8s.io/v1
|
||||
kind: Role
|
||||
metadata:
|
||||
name: q3-deploy-role
|
||||
namespace: q3 # Should be namespace you are granting access to
|
||||
rules:
|
||||
- apiGroups: ["*"]
|
||||
resources: ["*"]
|
||||
verbs: ["*"]
|
||||
---
|
||||
apiVersion: rbac.authorization.k8s.io/v1
|
||||
kind: RoleBinding
|
||||
metadata:
|
||||
name: q3-rolebinding
|
||||
namespace: q3
|
||||
roleRef:
|
||||
apiGroup: rbac.authorization.k8s.io
|
||||
kind: Role
|
||||
name: q3-deploy-role
|
||||
subjects:
|
||||
- namespace: q3
|
||||
kind: ServiceAccount
|
||||
name: q3-deploy
|
24
kube/q3-status-deployment.yaml
Normal file
24
kube/q3-status-deployment.yaml
Normal file
|
@ -0,0 +1,24 @@
|
|||
---
|
||||
apiVersion: apps/v1
|
||||
kind: Deployment
|
||||
metadata:
|
||||
name: q3-status-deployment-__LEVEL__
|
||||
namespace: __NAMESPACE__
|
||||
spec:
|
||||
selector:
|
||||
matchLabels:
|
||||
app: q3-status
|
||||
level: __LEVEL__
|
||||
replicas: 1
|
||||
template:
|
||||
metadata:
|
||||
labels:
|
||||
app: q3-status
|
||||
level: __LEVEL__
|
||||
spec:
|
||||
containers:
|
||||
- name: q3-status
|
||||
image: kleph/q3-status:__IMAGE_TAG__
|
||||
imagePullPolicy: Always
|
||||
ports:
|
||||
- containerPort: 5000
|
13
kube/q3-status-service.yaml
Normal file
13
kube/q3-status-service.yaml
Normal file
|
@ -0,0 +1,13 @@
|
|||
apiVersion: v1
|
||||
kind: Service
|
||||
metadata:
|
||||
name: q3-status
|
||||
namespace: q3
|
||||
spec:
|
||||
selector:
|
||||
app: q3-status
|
||||
level: live
|
||||
ports:
|
||||
- protocol: TCP
|
||||
port: 80
|
||||
targetPort: 5000
|
36
quake3_status.py
Normal file
36
quake3_status.py
Normal file
|
@ -0,0 +1,36 @@
|
|||
#!/usr/bin/env python3.6
|
||||
# -*- coding:utf-8 -*-
|
||||
""" basic q3 status page for my home server """
|
||||
|
||||
from flask import Flask
|
||||
from flask import render_template
|
||||
from pyquake3 import PyQuake3
|
||||
import os
|
||||
|
||||
# pylint: disable=invalid-name
|
||||
app = Flask(__name__)
|
||||
app.url_map.strict_slashes = False
|
||||
|
||||
@app.route('/')
|
||||
def index(hours=None, minutes=None):
|
||||
""" main and only app """
|
||||
|
||||
q3server = os.environ.get("Q3_SERVER")
|
||||
rcon_password = os.environ.get("RCONN_PASSWORD")
|
||||
|
||||
q = PyQuake3(q3server, rcon_password)
|
||||
q.update()
|
||||
|
||||
data = 'The name of %s is %s, running map %s with %s player(s).' % \
|
||||
(q.get_address(), q.vars['sv_hostname'], \
|
||||
q.vars['mapname'], len(q.players))
|
||||
|
||||
return data
|
||||
|
||||
def main():
|
||||
""" main func """
|
||||
app.run(host='::')
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
Loading…
Reference in a new issue