Skip to content

Commit 5af23a5

Browse files
Merge pull request #262 from gofr-dev/release-v0.2.0
Release v0.2.0
2 parents 5783131 + f1261c7 commit 5af23a5

File tree

64 files changed

+2331
-464
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

64 files changed

+2331
-464
lines changed

Diff for: .github/workflows/docs.yml

+163
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,163 @@
1+
name: Build and Deploy
2+
'on':
3+
push:
4+
paths:
5+
- 'docs/**'
6+
env:
7+
APP_NAME: gofr-web
8+
REGISTRY: gcr.io
9+
WEBSITE_REGISTRY: ghcr.io
10+
GCR_PROJECT: zs-products
11+
CLUSTER_NAME: products-cluster
12+
DEPLOYMENT_ZONE: us-central1
13+
STAGE_NAMESPACE: gofr-stage
14+
PROD_NAMESPACE: gofr
15+
jobs:
16+
dockerize_stage:
17+
runs-on: ubuntu-latest
18+
outputs:
19+
image: ${{ steps.output-image.outputs.image }}
20+
name: 🐳 Dockerize Stage
21+
steps:
22+
- name: Checkout Code
23+
uses: actions/checkout@v4
24+
25+
- name: Set up Docker Buildx
26+
uses: docker/setup-buildx-action@v2
27+
28+
- name: Login to GCR
29+
uses: docker/login-action@v2
30+
with:
31+
registry: ${{ env.REGISTRY }}
32+
username: _json_key
33+
password: ${{ secrets.GCR_KEY }}
34+
35+
- name: Log in to the Container registry
36+
uses: docker/login-action@v1
37+
with:
38+
registry: ${{ env.WEBSITE_REGISTRY }}
39+
username: ${{ github.actor }}
40+
password: ${{ secrets.GITHUB_TOKEN }}
41+
42+
- name: Download UI Image
43+
run: |
44+
docker pull ${{ env.WEBSITE_REGISTRY }}/gofr-dev/website:latest
45+
46+
- name: Build and Push Image Stage
47+
uses: docker/build-push-action@v4
48+
with:
49+
push: true
50+
context: ./
51+
file: ./docs/Dockerfile
52+
tags: ${{ env.REGISTRY }}/${{ env.GCR_PROJECT }}/${{ env.APP_NAME }}:${{ github.sha }}
53+
54+
- id: output-image
55+
run: echo "image=`echo ${{ env.REGISTRY }}/${{ env.GCR_PROJECT }}/${{ env.APP_NAME }}:${{ github.sha }}`" >> "$GITHUB_OUTPUT"
56+
57+
stage_deployment:
58+
runs-on: ubuntu-latest
59+
name: 🚀 Deploy to Stage
60+
if: (github.ref == 'refs/heads/development' || github.ref == 'refs/heads/main')
61+
needs: dockerize_stage
62+
container:
63+
image: ghcr.io/zopsmart/gha-images:deployments-0.1.3
64+
options: --rm
65+
env:
66+
image: ${{needs.dockerize_stage.outputs.image}}
67+
68+
steps:
69+
- name: Authorize to GCP service account
70+
uses: google-github-actions/auth@v1
71+
with:
72+
credentials_json: ${{ secrets.DEPLOY_KEY }}
73+
74+
- name: Set GCloud Project and Fetch Cluster Credentials
75+
run:
76+
gcloud container clusters get-credentials ${{ env.CLUSTER_NAME }} --zone=${{ env.DEPLOYMENT_ZONE }} --project=${{ env.GCR_PROJECT }}
77+
78+
- name: Update Deployment Image
79+
run: kubectl set image deployment/${{ env.APP_NAME }} ${{ env.APP_NAME }}=${{ env.image }} --namespace ${{ env.STAGE_NAMESPACE }}
80+
81+
check-tag:
82+
runs-on: ubuntu-latest
83+
if: ${{ startsWith(github.ref, 'refs/tags/v')}}
84+
outputs:
85+
tag_exists: ${{ steps.tag-check.outputs.tag_exists }}
86+
87+
steps:
88+
- name: Checkout code
89+
uses: actions/checkout@v4
90+
91+
- name: Authorize to GCP service account
92+
uses: google-github-actions/auth@v1
93+
with:
94+
credentials_json: ${{ secrets.GCR_KEY }}
95+
96+
- name: Check if tag exists
97+
id: tag-check
98+
run: |
99+
if gcloud container images describe ${{ env.REGISTRY }}/${{ env.GCR_PROJECT }}/${{ env.APP_NAME }}:${{ github.sha }} 2>/dev/null; then
100+
echo "tag_exists=true" >> "$GITHUB_OUTPUT"
101+
else
102+
echo "tag_exists=false" >> "$GITHUB_OUTPUT"
103+
fi
104+
105+
- name: Print commit has value
106+
run: |
107+
echo "${{ github.sha }}"
108+
109+
- name: Print tag_exists value
110+
run: |
111+
echo "${{ steps.tag-check.outputs.tag_exists }}"
112+
113+
dockerize_prod:
114+
runs-on: ubuntu-latest
115+
needs: check-tag
116+
name: 🐳 Dockerize Prod
117+
if: ${{ needs.check-tag.outputs.tag_exists == 'true' }}
118+
outputs:
119+
image: ${{ steps.output-image.outputs.image }}
120+
121+
steps:
122+
- name: Extract Release Tag
123+
run: echo "RELEASE_VERSION=${GITHUB_REF#refs/*/}" >> $GITHUB_ENV
124+
125+
- name: Checkout Code
126+
uses: actions/checkout@v4
127+
128+
- name: Login to GCR
129+
uses: docker/login-action@v1
130+
with:
131+
registry: ${{ env.REGISTRY }}
132+
username: _json_key
133+
password: ${{ secrets.GCR_KEY }}
134+
135+
- name: Re tag and Push Docker Image to GCR
136+
run: |
137+
docker pull ${{ env.REGISTRY }}/${{ env.GCR_PROJECT }}/${{ env.APP_NAME }}:${{ github.sha }}
138+
docker tag ${{ env.REGISTRY }}/${{ env.GCR_PROJECT }}/${{ env.APP_NAME }}:${{ github.sha }} ${{ env.REGISTRY }}/${{ env.GCR_PROJECT }}/${{ env.APP_NAME }}:${{ env.RELEASE_VERSION }}
139+
docker push ${{ env.REGISTRY }}/${{ env.GCR_PROJECT }}/${{ env.APP_NAME }}:${{ env.RELEASE_VERSION }}
140+
141+
- id: output-image
142+
run: echo "image=`echo ${{ env.REGISTRY }}/${{ env.GCR_PROJECT }}/${{ env.APP_NAME }}:${{ env.RELEASE_VERSION }}`" >> "$GITHUB_OUTPUT"
143+
144+
prod_deployment:
145+
runs-on: ubuntu-latest
146+
name: 🚀 Deploy to Prod
147+
needs: dockerize_prod
148+
container:
149+
image: ghcr.io/zopsmart/gha-images:deployments-0.1.3
150+
options: --rm
151+
env:
152+
image: ${{needs.dockerize_prod.outputs.image}}
153+
steps:
154+
- name: Authorize to GCP service account
155+
uses: google-github-actions/auth@v1
156+
with:
157+
credentials_json: ${{ secrets.DEPLOY_KEY }}
158+
159+
- name: Set GCloud Project and Fetch Cluster Credentials
160+
run: gcloud container clusters get-credentials ${{ env.CLUSTER_NAME }} --zone=${{ env.DEPLOYMENT_ZONE }} --project=${{ env.GCR_PROJECT }}
161+
162+
- name: Update Deployment Image
163+
run: kubectl set image deployment/${{ env.APP_NAME }} ${{ env.APP_NAME }}=${{ env.image }} --namespace ${{ env.PROD_NAMESPACE }}

Diff for: .github/workflows/go.yml

+12-18
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,14 @@ on:
55
branches:
66
- main
77
- development
8+
paths-ignore:
9+
- 'docs/**'
810
pull_request:
911
branches:
1012
- main
1113
- development
14+
paths-ignore:
15+
- 'docs/**'
1216

1317
jobs:
1418
Example-Unit-Testing:
@@ -45,6 +49,9 @@ jobs:
4549
run: |
4650
go mod download
4751
52+
- name: Start Zipkin
53+
run: docker run -d -p 2005:9411 openzipkin/zipkin:latest
54+
4855
- name: Test
4956
run: |
5057
export GOFR_ENV=test
@@ -60,20 +67,7 @@ jobs:
6067
PKG-Unit-Testing:
6168
name: PKG Unit Testing🛠
6269
runs-on: ubuntu-latest
63-
services:
64-
redis:
65-
image: redis:7.0.5
66-
ports:
67-
- "2002:6379"
68-
options: "--entrypoint redis-server"
6970

70-
mysql:
71-
image: mysql:8.2.0
72-
ports:
73-
- "2001:3306"
74-
env:
75-
MYSQL_ROOT_PASSWORD: "password"
76-
MYSQL_DATABASE: "test"
7771
steps:
7872
- name: Checkout code into go module directory
7973
uses: actions/checkout@v4
@@ -128,11 +122,11 @@ jobs:
128122
codeCoverage=${codeCoverage%?}
129123
echo "CODE_COVERAGE=$codeCoverage" >> $GITHUB_ENV
130124
131-
# - name: Check if code-coverage is greater than threshold
132-
# run: |
133-
# codeCoverage=${{ env.CODE_COVERAGE }}
134-
# codeCoverage=${codeCoverage%??}
135-
# if [[ $codeCoverage -lt 92 ]]; then echo "code coverage cannot be less than 92%, currently its ${{ env.CODE_COVERAGE }}%" && exit 1; fi;
125+
# - name: Check if code-coverage is greater than threshold
126+
# run: |
127+
# codeCoverage=${{ env.CODE_COVERAGE }}
128+
# codeCoverage=${codeCoverage%??}
129+
# if [[ $codeCoverage -lt 92 ]]; then echo "code coverage cannot be less than 92%, currently its ${{ env.CODE_COVERAGE }}%" && exit 1; fi;
136130

137131
upload_coverage:
138132
name: Upload Coverage📊

Diff for: docs/Dockerfile

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
FROM ghcr.io/gofr-dev/website:latest
2+
3+
WORKDIR /app
4+
5+
COPY docs/quick-start /app/src/app/docs/quick-start
6+
COPY docs/advanced-guide /app/src/app/docs/advanced-guide
7+
COPY docs/page.md /app/src/app/docs
8+
COPY docs/navigation.js /app/src/lib
9+
10+
ENV NODE_ENV production
11+
12+
RUN npm install
13+
RUN npm run build
14+
15+
RUN addgroup -g 1001 -S nodejs
16+
RUN adduser -S nextjs -u 1001
17+
18+
USER nextjs
19+
20+
EXPOSE 3000
21+
ENV PORT 3000
22+
23+
ENV NEXT_TELEMETRY_DISABLED 1
24+
25+
CMD ["node_modules/.bin/next", "start"]

Diff for: docs/advanced-guide/interservice-http-call/page.md

+43-12
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,69 @@
11
# Interservice HTTP Calls
2-
32
GoFr supports inter-service http calls which provide the following benefits :
43

54
1. Access to the following method from container - GET, PUT, POST, PATCH, DELETE.
65
2. Logs and traces for the request.
6+
3. Circuit breaking for enhanced resilience and fault tolerance.
7+
4. Custom Health Check Endpoints
78

89
## Usage
910

1011
### Registering HTTP Service
1112

1213
```go
14+
package main
15+
16+
import (
17+
"io"
18+
"time"
19+
20+
"gofr.dev/pkg/gofr"
21+
"gofr.dev/pkg/gofr/service"
22+
)
23+
1324
func main() {
1425
// Create a new application
1526
a := gofr.New()
1627

17-
a.AddHTTPService("anotherService", "http://localhost:9000")
18-
19-
a.GET("/redis", RedisHandler)
28+
a.AddHTTPService("order", "http://localhost:9000",nil)
29+
30+
// service with circuit breaker
31+
a.AddHTTPService("catalogue", "http://localhost:8000",&service.CircuitBreakerConfig{
32+
Threshold: 4, // after how many failed request circuit breaker will start blocking the requests
33+
Interval: 1 * time.Second, // time interval duration between hitting the HealthURL
34+
},)
2035

36+
// gofr by default hits the `/.well-known/alive` endpoint for service health check.
37+
// it can be over-ridden using the following option
38+
a.AddHTTPService("payment", "http://localhost:7000",&service.HealthConfig{
39+
HealthEndpoint: "my-health",
40+
},)
41+
42+
a.GET("/customer", Customer)
43+
2144
// Run the application
2245
a.Run()
2346
}
47+
}
2448
```
2549

2650
### Accessing HTTP Service in handler
2751

2852
```go
29-
func RedisHandler(ctx *gofr.Context) (interface{}, error) {
30-
//Call Another service
31-
resp, err := ctx.GetHTTPService("anotherService").Get(c, "redis", nil)
32-
if err != nil {
33-
return nil, err
34-
}
35-
36-
return resp, nil
53+
func Customer(ctx *gofr.Context) (interface{}, error) {
54+
//Get & Call Another service
55+
resp, err := ctx.GetHTTPService("payment").Get(ctx, "user", nil)
56+
if err != nil {
57+
return nil, err
58+
}
59+
60+
defer resp.Body.Close()
61+
62+
body, err := io.ReadAll(resp.Body)
63+
if err != nil {
64+
return nil, err
65+
}
66+
67+
return string(body), nil
3768
}
3869
```

0 commit comments

Comments
 (0)