From 216049fcb66427d9ebce42924ad1bd8d6b392fcb Mon Sep 17 00:00:00 2001 From: river Date: Fri, 1 May 2026 10:48:30 +0300 Subject: [PATCH 1/6] feat: add Docker Buildx setup step in deployment workflow --- .github/workflows/deploy.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index af6b246..2ea1c73 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -36,6 +36,9 @@ jobs: type=sha,format=long latest + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v4 + - name: Build and push Docker image uses: docker/build-push-action@v7 with: From ee0654023ce762f487c01cc986013b38d99dcbfa Mon Sep 17 00:00:00 2001 From: river Date: Sat, 2 May 2026 09:50:11 +0300 Subject: [PATCH 2/6] feat: add Kubernetes cluster management commands and PostgreSQL cluster configuration --- Makefile | 14 +++++++++++++- README.md | 29 +++++++++++++++++++++++++++++ postgres-cluster.yaml | 22 ++++++++++++++++++++++ 3 files changed, 64 insertions(+), 1 deletion(-) create mode 100644 README.md create mode 100644 postgres-cluster.yaml diff --git a/Makefile b/Makefile index 70230f5..abb4d80 100644 --- a/Makefile +++ b/Makefile @@ -31,4 +31,16 @@ mock: server: go run main.go -.PHONY: postgres createdb dropdb migrateup migratedown sqlc test mock server migrateup1 migratedown1 +cluster_stop: + k3d cluster stop gobank-cluster + +cluster_start: + k3d cluster start gobank-cluster + +cluster_db: + kubectl apply -f postgres-cluster.yaml + +cluster_gobank: + k3d cluster create gobank-cluster --api-port 6550 -p "80:80@loadbalancer" -p "443:443@loadbalancer" --agents 2 + +.PHONY: postgres createdb dropdb migrateup migratedown sqlc test mock server migrateup1 migratedown1 cluster_db cluster_start cluster_stop cluster_gobank diff --git a/README.md b/README.md new file mode 100644 index 0000000..3a03b4d --- /dev/null +++ b/README.md @@ -0,0 +1,29 @@ +Create gobank cluster via: +```bash +make cluster_gobank +``` + +Create postgres database cluster credentials via: +```bash +kubectl create secret generic db-creds --from-literal=username=root --from-literal=password='' +``` + +Create postgres database cluster via: +```bash +make cluster_db +``` + +Start cluster via: +```bash +make cluster_start +``` + +Stop cluster via: +```bash +make cluster_stop +``` + +Expose a port to database via: +```bash +kubectl port-forward svc/gobank-db-rw 5432:5432 +``` \ No newline at end of file diff --git a/postgres-cluster.yaml b/postgres-cluster.yaml new file mode 100644 index 0000000..bb84009 --- /dev/null +++ b/postgres-cluster.yaml @@ -0,0 +1,22 @@ +apiVersion: postgresql.cnpg.io/v1 +kind: Cluster +metadata: + name: gobank-db +spec: + instances: 3 + + imageName: ghcr.io/cloudnative-pg/postgresql:18.3 + + bootstrap: + initdb: + database: gobank + owner: root + secret: + name: db-creds + + storage: + size: 1Gi + + affinity: + enablePodAntiAffinity: true + topologyKey: kubernetes.io/hostname \ No newline at end of file From 9c85eb8b2c64477bc628858d7b4dedf76a0560a9 Mon Sep 17 00:00:00 2001 From: river Date: Sat, 2 May 2026 12:12:54 +0300 Subject: [PATCH 3/6] feat: add create_secret target to Makefile and update README; introduce gobank-api deployment configuration --- .github/workflows/deploy.yml | 4 +- Makefile | 16 +++++++- README.md | 7 +++- gobank-api-deployment.yaml | 73 ++++++++++++++++++++++++++++++++++++ 4 files changed, 97 insertions(+), 3 deletions(-) create mode 100644 gobank-api-deployment.yaml diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index 2ea1c73..7cef36a 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -34,7 +34,9 @@ jobs: images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} tags: | type=sha,format=long - latest + type=raw,value=latest + flavor: | + lower=true - name: Set up Docker Buildx uses: docker/setup-buildx-action@v4 diff --git a/Makefile b/Makefile index abb4d80..0b97e9c 100644 --- a/Makefile +++ b/Makefile @@ -31,6 +31,14 @@ mock: server: go run main.go +create_secret: + $(eval ENCODED_PWD := $(shell python3 -c "import urllib.parse; print(urllib.parse.quote('$(PWD)', safe=''))")) + @kubectl delete secret db-creds --ignore-not-found + @kubectl create secret generic db-creds \ + --from-literal=username=root \ + --from-literal=password='$(ENCODED_PWD)' + @echo "Secret created with encoded password." + cluster_stop: k3d cluster stop gobank-cluster @@ -40,7 +48,13 @@ cluster_start: cluster_db: kubectl apply -f postgres-cluster.yaml +cluster_gobank_api: + kubectl apply -f gobank-api-deployment.yaml + cluster_gobank: k3d cluster create gobank-cluster --api-port 6550 -p "80:80@loadbalancer" -p "443:443@loadbalancer" --agents 2 -.PHONY: postgres createdb dropdb migrateup migratedown sqlc test mock server migrateup1 migratedown1 cluster_db cluster_start cluster_stop cluster_gobank +db_tunnel: + kubectl port-forward svc/gobank-db-rw 5432:5432 + +.PHONY: postgres createdb dropdb migrateup migratedown sqlc test mock server migrateup1 migratedown1 cluster_db cluster_start cluster_stop cluster_gobank cluster_gobank_api create_secret db_tunnel diff --git a/README.md b/README.md index 3a03b4d..f031248 100644 --- a/README.md +++ b/README.md @@ -5,7 +5,7 @@ make cluster_gobank Create postgres database cluster credentials via: ```bash -kubectl create secret generic db-creds --from-literal=username=root --from-literal=password='' +make create_secret PWD='the_password' ``` Create postgres database cluster via: @@ -13,6 +13,11 @@ Create postgres database cluster via: make cluster_db ``` +Create gobank-api cluster via: +```bash +make cluster_gobank_api +``` + Start cluster via: ```bash make cluster_start diff --git a/gobank-api-deployment.yaml b/gobank-api-deployment.yaml new file mode 100644 index 0000000..5533380 --- /dev/null +++ b/gobank-api-deployment.yaml @@ -0,0 +1,73 @@ +apiVersion: apps/v1 +kind: Deployment +metadata: + name: gobank-api + labels: + app: gobank-api +spec: + replicas: 2 + selector: + matchLabels: + app: gobank-api + template: + metadata: + labels: + app: gobank-api + spec: + containers: + - name: gobank-api + image: ghcr.io/hypernaser/gobank:latest + ports: + - containerPort: 8080 + resources: + requests: + cpu: "100m" + memory: "64Mi" + limits: + cpu: "500m" + memory: "128Mi" + env: + - name: DB_USER + valueFrom: + secretKeyRef: + name: db-creds + key: username + - name: DB_PASSWORD + valueFrom: + secretKeyRef: + name: db-creds + key: password + - name: DB_SOURCE + value: "postgresql://$(DB_USER):$(DB_PASSWORD)@gobank-db-rw:5432/gobank?sslmode=disable" + +# The Service (The Internal Load Balancer) +apiVersion: v1 +kind: Service +metadata: + name: gobank-api-service +spec: + selector: + app: gobank-api + ports: + - protocol: TCP + port: 80 + targetPort: 8080 + +# The Ingress (The External Load Balancer) +apiVersion: networking.k8s.io/v1 +kind: Ingress +metadata: + name: gobank-ingress + annotations: + traefik.ingress.kubernetes.io/router.entrypoints: web +spec: + rules: + - http: + paths: + - path: / + pathType: Prefix + backend: + service: + name: gobank-api-service + port: + number: 80 \ No newline at end of file From bbb21a63340bf9543193ca4d1b38abb701ec94f0 Mon Sep 17 00:00:00 2001 From: river Date: Sat, 2 May 2026 14:17:52 +0300 Subject: [PATCH 4/6] refactor: remove create_secret target from Makefile; update README for secret management; adjust environment variables in gobank-api deployment --- Makefile | 10 +--------- README.md | 22 +++++++++++++++++++++- gobank-api-deployment.yaml | 14 +++++++------- 3 files changed, 29 insertions(+), 17 deletions(-) diff --git a/Makefile b/Makefile index 0b97e9c..9eaf60f 100644 --- a/Makefile +++ b/Makefile @@ -31,14 +31,6 @@ mock: server: go run main.go -create_secret: - $(eval ENCODED_PWD := $(shell python3 -c "import urllib.parse; print(urllib.parse.quote('$(PWD)', safe=''))")) - @kubectl delete secret db-creds --ignore-not-found - @kubectl create secret generic db-creds \ - --from-literal=username=root \ - --from-literal=password='$(ENCODED_PWD)' - @echo "Secret created with encoded password." - cluster_stop: k3d cluster stop gobank-cluster @@ -57,4 +49,4 @@ cluster_gobank: db_tunnel: kubectl port-forward svc/gobank-db-rw 5432:5432 -.PHONY: postgres createdb dropdb migrateup migratedown sqlc test mock server migrateup1 migratedown1 cluster_db cluster_start cluster_stop cluster_gobank cluster_gobank_api create_secret db_tunnel +.PHONY: postgres createdb dropdb migrateup migratedown sqlc test mock server migrateup1 migratedown1 cluster_db cluster_start cluster_stop cluster_gobank cluster_gobank_api db_tunnel diff --git a/README.md b/README.md index f031248..e1b17cc 100644 --- a/README.md +++ b/README.md @@ -5,7 +5,27 @@ make cluster_gobank Create postgres database cluster credentials via: ```bash -make create_secret PWD='the_password' +kubectl create secret generic db-creds --from-literal=username=root --from-literal=password='YOUR_PASSWORD_HERE' +``` + +Delete postgres database cluster credentials via: +```bash +kubectl delete secret db-creds +``` + +Check pods via: +```bash +kubectl get pods +``` + +Delete a deployment via: +```bash +kubectl delete deployment DEPLOYMENT_NAME +``` + +Apply a deployment yaml file via: +```bash +kubectl apply -f PATH_TO_YAML ``` Create postgres database cluster via: diff --git a/gobank-api-deployment.yaml b/gobank-api-deployment.yaml index 5533380..5472102 100644 --- a/gobank-api-deployment.yaml +++ b/gobank-api-deployment.yaml @@ -27,19 +27,19 @@ spec: cpu: "500m" memory: "128Mi" env: - - name: DB_USER + - name: PGPASSWORD valueFrom: secretKeyRef: name: db-creds - key: username - - name: DB_PASSWORD + key: password + - name: PGUSER valueFrom: secretKeyRef: name: db-creds - key: password + key: username - name: DB_SOURCE - value: "postgresql://$(DB_USER):$(DB_PASSWORD)@gobank-db-rw:5432/gobank?sslmode=disable" - + value: "postgres://gobank-db-rw:5432/gobank?sslmode=disable" +--- # The Service (The Internal Load Balancer) apiVersion: v1 kind: Service @@ -52,7 +52,7 @@ spec: - protocol: TCP port: 80 targetPort: 8080 - +--- # The Ingress (The External Load Balancer) apiVersion: networking.k8s.io/v1 kind: Ingress From 28335858c4fb99e0efed45f9938a41ed7cce768f Mon Sep 17 00:00:00 2001 From: river Date: Sat, 2 May 2026 14:28:19 +0300 Subject: [PATCH 5/6] docs: add section header for basic commands in README --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index e1b17cc..e08912d 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,6 @@ Create gobank cluster via: +# Basic Commands + ```bash make cluster_gobank ``` From dbddb9f3b92ba1d65613f57b8e4106149e7adc06 Mon Sep 17 00:00:00 2001 From: river Date: Sat, 2 May 2026 14:36:15 +0300 Subject: [PATCH 6/6] chore: remove unused flavor configuration from Docker metadata action --- .github/workflows/deploy.yml | 2 -- 1 file changed, 2 deletions(-) diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index 7cef36a..92b2107 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -35,8 +35,6 @@ jobs: tags: | type=sha,format=long type=raw,value=latest - flavor: | - lower=true - name: Set up Docker Buildx uses: docker/setup-buildx-action@v4