Skip to content

Commit a9ac038

Browse files
committed
cmd/relui: add deployment configuration
Add deployment configuration for relui using IAM database authentication. For golang/go#47401 Change-Id: Ifde113bd3e09d19eb69bffb5a0ce3689e6c6410a Reviewed-on: https://go-review.googlesource.com/c/build/+/363535 Trust: Alexander Rakoczy <[email protected]> Run-TryBot: Alexander Rakoczy <[email protected]> TryBot-Result: Go Bot <[email protected]> Reviewed-by: Heschi Kreinick <[email protected]>
1 parent da30d7a commit a9ac038

File tree

3 files changed

+111
-8
lines changed

3 files changed

+111
-8
lines changed

cmd/relui/Makefile

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,29 @@ migrate-down-up: docker
3939
test: postgres-dev docker-test
4040
docker run --rm --name=relui-test -v $(POSTGRES_RUN_DEV) -e PGUSER=$(POSTGRES_USER) -e PGDATABASE=relui-test golang/relui-test:$(VERSION)
4141

42+
DOCKER_IMAGE := golang/relui
43+
IMAGE_PROD := gcr.io/symbolic-datum-552/relui
44+
MUTABLE_VERSION := latest
45+
4246
.PHONY: docker
4347
docker:
44-
docker build -f Dockerfile -t golang/relui:$(VERSION) ../..
48+
docker build -f Dockerfile -t $(DOCKER_IMAGE):$(VERSION) ../..
4549

4650
.PHONY: docker-test
4751
docker-test:
4852
docker build -f Dockerfile.test -t golang/relui-test:$(VERSION) ../..
53+
54+
.PHONY: docker-prod
55+
docker-prod: docker
56+
docker tag $(DOCKER_IMAGE):$(VERSION) $(IMAGE_PROD):$(VERSION)
57+
docker tag $(DOCKER_IMAGE):$(VERSION) $(IMAGE_PROD):$(MUTABLE_VERSION)
58+
59+
.PHONY: push-prod
60+
push-prod: docker-prod
61+
docker push $(IMAGE_PROD):$(VERSION)
62+
docker push $(IMAGE_PROD):$(MUTABLE_VERSION)
63+
64+
.PHONY: deploy-prod
65+
deploy-prod: push-prod
66+
go install golang.org/x/build/cmd/xb
67+
xb --prod kubectl --namespace prod set image deployment/relui-deployment relui=$(IMAGE_PROD):$(VERSION)

cmd/relui/deployment-prod.yaml

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
apiVersion: apps/v1
2+
kind: Deployment
3+
metadata:
4+
namespace: prod
5+
name: relui-deployment
6+
spec:
7+
selector:
8+
matchLabels:
9+
app: relui
10+
strategy:
11+
type: Recreate
12+
template:
13+
metadata:
14+
labels:
15+
app: relui
16+
spec:
17+
serviceAccountName: relui
18+
containers:
19+
- name: relui
20+
image: gcr.io/symbolic-datum-552/relui:latest
21+
imagePullPolicy: Always
22+
command: ["/sbin/tini", "--", "./relui", "--listen-https-selfsigned=:444"]
23+
ports:
24+
- containerPort: 444
25+
env:
26+
- name: PGUSER
27+
value: relui
28+
- name: PGDATABASE
29+
value: relui-prod
30+
resources:
31+
requests:
32+
cpu: "2"
33+
memory: "4Gi"
34+
- name: cloud-sql-proxy
35+
# It is recommended to use the latest version of the Cloud SQL proxy
36+
image: gcr.io/cloudsql-docker/gce-proxy:latest
37+
command:
38+
- "/cloud_sql_proxy"
39+
40+
# If connecting from a VPC-native GKE cluster, you can use the
41+
# following flag to have the proxy connect over private IP
42+
- "-ip_address_types=PRIVATE"
43+
44+
# Replace DB_PORT with the port the proxy should listen on
45+
# Defaults: MySQL: 3306, Postgres: 5432, SQLServer: 1433
46+
- "-instances=symbolic-datum-552:us-central1:relui-prod-01=tcp:5432"
47+
securityContext:
48+
# The default Cloud SQL proxy image runs as the
49+
# "nonroot" user and group (uid: 65532) by default.
50+
runAsNonRoot: true
51+
# Resource configuration depends on an application's requirements. You
52+
# should adjust the following values based on what your application
53+
# needs. For details, see https://kubernetes.io/docs/concepts/configuration/manage-resources-containers/
54+
resources:
55+
requests:
56+
# The proxy's memory use scales linearly with the number of active
57+
# connections. Fewer open connections will use less memory. Adjust
58+
# this value based on your application's requirements.
59+
memory: "2Gi"
60+
# The proxy's CPU use scales linearly with the amount of IO between
61+
# the database and the application. Adjust this value based on your
62+
# application's requirements.
63+
cpu: "1"
64+
---
65+
apiVersion: v1
66+
kind: ServiceAccount
67+
metadata:
68+
namespace: prod
69+
name: relui
70+
annotations:
71+
iam.gke.io/gcp-service-account: [email protected]
72+
---
73+
apiVersion: v1
74+
kind: Service
75+
metadata:
76+
namespace: prod
77+
name: relui-internal
78+
annotations:
79+
cloud.google.com/neg: '{"ingress": false}'
80+
cloud.google.com/app-protocols: '{"https":"HTTP2"}'
81+
spec:
82+
ports:
83+
- port: 444
84+
targetPort: 444
85+
name: https
86+
selector:
87+
app: relui
88+
type: NodePort

cmd/relui/main.go

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@ import (
99
"context"
1010
"flag"
1111
"log"
12-
"os"
1312

1413
"github.com/jackc/pgx/v4/pgxpool"
14+
"golang.org/x/build/internal/https"
1515
"golang.org/x/build/internal/relui"
1616
)
1717

@@ -22,6 +22,7 @@ var (
2222
)
2323

2424
func main() {
25+
https.RegisterFlags(flag.CommandLine)
2526
flag.Parse()
2627
ctx := context.Background()
2728
if err := relui.InitDB(ctx, *pgConnect); err != nil {
@@ -50,10 +51,5 @@ func main() {
5051
if err != nil {
5152
log.Fatalf("relui.NewServer() = %v", err)
5253
}
53-
port := os.Getenv("PORT")
54-
if port == "" {
55-
port = "8080"
56-
}
57-
log.Printf("Listening on :" + port)
58-
log.Fatal(s.Serve(port))
54+
log.Fatalln(https.ListenAndServe(ctx, s))
5955
}

0 commit comments

Comments
 (0)