Skip to content

Commit d437033

Browse files
committed
Update deployment configuration and Dockerfile for xdatabase-proxy
- Modify GitHub Actions workflow to include test job with matrix strategy for different OS and Go versions. - Update Dockerfile to specify GOOS and GOARCH for building the binary. - Change Kubernetes deployment ports from 5432 to 4545 and update health check ports to 8080.
1 parent de6436f commit d437033

File tree

3 files changed

+52
-12
lines changed

3 files changed

+52
-12
lines changed

.github/workflows/deploy.yaml

Lines changed: 37 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,49 @@ on:
99
- "v*"
1010
release:
1111
types: [created]
12+
pull_request:
13+
branches:
14+
- main
15+
- development
1216

1317
env:
1418
REGISTRY: ghcr.io
1519
IMAGE_NAME: ${{ github.repository }}
1620

1721
jobs:
22+
test:
23+
strategy:
24+
matrix:
25+
os: [ubuntu-latest, macos-latest]
26+
go-version: ["1.23.4"]
27+
runs-on: ${{ matrix.os }}
28+
steps:
29+
- name: Checkout repository
30+
uses: actions/checkout@v4
31+
32+
- name: Set up Go
33+
uses: actions/setup-go@v4
34+
with:
35+
go-version: ${{ matrix.go-version }}
36+
37+
- name: Cache Go modules
38+
uses: actions/cache@v4
39+
with:
40+
path: |
41+
~/.cache/go-build
42+
~/go/pkg/mod
43+
key: ${{ runner.os }}-go-${{ matrix.go-version }}-${{ hashFiles('**/go.sum') }}
44+
restore-keys: |
45+
${{ runner.os }}-go-${{ matrix.go-version }}-
46+
47+
- name: Run tests
48+
run: go test -v ./...
49+
50+
- name: Build binary for ${{ matrix.os }}
51+
run: CGO_ENABLED=0 go build -o xdatabase-proxy cmd/proxy/main.go
52+
1853
build-and-push:
54+
needs: test
1955
runs-on: ubuntu-latest
2056
if: github.ref == 'refs/heads/main' || startsWith(github.ref, 'refs/tags/v')
2157
permissions:
@@ -31,9 +67,6 @@ jobs:
3167
with:
3268
go-version: "1.23.4"
3369

34-
- name: Run tests
35-
run: go test -v ./...
36-
3770
- name: Log in to the Container registry
3871
uses: docker/login-action@v3
3972
with:
@@ -67,6 +100,7 @@ jobs:
67100
platforms: linux/amd64,linux/arm64,linux/386
68101

69102
build-and-push-development:
103+
needs: test
70104
runs-on: ubuntu-latest
71105
if: github.ref == 'refs/heads/development'
72106
permissions:
@@ -82,9 +116,6 @@ jobs:
82116
with:
83117
go-version: "1.23.4"
84118

85-
- name: Run tests
86-
run: go test -v ./...
87-
88119
- name: Log in to the Container registry
89120
uses: docker/login-action@v3
90121
with:

Dockerfile

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,25 @@
1+
# Build stage
12
FROM golang:1.23.4-alpine as builder
23

34
WORKDIR /app
45

56
COPY . .
67

78
RUN go mod download
8-
RUN CGO_ENABLED=0 go build -o main cmd/proxy/main.go
9+
RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o main cmd/proxy/main.go
910

11+
# Runtime stage
1012
FROM alpine:latest as runner
1113

1214
WORKDIR /app
1315

16+
RUN apk add --no-cache ca-certificates tzdata
17+
1418
COPY --from=builder /app/main /app/main
1519

20+
EXPOSE 5432
21+
22+
HEALTHCHECK --interval=30s --timeout=3s --start-period=5s --retries=3 \
23+
CMD test -f /app/main || exit 1
24+
1625
CMD ["./main"]

kubernetes/examples/production/deploy.yaml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,8 @@ spec:
7575
image: ghcr.io/hasirciogluhq/xdatabase-proxy:latest
7676
imagePullPolicy: Always
7777
ports:
78-
- containerPort: 5432
79-
hostPort: 5432
78+
- containerPort: 4545
79+
hostPort: 4545
8080
name: proxy-port
8181
env:
8282
- name: MODE
@@ -86,7 +86,7 @@ spec:
8686
- name: NAMESPACE
8787
value: xdatabase-proxy
8888
- name: POSTGRESQL_PROXY_START_PORT
89-
value: "5432"
89+
value: "4545"
9090
resources:
9191
requests:
9292
cpu: 100m
@@ -97,7 +97,7 @@ spec:
9797
livenessProbe:
9898
httpGet:
9999
path: /healthz
100-
port: 80
100+
port: 8080
101101
scheme: HTTP
102102
initialDelaySeconds: 15
103103
periodSeconds: 20
@@ -107,7 +107,7 @@ spec:
107107
readinessProbe:
108108
httpGet:
109109
path: /ready
110-
port: 80
110+
port: 8080
111111
scheme: HTTP
112112
initialDelaySeconds: 5
113113
periodSeconds: 10

0 commit comments

Comments
 (0)