Skip to content

Commit 19912e1

Browse files
benc-ukCopilot
andauthored
2025 refresh (#14)
* Remove old nginx conf * Refreshed for eslint and all packages to latest * Fix run target dependency to ensure frontend modules are available before starting processes * Refactor golangci-lint configuration for improved clarity and organization * golangci-lint fixes * Update base images in Dockerfiles to latest stable versions * Update Dapr sidecar images to latest version and clean up Dockerfile * Bump version to 0.8.6 in Makefile * Version bumps * Major refactor of testing * Add Bruno collection * Add TypeSpec for API * Update README.md to enhance Docker instructions and clarify identity provider configuration * Update CI workflow to use latest actions and Go version * Update CI workflows: add golangci-lint installation and upgrade checkout action to v4 * Refactor CI workflow: update integration test steps and remove unused linting commands * Update CI workflow and Makefile: add integration test reporting and improve test command * Update CI workflow: initialize Dapr and upgrade test reporting action to v15 * Update CI workflow and Makefile: add golangci-lint installation, improve test reporting, and enhance test commands * Update CI workflow and Makefile: install go-junit-report, enhance test reporting, and improve integration test command * Update CI workflow and Makefile: rename test report output files for consistency and install additional Go tools * Update CI workflow: re-enable build and push Docker images job with proper configuration * Update CI workflow and Makefile: standardize test report paths and improve output directory management * Names for tests * Update README.md: add GitHub Actions workflow status badge * Update CI workflow: replace sleep with inotifywait for API integration tests and adjust Makefile for process management * Update CI workflow: modify inotifywait to monitor specific file for API integration tests * Update CI workflow: replace inotifywait with sleep for API integration tests * Update .github/workflows/ci-build.yml Co-authored-by: Copilot <[email protected]> * Update CI workflow to run API integration tests with a new URL check script --------- Co-authored-by: Copilot <[email protected]>
1 parent b018a71 commit 19912e1

Some content is hidden

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

79 files changed

+5697
-3415
lines changed

.github/workflows/ci-build.yml

Lines changed: 56 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,44 +14,92 @@ on:
1414
permissions:
1515
contents: read
1616
packages: write
17+
checks: write
1718

1819
env:
19-
VERSION: 0.8.5
20+
VERSION: 0.8.6
2021
BUILD_INFO: "Build:development / Workflow:${{ github.workflow }} / RunId:${{ github.run_id }} / Ref:${{ github.ref }} / SHA:${{ github.sha }} / ImageTag:${{ github.run_id }}"
2122
IMAGE_REG: ghcr.io
2223
IMAGE_TAG: ${{ github.run_id }}
2324

2425
jobs:
2526
# ===== Testing & code checking ======
2627
tests-linting:
28+
name: "Run Lint & All Tests"
2729
runs-on: ubuntu-latest
2830
outputs:
2931
imageTag: ${{ steps.createTag.outputs.IMAGE_TAG }}
3032

3133
steps:
3234
- name: "Checkout source"
33-
uses: actions/checkout@v3
35+
uses: actions/checkout@v4
3436

3537
- name: "Set Go version and paths"
36-
uses: actions/setup-go@v3
38+
uses: actions/setup-go@v5
3739
with:
38-
go-version: "^1.21.0"
40+
go-version: "^1.24.0"
3941

40-
- name: "Install extra tools"
42+
- name: "Install extra Go tools"
4143
run: |
42-
go install gotest.tools/gotestsum@latest
44+
go install github.com/jstemmer/go-junit-report@latest
4345
curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(go env GOPATH)/bin
4446
4547
- name: "Check code & lint"
4648
run: |
4749
go get ./...
4850
make lint
4951
50-
- name: "Run all unit tests"
51-
run: make test
52+
- name: "Run all unit tests and generate reports"
53+
run: |
54+
make test-report
55+
56+
- name: "Test Report (Frontend)"
57+
uses: phoenix-actions/test-reporting@v15
58+
if: success() || failure()
59+
with:
60+
name: Frontend Tests
61+
path: test-reports/frontend.xml
62+
reporter: java-junit
63+
64+
- name: "Test Report (Unit Tests)"
65+
uses: phoenix-actions/test-reporting@v15
66+
if: success() || failure()
67+
with:
68+
name: Unit Tests
69+
path: test-reports/unit.xml
70+
reporter: java-junit
71+
72+
- name: "Dapr tool installer"
73+
uses: dapr/setup-dapr@v1
74+
with:
75+
version: "1.15.1"
76+
77+
- name: "Initialize Dapr"
78+
run: |
79+
dapr init
80+
81+
- name: "Run API integration tests, with report"
82+
run: |
83+
echo "Starting Dapr Store all components..."
84+
make run &
85+
86+
echo "Waiting for API to start..."
87+
./scripts/url-check.sh http://localhost:9000/v1.0/invoke/products/method/catalog prd001
88+
89+
echo "Running API tests..."
90+
make test-api-report
91+
92+
- name: "Test Report (API)"
93+
uses: phoenix-actions/test-reporting@v15
94+
if: success() || failure()
95+
with:
96+
name: API Integration Tests
97+
path: test-reports/api.xml
98+
reporter: java-junit
5299

53100
# ===== Build container images ======
54101
build-images:
102+
name: "Build & Push Images"
55103
runs-on: ubuntu-latest
56104
needs: tests-linting
57105
strategy:

.github/workflows/release-images.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ jobs:
1818
runs-on: ubuntu-latest
1919

2020
steps:
21-
- uses: actions/checkout@v3
21+
- uses: actions/checkout@v4
2222

2323
- name: "Run all image builds"
2424
run: |

.gitignore

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,5 +17,8 @@ components/*.yaml
1717
web/frontend/coverage
1818
**/node_modules/**
1919
output/**
20+
test-reports/
2021
bin/**
21-
.secrets
22+
.secrets
23+
*.xml
24+
running

.golangci.yaml

Lines changed: 47 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,50 @@
1-
# =================================================================
2-
# An opinionated config for linting Go code with golangci-lint
3-
# See https://golangci-lint.run/usage/linters
4-
# =================================================================
5-
1+
version: "2"
62
linters:
73
enable:
8-
- revive # Replacement for golint
9-
- gofmt # Runs gofmt as part of the linter
10-
- wsl # Whitespace style enforcer, a matter of taste
11-
- stylecheck # A few Go style rules
12-
- misspell # Find misspelled words
13-
- cyclop # Find cyclomatic complexity
14-
- gocyclo # Also find cyclomatic complexity
15-
- bodyclose # Check for HTTP body close errors
16-
- nilerr # Find bad nil/err handling
17-
- nilnil # Also find bad nil/err handling
18-
19-
linters-settings:
20-
misspell:
21-
locale: UK # Enable UK spelling
22-
23-
# Check struck tag naming
24-
tagliatelle:
25-
case:
26-
use-field-name: true
4+
- bodyclose
5+
- cyclop
6+
- gocyclo
7+
- misspell
8+
- nilerr
9+
- nilnil
10+
- revive
11+
- staticcheck
12+
- wsl
13+
settings:
14+
misspell:
15+
locale: UK
16+
revive:
17+
confidence: 0.5
18+
severity: error
19+
enable-all-rules: false
2720
rules:
28-
json: goCamel
29-
yaml: goCamel
30-
31-
revive:
32-
severity: error
33-
enable-all-rules: false
34-
confidence: 0.5
35-
rules:
36-
# There are MANY rules you could enable...
37-
# See https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md
38-
# And https://golangci-lint.run/usage/linters/#revive
39-
- name: line-length-limit
40-
severity: error
41-
arguments: [160]
21+
- name: line-length-limit
22+
arguments:
23+
- 160
24+
severity: error
25+
tagliatelle:
26+
case:
27+
rules:
28+
json: goCamel
29+
yaml: goCamel
30+
use-field-name: true
31+
exclusions:
32+
generated: lax
33+
presets:
34+
- comments
35+
- common-false-positives
36+
- legacy
37+
- std-error-handling
38+
paths:
39+
- third_party$
40+
- builtin$
41+
- examples$
42+
formatters:
43+
enable:
44+
- gofmt
45+
exclusions:
46+
generated: lax
47+
paths:
48+
- third_party$
49+
- builtin$
50+
- examples$

Makefile

Lines changed: 29 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
SERVICE_DIR := cmd
22
FRONTEND_DIR := web/frontend
3-
OUTPUT_DIR := ./output
4-
VERSION ?= 0.8.5
3+
TEST_OUT_DIR := ./test-reports
4+
VERSION ?= 0.8.6
55
BUILD_INFO ?= "Local makefile build"
66
DAPR_RUN_LOGLEVEL := warn
77

@@ -14,6 +14,7 @@ IMAGE_REG ?= ghcr.io
1414
IMAGE_REPO ?= azure-samples/dapr-store
1515
IMAGE_TAG ?= latest
1616
IMAGE_PREFIX := $(IMAGE_REG)/$(IMAGE_REPO)
17+
API_ENDPOINT := http://localhost:9000/v1.0/invoke
1718

1819
.EXPORT_ALL_VARIABLES:
1920
.PHONY: help lint lint-fix test test-reports docker-build docker-run docker-stop docker-push bundle clean run stop
@@ -30,16 +31,28 @@ lint-fix: $(FRONTEND_DIR)/node_modules ## 📝 Lint & format, fixes errors and
3031
golangci-lint run --modules-download-mode=mod --timeout=4m --fix ./...
3132
cd $(FRONTEND_DIR); npm run lint-fix
3233

33-
test: ## 🎯 Unit tests for services and snapshot tests for SPA frontend
34+
test: $(FRONTEND_DIR)/node_modules ## 🎯 Run unit tests for services and snapshot tests for SPA frontend
3435
go test -v -count=1 ./$(SERVICE_DIR)/...
3536
@cd $(FRONTEND_DIR); npm run test:unit
3637

38+
test-report: $(FRONTEND_DIR)/node_modules ## 🎯 Run unit tests and generate report
39+
mkdir -p $(TEST_OUT_DIR)
40+
go test -v -count=1 ./$(SERVICE_DIR)/... | go-junit-report -set-exit-code > $(TEST_OUT_DIR)/unit.xml
41+
@cd $(FRONTEND_DIR); npm run test:unit:report
42+
43+
test-api: ## 🧪 Run API integration tests with httpYac
44+
npx httpyac send api/api-tests.http --all --output short --var endpoint=$(API_ENDPOINT)
45+
46+
test-api-report: ## 🧪 Run API integration tests with httpYac & generate report
47+
mkdir -p $(TEST_OUT_DIR)
48+
npx httpyac send api/api-tests.http --all --output short --var endpoint=$(API_ENDPOINT) --junit > $(TEST_OUT_DIR)/api.xml
49+
3750
frontend: $(FRONTEND_DIR)/node_modules ## 💻 Build and bundle the frontend Vue SPA
3851
cd $(FRONTEND_DIR); npm run build
3952
cd $(SERVICE_DIR)/frontend-host; go build
4053

4154
clean: ## 🧹 Clean the project, remove modules, binaries and outputs
42-
rm -rf output
55+
rm -rf $(TEST_OUT_DIR)
4356
rm -rf $(FRONTEND_DIR)/node_modules
4457
rm -rf $(FRONTEND_DIR)/dist
4558
rm -rf $(FRONTEND_DIR)/coverage
@@ -49,14 +62,18 @@ clean: ## 🧹 Clean the project, remove modules, binaries and outputs
4962
rm -rf $(SERVICE_DIR)/products/products
5063
rm -rf $(SERVICE_DIR)/frontend-host/frontend-host
5164

52-
run: ## 🚀 Start & run everything locally as processes
65+
clear-state: ## 💥 Clear all state from Redis (wipe the database)
66+
docker run --rm --network host redis redis-cli flushall
67+
68+
run: $(FRONTEND_DIR)/node_modules ## 🚀 Start & run everything locally as processes
5369
cd $(FRONTEND_DIR); npm run dev &
5470
dapr run --app-id cart --app-port 9001 --log-level $(DAPR_RUN_LOGLEVEL) go run github.com/azure-samples/dapr-store/cmd/cart &
5571
dapr run --app-id products --app-port 9002 --log-level $(DAPR_RUN_LOGLEVEL) go run github.com/azure-samples/dapr-store/cmd/products ./cmd/products/sqlite.db &
5672
dapr run --app-id users --app-port 9003 --log-level $(DAPR_RUN_LOGLEVEL) go run github.com/azure-samples/dapr-store/cmd/users &
5773
dapr run --app-id orders --app-port 9004 --log-level $(DAPR_RUN_LOGLEVEL) go run github.com/azure-samples/dapr-store/cmd/orders &
5874
@sleep 6
5975
@./scripts/local-gateway/run.sh &
76+
@touch -m /tmp/dapr-store-running
6077
@sleep infinity
6178
@echo "!!! Processes may still be running, please run `make stop` in order to shutdown everything"
6279

@@ -76,13 +93,20 @@ docker-stop: ## 🚫 Stop and remove local containers
7693

7794
stop: ## ⛔ Stop & kill everything started locally from `make run`
7895
docker rm -f api-gateway || true
96+
rm -f /tmp/dapr-store-running
7997
dapr stop --app-id api-gateway
8098
dapr stop --app-id cart
8199
dapr stop --app-id products
82100
dapr stop --app-id users
83101
dapr stop --app-id orders
84102
pkill cart; pkill users; pkill orders; pkill products; pkill main
85103

104+
api-spec: ## 📜 Generate OpenAPI spec & JSON schemas from TypeSpec
105+
cd api/typespec; npm install --silent
106+
rm -rf ./api/typespec/out
107+
npx --package=@typespec/compiler tsp compile ./api/typespec/ --output-dir ./api/typespec/
108+
mv ./api/typespec/out/* ./api/
109+
86110
# ===============================================================================
87111

88112
$(FRONTEND_DIR)/node_modules: $(FRONTEND_DIR)/package.json

README.md

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -20,21 +20,20 @@ The following diagram shows all the components of the application and main inter
2020
The application uses the following [Dapr Building Blocks](https://docs.dapr.io/developing-applications/building-blocks/) and APIs
2121

2222
- **Service Invocation** — The API gateway calls the four main microservices using HTTP calls to [Dapr service invocation](https://docs.dapr.io/developing-applications/building-blocks/service-invocation/service-invocation-overview/). This provides retries, mTLS and service discovery.
23-
- **State** — State is held for *users* and *orders* using the [Dapr state management API](https://docs.dapr.io/developing-applications/building-blocks/state-management/state-management-overview/). The state provider used is Redis, however any other provider could be plugged in without any application code changes.
23+
- **State** — State is held for _users_ and _orders_ using the [Dapr state management API](https://docs.dapr.io/developing-applications/building-blocks/state-management/state-management-overview/). The state provider used is Redis, however any other provider could be plugged in without any application code changes.
2424
- **Pub/Sub** — The submission of new orders through the cart service, is decoupled from the order processing via pub/sub messaging and the [Dapr pub/sub messaging API](https://docs.dapr.io/developing-applications/building-blocks/pubsub/pubsub-overview/). New orders are placed on a topic as messages, to be collected by the orders service. This allows the orders service to independently scale and separates our reads & writes
2525
- **Output Bindings** — To communicate with downstream & 3rd party systems, the [Dapr Bindings API](https://docs.dapr.io/developing-applications/building-blocks/bindings/bindings-overview/) is used. This allows the system to carry out tasks such as saving order details into external storage (e.g. Azure Blob) and notify uses with emails via SendGrid
2626
- **Middleware** — Dapr supports a range of HTTP middleware, for this project traffic rate limiting can enabled on any of the APIs with a single Kubernetes annotation
2727

2828
# Project Status
2929

30-
![](https://img.shields.io/github/last-commit/azure-samples/dapr-store) ![](https://img.shields.io/github/release-date/azure-samples/dapr-store) ![](https://img.shields.io/github/v/release/azure-samples/dapr-store) ![](https://img.shields.io/github/commit-activity/m/azure-samples/dapr-store)
31-
30+
![](https://img.shields.io/github/last-commit/azure-samples/dapr-store) ![](https://img.shields.io/github/release-date/azure-samples/dapr-store) ![](https://img.shields.io/github/v/release/azure-samples/dapr-store) ![](https://img.shields.io/github/commit-activity/m/azure-samples/dapr-store) ![GitHub Actions Workflow Status](https://img.shields.io/github/actions/workflow/status/Azure-Samples/dapr-store/ci-build.yml?branch=main)
3231

3332
# Application Elements & Services
3433

3534
The main elements and microservices that make up the Dapr Store system are described here
3635

37-
Each service uses the [Go REST API Starter Kit & Library](https://github.com/benc-uk/go-rest-api) as a starting basis. Most of the boilerplate and
36+
Each service uses the [Go REST API Starter Kit & Library](https://github.com/benc-uk/go-rest-api) as a starting basis. Most of the boilerplate and
3837
base code for handling requests and generally acting as a RESTful HTTP endpoint is handled by this package.
3938

4039
## Service Code
@@ -193,10 +192,10 @@ This is a (very) basic guide to running Dapr Store locally. Only instructions fo
193192

194193
### Prereqs
195194

196-
- Docker
195+
- Docker (Podman _might_ work, but I've never tried it)
197196
- GCC for CGO & go-sqlite3 (apt-get install build-essential)
198-
- Go v1.20+
199-
- Node.js v18+
197+
- Go v1.23+
198+
- Node.js v20+
200199

201200
### Setup
202201

@@ -207,7 +206,7 @@ wget -q https://raw.githubusercontent.com/dapr/cli/master/install/install.sh -O
207206
dapr init
208207
```
209208

210-
First time only, you will need to setup *go-sqlite3* library
209+
First time only, you will need to setup _go-sqlite3_ library
211210

212211
```bash
213212
CGO_ENABLED=1 go install github.com/mattn/go-sqlite3
@@ -239,16 +238,20 @@ A makefile is provided to assist working with the project and building/running i
239238
help 💬 This help message :)
240239
lint 🔎 Lint & format, check to be run in CI, sets exit code on error
241240
lint-fix 📝 Lint & format, fixes errors and modifies code
242-
test 🎯 Unit tests for services and snapshot tests for SPA frontend
243-
test-reports 📜 Unit tests with coverage and test reports (deprecated)
244-
bundle 💻 Build and bundle the frontend Vue SPA
241+
test 🎯 Unit tests for services and snapshot tests for SPA frontend
242+
test-report 🎯 Unit tests and generate report
243+
test-api 🧪 Run API integration tests with httpYac
244+
test-api-report 🧪 Run API integration tests with httpYac & generate report
245+
frontend 💻 Build and bundle the frontend Vue SPA
245246
clean 🧹 Clean the project, remove modules, binaries and outputs
247+
clear-state 💥 Clear all state from Redis (wipe the database)
246248
run 🚀 Start & run everything locally as processes
247249
docker-run 🐋 Run locally using containers and Docker compose
248250
docker-build 🔨 Build all containers using Docker compose
249251
docker-push 📤 Push all containers using Docker compose
250252
docker-stop 🚫 Stop and remove local containers
251253
stop ⛔ Stop & kill everything started locally from `make run`
254+
api-spec 📜 Generate OpenAPI spec & JSON schemas from TypeSpec
252255
```
253256

254257
# CI / CD
@@ -263,7 +266,7 @@ A set of CI and CD release GitHub actions workflows are included in `.github/wor
263266

264267
The default mode of operation for the Dapr Store is in "demo mode" where there is no identity provider configured, and no security enforcement on the APIs. This makes it simple to run and allows us to focus on the Dapr aspects of the project. In this mode a demo/dummy user account is used to sign-in and place orders in the store.
265268

266-
Optionally Dapr store can be configured utilise the [Microsoft identity platform](https://docs.microsoft.com/en-us/azure/active-directory/develop/) (aka Microsoft Entra ID) as an identity provider. This then supports real user sign-in, and securing of the APIs.
269+
Optionally Dapr store can be configured utilise the [Microsoft identity platform](https://docs.microsoft.com/en-us/azure/active-directory/develop/) (aka Microsoft Entra ID) as an identity provider. When this is configured, the app supports real user sign-in, and the APIs are secured.
267270

268271
#### [📃 Extra Doc: Security, identity & authentication](./docs/auth-identity/)
269272

@@ -277,12 +280,12 @@ All services support the following environmental variables. All settings are opt
277280
- `AUTH_CLIENT_ID` - Used to enable integration with Azure AD for identity and authentication. Default is _blank_, which runs the service with no identity backend. See the [security, identity & authentication docs](#security-identity--authentication) for more details.
278281
- `DAPR_STORE_NAME` - Name of the Dapr state component to use. Default is `statestore`
279282

280-
The following vars are used only by the *Cart* and *Orders* services:
283+
The following vars are used only by the _Cart_ and _Orders_ services:
281284

282285
- `DAPR_ORDERS_TOPIC` - Name of the Dapr pub/sub topic to use for orders. Default is `orders-queue`
283286
- `DAPR_PUBSUB_NAME` - Name of the Dapr pub/sub component to use for orders. Default is `pubsub`
284287

285-
The following vars are only used by the *Orders* service:
288+
The following optional vars are only used by the _Orders_ service:
286289

287290
- `DAPR_EMAIL_NAME` - Name of the Dapr SendGrid component to use for sending order emails. Default is `orders-email`
288291
- `DAPR_REPORT_NAME` - Name of the Dapr Azure Blob component to use for saving order reports. Default is `orders-report`

0 commit comments

Comments
 (0)