Skip to content

Commit

Permalink
change deployment resources
Browse files Browse the repository at this point in the history
  • Loading branch information
philipsahli committed Jan 4, 2019
1 parent d6aa174 commit f3454cd
Show file tree
Hide file tree
Showing 10 changed files with 311 additions and 134 deletions.
6 changes: 3 additions & 3 deletions Gopkg.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

37 changes: 37 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,39 @@
# contador
A 12-factor counter microservice

## Services

### Telegraf

Run somewhere

nc -l 2003

### Redis

Run somewhere

docker run --name gontador-redis -p 6379:6379 -d redis


## Test local

go build -o gontador src/*.go
REDIS_URL=192.168.1.2:6379 METRIC_HOST=192.168.1.2 METRIC_PORT=2003 ./gontador

### HTTP Interface

curl http://localhost:3000/counter

## Test on Openshift

bash -xe deploy/deploy.sh

URL=`oc get route.route.openshift.io/gontador -o go-template --template={{.spec.host}}`

curl -v $URL/counter

## Undeploy

oc delete all -l app=gontador
oc delete template gontador-template
50 changes: 50 additions & 0 deletions deploy/build.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
apiVersion: build.openshift.io/v1
kind: BuildConfig
metadata:
# annotations:
# description: Defines how to build the application
# template.alpha.openshift.io/wait-for-ready: 'true'
# labels:
# app: gontador
# template: gontador
name: gontador-build
# namespace: gontador
spec:
# failedBuildsHistoryLimit: 5
# nodeSelector: null
output:
to:
kind: ImageStreamTag
name: 'gontador:latest'
# postCommit:
# script: ./manage.py test
# resources: {}
# runPolicy: Serial
source:
git:
uri: 'https://github.com/philipsahli/gontador.git'
ref: 'go-implementation'
type: Git
strategy:
type: Docker
dockerStrategy:
dockerfilePath: Dockerfile

# env:
# - name: PIP_INDEX_URL
# from:
# kind: ImageStreamTag
# name: 'python:3.6'
# namespace: openshift

# successfulBuildsHistoryLimit: 5
triggers:
- imageChange:
type: ImageChange
- type: ConfigChange
- github:
secret: 4tqgB6gCvDQBoWBiKtNcm3NsT37MM602KhLGKrCR
type: GitHub
# status:
# lastVersion: 1

14 changes: 14 additions & 0 deletions deploy/deploy.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#!/bin/bash -xe

# Build docker image in openshift
# oc apply -f imagestream.yaml

# Deploy app
oc create -f template.yaml
oc new-app --template=gontador-template --name gontador
oc apply -f build.yaml
oc start-build gontador-build -n gontador

# Publish service
# oc apply -f service.yaml
oc apply -f route.yaml
10 changes: 10 additions & 0 deletions deploy/imagestream.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
apiVersion: image.openshift.io/v1
kind: ImageStream
metadata:
annotations:
description: Keeps track of changes in the application image
name: gontador
namespace: gontador
spec:
lookupPolicy:
local: false
31 changes: 31 additions & 0 deletions deploy/route.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
apiVersion: route.openshift.io/v1
kind: Route
metadata:
annotations:
openshift.io/host.generated: 'true'
creationTimestamp: '2018-12-31T10:24:53Z'
labels:
app: gontador
name: gontador
namespace: gontador
resourceVersion: '58060'
selfLink: /apis/route.openshift.io/v1/namespaces/gontador/routes/gontador
uid: 50250017-0ce6-11e9-8918-2215dd3699dc
spec:
host: gontador-gontador.192.168.64.7.nip.io
port:
targetPort: gontador
to:
kind: Service
name: gontador
weight: 100
wildcardPolicy: None
status:
ingress:
- conditions:
- lastTransitionTime: '2018-12-31T10:24:54Z'
status: 'True'
type: Admitted
host: gontador-gontador.192.168.64.7.nip.io
routerName: router
wildcardPolicy: None
23 changes: 23 additions & 0 deletions deploy/service.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
apiVersion: v1
kind: Service
metadata:
annotations:
description: Exposes the gontador service
creationTimestamp: '2018-12-31T06:50:19Z'
labels:
app: gontador
name: gontador
namespace: gontador
resourceVersion: '3000'
spec:
ports:
- name: gontador
port: 3000
protocol: TCP
targetPort: 3000
selector:
app: gontador
sessionAffinity: None
type: ClusterIP
status:
loadBalancer: {}
142 changes: 142 additions & 0 deletions deploy/template.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,142 @@
apiVersion: v1
kind: Template
metadata:
creationTimestamp: null
name: gontador-template
objects:
- apiVersion: v1
kind: Service
metadata:
annotations:
description: Exposes the gontador service
creationTimestamp: '2018-12-31T06:50:19Z'
labels:
app: gontador
name: gontador
namespace: gontador
spec:
ports:
- name: gontador
port: 3000
protocol: TCP
targetPort: 3000
selector:
app: gontador
sessionAffinity: None
type: ClusterIP
status:
loadBalancer: {}

- apiVersion: v1
kind: ImageStream
metadata:
annotations:
description: Keeps track of changes in the application image
name: gontador
namespace: gontador
spec:
lookupPolicy:
local: false


- apiVersion: v1
kind: DeploymentConfig
metadata:
labels:
app: gontador
name: gontador
namespace: gontador
spec:
replicas: 2
selector:
app: gontador
deploymentconfig: gontador
# strategy:
# activeDeadlineSeconds: 21600
# resources: {}
# rollingParams:
# intervalSeconds: 1d
# maxSurge: 25%
# maxUnavailable: 25%
# timeoutSeconds: 600
# updatePeriodSeconds: 1
# type: Rolling
template:
metadata:
labels:
app: gontador
deploymentconfig: gontador
spec:
containers:
- image: >-
172.30.1.1:5000/gontador/gontador@sha256:9fd64c947842884d6def85ca5ee907efefb2c636960ca5069a06eb89adeda1ec
imagePullPolicy: Always
livenessProbe:
failureThreshold: 3
httpGet:
path: /health/live
port: 3000
scheme: HTTP
initialDelaySeconds: 2
periodSeconds: 10
successThreshold: 1
timeoutSeconds: 10
name: gontador
ports:
- containerPort: 3000
protocol: TCP
readinessProbe:
failureThreshold: 3
httpGet:
path: /health/ready
port: 3000
scheme: HTTP
initialDelaySeconds: 2
periodSeconds: 10
successThreshold: 1
timeoutSeconds: 10
resources: {}
terminationMessagePath: /dev/termination-log
terminationMessagePolicy: File
env:
- name: SYSTEM_ENV
value: dev
- name: SYSTEM_INSTANCE
value: demo-stao
- name: SERVICE_HOST
valueFrom:
fieldRef:
# apiVersion: v1
fieldPath: spec.nodeName
- name: SERVICE_PORT
value: '3000'
- name: SERVICE_INSTANCE
valueFrom:
fieldRef:
# apiVersion: v1
fieldPath: metadata.name
- name: METRIC_HOST
value: 192.168.1.2
- name: METRIC_PORT
value: '2003'
- name: REDIS_URL
value: '192.168.1.2:6379'
dnsPolicy: ClusterFirst
restartPolicy: Always
securityContext: {}
terminationGracePeriodSeconds: 30
test: false
triggers:
- imageChangeParams:
automatic: true
containerNames:
- gontador
from:
kind: ImageStreamTag
name: 'gontador:latest'
namespace: gontador
lastTriggeredImage: >-
172.30.1.1:5000/gontador/gontador@sha256:9fd64c947842884d6def85ca5ee907efefb2c636960ca5069a06eb89adeda1ec
type: ImageChange
- type: ConfigChange
status: {}
2 changes: 1 addition & 1 deletion src/helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ func ready(w http.ResponseWriter, r *http.Request) {
}

func live(w http.ResponseWriter, r *http.Request) {
log.Println("Checking liveness")
log.Println("Checking liveness: true")
}

func randomHex(n int) (string, error) {
Expand Down
Loading

0 comments on commit f3454cd

Please sign in to comment.