Skip to content

Commit fb1dc92

Browse files
committed
Merge upstream/main and resolve conflicts - use flag-based SSL
2 parents 5feb8f8 + f04b8cf commit fb1dc92

File tree

21 files changed

+318
-279
lines changed

21 files changed

+318
-279
lines changed

.github/workflows/build-and-publish.yml

Lines changed: 0 additions & 78 deletions
This file was deleted.

.github/workflows/pipeline.yml

Lines changed: 135 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,135 @@
1+
name: CI/CD - v0.3
2+
3+
on:
4+
push:
5+
pull_request:
6+
7+
jobs:
8+
Test:
9+
runs-on: ubuntu-latest
10+
11+
steps:
12+
- name: Checkout code
13+
uses: actions/checkout@v4
14+
15+
- name: Set up Go
16+
uses: actions/setup-go@v4
17+
with:
18+
go-version: "1.22"
19+
20+
- name: Cache Go modules
21+
uses: actions/cache@v4
22+
with:
23+
path: |
24+
~/.cache/go-build
25+
~/go/pkg/mod
26+
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
27+
restore-keys: |
28+
${{ runner.os }}-go-
29+
30+
- name: Install static analysis tools
31+
run: |
32+
go install golang.org/x/lint/golint@latest
33+
go install honnef.co/go/tools/cmd/staticcheck@latest
34+
go install github.com/securego/gosec/v2/cmd/gosec@latest
35+
go install github.com/psampaz/go-mod-outdated@latest
36+
go install github.com/remyoudompheng/go-misc/deadcode@latest
37+
38+
- name: Go static analysis
39+
run: |
40+
golint ./...
41+
staticcheck ./...
42+
go vet ./...
43+
deadcode .
44+
45+
- name: Dependency management
46+
run: |
47+
go mod vendor
48+
go mod verify
49+
go mod tidy
50+
51+
- name: Security scanning
52+
run: |
53+
gosec ./...
54+
55+
Build:
56+
needs: Test
57+
runs-on: ubuntu-latest
58+
59+
steps:
60+
- uses: actions/checkout@v4
61+
62+
- name: Set up Docker Buildx
63+
uses: docker/setup-buildx-action@v3
64+
65+
- name: Login to DockerHub
66+
uses: docker/login-action@v3
67+
with:
68+
username: ${{ secrets.DOCKER_USERNAME }}
69+
password: ${{ secrets.DOCKER_PASSWORD }}
70+
71+
- name: Docker build and push
72+
run: |
73+
docker buildx build \
74+
--platform linux/amd64 \
75+
--pull \
76+
--build-arg VERSION=v${{ github.run_number }} \
77+
--build-arg GIT_COMMIT=${{ github.sha }} \
78+
--build-arg BUILD_DATE=$(date -u +"%Y-%m-%dT%H:%M:%SZ") \
79+
--cache-from supporttools/go-sql-proxy:latest \
80+
-t supporttools/go-sql-proxy:"0.3.${{ github.run_number }}" \
81+
-t supporttools/go-sql-proxy:latest \
82+
--push \
83+
-f Dockerfile .
84+
85+
Publish:
86+
runs-on: ubuntu-latest
87+
needs:
88+
- Build
89+
90+
steps:
91+
- name: Checkout repository
92+
uses: actions/checkout@v4
93+
94+
- name: Set up Helm
95+
uses: azure/setup-helm@v4.2.0
96+
97+
- name: Helm Lint
98+
run: helm lint charts/go-sql-proxy/
99+
100+
- name: Set up Helm
101+
uses: azure/setup-helm@v1
102+
with:
103+
version: v3.7.1
104+
105+
- name: Package Helm chart
106+
run: |
107+
export CHART_VERSION="0.3.${{ github.run_number }}"
108+
export APP_VERSION="0.3.${{ github.run_number }}"
109+
export IMAGE_TAG="0.3.${{ github.run_number }}"
110+
echo "CHART_VERSION=${CHART_VERSION}"
111+
echo "APP_VERSION=${APP_VERSION}"
112+
envsubst < charts/go-sql-proxy/Chart.yaml.template > charts/go-sql-proxy/Chart.yaml
113+
envsubst < charts/go-sql-proxy/values.yaml.template > charts/go-sql-proxy/values.yaml
114+
helm package charts/go-sql-proxy --destination helm/repo
115+
116+
- name: Checkout helm-chart repository
117+
uses: actions/checkout@v4
118+
with:
119+
repository: supporttools/helm-chart
120+
path: helm-chart
121+
token: ${{ secrets.BOT_TOKEN }}
122+
123+
- name: Configure Git
124+
run: |
125+
git config --global user.email "github-action@users.noreply.github.com"
126+
git config --global user.name "GitHub Action"
127+
128+
- name: Update Helm repository
129+
run: |
130+
cp helm/repo/go-sql-proxy-*.tgz helm-chart/
131+
cd helm-chart
132+
helm repo index . --url https://charts.support.tools/
133+
git add .
134+
git commit -m "Update Helm chart for go-sql-proxy"
135+
git push

Dockerfile

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
# Use a full-featured base image for building
2-
FROM golang:1.21.6-alpine3.18 AS builder
1+
# Use golang alpine image as the builder stage
2+
FROM golang:1.22.4-alpine3.20 AS builder
33

4-
# Install git if your project requires
5-
RUN apk update && apk add --no-cache git
4+
# Install git and other necessary tools
5+
RUN apk update && apk add --no-cache git bash
66

77
# Set the Current Working Directory inside the container
88
WORKDIR /src
@@ -14,21 +14,26 @@ COPY . .
1414
RUN go mod download
1515

1616
# Version and Git Commit build arguments
17-
ARG VERSION=
17+
ARG VERSION
1818
ARG GIT_COMMIT
1919
ARG BUILD_DATE
2020

2121
# Build the Go app with versioning information
22-
RUN GOOS=linux GOARCH=amd64 go build -ldflags "-X github.com/supporttools/go-sql-proxy/pkg/health.version=$VERSION -X github.com/supporttools/go-sql-proxy/pkg/health.GitCommit=$GIT_COMMIT -X github.com/supporttools/go-sql-proxy/pkg/health.BuildTime=$BUILD_DATE" -o /bin/go-sql-proxy
22+
RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -a -installsuffix cgo \
23+
-ldflags "-X github.com/supporttools/go-sql-proxy/pkg/health.version=$VERSION -X github.com/supporttools/go-sql-proxy/pkg/health.GitCommit=$GIT_COMMIT -X github.com/supporttools/go-sql-proxy/pkg/health.BuildTime=$BUILD_DATE" \
24+
-o /bin/go-sql-proxy
2325

2426
# Start from scratch for the runtime stage
2527
FROM scratch
2628

27-
# Set the working directory to /app
28-
WORKDIR /app
29+
# Set the Current Working Directory inside the container
30+
WORKDIR /root/
31+
32+
# Copy CA certificates
33+
COPY --from=builder /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/
2934

3035
# Copy the built binary and config file from the builder stage
31-
COPY --from=builder /bin/go-sql-proxy /app/
36+
COPY --from=builder /bin/go-sql-proxy /bin/
3237

3338
# Set the binary as the entrypoint of the container
34-
ENTRYPOINT ["/app/go-sql-proxy"]
39+
ENTRYPOINT ["/bin/go-sql-proxy"]

README.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,14 @@
1+
<p align="center">
2+
<img src="https://cdn.support.tools/go-sql-proxy/go-sql-proxy-no-bg.png">
3+
</p>
4+
15
# Go-SQL-Proxy
26

37
This project implements a SQL proxy server in Golang that acts as an intermediary between a client and a MySQL server. The proxy server can handle protocol decoding and data transfer while measuring and updating metrics for monitoring purposes.
48

9+
[![Go Report Card](https://goreportcard.com/badge/github.com/SupportTools/go-sql-proxy)](https://goreportcard.com/report/github.com/SupportTools/go-sql-proxy)
10+
[![Go Reference](https://pkg.go.dev/badge/github.com/SupportTools/go-sql-proxy.svg)](https://pkg.go.dev/github.com/SupportTools/go-sql-proxy)
11+
512
## Project Structure
613

714
The project is structured as follows:

charts/go-sql-proxy/Chart.yaml.template

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ apiVersion: v1
22
name: go-sql-proxy
33
version: ${CHART_VERSION}
44
appVersion: ${APP_VERSION}
5-
description: go-sql-proxy is a tool for backing up the configuration files in a Kubernetes cluster and uploading them to a S3 bucket.
5+
description: This project implements a SQL proxy server in Golang that acts as an intermediary between a client and a MySQL server. The proxy server can handle protocol decoding and data transfer while measuring and updating metrics for monitoring purposes.
66
keywords:
77
- kubernetes
88
- backup

go.mod

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
module github.com/supporttools/go-sql-proxy
22

3-
go 1.21.6
3+
go 1.22.4
44

55
require (
6+
github.com/ccoveille/go-safecast v1.2.0
67
github.com/go-sql-driver/mysql v1.7.1
78
github.com/prometheus/client_golang v1.18.0
89
github.com/sirupsen/logrus v1.9.3

go.sum

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
github.com/beorn7/perks v1.0.1 h1:VlbKKnNfV8bJzeqoa4cOKqO6bYr3WgKZxO8Z16+hsOM=
22
github.com/beorn7/perks v1.0.1/go.mod h1:G2ZrVWU2WbWT9wwq4/hrbKbnv/1ERSJQ0ibhJ6rlkpw=
3+
github.com/ccoveille/go-safecast v1.2.0 h1:H4X7aosepsU1Mfk+098CTdKpsDH0cfYJ2RmwXFjgvfc=
4+
github.com/ccoveille/go-safecast v1.2.0/go.mod h1:QqwNjxQ7DAqY0C721OIO9InMk9zCwcsO7tnRuHytad8=
35
github.com/cespare/xxhash/v2 v2.2.0 h1:DC2CZ1Ep5Y4k3ZQ899DldepgrayRUGE6BBZ/cd9Cj44=
46
github.com/cespare/xxhash/v2 v2.2.0/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs=
57
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=

main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ func main() {
4141
ctx, cancel := context.WithCancel(context.Background())
4242
defer cancel() // Ensure cancel is called to release resources if main exits before signal
4343

44-
p := proxy.NewProxy(config.CFG.SourceDatabaseServer, config.CFG.SourceDatabasePort, ctx)
44+
p := proxy.NewProxy(ctx, config.CFG.SourceDatabaseServer, config.CFG.SourceDatabasePort, config.CFG.UseSSL)
4545
p.EnableDecoding = true
4646

4747
var wg sync.WaitGroup

makefile

Lines changed: 34 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,50 @@
1-
#Dockerfile vars
1+
# Dockerfile vars
22
TAG=0.0.0
33

4-
#vars
4+
# vars
55
IMAGENAME=go-sql-proxy
66
REPO=docker.io/supporttools
77
IMAGEFULLNAME=${REPO}/${IMAGENAME}:${TAG}
88

9-
.PHONY: help build push all
9+
.PHONY: help test build push bump all
1010

1111
help:
12-
@echo "Makefile arguments:"
13-
@echo ""
14-
@echo "tag - Docker Tag"
15-
@echo ""
16-
@echo "Makefile commands:"
17-
@echo "build"
18-
@echo "push"
19-
@echo "bump"
20-
@echo "all"
12+
@echo "Makefile arguments:"
13+
@echo ""
14+
@echo "tag - Docker Tag"
15+
@echo ""
16+
@echo "Makefile commands:"
17+
@echo "test - Run tests and static analysis"
18+
@echo "build - Build the Docker image"
19+
@echo "push - Push the Docker image to the repository"
20+
@echo "bump - Build and push a new image"
21+
@echo "all - Run tests, build, and push"
2122

2223
.DEFAULT_GOAL := all
2324

25+
test:
26+
@echo "Running tests and static analysis..."
27+
golint ./... && \
28+
staticcheck ./... && \
29+
go vet ./... && \
30+
go mod tidy && \
31+
go mod verify && \
32+
gosec ./... && \
33+
deadcode ./... && \
34+
go fmt ./...
35+
2436
build:
25-
@docker buildx build --platform linux/amd64 --pull --build-arg GIT_COMMIT=`git rev-parse HEAD` --build-arg VERSION=${TAG} --build-arg BUILD_DATE=`date -u +"%Y-%m-%dT%H:%M:%SZ"` -t ${IMAGEFULLNAME} . --push
37+
@docker buildx build --platform linux/amd64 --pull \
38+
--build-arg GIT_COMMIT=`git rev-parse HEAD` \
39+
--build-arg VERSION=${TAG} \
40+
--build-arg BUILD_DATE=`date -u +"%Y-%m-%dT%H:%M:%SZ"` \
41+
-t ${IMAGEFULLNAME} . --push
2642

2743
push:
28-
@docker push ${IMAGEFULLNAME}
29-
@docker tag ${IMAGEFULLNAME} ${REPO}/${IMAGENAME}:latest
30-
@docker push ${REPO}/${IMAGENAME}:latest
44+
@docker push ${IMAGEFULLNAME}
45+
@docker tag ${IMAGEFULLNAME} ${REPO}/${IMAGENAME}:latest
46+
@docker push ${REPO}/${IMAGENAME}:latest
3147

32-
bump:
33-
@make build push
48+
bump: build push
3449

35-
all: build push
50+
all: test build push

pkg/config/config.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ type AppConfig struct {
2424
SSLKeyFile string `json:"sslKeyFile"`
2525
}
2626

27+
// CFG is the global configuration object.
2728
var CFG AppConfig
2829

2930
// LoadConfiguration loads configuration from environment variables.

0 commit comments

Comments
 (0)