add prod builds and migrate env to a namespaced configuration in k8s

pull/7/head
Adam Veldhousen 12 months ago
parent 000ff9a711
commit ebfcccabfe
Signed by: adam
GPG Key ID: 6DB29003C6DD1E4B

@ -15,11 +15,44 @@ clobber:
@rm -f $(KUBECONFIG)
.PHONY: build
build:
docker build --build-arg "service=runner" -t bh/service-runner -f ./src/Dockerfile.service ./src
docker build --build-arg "service=catalog" -t bh/service-catalog -f ./src/Dockerfile.service ./src
docker build --build-arg "service=proxy-admin" -t bh/service-proxy-admin -f ./src/Dockerfile.service ./src
SERVICE = "catalog"
ORIGIN = "https://barretthousen.com"
BUILD_INITIATOR = "Development Machine"
VERSION = $(shell git rev-parse --verify --short HEAD)
GIT_REF = $(shell git rev-parse --verify HEAD)
BUILD_DATE := $(shell date +%Y-%m-%d-%T)
.PHONY: build-client-image
build-client-image:
docker build \
--label 'com.barretthousen.service=$(SERVICE)' \
--label 'com.barretthousen.version=$(VERSION)' \
--label 'com.barretthousen.git-ref=$(GIT_REF)' \
--label 'com.barretthousen.build-date=$(BUILD_DATE)' \
--label 'com.barrethousen.builder=$(BUILD_INITIATOR)' \
--build-arg 'origin=$(ORIGIN)' \
-t barretthousen/client-$(SERVICE):$(VERSION) \
-t git.vdhsn.com/barretthousen/client-$(SERVICE):$(VERSION) \
-f ./src/$(SERVICE)/Dockerfile.frontend ./src/$(SERVICE)
docker push git.vdhsn.com/barretthousen/client-$(SERVICE):$(VERSION)
.PHONY: build-backend-image
build-backend-image:
docker build \
--label 'com.barretthousen.service=$(SERVICE)' \
--label 'com.barretthousen.version="$(VERSION)"' \
--label 'com.barretthousen.git-ref="$(GIT_REF)"' \
--label 'com.barretthousen.build-date=$(BUILD_DATE)' \
--label 'com.barrethousen.builder=$(BUILD_INITIATOR)' \
--build-arg "service=$(SERVICE)" \
-t barretthousen/service-$(SERVICE):$(VERSION) \
-t git.vdhsn.com/barretthousen/service-$(SERVICE):$(VERSION) \
-f ./src/Dockerfile.prod-backend ./src
docker push git.vdhsn.com/barretthousen/service-$(SERVICE):$(VERSION)
.PHONY: push-image
push-image:
.PHONY: acceptance-test
acceptance-test:

@ -16,21 +16,22 @@ helm_repo('grafana', 'https://grafana.github.io/helm-charts', labels=["9-repos"]
helm_resource(
'ingress',
'traefik/traefik',
namespace='barretthousen-local',
flags=[
'--set', 'logs.access.enabled=true'
],
resource_deps=['traefik'],
port_forwards=[
port_forward(8000, 8000, name='Barretthousen'),
port_forward(9000, 9000, name='Traefik', link_path='/dashboard/#/')
],
resource_deps=['traefik'],
labels=["1-ingress"]
)
helm_resource(
'postgres',
'bitnami/postgresql',
resource_deps=['bitnami'],
namespace='barretthousen-local',
flags=[
'--set', 'fullnameOverride=bh-db',
'--set', 'auth.enablePostgresUser=true',
@ -39,6 +40,7 @@ helm_resource(
],
port_forwards=[
port_forward(5432, 5432, name='BH DB')],
resource_deps=['bitnami'],
labels=["9-data"])
@ -48,7 +50,8 @@ def bh_backend_service(service="", port_forwards=[], migrateDB=False, devMode=Tr
'{}-go-compile'.format(service),
'CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -gcflags "all=-N -l" -o .bin/{}-debug ./src/{}'.format(service, service),
deps=['./src/{}'.format(service), './src/lib'],
resource_deps=deps
resource_deps=deps,
labels=['3-compilation']
)
entry_cmd = [
@ -93,7 +96,7 @@ def bh_backend_service(service="", port_forwards=[], migrateDB=False, devMode=Tr
)
k8s_resource(
workload='local-{}'.format(service),
workload='{}-local'.format(service),
port_forwards=port_forwards,
labels=labels,
resource_deps=deps,
@ -124,7 +127,7 @@ docker_build(
target='development'
)
k8s_resource(
workload='local-web-client',
workload='web-client-local',
port_forwards=['8080:80'],
labels=['2-services'],
resource_deps=['ingress']
@ -153,6 +156,11 @@ k8s_yaml(
kustomize("./env/local")
)
k8s_resource(
workload='runner-sync-local',
labels='2-services'
)
k8s_resource(
workload='ingress',
labels='1-ingress',

@ -12,9 +12,11 @@ spec:
labels:
service: catalog
spec:
serviceAccountName: barretthousen-service
containers:
- name: catalog
image: barretthousen/service-catalog
image: barretthousen/service-catalog:prod
imagePullPolicy: Always
ports:
- containerPort: 5001
name: grpc

@ -1,4 +1,5 @@
resources:
- ./namespace.yaml
- ./catalog-deployment.yaml
- ./runner-deployment.yaml
- ./proxy-admin-deployment.yaml

@ -0,0 +1,15 @@
apiVersion: v1
kind: Namespace
metadata:
name: barretthousen
annotations:
description: |
environment for barretthousen
labels:
name: barretthousen
app: barretthousen
---
apiVersion: v1
kind: ServiceAccount
metadata:
name: barretthousen-service

@ -11,9 +11,11 @@ spec:
labels:
service: proxy-admin
spec:
serviceAccountName: barretthousen-service
containers:
- name: proxy-admin
image: barretthousen/service-proxy-admin
image: barretthousen/service-proxy-admin:prod
imagePullPolicy: Always
ports:
- containerPort: 80
name: http
@ -51,4 +53,4 @@ data:
log_level: 2
port: 80
endpoints:
runner: local-runner:5001
runner: runner-local:5001

@ -11,9 +11,11 @@ spec:
labels:
service: proxy-client
spec:
serviceAccountName: barretthousen-service
containers:
- name: proxy-client
image: barretthousen/service-proxy-client
image: barretthousen/service-proxy-client:prod
imagePullPolicy: Always
ports:
- containerPort: 80
name: http

@ -12,11 +12,11 @@ spec:
labels:
service: runner
spec:
serviceAccountName: barretthousen-service
containers:
- name: runner
image: barretthousen/service-runner
tty: true
stdin: true
image: barretthousen/service-runner:prod
imagePullPolicy: Always
ports:
- containerPort: 5001
name: grpc

@ -3,7 +3,7 @@ kind: CronJob
metadata:
name: runner-sync
spec:
schedule: "* * * * *"
schedule: "*/2 * * * *"
jobTemplate:
spec:
template:
@ -13,12 +13,12 @@ spec:
spec:
restartPolicy: OnFailure
containers:
- name: sync-runner
- name: runner-curl
image: curlimages/curl:latest
command:
[
"curl",
"http://local-proxy-admin/api/v1/sync",
"http://proxy-admin-local/api/v1/sync",
'-d=''{"target":"liveauctioneers"}''',
"-vvvv",
]

@ -11,9 +11,11 @@ spec:
labels:
app: web-client
spec:
serviceAccountName: barretthousen-service
containers:
- name: web-client
image: barretthousen/service-web-client
image: barretthousen/service-web-client:prod
imagePullPolicy: Always
stdin: true
tty: true
ports:

@ -4,11 +4,8 @@ resources:
commonLabels:
environment: beta
namePrefix: beta-
# patchesStrategicMerge:
# - debug-catalog.yaml
# - debug-runner.yaml
nameSuffix: -beta
namespace: barretthousen-beta
patches:
- target:
@ -18,6 +15,7 @@ patches:
- op: replace
path: /spec/rules/0/host
value: admin.beta.barretthousen.com
- target:
kind: Ingress
name: web
@ -25,3 +23,51 @@ patches:
- op: replace
path: /spec/rules/0/host
value: beta.barretthousen.com
- target:
kind: Deployment
name: catalog
patch: |-
- op: replace
path: /spec/template/spec/containers/0/image
value: git.vdhsn.com/barretthousen/service-catalog:beta
- target:
kind: Deployment
name: runner
patch: |-
- op: replace
path: /spec/template/spec/containers/0/image
value: git.vdhsn.com/barretthousen/service-runner:beta
- target:
kind: Deployment
name: proxy-admin
patch: |-
- op: replace
path: /spec/template/spec/containers/0/image
value: git.vdhsn.com/barretthousen/service-proxy-admin:beta
- target:
kind: Deployment
name: proxy-client
patch: |-
- op: replace
path: /spec/template/spec/containers/0/image
value: git.vdhsn.com/barretthousen/service-proxy-client:beta
- target:
kind: Deployment
name: web-client
patch: |-
- op: replace
path: /spec/template/spec/containers/0/image
value: git.vdhsn.com/barretthousen/client-web-client:beta
- target:
kind: ServiceAccount
name: barretthousen
patch: |-
- op: replace
path: /spec/template/spec/containers/0/image
value: git.vdhsn.com/barretthousen/client-web-client:beta

@ -4,13 +4,21 @@ resources:
commonLabels:
environment: local
namePrefix: local-
nameSuffix: -local
namespace: barretthousen-local
patchesStrategicMerge:
- debug-catalog.yaml
- debug-runner.yaml
patches:
- target:
kind: CronJob
name: runner-sync
patch: |-
- op: replace
path: /spec/schedule
value: "* * * * *"
- target:
kind: Ingress
name: admin

@ -1,4 +1,4 @@
FROM golang:1.19-alpine as builder
FROM golang:1.19 as builder
ARG service
@ -7,11 +7,12 @@ RUN go install github.com/kyleconroy/sqlc/cmd/sqlc@latest
COPY . /go/src
WORKDIR /go/src/${service}
WORKDIR /go/src/
RUN /go/bin/sqlc generate -f /go/src/sqlc.yaml
RUN /go/bin/buf mod update /go/src/src \
&& /go/bin/buf generate
RUN /go/bin/buf mod update /go/src && /go/bin/buf generate
WORKDIR /go/src/${service}
RUN go mod tidy \
&& CGO_ENABLED=0 go build -v -gcflags="-trimpath=$(go env GOPATH)" -asmflags="-trimpath=$(go env GOPATH)" -o /opt/${service} /go/src/${service}
@ -24,4 +25,4 @@ COPY --from=builder /opt/${service} /opt/${service}
ENV SERVICE=${SERVICE}
ENTRYPOINT ['/opt/${SERVICE}']
ENTRYPOINT ["/opt/${SERVICE}"]

@ -42,7 +42,7 @@ func main() {
flag.Parse()
kernel.Run(context.Background(), &runnerApp{
CatalogEndpoint: "local-catalog:5001",
CatalogEndpoint: "catalog-local:5001",
LogLevel: kernel.LevelTrace,
Port: 5001,
})

@ -23,20 +23,33 @@ WORKDIR /opt/web-client
COPY --from=development /opt/web-client .
RUN npm build \
RUN npm run build \
&& cp -rv /opt/web-client/package.json /opt/web-client/build \
&& cp -rv /opt/web-client/package-lock.json /opt/web-client/build
FROM node:lts AS production
LABEL com.barretthousen.service="web-client"
LABEL com.barretthousen.tags="frontend,public"
LABEL com.barretthousen.release-date="2023-05-01"
LABEL com.barretthousen.version="alpha-0.0.1"
LABEL com.barretthousen.git-ref="000000000000000000000000000000000000000000000000"
ARG origin=https://barretthousen.com
ENV ENV=production
ENV PROTOCOL_HEADER=x-forwarded-proto
ENV HOST_HEADER=x-forwarded-host
ENV ADDRESS_HEADER=True-Client-IP
ENV ORIGIN=${origin}
WORKDIR /opt
COPY --from=build /var/web-client/build/* /opt/web-client
COPY --from=build /opt/web-client/build/* /opt/web-client
ENV PORT 80
EXPOSE 80
ENTRYPOINT ['node']
CMD ['web-client']
ENTRYPOINT ["node", "web-client"]

@ -2,7 +2,7 @@ import { browser } from '$app/environment';
import type { PageLoad } from './$types';
// TODO: change to env var
const API_HOST = `${browser ? '': 'http://local-proxy-client.default'}/api/v1`;
const API_HOST = `${browser ? '': 'http://proxy-client-local'}/api/v1`;
interface SearchPageData {
page: number

Loading…
Cancel
Save