Permalink
Browse files

Support k8s

  • Loading branch information...
making committed Dec 2, 2017
1 parent a37dd2b commit c67ee82ae4a00f20038e3b0e4e78b7b589e380ed
Showing with 279 additions and 48 deletions.
  1. +5 −0 Dockerfile
  2. +184 −48 ci/pipeline.yml
  3. +90 −0 k8s/blog-api.yml
View
@@ -0,0 +1,5 @@
FROM openjdk:8-alpine
VOLUME /tmp
ARG JAR_FILE
ADD ${JAR_FILE} /app.jar
ENTRYPOINT ["java","-Djava.security.egd=file:/dev/./urandom","-jar","/app.jar"]
View
@@ -10,6 +10,11 @@ resource_types:
source:
repository: pivotalpa/maven-resource
tag: 1.3.4
- name: kubernetes
type: docker-image
source:
repository: zlabjp/kubernetes-resource
tag: "1.8"
resources:
- name: repo-master
@@ -33,24 +38,34 @@ resources:
file: version
driver: git
initial_version: 4.0.0
- name: cf-master
type: cf
# - name: cf-master
# type: cf
# source:
# api: ((pws-api))
# username: ((pws-username))
# password: ((pws-password))
# organization: ((pws-org))
# space: production
# skip_cert_check: true
# - name: cf-develop
# type: cf
# source:
# api: ((cf-api))
# username: ((cf-username))
# password: ((cf-password))
# organization: ((cf-org))
# space: blog-dev
# skip_cert_check: true
- name: docker
type: docker-image
source:
api: ((pws-api))
username: ((pws-username))
password: ((pws-password))
organization: ((pws-org))
space: production
skip_cert_check: true
- name: cf-develop
type: cf
repository: asia.gcr.io/fe-tmaki/blog-api
username: _json_key
password: ((gcr-key))
- name: k8s-master
type: kubernetes
source:
api: ((cf-api))
username: ((cf-username))
password: ((cf-password))
organization: ((cf-org))
space: blog-dev
skip_cert_check: true
kubeconfig: ((kubeconfig))
- name: nexus
type: maven
source:
@@ -160,24 +175,70 @@ jobs:
put: slack-alert
params:
<<: *SLACK_FAILURE
- name: deploy-develop
#- name: deploy-develop
# plan:
# - get: repo
# resource: repo-develop
# passed:
# - upload-to-nexus-snapshots
# trigger: true
# - get: nexus
# passed:
# - upload-to-nexus-snapshots
# - put: cf-develop
# params:
# manifest: repo/manifest-dev.yml
# path: nexus/*.jar
# current_app_name: blog-api-dev
# environment_variables:
# SECURITY_USER_NAME: ((ops-username))
# SECURITY_USER_PASSWORD: ((ops-password))
# on_failure:
# put: slack-alert
# params:
# <<: *SLACK_FAILURE
# on_success:
# put: slack-alert
# params:
# <<: *SLACK_SUCCESS
- name: docker-push-develop
plan:
- get: repo
resource: repo-develop
passed:
- upload-to-nexus-snapshots
trigger: true
- get: nexus
passed:
- upload-to-nexus-snapshots
- put: cf-develop
params:
manifest: repo/manifest-dev.yml
path: nexus/*.jar
current_app_name: blog-api-dev
environment_variables:
SECURITY_USER_NAME: ((ops-username))
SECURITY_USER_PASSWORD: ((ops-password))
- aggregate:
- get: repo
resource: repo-develop
passed:
- upload-to-nexus-snapshots
trigger: true
- get: repo-version
- get: nexus
passed:
- upload-to-nexus-snapshots
- task: update-docker
config: &COPY_DOCKERFILE
platform: linux
image_resource:
type: docker-image
source:
repository: ubuntu
inputs:
- name: repo
- name: nexus
outputs:
- name: updated
run:
path: bash
args:
- -c
- |
set -e
mv nexus/*.jar updated/app.jar
cp repo/Dockerfile updated/Dockerfile
cat updated/Dockerfile
- put: docker
params: &DOCKER_PUSH
build: updated
build_args:
JAR_FILE: app.jar
on_failure:
put: slack-alert
params:
@@ -193,7 +254,8 @@ jobs:
- get: repo-src
resource: repo-develop
passed:
- deploy-develop
# - deploy-develop
- docker-push-develop
- get: repo-dest
resource: repo-master
- task: merge-develop-to-master
@@ -335,21 +397,94 @@ jobs:
put: slack-alert
params:
<<: *SLACK_FAILURE
- name: deploy-master
#- name: deploy-master
# plan:
# - get: repo
# resource: repo-master
# passed:
# - upload-to-nexus-releases
# trigger: true
# - get: nexus
# passed:
# - upload-to-nexus-releases
# - put: cf-master
# params:
# manifest: repo/manifest.yml
# path: nexus/*.jar
# current_app_name: blog-api
# environment_variables:
# SECURITY_USER_NAME: ((ops-username))
# SECURITY_USER_PASSWORD: ((ops-password))
# on_failure:
# put: slack-alert
# params:
# <<: *SLACK_FAILURE
# on_success:
# put: slack-alert
# params:
# <<: *SLACK_SUCCESS
- name: docker-push-master
plan:
- get: repo
resource: repo-master
passed:
- upload-to-nexus-releases
trigger: true
- get: nexus
passed:
- upload-to-nexus-releases
- put: cf-master
- aggregate:
- get: repo
resource: repo-master
passed:
- upload-to-nexus-releases
trigger: true
- get: repo-version
- get: nexus
passed:
- upload-to-nexus-releases
- task: update-docker
config:
<<: *COPY_DOCKERFILE
- put: docker
params:
<<: *DOCKER_PUSH
tag: repo-version/number
tag_as_latest: true
on_failure:
put: slack-alert
params:
<<: *SLACK_FAILURE
on_success:
put: slack-alert
params:
<<: *SLACK_SUCCESS
- name: deploy-k8s-master
plan:
- aggregate:
- get: repo
resource: repo-master
passed:
- docker-push-master
trigger: true
- get: repo-version
- task: update-k8s-manifest
config:
platform: linux
image_resource:
type: docker-image
source:
repository: ubuntu
inputs:
- name: repo
- name: repo-version
outputs:
- name: updated
run:
path: bash
args:
- -c
- |
set -e
VERSION=`cat repo-version/number`
sed "s/latest/${VERSION}/g" repo/k8s/blog-api.yml | sed "s/FIXME/Bump to ${VERSION}/g" > updated/blog-api.yml
- put: k8s-master
params:
manifest: repo/manifest.yml
path: nexus/*.jar
current_app_name: blog-api
kubectl: apply -f updated/blog-api.yml
wait_until_ready: 120
wait_until_ready_selector: app=blog-api
on_failure:
put: slack-alert
params:
@@ -364,7 +499,8 @@ jobs:
- get: repo-src
resource: repo-master
passed:
- deploy-master
# - deploy-master
- deploy-k8s-master
trigger: true
- get: repo-dest
resource: repo-develop
View
@@ -0,0 +1,90 @@
kind: Service
apiVersion: v1
metadata:
name: blog-api-service
labels:
app: blog-api
spec:
selector:
app: blog-api
ports:
- protocol: TCP
port: 8080
nodePort: 30084
type: NodePort
---
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
name: blog-api-deployment
labels:
app: blog-api
spec:
replicas: 1
revisionHistoryLimit: 4
strategy:
rollingUpdate:
maxSurge: 1
maxUnavailable: 1
type: RollingUpdate
template:
metadata:
labels:
app: blog-api
annotations:
kubernetes.io/change-cause: "FIXME"
spec:
containers:
- name: blog-api
image: asia.gcr.io/fe-tmaki/blog-api:latest
imagePullPolicy: Always
ports:
- containerPort: 8080
env:
- name: PORT
value: "8080"
- name: SPRING_PROFILES_ACTIVE
value: cloud,kubernetes
- name: JAVA_OPTS
value: "-Xmx304M -Xss1M -XX:MaxMetaspaceSize=145M -XX:ReservedCodeCacheSize=240M -XX:CompressedClassSpaceSize=24M -XX:MaxDirectMemorySize=10M -XX:+UnlockExperimentalVMOptions -XX:+UseCGroupMemoryLimitForHeap -XX:MaxRAMFraction=1"
- name: SECURITY_USER_NAME
valueFrom:
configMapKeyRef:
name: blog-config
key: ops-username
- name: SECURITY_USER_PASSWORD
valueFrom:
configMapKeyRef:
name: blog-config
key: ops-password
- name: VCAP_APPLICATION
valueFrom:
configMapKeyRef:
name: blog-api-config
key: vcap-application.json
- name: VCAP_SERVICES
valueFrom:
configMapKeyRef:
name: blog-api-config
key: vcap-services.json
resources:
limits:
memory: "1024Mi"
requests:
memory: "1024Mi"
readinessProbe:
httpGet:
path: /health
port: 8080
initialDelaySeconds: 15
timeoutSeconds: 3
periodSeconds: 10
failureThreshold: 3
livenessProbe:
httpGet:
path: /health
port: 8080
initialDelaySeconds: 180
timeoutSeconds: 3
periodSeconds: 10
failureThreshold: 3

0 comments on commit c67ee82

Please sign in to comment.