Skip to content

Changed from GCR to GAR, Go version up #6

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 18, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions .github/workflows/auto-author-assign.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
name: Auto Author Assign

on:
pull_request_target:
types: [opened, reopened]

permissions:
pull-requests: write

jobs:
assign-author:
runs-on: ubuntu-latest
steps:
- uses: toshimaru/auto-author-assign@v2.1.1
6 changes: 3 additions & 3 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@ jobs:
docker-build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- name: Build the Docker image
run: cd app && docker build . -t ${{ secrets.IMAGE_NAME }}:$(date +%s)
sonarqube:
name: Sonarqube
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- name: Set up JDK 11
uses: actions/setup-java@v3
with:
Expand All @@ -39,4 +39,4 @@ jobs:
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # Needed to get PR information, if any
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
run: ./gradlew build sonarqube --info
run: ./gradlew build sonarqube --info
3 changes: 3 additions & 0 deletions .github/workflows/pull_request_template.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Summary

## Related Issues
6 changes: 6 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
output:
show-stats: true
sort-results: true
sort-order:
- linter
- file
9 changes: 9 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v5.0.0
hooks:
- id: check-merge-conflict
- id: end-of-file-fixer
- id: trailing-whitespace
- id: check-json
# - id: check-yaml
37 changes: 20 additions & 17 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,18 @@
[![Build](https://github.com/DevSecOpsSamples/gcp-golang-performance-test/actions/workflows/build.yml/badge.svg?branch=master)](https://github.com/DevSecOpsSamples/gcp-golang-performance-test/actions/workflows/build.yml)
[![Quality Gate Status](https://sonarcloud.io/api/project_badges/measure?project=DevSecOpsSamples_gcp-golang-performance-test&metric=alert_status)](https://sonarcloud.io/summary/new_code?id=DevSecOpsSamples_gcp-golang-performance-test) [![Lines of Code](https://sonarcloud.io/api/project_badges/measure?project=DevSecOpsSamples_gcp-golang-performance-test&metric=ncloc)](https://sonarcloud.io/summary/new_code?id=DevSecOpsSamples_gcp-golang-performance-test)

Performance testing on GKE using the https://echo.labstack.com application.

Performance testing on GKE using the <https://echo.labstack.com> application.

## Table of Contents

- [1. Create a GKE cluster](#1-create-a-gke-cluster)
- [2. Deploy two applications for checking the performance per Pod and scaling](#2-deploy-two-applications-for-checking-the-performance-per-pod-and-scaling)
- [2.1. Deploy for performance of one Pod](#21-deploy-for-performance-of-one-pod)
- [2.2. Deploy for Scaling Test](#22-deploy-for-scaling-test)
- [2.1. Deploy for performance of one Pod](#21-deploy-for-performance-of-one-pod)
- [2.2. Deploy for Scaling Test](#22-deploy-for-scaling-test)
- [3. Performance Testing](#3-performance-testing)
- [3.1. Install the Taurus](#31-install-the-taurus)
- [3.2. Test for performance of one Pod](#32-test-for-performance-of-one-pod)
- [3.3. Test with auto scaling](#33-test-with-auto-scaling)
- [3.1. Install the Taurus](#31-install-the-taurus)
- [3.2. Test for performance of one Pod](#32-test-for-performance-of-one-pod)
- [3.3. Test with auto scaling](#33-test-with-auto-scaling)
- [Cleanup](#6-cleanup)

---
Expand All @@ -26,7 +25,7 @@ Performance testing on GKE using the https://echo.labstack.com application.

- [Install the gcloud CLI](https://cloud.google.com/sdk/docs/install)
- [Install kubectl and configure cluster access](https://cloud.google.com/kubernetes-engine/docs/how-to/cluster-access-for-kubectl)
- [Installing and Upgrading for the Taurus ](https://gettaurus.org/install/Installation/)
- [Installing and Upgrading for the Taurus](https://gettaurus.org/install/Installation/)

### Set environment variables

Expand Down Expand Up @@ -56,21 +55,24 @@ gcloud container clusters get-credentials sample-cluster

## 2. Deploy two applications for checking the performance per Pod and scaling

Build and push to GCR:
Build and push to GAR:

```bash
gcloud auth login
gcloud auth configure-docker us-docker.pkg.dev

cd app
docker build -t go-echo-api . --platform linux/amd64
docker tag go-echo-api:latest gcr.io/${PROJECT_ID}/go-echo-api:latest

gcloud auth configure-docker
docker push gcr.io/${PROJECT_ID}/go-echo-api:latest
docker tag go-echo-api:latest us-docker.pkg.dev/${PROJECT_ID}/${REPOSITORY}/go-echo-api:latest
docker push us-docker.pkg.dev/${PROJECT_ID}/${REPOSITORY}/go-echo-api:latest
```

[build-and-push.sh](app/build-and-push.sh)

```bash
kubectl get namespaces
kubectl get ns

kubectl create namespace echo-test
kubectl create ns echo-test
```

Two deployments may take around 5 minutes to create a load balancer, including health checking.
Expand Down Expand Up @@ -137,7 +139,7 @@ curl http://${LB_IP_ADDRESS}/

### 3.1. Install the Taurus

https://gettaurus.org/install/Installation/
<https://gettaurus.org/install/Installation/>

```bash
sudo apt-get update -y
Expand Down Expand Up @@ -186,11 +188,12 @@ kubectl scale deployment go-echo-api -n echo-test --replicas=0

kubectl delete -f app/go-echo-api-onepod.yaml -n echo-test
kubectl delete -f app/go-echo-api.yaml -n echo-test
kubectl delete namespace echo-test
```

## References

- https://echo.labstack.com
- <https://echo.labstack.com>

- [Cloud SDK > Documentation > Reference > gcloud container clusters](https://cloud.google.com/sdk/gcloud/reference/container/clusters)

Expand Down
26 changes: 13 additions & 13 deletions app/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
FROM golang:1.18 AS builder
FROM golang:1.23-alpine AS builder

RUN mkdir /app

COPY ./go.mod /app/
COPY ./go.sum /app/
COPY ./main.go /app/
WORKDIR /app

RUN go install
RUN go build main.go
COPY go.mod go.sum ./
RUN go mod download

COPY . .
RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o server ./

RUN adduser go
RUN chown go ./main
FROM scratch

WORKDIR /app

USER go
COPY --from=builder /app/server .
COPY --from=builder /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/

EXPOSE 8000
EXPOSE 8080

CMD ["./main"]
ENTRYPOINT ["/app/server"]
23 changes: 21 additions & 2 deletions app/Makefile
Original file line number Diff line number Diff line change
@@ -1,11 +1,30 @@
.PHONY: install build build-docker test all clean

all: install build test build-docker

build:
go build ./...

build-docker:
docker build --progress=plain -t go-echo-api .

install:
go install -mod=vendor -v ./...
go install -v ./...

fmt:
go fmt ./...

lint: fmt
golangci-lint run

run: fmt
go run ./main.go

run-docker:
docker run -it -p 8080:8080 go-echo-api:latest

test:
go test ./...

clean:
go clean ./...
go clean ./...
11 changes: 11 additions & 0 deletions app/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# Build

```bash
make build
make run
```

```bash
make build-docker
make run-docker
```
21 changes: 21 additions & 0 deletions app/build-and-push.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#!/bin/bash
set -e

# gcloud config set project <PROJECT_ID>
PROJECT_ID=$(gcloud config get-value project)
echo "PROJECT_ID: ${PROJECT_ID}"

# Set your repository name
RESPOSITORY="docker"

# gcloud artifacts repositories create ${RESPOSITORY} --repository-format=docker --location=us --description="Docker repository for go-echo-api"

docker build -t go-echo-api . --platform linux/amd64
docker tag go-echo-api:latest us-docker.pkg.dev/${PROJECT_ID}/${RESPOSITORY}/go-echo-api:latest

gcloud auth configure-docker us-docker.pkg.dev
docker push us-docker.pkg.dev/${PROJECT_ID}/${RESPOSITORY}/go-echo-api:latest

# docker run -it -p 8080:8080 go-echo-api:latest

# docker run -it -p 8080:8080 us-docker.pkg.dev/${PROJECT_ID}/go-echo-api:latest
17 changes: 17 additions & 0 deletions app/build-multi-arch-and-push.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#!/bin/bash
set -e

# gcloud config set project <PROJECT_ID>
PROJECT_ID=$(gcloud config get-value project)
echo "PROJECT_ID: ${PROJECT_ID}"

# Set your repository name
RESPOSITORY="docker"

docker buildx ls

docker buildx rm builder || true
docker buildx create --name builder --use

gcloud auth configure-docker us-docker.pkg.dev
time docker buildx build -t us-docker.pkg.dev/${PROJECT_ID}/${RESPOSITORY}/go-echo-api:latest . --platform linux/amd64,linux/arm/v7 --push
8 changes: 0 additions & 8 deletions app/build-multi-arch.sh

This file was deleted.

12 changes: 0 additions & 12 deletions app/build.sh

This file was deleted.

11 changes: 5 additions & 6 deletions app/go-echo-api-onepod-template.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
---
apiVersion: apps/v1
kind: Deployment
metadata:
Expand All @@ -18,10 +17,10 @@ spec:
spec:
containers:
- name: go-echo-api-onepod
image: gcr.io/<project-id>/go-echo-api:latest
image: us-docker.pkg.dev/<project-id>/go-echo-api:latest
imagePullPolicy: Always
ports:
- containerPort: 8000
- containerPort: 8080
resources:
requests:
cpu: "1"
Expand All @@ -41,7 +40,7 @@ spec:
type: ClusterIP
ports:
- port: 30000
targetPort: 8000
targetPort: 8080
protocol: TCP
---
apiVersion: networking.k8s.io/v1
Expand Down Expand Up @@ -77,7 +76,7 @@ spec:
timeoutSec: 30
healthyThreshold: 1
unhealthyThreshold: 3
port: 8000
port: 8080
type: HTTP
requestPath: /
---
Expand All @@ -99,4 +98,4 @@ spec:
name: cpu
target:
type: Utilization
averageUtilization: 90
averageUtilization: 90
12 changes: 6 additions & 6 deletions app/go-echo-api-template.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
---

apiVersion: apps/v1
kind: Deployment
metadata:
Expand All @@ -18,10 +18,10 @@ spec:
spec:
containers:
- name: go-echo-api
image: gcr.io/<project-id>/go-echo-api:latest
image: us-docker.pkg.dev/<project-id>/go-echo-api:latest
imagePullPolicy: Always
ports:
- containerPort: 8000
- containerPort: 8080
resources:
requests:
cpu: "1"
Expand All @@ -41,7 +41,7 @@ spec:
type: ClusterIP
ports:
- port: 30001
targetPort: 8000
targetPort: 8080
protocol: TCP
---
apiVersion: networking.k8s.io/v1
Expand Down Expand Up @@ -77,7 +77,7 @@ spec:
timeoutSec: 30
healthyThreshold: 1
unhealthyThreshold: 3
port: 8000
port: 8080
type: HTTP
requestPath: /
---
Expand All @@ -99,4 +99,4 @@ spec:
name: cpu
target:
type: Utilization
averageUtilization: 90
averageUtilization: 90
5 changes: 3 additions & 2 deletions app/go.mod
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
module echo

go 1.18
go 1.23.0

require github.com/labstack/echo/v4 v4.10.0

require (
github.com/labstack/echo/v4 v4.10.0 // indirect
github.com/labstack/gommon v0.4.0 // indirect
github.com/mattn/go-colorable v0.1.13 // indirect
github.com/mattn/go-isatty v0.0.16 // indirect
Expand Down
Loading
Loading