Skip to content

Commit

Permalink
chore: update tutorials
Browse files Browse the repository at this point in the history
  • Loading branch information
mloiseleur authored Sep 20, 2024
1 parent d10e70f commit 3d170dc
Show file tree
Hide file tree
Showing 11 changed files with 73 additions and 79 deletions.
8 changes: 4 additions & 4 deletions WALKTHROUGH.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ helm repo add --force-update traefik https://traefik.github.io/charts
kubectl create namespace traefik
# Install the Helm chart
helm install traefik -n traefik --wait \
--version v31.0.0 \
--version v31.1.1 \
--set ingressClass.enabled=false \
--set ingressRoute.dashboard.enabled=true \
--set ingressRoute.dashboard.matchRule='Host(`dashboard.docker.localhost`)' \
Expand Down Expand Up @@ -262,12 +262,12 @@ Then, upgrade Traefik Proxy to Traefik Hub using the same Helm chart:

```shell
helm upgrade traefik -n traefik --wait \
--version v31.0.0 \
--version v31.1.1 \
--reuse-values \
--set hub.token=traefik-hub-license \
--set image.registry=ghcr.io \
--set image.repository=traefik/traefik-hub \
--set image.tag=v3.4.0 \
--set image.tag=v3.4.1 \
traefik/traefik
```

Expand Down Expand Up @@ -392,7 +392,7 @@ First, we enable API Management on Traefik Traefik Hub using the same Helm chart

```shell
helm upgrade traefik -n traefik --wait \
--version v31.0.0 \
--version v31.1.1 \
--reuse-values \
--set hub.apimanagement.enabled=true \
traefik/traefik
Expand Down
6 changes: 3 additions & 3 deletions api-gateway/1-getting-started/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -89,15 +89,15 @@ Install Traefik Hub API Gateway using Helm:
helm repo add --force-update traefik https://traefik.github.io/charts
# Install the Helm chart
helm install traefik -n traefik --wait \
--version v31.0.0 \
--version v31.1.1 \
--set hub.token=traefik-hub-license \
--set ingressClass.enabled=false \
--set ingressRoute.dashboard.enabled=true \
--set ingressRoute.dashboard.matchRule='Host(`dashboard.docker.localhost`)' \
--set ingressRoute.dashboard.entryPoints={web} \
--set image.registry=ghcr.io \
--set image.repository=traefik/traefik-hub \
--set image.tag=v3.4.0 \
--set image.tag=v3.4.1 \
--set ports.web.nodePort=30000 \
--set ports.websecure.nodePort=30001 \
traefik/traefik
Expand All @@ -119,7 +119,7 @@ helm upgrade traefik -n traefik --wait \
--set ingressRoute.dashboard.entryPoints={web} \
--set image.registry=ghcr.io \
--set image.repository=traefik/traefik-hub \
--set image.tag=v3.4.0 \
--set image.tag=v3.4.1 \
--set ports.web.nodePort=30000 \
--set ports.websecure.nodePort=30001 \
traefik/traefik
Expand Down
1 change: 0 additions & 1 deletion api-gateway/1-getting-started/linux/traefik-hub.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
################################################################
[hub]
token = "PASTE_YOUR_TOKEN_HERE"
platformUrl = "https://platform-preview.hub.traefik.io/agent"

################################################################
# Entrypoints configuration
Expand Down
10 changes: 5 additions & 5 deletions api-management/1-getting-started/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ Now, install Traefik Hub with Helm:
helm repo add --force-update traefik https://traefik.github.io/charts
# Install the Helm chart
helm install traefik -n traefik --wait \
--version v31.0.0 \
--version v31.1.1 \
--set hub.token=traefik-hub-license \
--set hub.apimanagement.enabled=true \
--set ingressClass.enabled=false \
Expand All @@ -91,7 +91,7 @@ helm install traefik -n traefik --wait \
--set ingressRoute.dashboard.entryPoints={web} \
--set image.registry=ghcr.io \
--set image.repository=traefik/traefik-hub \
--set image.tag=v3.4.0 \
--set image.tag=v3.4.1 \
--set ports.web.nodePort=30000 \
--set ports.websecure.nodePort=30001 \
traefik/traefik
Expand All @@ -114,7 +114,7 @@ helm upgrade traefik -n traefik --wait \
--set ingressRoute.dashboard.entryPoints={web} \
--set image.registry=ghcr.io \
--set image.repository=traefik/traefik-hub \
--set image.tag=v3.4.0 \
--set image.tag=v3.4.1 \
--set ports.web.nodePort=30000 \
--set ports.websecure.nodePort=30001 \
traefik/traefik
Expand Down Expand Up @@ -177,7 +177,7 @@ ingressroute.traefik.io/getting-started-apimanagement created
At this moment, this API is exposed. It's possible to reach it using `curl` command:

```shell
curl http://getting-started.apimanagement.docker.localhost/weather
curl -s http://getting-started.apimanagement.docker.localhost/weather | jq
```

```json
Expand Down Expand Up @@ -343,7 +343,7 @@ export ADMIN_TOKEN=
The weather API is reachable with this token set as header :tada: :

```shell
curl -H "Authorization: Bearer $ADMIN_TOKEN" http://api.getting-started.apimanagement.docker.localhost/weather
curl -s -H "Authorization: Bearer $ADMIN_TOKEN" http://api.getting-started.apimanagement.docker.localhost/weather | jq
```

```json
Expand Down
16 changes: 8 additions & 8 deletions api-management/3-api-lifecycle-management/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export ADMIN_TOKEN=
# This call is not allowed
curl -i http://api.lifecycle.apimanagement.docker.localhost/weather
# This call is allowed
curl -H "Authorization: Bearer $ADMIN_TOKEN" http://api.lifecycle.apimanagement.docker.localhost/weather
curl -s -H "Authorization: Bearer $ADMIN_TOKEN" http://api.lifecycle.apimanagement.docker.localhost/weather | jq
```

## Publish the first API Version
Expand Down Expand Up @@ -132,7 +132,7 @@ And confirm it's still working:
# This call is not allowed
curl -i http://api.lifecycle.apimanagement.docker.localhost/weather-v1/weather
# This call is allowed
curl -H "Authorization: Bearer $ADMIN_TOKEN" http://api.lifecycle.apimanagement.docker.localhost/weather-v1/weather
curl -s -H "Authorization: Bearer $ADMIN_TOKEN" http://api.lifecycle.apimanagement.docker.localhost/weather-v1/weather | jq
```

## Publish a second API Version
Expand Down Expand Up @@ -258,9 +258,9 @@ Now, we can test if it works:
# Even with preview X-Version header, it should return 401 without token
curl -i -H "X-Version: preview" http://api.lifecycle.apimanagement.docker.localhost/weather-multi-versions/weather
# Regular access => returns weather data
curl -H "Authorization: Bearer $ADMIN_TOKEN" http://api.lifecycle.apimanagement.docker.localhost/weather-multi-versions/weather
curl -s -H "Authorization: Bearer $ADMIN_TOKEN" http://api.lifecycle.apimanagement.docker.localhost/weather-multi-versions/weather | jq
# Preview access, with special header => returns forecast data
curl -H "X-Version: preview" -H "Authorization: Bearer $ADMIN_TOKEN" http://api.lifecycle.apimanagement.docker.localhost/weather-multi-versions/weather
curl -s -H "X-Version: preview" -H "Authorization: Bearer $ADMIN_TOKEN" http://api.lifecycle.apimanagement.docker.localhost/weather-multi-versions/weather | jq
```

To go further, one can use this pattern with other Traefik Middlewares to route versions based on many parameters: path, query, content type, clientIP, basicAuth, forwardAuth, and many others!
Expand Down Expand Up @@ -385,10 +385,10 @@ ingressroute.traefik.io/weather-api created
A simple test should confirm that it works:

```shell
curl -H "Authorization: Bearer $ADMIN_TOKEN" http://api.lifecycle.apimanagement.docker.localhost/weather-v1-wrr/weather
curl -H "Authorization: Bearer $ADMIN_TOKEN" http://api.lifecycle.apimanagement.docker.localhost/weather-v1-wrr/weather
curl -H "Authorization: Bearer $ADMIN_TOKEN" http://api.lifecycle.apimanagement.docker.localhost/weather-v1-wrr/weather
curl -H "Authorization: Bearer $ADMIN_TOKEN" http://api.lifecycle.apimanagement.docker.localhost/weather-v1-wrr/weather
curl -s -H "Authorization: Bearer $ADMIN_TOKEN" http://api.lifecycle.apimanagement.docker.localhost/weather-v1-wrr/weather | jq
curl -s -H "Authorization: Bearer $ADMIN_TOKEN" http://api.lifecycle.apimanagement.docker.localhost/weather-v1-wrr/weather | jq
curl -s -H "Authorization: Bearer $ADMIN_TOKEN" http://api.lifecycle.apimanagement.docker.localhost/weather-v1-wrr/weather | jq
curl -s -H "Authorization: Bearer $ADMIN_TOKEN" http://api.lifecycle.apimanagement.docker.localhost/weather-v1-wrr/weather | jq
```

To go further, it's also possible to mirror production traffic to a new version and/or to use a sticky session.
2 changes: 1 addition & 1 deletion src/api-server/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# syntax=docker/dockerfile:1.9
# syntax=docker/dockerfile:1.10

# golang builder
FROM golang:1.23 AS builder
Expand Down
6 changes: 3 additions & 3 deletions tests/apimanagement/apimanagement_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -237,14 +237,14 @@ func (s *APIManagementTestSuite) TestAPILifeCycleManagement() {
req, err = http.NewRequest(http.MethodGet, "http://api.lifecycle.apimanagement.docker.localhost/weather-multi-versions/weather", nil)
s.Require().NoError(err)
req.Header.Add("Authorization", "Bearer "+adminToken)
err = try.RequestWithTransport(req, 10*time.Second, s.tr, try.BodyContains("GopherCity"))
err = try.RequestWithTransport(req, 10*time.Second, s.tr, try.BodyContains("GopherRocks"))
s.Assert().NoError(err)

req, err = http.NewRequest(http.MethodGet, "http://api.lifecycle.apimanagement.docker.localhost/weather-multi-versions/weather", nil)
s.Require().NoError(err)
req.Header.Add("X-Version", "preview")
req.Header.Add("Authorization", "Bearer "+adminToken)
err = try.RequestWithTransport(req, 10*time.Second, s.tr, try.BodyContains("GopherRocks"))
err = try.RequestWithTransport(req, 10*time.Second, s.tr, try.BodyContains("GopherCentral"))
s.Assert().NoError(err)

// Try the new version with a part of the traffic
Expand All @@ -257,7 +257,7 @@ func (s *APIManagementTestSuite) TestAPILifeCycleManagement() {
req.Header.Add("Authorization", "Bearer "+adminToken)
err = try.RequestWithTransport(req, 10*time.Second, s.tr, try.BodyContains("GopherRocks"))
s.Assert().NoError(err)
err = try.RequestWithTransport(req, 10*time.Second, s.tr, try.BodyContains("GopherCity"))
err = try.RequestWithTransport(req, 10*time.Second, s.tr, try.BodyContains("GopherCentral"))
s.Assert().NoError(err)

}
Expand Down
29 changes: 14 additions & 15 deletions tests/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ module github.com/traefik/hub/tests
go 1.23.0

require (
github.com/docker/docker v27.1.2+incompatible
github.com/docker/docker v27.3.0+incompatible
github.com/pkg/errors v0.9.1
github.com/stretchr/testify v1.9.0
github.com/testcontainers/testcontainers-go v0.32.0
github.com/testcontainers/testcontainers-go/modules/k3s v0.32.0
github.com/testcontainers/testcontainers-go v0.33.0
github.com/testcontainers/testcontainers-go/modules/k3s v0.33.0
github.com/traefik/traefik/v3 v3.1.2
k8s.io/api v0.31.0
k8s.io/apimachinery v0.31.0
Expand All @@ -16,12 +16,11 @@ require (
)

require (
dario.cat/mergo v1.0.0 // indirect
dario.cat/mergo v1.0.1 // indirect
github.com/AdaLogics/go-fuzz-headers v0.0.0-20230811130428-ced1acdcaa24 // indirect
github.com/Azure/go-ansiterm v0.0.0-20230124172434-306776ec8161 // indirect
github.com/Microsoft/go-winio v0.6.2 // indirect
github.com/Microsoft/hcsshim v0.12.5 // indirect
github.com/cenkalti/backoff/v4 v4.3.0 // indirect
github.com/containerd/containerd v1.7.20 // indirect
github.com/containerd/log v0.1.0 // indirect
github.com/containerd/platforms v0.2.1 // indirect
github.com/cpuguy83/dockercfg v0.3.1 // indirect
Expand Down Expand Up @@ -50,7 +49,7 @@ require (
github.com/json-iterator/go v1.1.12 // indirect
github.com/klauspost/compress v1.17.9 // indirect
github.com/kvtools/valkeyrie v1.0.0 // indirect
github.com/lufia/plan9stats v0.0.0-20240513124658-fba389f38bae // indirect
github.com/lufia/plan9stats v0.0.0-20240909124753-873cd0166683 // indirect
github.com/magiconair/properties v1.8.7 // indirect
github.com/mailru/easyjson v0.7.7 // indirect
github.com/mattn/go-colorable v0.1.13 // indirect
Expand Down Expand Up @@ -78,16 +77,16 @@ require (
github.com/tklauser/numcpus v0.8.0 // indirect
github.com/x448/float16 v0.8.4 // indirect
github.com/yusufpapurcu/wmi v1.2.4 // indirect
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.53.0 // indirect
go.opentelemetry.io/otel v1.28.0 // indirect
go.opentelemetry.io/otel/metric v1.28.0 // indirect
go.opentelemetry.io/otel/trace v1.28.0 // indirect
golang.org/x/crypto v0.26.0 // indirect
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.55.0 // indirect
go.opentelemetry.io/otel v1.30.0 // indirect
go.opentelemetry.io/otel/metric v1.30.0 // indirect
go.opentelemetry.io/otel/trace v1.30.0 // indirect
golang.org/x/crypto v0.27.0 // indirect
golang.org/x/net v0.28.0 // indirect
golang.org/x/oauth2 v0.22.0 // indirect
golang.org/x/sys v0.24.0 // indirect
golang.org/x/term v0.23.0 // indirect
golang.org/x/text v0.17.0 // indirect
golang.org/x/sys v0.25.0 // indirect
golang.org/x/term v0.24.0 // indirect
golang.org/x/text v0.18.0 // indirect
golang.org/x/time v0.6.0 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20240814211410-ddb44dafa142 // indirect
google.golang.org/protobuf v1.34.2 // indirect
Expand Down
Loading

0 comments on commit 3d170dc

Please sign in to comment.