├── .DS_Store
├── .dockerignore
├── .gitignore
├── .helmignore
├── Dockerfile
├── Jenkinsfile
├── LICENSE
├── README.md
├── charts
├── .DS_Store
├── preview
│ ├── Chart.yaml
│ ├── Makefile
│ ├── requirements.yaml
│ └── values.yaml
└── s1p-gateway
│ ├── .DS_Store
│ ├── .helmignore
│ ├── Chart.yaml
│ ├── Makefile
│ ├── README.md
│ ├── templates
│ ├── NOTES.txt
│ ├── _helpers.tpl
│ ├── deployment.yaml
│ ├── role.yaml
│ ├── rolebinding.yaml
│ ├── service.yaml
│ └── serviceaccount.yaml
│ └── values.yaml
├── pom.xml
├── skaffold.yaml
└── src
└── main
├── java
└── org
│ └── s1p
│ └── demo
│ └── gateway
│ └── GatewayApplication.java
└── resources
├── application.yml
├── bootstrap.yml
└── logback-spring.xml
/.DS_Store:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/salaboy/s1p_gateway/779a3f0e867fb295b3163a82b28c686b16672d05/.DS_Store
--------------------------------------------------------------------------------
/.dockerignore:
--------------------------------------------------------------------------------
1 | draft.toml
2 | charts/
3 | NOTICE
4 | LICENSE
5 | README.md
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | # Compiled class file
2 | *.class
3 | *.iml
4 | # Log file
5 | *.log
6 |
7 | # BlueJ files
8 | *.ctxt
9 |
10 | # Mobile Tools for Java (J2ME)
11 | .mtj.tmp/
12 |
13 | # Package Files #
14 | *.jar
15 | *.war
16 | *.nar
17 | *.ear
18 | *.zip
19 | *.tar.gz
20 | *.rar
21 | .idea/
22 | # virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
23 | hs_err_pid*
24 |
25 | target/
26 |
--------------------------------------------------------------------------------
/.helmignore:
--------------------------------------------------------------------------------
1 | # Patterns to ignore when building packages.
2 | # This supports shell glob matching, relative path matching, and
3 | # negation (prefixed with !). Only one pattern per line.
4 | .DS_Store
5 | # Common VCS dirs
6 | .git/
7 | .gitignore
8 | .bzr/
9 | .bzrignore
10 | .hg/
11 | .hgignore
12 | .svn/
13 | # Common backup files
14 | *.swp
15 | *.bak
16 | *.tmp
17 | *~
18 | # Various IDEs
19 | .project
20 | .idea/
21 | *.tmproj
22 | *.png
23 |
24 | # known compile time folders
25 | target/
26 | node_modules/
27 | vendor/
--------------------------------------------------------------------------------
/Dockerfile:
--------------------------------------------------------------------------------
1 | FROM openjdk:8-jdk-slim
2 | ENV PORT 8080
3 | ENV CLASSPATH /opt/lib
4 | EXPOSE 8080
5 |
6 | COPY pom.xml target/lib* /opt/lib/
7 |
8 | COPY target/*.jar /opt/app.jar
9 | WORKDIR /opt
10 | ENTRYPOINT exec java $JAVA_OPTS -jar app.jar
11 |
--------------------------------------------------------------------------------
/Jenkinsfile:
--------------------------------------------------------------------------------
1 | pipeline {
2 | agent {
3 | label "jenkins-maven"
4 | }
5 | environment {
6 | ORG = 'salaboy'
7 | APP_NAME = 's1p-gateway'
8 | CHARTMUSEUM_CREDS = credentials('jenkins-x-chartmuseum')
9 | }
10 | stages {
11 | stage('CI Build and push snapshot') {
12 | when {
13 | branch 'PR-*'
14 | }
15 | environment {
16 | PREVIEW_VERSION = "0.0.0-SNAPSHOT-$BRANCH_NAME-$BUILD_NUMBER"
17 | PREVIEW_NAMESPACE = "$APP_NAME-$BRANCH_NAME".toLowerCase()
18 | HELM_RELEASE = "$PREVIEW_NAMESPACE".toLowerCase()
19 | }
20 | steps {
21 | container('maven') {
22 | sh "mvn versions:set -DnewVersion=$PREVIEW_VERSION"
23 | sh "mvn install"
24 | sh 'export VERSION=$PREVIEW_VERSION && skaffold build -f skaffold.yaml'
25 |
26 |
27 | sh "jx step post build --image $DOCKER_REGISTRY/$ORG/$APP_NAME:$PREVIEW_VERSION"
28 | }
29 |
30 | dir ('./charts/preview') {
31 | container('maven') {
32 | sh "make preview"
33 | sh "jx preview --app $APP_NAME --dir ../.."
34 | }
35 | }
36 | }
37 | }
38 | stage('Build Release') {
39 | when {
40 | branch 'master'
41 | }
42 | steps {
43 | container('maven') {
44 | // ensure we're not on a detached head
45 | sh "git checkout master"
46 | sh "git config --global credential.helper store"
47 |
48 | sh "jx step git credentials"
49 | // so we can retrieve the version in later steps
50 | sh "echo \$(jx-release-version) > VERSION"
51 | sh "mvn versions:set -DnewVersion=\$(cat VERSION)"
52 | }
53 | dir ('./charts/s1p-gateway') {
54 | container('maven') {
55 | sh "make tag"
56 | }
57 | }
58 | container('maven') {
59 | sh 'mvn clean deploy'
60 |
61 | sh 'export VERSION=`cat VERSION` && skaffold build -f skaffold.yaml'
62 |
63 |
64 | sh "jx step post build --image $DOCKER_REGISTRY/$ORG/$APP_NAME:\$(cat VERSION)"
65 | }
66 | }
67 | }
68 | stage('Promote to Environments') {
69 | when {
70 | branch 'master'
71 | }
72 | steps {
73 | dir ('./charts/s1p-gateway') {
74 | container('maven') {
75 | sh 'jx step changelog --version v\$(cat ../../VERSION)'
76 |
77 | // release the helm chart
78 | sh 'jx step helm release'
79 |
80 | // promote through all 'Auto' promotion Environments
81 | sh 'jx promote -b --all-auto --timeout 1h --version \$(cat ../../VERSION)'
82 | }
83 | }
84 | }
85 | }
86 | }
87 | post {
88 | always {
89 | cleanWs()
90 | }
91 | failure {
92 | input """Pipeline failed.
93 | We will keep the build pod around to help you diagnose any failures.
94 |
95 | Select Proceed or Abort to terminate the build pod"""
96 | }
97 | }
98 | }
99 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | Apache License
2 | Version 2.0, January 2004
3 | http://www.apache.org/licenses/
4 |
5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6 |
7 | 1. Definitions.
8 |
9 | "License" shall mean the terms and conditions for use, reproduction,
10 | and distribution as defined by Sections 1 through 9 of this document.
11 |
12 | "Licensor" shall mean the copyright owner or entity authorized by
13 | the copyright owner that is granting the License.
14 |
15 | "Legal Entity" shall mean the union of the acting entity and all
16 | other entities that control, are controlled by, or are under common
17 | control with that entity. For the purposes of this definition,
18 | "control" means (i) the power, direct or indirect, to cause the
19 | direction or management of such entity, whether by contract or
20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the
21 | outstanding shares, or (iii) beneficial ownership of such entity.
22 |
23 | "You" (or "Your") shall mean an individual or Legal Entity
24 | exercising permissions granted by this License.
25 |
26 | "Source" form shall mean the preferred form for making modifications,
27 | including but not limited to software source code, documentation
28 | source, and configuration files.
29 |
30 | "Object" form shall mean any form resulting from mechanical
31 | transformation or translation of a Source form, including but
32 | not limited to compiled object code, generated documentation,
33 | and conversions to other media types.
34 |
35 | "Work" shall mean the work of authorship, whether in Source or
36 | Object form, made available under the License, as indicated by a
37 | copyright notice that is included in or attached to the work
38 | (an example is provided in the Appendix below).
39 |
40 | "Derivative Works" shall mean any work, whether in Source or Object
41 | form, that is based on (or derived from) the Work and for which the
42 | editorial revisions, annotations, elaborations, or other modifications
43 | represent, as a whole, an original work of authorship. For the purposes
44 | of this License, Derivative Works shall not include works that remain
45 | separable from, or merely link (or bind by name) to the interfaces of,
46 | the Work and Derivative Works thereof.
47 |
48 | "Contribution" shall mean any work of authorship, including
49 | the original version of the Work and any modifications or additions
50 | to that Work or Derivative Works thereof, that is intentionally
51 | submitted to Licensor for inclusion in the Work by the copyright owner
52 | or by an individual or Legal Entity authorized to submit on behalf of
53 | the copyright owner. For the purposes of this definition, "submitted"
54 | means any form of electronic, verbal, or written communication sent
55 | to the Licensor or its representatives, including but not limited to
56 | communication on electronic mailing lists, source code control systems,
57 | and issue tracking systems that are managed by, or on behalf of, the
58 | Licensor for the purpose of discussing and improving the Work, but
59 | excluding communication that is conspicuously marked or otherwise
60 | designated in writing by the copyright owner as "Not a Contribution."
61 |
62 | "Contributor" shall mean Licensor and any individual or Legal Entity
63 | on behalf of whom a Contribution has been received by Licensor and
64 | subsequently incorporated within the Work.
65 |
66 | 2. Grant of Copyright License. Subject to the terms and conditions of
67 | this License, each Contributor hereby grants to You a perpetual,
68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69 | copyright license to reproduce, prepare Derivative Works of,
70 | publicly display, publicly perform, sublicense, and distribute the
71 | Work and such Derivative Works in Source or Object form.
72 |
73 | 3. Grant of Patent License. Subject to the terms and conditions of
74 | this License, each Contributor hereby grants to You a perpetual,
75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76 | (except as stated in this section) patent license to make, have made,
77 | use, offer to sell, sell, import, and otherwise transfer the Work,
78 | where such license applies only to those patent claims licensable
79 | by such Contributor that are necessarily infringed by their
80 | Contribution(s) alone or by combination of their Contribution(s)
81 | with the Work to which such Contribution(s) was submitted. If You
82 | institute patent litigation against any entity (including a
83 | cross-claim or counterclaim in a lawsuit) alleging that the Work
84 | or a Contribution incorporated within the Work constitutes direct
85 | or contributory patent infringement, then any patent licenses
86 | granted to You under this License for that Work shall terminate
87 | as of the date such litigation is filed.
88 |
89 | 4. Redistribution. You may reproduce and distribute copies of the
90 | Work or Derivative Works thereof in any medium, with or without
91 | modifications, and in Source or Object form, provided that You
92 | meet the following conditions:
93 |
94 | (a) You must give any other recipients of the Work or
95 | Derivative Works a copy of this License; and
96 |
97 | (b) You must cause any modified files to carry prominent notices
98 | stating that You changed the files; and
99 |
100 | (c) You must retain, in the Source form of any Derivative Works
101 | that You distribute, all copyright, patent, trademark, and
102 | attribution notices from the Source form of the Work,
103 | excluding those notices that do not pertain to any part of
104 | the Derivative Works; and
105 |
106 | (d) If the Work includes a "NOTICE" text file as part of its
107 | distribution, then any Derivative Works that You distribute must
108 | include a readable copy of the attribution notices contained
109 | within such NOTICE file, excluding those notices that do not
110 | pertain to any part of the Derivative Works, in at least one
111 | of the following places: within a NOTICE text file distributed
112 | as part of the Derivative Works; within the Source form or
113 | documentation, if provided along with the Derivative Works; or,
114 | within a display generated by the Derivative Works, if and
115 | wherever such third-party notices normally appear. The contents
116 | of the NOTICE file are for informational purposes only and
117 | do not modify the License. You may add Your own attribution
118 | notices within Derivative Works that You distribute, alongside
119 | or as an addendum to the NOTICE text from the Work, provided
120 | that such additional attribution notices cannot be construed
121 | as modifying the License.
122 |
123 | You may add Your own copyright statement to Your modifications and
124 | may provide additional or different license terms and conditions
125 | for use, reproduction, or distribution of Your modifications, or
126 | for any such Derivative Works as a whole, provided Your use,
127 | reproduction, and distribution of the Work otherwise complies with
128 | the conditions stated in this License.
129 |
130 | 5. Submission of Contributions. Unless You explicitly state otherwise,
131 | any Contribution intentionally submitted for inclusion in the Work
132 | by You to the Licensor shall be under the terms and conditions of
133 | this License, without any additional terms or conditions.
134 | Notwithstanding the above, nothing herein shall supersede or modify
135 | the terms of any separate license agreement you may have executed
136 | with Licensor regarding such Contributions.
137 |
138 | 6. Trademarks. This License does not grant permission to use the trade
139 | names, trademarks, service marks, or product names of the Licensor,
140 | except as required for reasonable and customary use in describing the
141 | origin of the Work and reproducing the content of the NOTICE file.
142 |
143 | 7. Disclaimer of Warranty. Unless required by applicable law or
144 | agreed to in writing, Licensor provides the Work (and each
145 | Contributor provides its Contributions) on an "AS IS" BASIS,
146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147 | implied, including, without limitation, any warranties or conditions
148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149 | PARTICULAR PURPOSE. You are solely responsible for determining the
150 | appropriateness of using or redistributing the Work and assume any
151 | risks associated with Your exercise of permissions under this License.
152 |
153 | 8. Limitation of Liability. In no event and under no legal theory,
154 | whether in tort (including negligence), contract, or otherwise,
155 | unless required by applicable law (such as deliberate and grossly
156 | negligent acts) or agreed to in writing, shall any Contributor be
157 | liable to You for damages, including any direct, indirect, special,
158 | incidental, or consequential damages of any character arising as a
159 | result of this License or out of the use or inability to use the
160 | Work (including but not limited to damages for loss of goodwill,
161 | work stoppage, computer failure or malfunction, or any and all
162 | other commercial damages or losses), even if such Contributor
163 | has been advised of the possibility of such damages.
164 |
165 | 9. Accepting Warranty or Additional Liability. While redistributing
166 | the Work or Derivative Works thereof, You may choose to offer,
167 | and charge a fee for, acceptance of support, warranty, indemnity,
168 | or other liability obligations and/or rights consistent with this
169 | License. However, in accepting such obligations, You may act only
170 | on Your own behalf and on Your sole responsibility, not on behalf
171 | of any other Contributor, and only if You agree to indemnify,
172 | defend, and hold each Contributor harmless for any liability
173 | incurred by, or claims asserted against, such Contributor by reason
174 | of your accepting any such warranty or additional liability.
175 |
176 | END OF TERMS AND CONDITIONS
177 |
178 | APPENDIX: How to apply the Apache License to your work.
179 |
180 | To apply the Apache License to your work, attach the following
181 | boilerplate notice, with the fields enclosed by brackets "[]"
182 | replaced with your own identifying information. (Don't include
183 | the brackets!) The text should be enclosed in the appropriate
184 | comment syntax for the file format. We also recommend that a
185 | file or class name and description of purpose be included on the
186 | same "printed page" as the copyright notice for easier
187 | identification within third-party archives.
188 |
189 | Copyright [yyyy] [name of copyright owner]
190 |
191 | Licensed under the Apache License, Version 2.0 (the "License");
192 | you may not use this file except in compliance with the License.
193 | You may obtain a copy of the License at
194 |
195 | http://www.apache.org/licenses/LICENSE-2.0
196 |
197 | Unless required by applicable law or agreed to in writing, software
198 | distributed under the License is distributed on an "AS IS" BASIS,
199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200 | See the License for the specific language governing permissions and
201 | limitations under the License.
202 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # S1P :: Gateway
2 | Based on the new Spring Cloud Gateway, configured to use the Spring Cloud Kubernetes Discovery and Config modules to automatically register routes to (k8s) services matching with the following SPEL Filter:
3 | **metadata.labels['s1p'] = true**
4 |
5 | Only if the services contain this label will be automatically registered and the gateway will forward requests to them.
6 |
7 | ```
8 |
9 | org.springframework.cloud
10 | spring-cloud-starter-gateway
11 |
12 |
13 | org.springframework.cloud
14 | spring-cloud-kubernetes-discovery
15 |
16 |
17 | org.springframework.cloud
18 | spring-cloud-kubernetes-config
19 |
20 | ```
21 |
22 | You can also find inside the [charts/s1p-gateway/templates](charts/s1p-gateway/templates) directory the descriptors
23 | needed to deploy this gateway and to grant access to the Kubernetes APIs. The Role, RoleBinding and Services accounts
24 | are configured to enable the deployed container to access the Kubernetes APIs from inside a Pod.
25 |
26 |
--------------------------------------------------------------------------------
/charts/.DS_Store:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/salaboy/s1p_gateway/779a3f0e867fb295b3163a82b28c686b16672d05/charts/.DS_Store
--------------------------------------------------------------------------------
/charts/preview/Chart.yaml:
--------------------------------------------------------------------------------
1 | apiVersion: v1
2 | description: A Helm chart for Kubernetes
3 | icon: https://raw.githubusercontent.com/jenkins-x/jenkins-x-platform/master/images/java.png
4 | name: preview
5 | version: 0.1.0-SNAPSHOT
6 |
--------------------------------------------------------------------------------
/charts/preview/Makefile:
--------------------------------------------------------------------------------
1 | OS := $(shell uname)
2 |
3 | preview:
4 | ifeq ($(OS),Darwin)
5 | sed -i "" -e "s/version:.*/version: $(PREVIEW_VERSION)/" Chart.yaml
6 | sed -i "" -e "s/version:.*/version: $(PREVIEW_VERSION)/" ../*/Chart.yaml
7 | sed -i "" -e "s/tag: .*/tag: $(PREVIEW_VERSION)/" values.yaml
8 | else ifeq ($(OS),Linux)
9 | sed -i -e "s/version:.*/version: $(PREVIEW_VERSION)/" Chart.yaml
10 | sed -i -e "s/version:.*/version: $(PREVIEW_VERSION)/" ../*/Chart.yaml
11 | sed -i -e "s|repository: .*|repository: $(DOCKER_REGISTRY)\/salaboy\/s1p-gateway|" values.yaml
12 | sed -i -e "s/tag: .*/tag: $(PREVIEW_VERSION)/" values.yaml
13 | else
14 | echo "platfrom $(OS) not supported to release from"
15 | exit -1
16 | endif
17 | echo " version: $(PREVIEW_VERSION)" >> requirements.yaml
18 | jx step helm build
19 |
--------------------------------------------------------------------------------
/charts/preview/requirements.yaml:
--------------------------------------------------------------------------------
1 |
2 | dependencies:
3 | - alias: expose
4 | name: exposecontroller
5 | repository: https://chartmuseum.build.cd.jenkins-x.io
6 | version: 2.3.56
7 | - alias: cleanup
8 | name: exposecontroller
9 | repository: https://chartmuseum.build.cd.jenkins-x.io
10 | version: 2.3.56
11 | - alias: preview
12 | name: s1p-gateway
13 | repository: file://../s1p-gateway
14 |
--------------------------------------------------------------------------------
/charts/preview/values.yaml:
--------------------------------------------------------------------------------
1 |
2 | expose:
3 | Annotations:
4 | helm.sh/hook: post-install,post-upgrade
5 | helm.sh/hook-delete-policy: hook-succeeded
6 | config:
7 | exposer: Ingress
8 | http: true
9 | tlsacme: false
10 |
11 | cleanup:
12 | Args:
13 | - --cleanup
14 | Annotations:
15 | helm.sh/hook: pre-delete
16 | helm.sh/hook-delete-policy: hook-succeeded
17 |
18 | preview:
19 | image:
20 | repository:
21 | tag:
22 | pullPolicy: IfNotPresent
--------------------------------------------------------------------------------
/charts/s1p-gateway/.DS_Store:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/salaboy/s1p_gateway/779a3f0e867fb295b3163a82b28c686b16672d05/charts/s1p-gateway/.DS_Store
--------------------------------------------------------------------------------
/charts/s1p-gateway/.helmignore:
--------------------------------------------------------------------------------
1 | # Patterns to ignore when building packages.
2 | # This supports shell glob matching, relative path matching, and
3 | # negation (prefixed with !). Only one pattern per line.
4 | .DS_Store
5 | # Common VCS dirs
6 | .git/
7 | .gitignore
8 | .bzr/
9 | .bzrignore
10 | .hg/
11 | .hgignore
12 | .svn/
13 | # Common backup files
14 | *.swp
15 | *.bak
16 | *.tmp
17 | *~
18 | # Various IDEs
19 | .project
20 | .idea/
21 | *.tmproj
22 |
--------------------------------------------------------------------------------
/charts/s1p-gateway/Chart.yaml:
--------------------------------------------------------------------------------
1 | apiVersion: v1
2 | description: A Helm chart for Kubernetes
3 | icon: https://raw.githubusercontent.com/jenkins-x/jenkins-x-platform/master/images/java.png
4 | name: s1p-gateway
5 | version: 0.1.0-SNAPSHOT
6 |
--------------------------------------------------------------------------------
/charts/s1p-gateway/Makefile:
--------------------------------------------------------------------------------
1 | CHART_REPO := http://jenkins-x-chartmuseum:8080
2 | CURRENT=$(pwd)
3 | NAME := s1p-gateway
4 | OS := $(shell uname)
5 | RELEASE_VERSION := $(shell cat ../../VERSION)
6 |
7 | build: clean
8 | rm -rf requirements.lock
9 | helm dependency build
10 | helm lint
11 |
12 | install: clean build
13 | helm install . --name ${NAME}
14 |
15 | upgrade: clean build
16 | helm upgrade ${NAME} .
17 |
18 | delete:
19 | helm delete --purge ${NAME}
20 |
21 | clean:
22 | rm -rf charts
23 | rm -rf ${NAME}*.tgz
24 |
25 | release: clean
26 | helm dependency build
27 | helm lint
28 | helm init --client-only
29 | helm package .
30 | curl --fail -u $(CHARTMUSEUM_CREDS_USR):$(CHARTMUSEUM_CREDS_PSW) --data-binary "@$(NAME)-$(shell sed -n 's/^version: //p' Chart.yaml).tgz" $(CHART_REPO)/api/charts
31 | rm -rf ${NAME}*.tgz%
32 |
33 | tag:
34 | ifeq ($(OS),Darwin)
35 | sed -i "" -e "s/version:.*/version: $(RELEASE_VERSION)/" Chart.yaml
36 | sed -i "" -e "s/tag: .*/tag: $(RELEASE_VERSION)/" values.yaml
37 | else ifeq ($(OS),Linux)
38 | sed -i -e "s/version:.*/version: $(RELEASE_VERSION)/" Chart.yaml
39 | sed -i -e "s|repository: .*|repository: $(DOCKER_REGISTRY)\/salaboy\/s1p-gateway|" values.yaml
40 | sed -i -e "s/tag: .*/tag: $(RELEASE_VERSION)/" values.yaml
41 | else
42 | echo "platfrom $(OS) not supported to release from"
43 | exit -1
44 | endif
45 | git add --all
46 | git commit -m "release $(RELEASE_VERSION)" --allow-empty # if first release then no verion update is performed
47 | git tag -fa v$(RELEASE_VERSION) -m "Release version $(RELEASE_VERSION)"
48 | git push origin v$(RELEASE_VERSION)
49 |
--------------------------------------------------------------------------------
/charts/s1p-gateway/README.md:
--------------------------------------------------------------------------------
1 | # Java application
--------------------------------------------------------------------------------
/charts/s1p-gateway/templates/NOTES.txt:
--------------------------------------------------------------------------------
1 |
2 | Get the application URL by running these commands:
3 |
4 | kubectl get ingress {{ template "fullname" . }}
5 |
--------------------------------------------------------------------------------
/charts/s1p-gateway/templates/_helpers.tpl:
--------------------------------------------------------------------------------
1 | {{/* vim: set filetype=mustache: */}}
2 | {{/*
3 | Expand the name of the chart.
4 | */}}
5 | {{- define "name" -}}
6 | {{- default .Chart.Name .Values.nameOverride | trunc 63 | trimSuffix "-" -}}
7 | {{- end -}}
8 |
9 | {{/*
10 | Create a default fully qualified app name.
11 | We truncate at 63 chars because some Kubernetes name fields are limited to this (by the DNS naming spec).
12 | */}}
13 | {{- define "fullname" -}}
14 | {{- $name := default .Chart.Name .Values.nameOverride -}}
15 | {{- printf "%s-%s" .Release.Name $name | trunc 63 | trimSuffix "-" -}}
16 | {{- end -}}
17 |
--------------------------------------------------------------------------------
/charts/s1p-gateway/templates/deployment.yaml:
--------------------------------------------------------------------------------
1 | apiVersion: extensions/v1beta1
2 | kind: Deployment
3 | metadata:
4 | name: {{ template "fullname" . }}
5 | labels:
6 | draft: {{ default "draft-app" .Values.draft }}
7 | chart: "{{ .Chart.Name }}-{{ .Chart.Version | replace "+" "_" }}"
8 | spec:
9 | replicas: {{ .Values.replicaCount }}
10 | template:
11 | metadata:
12 | labels:
13 | draft: {{ default "draft-app" .Values.draft }}
14 | app: {{ template "fullname" . }}
15 | {{- if .Values.podAnnotations }}
16 | annotations:
17 | {{ toYaml .Values.podAnnotations | indent 8 }}
18 | {{- end }}
19 | spec:
20 | containers:
21 | - name: {{ .Chart.Name }}
22 | image: "{{ .Values.image.repository }}:{{ .Values.image.tag }}"
23 | env:
24 | - name: JAVA_OPTS
25 | value: -Xmx{{ .Values.javaOpts.xmx }} -Xms{{ .Values.javaOpts.xms }} {{ .Values.javaOpts.other}}
26 | imagePullPolicy: {{ .Values.image.pullPolicy }}
27 | ports:
28 | - containerPort: {{ .Values.service.internalPort }}
29 | livenessProbe:
30 | httpGet:
31 | path: {{ .Values.probePath }}
32 | port: {{ .Values.service.internalPort }}
33 | initialDelaySeconds: {{ .Values.livenessProbe.initialDelaySeconds }}
34 | periodSeconds: {{ .Values.livenessProbe.periodSeconds }}
35 | successThreshold: {{ .Values.livenessProbe.successThreshold }}
36 | timeoutSeconds: {{ .Values.livenessProbe.timeoutSeconds }}
37 | readinessProbe:
38 | httpGet:
39 | path: {{ .Values.probePath }}
40 | port: {{ .Values.service.internalPort }}
41 | periodSeconds: {{ .Values.readinessProbe.periodSeconds }}
42 | successThreshold: {{ .Values.readinessProbe.successThreshold }}
43 | timeoutSeconds: {{ .Values.readinessProbe.timeoutSeconds }}
44 | resources:
45 | {{ toYaml .Values.resources | indent 12 }}
46 | terminationGracePeriodSeconds: {{ .Values.terminationGracePeriodSeconds }}
47 | serviceAccountName: {{ .Chart.Name }}
--------------------------------------------------------------------------------
/charts/s1p-gateway/templates/role.yaml:
--------------------------------------------------------------------------------
1 | apiVersion: rbac.authorization.k8s.io/v1
2 | kind: Role
3 | metadata:
4 | name: {{ .Chart.Name }}
5 | rules:
6 | - apiGroups:
7 | - extensions
8 | resources:
9 | - ingresses
10 | verbs:
11 | - get
12 | - list
13 | - watch
14 | - patch
15 | - create
16 | - update
17 | - delete
18 | - apiGroups:
19 | - ""
20 | resources:
21 | - configmaps
22 | - services
23 | - endpoints
24 | - pods
25 | - configmaps
26 | verbs:
27 | - get
28 | - list
29 | - watch
30 | - patch
31 | - update
32 | - apiGroups:
33 | - apps
34 | resources:
35 | - deployments
36 | verbs:
37 | - get
38 | - list
39 | - watch
40 | - patch
41 | - update
42 | - apiGroups:
43 | - ""
44 | resources:
45 | - routes
46 | verbs:
47 | - get
48 | - list
49 | - watch
50 | - patch
51 | - create
52 | - update
53 | - delete
54 |
--------------------------------------------------------------------------------
/charts/s1p-gateway/templates/rolebinding.yaml:
--------------------------------------------------------------------------------
1 | apiVersion: rbac.authorization.k8s.io/v1
2 | kind: RoleBinding
3 | metadata:
4 | name: {{ .Chart.Name }}
5 | namespace: {{ .Release.Namespace }}
6 | roleRef:
7 | apiGroup: rbac.authorization.k8s.io
8 | kind: Role
9 | name: {{ .Chart.Name }}
10 | subjects:
11 | - kind: ServiceAccount
12 | name: {{ .Chart.Name }}
13 | namespace: {{ .Release.Namespace }}
14 |
--------------------------------------------------------------------------------
/charts/s1p-gateway/templates/service.yaml:
--------------------------------------------------------------------------------
1 | apiVersion: v1
2 | kind: Service
3 | metadata:
4 | {{- if .Values.service.name }}
5 | name: {{ .Values.service.name }}
6 | {{- else }}
7 | name: {{ template "fullname" . }}
8 | {{- end }}
9 | labels:
10 | spring-boot: "true"
11 | chart: "{{ .Chart.Name }}-{{ .Chart.Version | replace "+" "_" }}"
12 | {{- if .Values.service.annotations }}
13 | annotations:
14 | {{ toYaml .Values.service.annotations | indent 4 }}
15 | {{- end }}
16 | spec:
17 | type: {{ .Values.service.type }}
18 | ports:
19 | - port: {{ .Values.service.externalPort }}
20 | targetPort: {{ .Values.service.internalPort }}
21 | protocol: TCP
22 | name: http
23 | selector:
24 | app: {{ template "fullname" . }}
25 |
--------------------------------------------------------------------------------
/charts/s1p-gateway/templates/serviceaccount.yaml:
--------------------------------------------------------------------------------
1 | apiVersion: v1
2 | kind: ServiceAccount
3 | metadata:
4 | labels:
5 | app: {{ .Chart.Name }}
6 | chart: "{{ .Chart.Name }}-{{ .Chart.Version }}"
7 | release: "{{ .Release.Name }}"
8 | heritage: "{{ .Release.Service }}"
9 | name: {{ .Chart.Name }}
10 |
--------------------------------------------------------------------------------
/charts/s1p-gateway/values.yaml:
--------------------------------------------------------------------------------
1 | # Default values for Maven projects.
2 | # This is a YAML-formatted file.
3 | # Declare variables to be passed into your templates.
4 | replicaCount: 1
5 | image:
6 | repository: draft
7 | tag: dev
8 | pullPolicy: IfNotPresent
9 | service:
10 | name: s1p-gateway
11 | type: ClusterIP
12 | externalPort: 80
13 | internalPort: 8080
14 | annotations:
15 | fabric8.io/expose: "true"
16 | fabric8.io/ingress.annotations: "kubernetes.io/ingress.class: nginx"
17 | resources:
18 | limits:
19 | cpu: 1000m
20 | memory: 1024Mi
21 | requests:
22 | cpu: 1000m
23 | memory: 1024Mi
24 | probePath: /actuator/health
25 | livenessProbe:
26 | initialDelaySeconds: 60
27 | periodSeconds: 10
28 | successThreshold: 1
29 | timeoutSeconds: 1
30 | readinessProbe:
31 | periodSeconds: 10
32 | successThreshold: 1
33 | timeoutSeconds: 1
34 | terminationGracePeriodSeconds: 10
35 | javaOpts:
36 | xmx: 1024m
37 | xms: 768m
38 | other: -XX:+UnlockExperimentalVMOptions -XX:+UseCGroupMemoryLimitForHeap -Dsun.zip.disableMemoryMapping=true -XX:+UseParallelGC -XX:MinHeapFreeRatio=5 -XX:MaxHeapFreeRatio=10 -XX:GCTimeRatio=4 -XX:AdaptiveSizePolicyWeight=90
39 |
--------------------------------------------------------------------------------
/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
5 | 4.0.0
6 | org.spring.cloud.k8s.s1p
7 | s1p-gateway
8 | 1.0-SNAPSHOT
9 | S1P :: Gateway
10 | S1P :: Gateway
11 |
12 | 1.8
13 | UTF-8
14 | UTF-8
15 | 3.7.0
16 | 2.0.4.RELEASE
17 | Finchley.SR1
18 | 1.0.0.BUILD-SNAPSHOT
19 |
20 |
21 |
22 |
23 | org.springframework.boot
24 | spring-boot-dependencies
25 | ${spring-boot.version}
26 | pom
27 | import
28 |
29 |
30 | org.springframework.cloud
31 | spring-cloud-dependencies
32 | ${spring-cloud.version}
33 | pom
34 | import
35 |
36 |
37 | org.springframework.cloud
38 | spring-cloud-kubernetes-dependencies
39 | ${spring.cloud.k8s.version}
40 | pom
41 | import
42 |
43 |
44 |
45 |
46 |
47 | org.springframework.boot
48 | spring-boot-starter-actuator
49 |
50 |
51 | org.springframework.boot
52 | spring-boot-autoconfigure
53 |
54 |
55 | org.springframework.cloud
56 | spring-cloud-starter-netflix-hystrix
57 |
58 |
59 | org.springframework.cloud
60 | spring-cloud-starter-gateway
61 |
62 |
63 | org.springframework.cloud
64 | spring-cloud-kubernetes-discovery
65 |
66 |
67 | org.springframework.cloud
68 | spring-cloud-kubernetes-config
69 |
70 |
71 |
72 |
73 |
74 | org.apache.maven.plugins
75 | maven-compiler-plugin
76 | ${maven-compiler-plugin.version}
77 |
78 | ${java.version}
79 | ${java.version}
80 | true
81 | true
82 | true
83 |
84 |
85 |
86 | org.springframework.boot
87 | spring-boot-maven-plugin
88 |
89 |
90 |
91 | repackage
92 | build-info
93 |
94 |
95 |
96 |
97 |
98 | org.apache.maven.plugins
99 | maven-deploy-plugin
100 | 2.8.2
101 |
102 |
103 |
104 |
105 |
106 | jenkinsx
107 | Jenkins X Releases
108 | http://nexus.jx.35.195.224.137.nip.io/repository/maven-group/
109 |
110 | true
111 |
112 |
113 |
114 |
115 |
--------------------------------------------------------------------------------
/skaffold.yaml:
--------------------------------------------------------------------------------
1 | apiVersion: skaffold/v1alpha2
2 | kind: Config
3 | build:
4 | tagPolicy:
5 | envTemplate:
6 | template: "{{.DOCKER_REGISTRY}}/salaboy/s1p-gateway:{{.VERSION}}"
7 | artifacts:
8 | - imageName: changeme
9 | workspace: .
10 | docker: {}
11 | local: {}
12 | deploy:
13 | kubectl:
14 | manifests:
15 | profiles:
16 | - name: dev
17 | build:
18 | tagPolicy:
19 | envTemplate:
20 | template: "{{.DOCKER_REGISTRY}}/salaboy/s1p-gateway:{{.DIGEST_HEX}}"
21 | artifacts:
22 | - docker: {}
23 | local: {}
24 | deploy:
25 | helm:
26 | releases:
27 | - name: s1p-gateway
28 | chartPath: charts/s1p-gateway
29 | setValueTemplates:
30 | image.repository: "{{.DOCKER_REGISTRY}}/salaboy/s1p-gateway"
31 | image.tag: "{{.TAG}}"
32 |
--------------------------------------------------------------------------------
/src/main/java/org/s1p/demo/gateway/GatewayApplication.java:
--------------------------------------------------------------------------------
1 | package org.s1p.demo.gateway;
2 |
3 | import org.springframework.boot.SpringApplication;
4 | import org.springframework.boot.autoconfigure.SpringBootApplication;
5 | import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
6 |
7 | @EnableDiscoveryClient
8 | @SpringBootApplication
9 | public class GatewayApplication {
10 |
11 | public static void main(String[] args) {
12 | SpringApplication.run(GatewayApplication.class,
13 | args);
14 | }
15 |
16 | }
17 |
--------------------------------------------------------------------------------
/src/main/resources/application.yml:
--------------------------------------------------------------------------------
1 | spring:
2 | application.name: gateway
3 | cloud:
4 | gateway:
5 | discovery:
6 | locator:
7 | enabled: true
8 | url-expression: "'http://'+serviceId"
9 | kubernetes:
10 | reload:
11 | enabled: true
12 | mode: polling
13 | period: 5000
14 | discovery:
15 | filter: "metadata.labels['s1p']"
16 |
17 |
18 | server.port: 8080
19 | logging:
20 | level:
21 | org.springframework.cloud.gateway: TRACE
22 | org.springframework.cloud.loadbalancer: TRACE
23 | management:
24 | endpoints:
25 | web:
26 | exposure:
27 | include: '*'
28 | endpoint:
29 | health:
30 | enabled: true
31 | restart:
32 | enabled: true
33 | info:
34 | enabled: true
--------------------------------------------------------------------------------
/src/main/resources/bootstrap.yml:
--------------------------------------------------------------------------------
1 | spring:
2 | cloud:
3 | kubernetes:
4 | reload:
5 | enabled: true
6 | mode: polling
7 | period: 5000
--------------------------------------------------------------------------------
/src/main/resources/logback-spring.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 | logstash:5000
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
--------------------------------------------------------------------------------