Skip to content

Commit 4bd4b3c

Browse files
committed
Merge branch 'main' into wait-for-postgres
- remove PCI
2 parents 090362e + 0dab099 commit 4bd4b3c

File tree

8 files changed

+118
-65
lines changed

8 files changed

+118
-65
lines changed

Dockerfile

+4-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
FROM golang:1.18-alpine as builder
22

3+
ARG version
34
WORKDIR /app
45

56
COPY . ./
@@ -17,4 +18,6 @@ COPY --from=builder /app/views/ ./views/
1718

1819
EXPOSE 8080
1920

20-
CMD [ "/app/todo-server" ]
21+
ARG version
22+
ENV VERSION=${version}
23+
CMD [ "/app/todo-server" ]

README.md

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
# Sample Golang To Do app
22

3-
The application code is based on a [blog](https://blog.logrocket.com/building-simple-app-go-postgresql/) published by Emmanuel John.
3+
The application code is based on a
4+
[blog](https://blog.logrocket.com/building-simple-app-go-postgresql/) published
5+
by Emmanuel John.
46

57
## Running
68

ci/Jenkinsfile

+21-31
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,23 @@
1-
podTemplate(yaml: '''
2-
apiVersion: v1
3-
kind: Pod
4-
spec:
5-
serviceAccountName: example-knative-jenkins-deployer
6-
containers:
7-
- name: kubectl
8-
image: bitnami/kubectl:1.22.13
9-
imagePullPolicy: Always
10-
command:
11-
- sleep
12-
args:
13-
- 99d
14-
securityContext:
15-
runAsUser: 0
16-
'''
17-
) {
1+
podTemplate(
2+
serviceAccount: 'example-knative-jenkins-deployer',
3+
containers: [
4+
containerTemplate(name: 'deploy', image: 'bitnami/kubectl:1.22.13', command: 'sleep', args: '99d', runAsUser: '0')
5+
]) {
186

19-
node(POD_LABEL) {
20-
stage('Deploy application') {
21-
git branch: 'main', url: 'https://github.com/syntasso/sample-golang-app.git'
22-
container('kubectl') {
23-
sh '''
24-
kubectl apply --filename ./k8s/serving.yaml
25-
until [ "$(curl -s -o /dev/null -w "%{http_code}" -H "host: todo.default.local.gd" kourier.kourier-system.svc.cluster.local)" -eq "200" ]
26-
do
27-
sleep 2
28-
done
29-
'''
30-
}
31-
}
32-
}
7+
node(POD_LABEL) {
8+
stage('deploy') {
9+
git branch: 'workshop-refactor', url: 'https://github.com/syntasso/sample-golang-app.git'
10+
container('deploy') {
11+
sh '''
12+
kubectl apply --filename ./k8s/app.yaml
13+
until [ "$(curl -s -o /dev/null -w "%{http_code}" -H "host: todo.local.gd" nginx-nginx-ingress.default.svc.cluster.local)" -eq "200" ]
14+
do
15+
sleep 2
16+
done
17+
'''
18+
}
19+
}
20+
}
3321
}
22+
23+

k8s/app.yaml

+67
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
---
2+
apiVersion: networking.k8s.io/v1
3+
kind: Ingress
4+
metadata:
5+
name: todo-ingress-resource-backend
6+
namespace: default
7+
spec:
8+
ingressClassName: nginx
9+
rules:
10+
- host: todo.local.gd
11+
http:
12+
paths:
13+
- path: /
14+
pathType: Prefix
15+
backend:
16+
service:
17+
name: todo
18+
port:
19+
number: 8080
20+
---
21+
apiVersion: v1
22+
kind: Service
23+
metadata:
24+
name: todo
25+
namespace: default
26+
spec:
27+
selector:
28+
run: todo
29+
ports:
30+
- name: web
31+
port: 8080
32+
protocol: TCP
33+
targetPort: 8080
34+
type: ClusterIP
35+
---
36+
apiVersion: apps/v1
37+
kind: Deployment
38+
metadata:
39+
labels:
40+
run: todo
41+
name: todo
42+
namespace: default
43+
spec:
44+
selector:
45+
matchLabels:
46+
run: todo
47+
template:
48+
metadata:
49+
labels:
50+
run: todo
51+
spec:
52+
containers:
53+
- image: syntasso/sample-todo-app:v0.1.2
54+
ports:
55+
- containerPort: 8080
56+
env:
57+
- name: PGPASSWORD
58+
valueFrom:
59+
secretKeyRef:
60+
name: postgres.acid-example-postgresql.credentials.postgresql.acid.zalan.do
61+
key: password
62+
- name: PGHOST
63+
value: acid-example-postgresql.default.svc.cluster.local
64+
- name: DBNAME
65+
value: bestdb
66+
imagePullPolicy: IfNotPresent
67+
name: todo

k8s/service-account.yaml

+13-1
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,20 @@ metadata:
2525
namespace: default
2626
rules:
2727
- apiGroups:
28-
- serving.knative.dev
28+
- ""
2929
resources:
3030
- services
3131
verbs:
3232
- "*"
33+
- apiGroups:
34+
- "networking.k8s.io"
35+
resources:
36+
- ingresses
37+
verbs:
38+
- "*"
39+
- apiGroups:
40+
- apps
41+
resources:
42+
- deployments
43+
verbs:
44+
- "*"

k8s/serving.yaml

-21
This file was deleted.

main.go

+6-5
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@ func main() {
2727

2828
connStr := fmt.Sprintf("postgresql://%s:%s@%s/%s?sslmode=%s", pgUser, pgPassword, pgHost, dbName, pgSSLMode)
2929

30+
version := os.Getenv("VERSION")
31+
fmt.Println("Version: ", version)
32+
3033
// Connect to database
3134
db, err := sql.Open("postgres", connStr)
3235
if err != nil {
@@ -50,7 +53,7 @@ func main() {
5053
})
5154

5255
app.Get("/", func(c *fiber.Ctx) error {
53-
return getTodos(c, db)
56+
return getTodos(c, db, version)
5457
})
5558

5659
app.Post("/", func(c *fiber.Ctx) error {
@@ -89,7 +92,7 @@ func main() {
8992
log.Println(app.Listen(fmt.Sprintf(":%v", port)))
9093
}
9194

92-
func getTodos(c *fiber.Ctx, db *sql.DB) error {
95+
func getTodos(c *fiber.Ctx, db *sql.DB, version string) error {
9396
var res string
9497
var todos []string
9598
rows, err := db.Query("SELECT * FROM todos")
@@ -104,12 +107,10 @@ func getTodos(c *fiber.Ctx, db *sql.DB) error {
104107
todos = append(todos, res)
105108
}
106109

107-
containsCC := os.Getenv("CONTAINS_CC") == "true"
108-
109110
return c.Render("index", fiber.Map{
110111
"Todos": todos,
111112
"Enterprise": os.Getenv("ENTERPRISE"),
112-
"PCI": containsCC,
113+
"Version": version,
113114
})
114115
}
115116

views/index.html

+4-5
Original file line numberDiff line numberDiff line change
@@ -23,19 +23,18 @@
2323
{{ if .Enterprise }}
2424
<br /><strong class="text-secondary">Enterprise Edition™️</strong>
2525
{{ end }}
26-
27-
{{ if .PCI }}
28-
<br /><strong class="text-secondary">PCI-Safe Edition™️</strong>
26+
{{ if .Version }}
27+
<br /><strong class="text-secondary">Version {{ .Version }}</strong>
2928
{{ end }}
3029
</div>
3130
</div>
3231
</div>
3332
<!-- Create todo section -->
3433
<div class="row m-1 p-3">
3534
<div class="col col-11 mx-auto">
36-
<form action="/" method="POST" class="row bg-white rounded shadow-sm p-2 add-todo-wrapper align-items-center justify-content-center">
35+
<form action="/" method="POST" autocomplete="off" class="row bg-white rounded shadow-sm p-2 add-todo-wrapper align-items-center justify-content-center">
3736
<div class="col">
38-
<input name="Item" class="form-control form-control-lg border-0 add-todo-input bg-transparent rounded" type="text" placeholder="Add new ..">
37+
<input name="Item" autocomplete="off" class="form-control form-control-lg border-0 add-todo-input bg-transparent rounded" type="text" placeholder="Add new ..">
3938
</div>
4039
<div class="col-auto px-0 mx-0 mr-2">
4140
<button type="submit" class="btn btn-primary">Add</button>

0 commit comments

Comments
 (0)