Skip to content

Commit d8e9f94

Browse files
authored
Merge pull request #6 from DevSecOpsSamples/change-to-gar
Changed from GCR to GAR, Go version up
2 parents f6d84bb + d1b4fd8 commit d8e9f94

21 files changed

+223
-69
lines changed
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
name: Auto Author Assign
2+
3+
on:
4+
pull_request_target:
5+
types: [opened, reopened]
6+
7+
permissions:
8+
pull-requests: write
9+
10+
jobs:
11+
assign-author:
12+
runs-on: ubuntu-latest
13+
steps:
14+
- uses: toshimaru/auto-author-assign@v2.1.1

.github/workflows/build.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,14 @@ jobs:
1010
docker-build:
1111
runs-on: ubuntu-latest
1212
steps:
13-
- uses: actions/checkout@v3
13+
- uses: actions/checkout@v4
1414
- name: Build the Docker image
1515
run: cd app && docker build . -t ${{ secrets.IMAGE_NAME }}:$(date +%s)
1616
sonarqube:
1717
name: Sonarqube
1818
runs-on: ubuntu-latest
1919
steps:
20-
- uses: actions/checkout@v3
20+
- uses: actions/checkout@v4
2121
- name: Set up JDK 11
2222
uses: actions/setup-java@v3
2323
with:
@@ -39,4 +39,4 @@ jobs:
3939
env:
4040
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # Needed to get PR information, if any
4141
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
42-
run: ./gradlew build sonarqube --info
42+
run: ./gradlew build sonarqube --info
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# Summary
2+
3+
## Related Issues

.golangci.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
output:
2+
show-stats: true
3+
sort-results: true
4+
sort-order:
5+
- linter
6+
- file

.pre-commit-config.yaml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
repos:
2+
- repo: https://github.com/pre-commit/pre-commit-hooks
3+
rev: v5.0.0
4+
hooks:
5+
- id: check-merge-conflict
6+
- id: end-of-file-fixer
7+
- id: trailing-whitespace
8+
- id: check-json
9+
# - id: check-yaml

README.md

Lines changed: 20 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,18 @@
33
[![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)
44
[![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)
55

6-
Performance testing on GKE using the https://echo.labstack.com application.
7-
6+
Performance testing on GKE using the <https://echo.labstack.com> application.
87

98
## Table of Contents
109

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

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

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

3130
### Set environment variables
3231

@@ -56,21 +55,24 @@ gcloud container clusters get-credentials sample-cluster
5655

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

59-
Build and push to GCR:
58+
Build and push to GAR:
6059

6160
```bash
61+
gcloud auth login
62+
gcloud auth configure-docker us-docker.pkg.dev
63+
6264
cd app
6365
docker build -t go-echo-api . --platform linux/amd64
64-
docker tag go-echo-api:latest gcr.io/${PROJECT_ID}/go-echo-api:latest
65-
66-
gcloud auth configure-docker
67-
docker push gcr.io/${PROJECT_ID}/go-echo-api:latest
66+
docker tag go-echo-api:latest us-docker.pkg.dev/${PROJECT_ID}/${REPOSITORY}/go-echo-api:latest
67+
docker push us-docker.pkg.dev/${PROJECT_ID}/${REPOSITORY}/go-echo-api:latest
6868
```
6969

70+
[build-and-push.sh](app/build-and-push.sh)
71+
7072
```bash
71-
kubectl get namespaces
73+
kubectl get ns
7274

73-
kubectl create namespace echo-test
75+
kubectl create ns echo-test
7476
```
7577

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

138140
### 3.1. Install the Taurus
139141

140-
https://gettaurus.org/install/Installation/
142+
<https://gettaurus.org/install/Installation/>
141143

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

187189
kubectl delete -f app/go-echo-api-onepod.yaml -n echo-test
188190
kubectl delete -f app/go-echo-api.yaml -n echo-test
191+
kubectl delete namespace echo-test
189192
```
190193

191194
## References
192195

193-
- https://echo.labstack.com
196+
- <https://echo.labstack.com>
194197

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

app/Dockerfile

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,20 @@
1-
FROM golang:1.18 AS builder
1+
FROM golang:1.23-alpine AS builder
22

3-
RUN mkdir /app
4-
5-
COPY ./go.mod /app/
6-
COPY ./go.sum /app/
7-
COPY ./main.go /app/
83
WORKDIR /app
94

10-
RUN go install
11-
RUN go build main.go
5+
COPY go.mod go.sum ./
6+
RUN go mod download
7+
8+
COPY . .
9+
RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o server ./
1210

13-
RUN adduser go
14-
RUN chown go ./main
11+
FROM scratch
12+
13+
WORKDIR /app
1514

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

18-
EXPOSE 8000
18+
EXPOSE 8080
1919

20-
CMD ["./main"]
20+
ENTRYPOINT ["/app/server"]

app/Makefile

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,30 @@
1+
.PHONY: install build build-docker test all clean
2+
3+
all: install build test build-docker
4+
15
build:
26
go build ./...
37

8+
build-docker:
9+
docker build --progress=plain -t go-echo-api .
10+
411
install:
5-
go install -mod=vendor -v ./...
12+
go install -v ./...
13+
14+
fmt:
15+
go fmt ./...
16+
17+
lint: fmt
18+
golangci-lint run
19+
20+
run: fmt
21+
go run ./main.go
22+
23+
run-docker:
24+
docker run -it -p 8080:8080 go-echo-api:latest
625

726
test:
827
go test ./...
928

1029
clean:
11-
go clean ./...
30+
go clean ./...

app/README.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# Build
2+
3+
```bash
4+
make build
5+
make run
6+
```
7+
8+
```bash
9+
make build-docker
10+
make run-docker
11+
```

app/build-and-push.sh

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#!/bin/bash
2+
set -e
3+
4+
# gcloud config set project <PROJECT_ID>
5+
PROJECT_ID=$(gcloud config get-value project)
6+
echo "PROJECT_ID: ${PROJECT_ID}"
7+
8+
# Set your repository name
9+
RESPOSITORY="docker"
10+
11+
# gcloud artifacts repositories create ${RESPOSITORY} --repository-format=docker --location=us --description="Docker repository for go-echo-api"
12+
13+
docker build -t go-echo-api . --platform linux/amd64
14+
docker tag go-echo-api:latest us-docker.pkg.dev/${PROJECT_ID}/${RESPOSITORY}/go-echo-api:latest
15+
16+
gcloud auth configure-docker us-docker.pkg.dev
17+
docker push us-docker.pkg.dev/${PROJECT_ID}/${RESPOSITORY}/go-echo-api:latest
18+
19+
# docker run -it -p 8080:8080 go-echo-api:latest
20+
21+
# docker run -it -p 8080:8080 us-docker.pkg.dev/${PROJECT_ID}/go-echo-api:latest

0 commit comments

Comments
 (0)