Skip to content

Commit

Permalink
fix image name when running k8s example without skaffold (#1139)
Browse files Browse the repository at this point in the history
* fix image name

* Change gateway port to 8081.
Add microk8s support to skaffold.
  • Loading branch information
Yshayy committed May 23, 2019
1 parent e438cab commit 22baf53
Show file tree
Hide file tree
Showing 20 changed files with 92 additions and 72 deletions.
5 changes: 2 additions & 3 deletions CONTRIBUTING.md
Expand Up @@ -44,9 +44,9 @@
```

2. Yarn start
3. Go to http://localhost:8080/login and use basic auth with (user: admin-app, password: 8v/iUG0vTH4BtVgkSn3Tng==)
3. Go to http://localhost:8081/login and use basic auth with (user: admin-app, password: 8v/iUG0vTH4BtVgkSn3Tng==)

Access Tweek gateway using localhost:8080.
Access Tweek gateway using localhost:8081.
Tweek gateway route all traffic to other resources based on: https://github.com/Soluto/tweek/blob/master/services/gateway/settings/settings.json
The root path redirect to Tweek Editor UI

Expand All @@ -64,7 +64,6 @@ After installing Skaffold, use `skaffold dev --port-forward=false`

### Debug

- if you haven't pulled or built the environment, run `npm run docker-compose pull tweek-git tweek-management tweek-api`
- run `npm run start:full-env`

### Unit Tests
Expand Down
20 changes: 10 additions & 10 deletions README.md
Expand Up @@ -56,7 +56,7 @@ After setting up our environment, we're going to create our first key.
Keys in tweek are the most basic building blocks and they represent a container for dynamic value that affect feature behaviors.
Our first key, will be a key that is responsible for the color of a "sign up" button.

- Open http://localhost:8080/login in browser.
- Open http://localhost:8081/login in browser.
- Login
- User Basic auth (user: admin-app, password: 8v/iUG0vTH4BtVgkSn3Tng==)
- Can also use OIDC mock server login button for testing OIDC (user: User, password: pwd)
Expand All @@ -77,9 +77,9 @@ More on [keys and paths](https://docs.tweek.fm/concepts/keys/keys-ands-paths)

Use curl/postman/chrome to fire GET Request:

- http://localhost:8080/api/v2/values/my_app/sign_button/color -> expected to be "red"
- http://localhost:8080/api/v2/values/my_app/sign_button/color?user.Country=canada -> expected to be "blue"
- http://localhost:8080/api/v2/values/my_app/sign_button/_?user.Country=canada -> expected to be {"color":"blue"}
- http://localhost:8081/api/v2/values/my_app/sign_button/color -> expected to be "red"
- http://localhost:8081/api/v2/values/my_app/sign_button/color?user.Country=canada -> expected to be "blue"
- http://localhost:8081/api/v2/values/my_app/sign_button/_?user.Country=canada -> expected to be {"color":"blue"}

Using the rest api, an application can query Tweek for getting the right set of values for each specific user.
More on Tweek [Rest api](https://docs.tweek.fm/api/rest-api).
Expand All @@ -96,11 +96,11 @@ Tweek provide UI and rest api for editing context.

After that, we can query Tweek API with:

- http://localhost:8080/api/v2/values/my_app/sign_button/color?user=john -> expected to be "blue"
- http://localhost:8081/api/v2/values/my_app/sign_button/color?user=john -> expected to be "blue"

You can also use the api for updating Tweek context:

- curl -X POST http://localhost:8080/api/v2/context/user/john \
- curl -X POST http://localhost:8081/api/v2/context/user/john \
-H 'content-type: application/json' \
-H 'x-client-id: admin-app' \
-H 'x-client-secret: 8v/iUG0vTH4BtVgkSn3Tng==' \
Expand All @@ -116,10 +116,10 @@ Create new key in the editor "my_app/sign_button/is_enabled" with value type "bo
Add new rule, remove all conditions, set the the rule value to gradual release with 50%.
Try querying configuration with different users and You'll have different results.

- http://localhost:8080/api/v2/values/my_app/sign_button/is_enabled?user=barny
- http://localhost:8080/api/v2/values/my_app/sign_button/is_enabled?user=robin
- http://localhost:8080/api/v2/values/my_app/sign_button/is_enabled?user=ted
- http://localhost:8080/api/v2/values/my_app/sign_button/is_enabled?user=lily
- http://localhost:8081/api/v2/values/my_app/sign_button/is_enabled?user=barny
- http://localhost:8081/api/v2/values/my_app/sign_button/is_enabled?user=robin
- http://localhost:8081/api/v2/values/my_app/sign_button/is_enabled?user=ted
- http://localhost:8081/api/v2/values/my_app/sign_button/is_enabled?user=lily
- etc...

More on how multi-variant keys work in Tweek. (link)
Expand Down
6 changes: 2 additions & 4 deletions deployments/dev/docker-compose.e2e.yml
Expand Up @@ -37,10 +37,6 @@ services:
- CONFIGOR_ENV=test

oidc-server-mock:
container_name: oidc-server-mock
image: soluto/oidc-server-mock
ports:
- "8081:80"
environment:
- REDIRECT_URIS=http://gateway/auth-result/oidc

Expand All @@ -50,6 +46,7 @@ services:
shm_size: 2g
volumes:
- ../../e2e/ui:/src
- /src/node_modules
depends_on:
- gateway
- editor
Expand All @@ -64,6 +61,7 @@ services:
container_name: e2e-integration
volumes:
- ../../e2e/integration:/opt/app
- /opt/app/node_modules
depends_on:
- gateway
environment:
Expand Down
8 changes: 4 additions & 4 deletions deployments/dev/docker-compose.override.yml
Expand Up @@ -114,16 +114,16 @@ services:
container_name: oidc-server-mock
image: soluto/oidc-server-mock
ports:
- "8081:80"
- "8082:80"
environment:
- ASPNETCORE_ENVIRONMENT=Development
- CLIENT_ID=tweek-openid-mock-client
- REDIRECT_URIS=http://localhost:8080/auth-result/oidc
- REDIRECT_URIS=http://localhost:8081/auth-result/oidc
- TEST_USER={"SubjectId":"user","Username":"user","Password":"pwd"}

gateway:
ports:
- "8080:80"
- "8081:80"
depends_on:
- minio
- nats
Expand All @@ -141,7 +141,7 @@ services:
- TWEEKGATEWAY_SECURITY_POLICYSTORAGE_MINIOSECURE=false
- TWEEKGATEWAY_SECURITY_POLICYSTORAGE_NATSENDPOINT=nats://nats:4222
- TWEEKGATEWAY_SECURITY_TWEEKSECRETKEY_PATH=/run/secrets/tweek_ssh_private_key
- TWEEKGATEWAY_SECURITY_AUTH_BASICAUTH_REDIRECTURLS=['http://localhost:8080', 'http://localhost:3000']
- TWEEKGATEWAY_SECURITY_AUTH_BASICAUTH_REDIRECTURLS=['http://localhost:8081', 'http://localhost:3000']
- TWEEKGATEWAY_CONFIGFILEPATH=/config/gateway.json
volumes:
- ./gateway/config:/config
Expand Down
4 changes: 2 additions & 2 deletions deployments/dev/gateway/config/gateway.json
Expand Up @@ -10,8 +10,8 @@
"providers": {
"mock": {
"name": "Mock OpenId Connect server",
"issuer": "http://localhost:8081",
"authority": "http://localhost:8081",
"issuer": "http://localhost:8082",
"authority": "http://localhost:8082",
"jwks_uri": "http://oidc-server-mock/.well-known/openid-configuration/jwks",
"client_id": "tweek-openid-mock-client",
"login_info": {
Expand Down
8 changes: 4 additions & 4 deletions deployments/dev/gateway/config/gateway.local.json
Expand Up @@ -9,9 +9,9 @@
"providers": {
"mock": {
"name": "Mock OpenId Connect server",
"issuer": "http://localhost:8081",
"authority": "http://localhost:8081",
"jwks_uri": "http://localhost:8081/.well-known/openid-configuration/jwks",
"issuer": "http://localhost:8082",
"authority": "http://localhost:8082",
"jwks_uri": "http://localhost:8082/.well-known/openid-configuration/jwks",
"client_id": "tweek-openid-mock-client",
"login_info": {
"login_type": "oidc",
Expand Down Expand Up @@ -43,6 +43,6 @@
}
},
"server": {
"ports": [3000, 8080]
"ports": [8081]
}
}
13 changes: 8 additions & 5 deletions deployments/kubernetes/README.md
Expand Up @@ -19,14 +19,17 @@ Install [Skaffold](https://github.com/GoogleContainerTools/skaffold/releases).
First of all, run the skaffold.

```
skaffold dev -f ./deployments/kubernetes/skaffold.yaml
skaffold dev
# add profile flag if using microk8s:
skaffold dev -p microk8s
```

If using Minikube create port forwarding:
If using Minikube/Microk8s create port forwarding:

```bash
kubectl port-forward deployment/gateway 8080:80
kubectl port-forward deployment/oidc-server-mock 8081:80
kubectl port-forward deployment/gateway 8081:80
kubectl port-forward deployment/oidc-server-mock 8082:80
```

Finally, open in browser [http://localhost:8080](http://localhost:8080).
Finally, open in browser [http://localhost:8081](http://localhost:8081).
2 changes: 1 addition & 1 deletion deployments/kubernetes/gateway.yaml
Expand Up @@ -78,5 +78,5 @@ spec:
selector:
app: gateway
ports:
- port: 8080
- port: 8081
targetPort: 80
2 changes: 1 addition & 1 deletion deployments/kubernetes/git.yaml
Expand Up @@ -11,7 +11,7 @@ spec:
spec:
containers:
- name: tweek-bare-repo
image: soluto/tweek-git
image: soluto/tweek-bare-repo
imagePullPolicy: IfNotPresent
ports:
- containerPort: 22
Expand Down
8 changes: 4 additions & 4 deletions deployments/kubernetes/infra/gateway-config.yaml
Expand Up @@ -16,9 +16,9 @@ data:
"providers": {
"mock": {
"name": "Mock OpenId Connect server",
"issuer": "http://localhost:8081",
"authority": "http://localhost:8081",
"jwks_uri": "http://oidc-server-mock:8081/.well-known/openid-configuration/jwks",
"issuer": "http://localhost:8082",
"authority": "http://localhost:8082",
"jwks_uri": "http://oidc-server-mock:8082/.well-known/openid-configuration/jwks",
"client_id": "tweek-openid-mock-client",
"login_info": {
"login_type": "oidc",
Expand All @@ -29,7 +29,7 @@ data:
},
"basic_auth": {
"redirect_urls": [
"http://localhost:8080"
"http://localhost:8081"
]
}
}
Expand Down
4 changes: 2 additions & 2 deletions deployments/kubernetes/infra/oidc-server-mock.yaml
Expand Up @@ -18,7 +18,7 @@ spec:
- name: CLIENT_ID
value: tweek-openid-mock-client
- name: REDIRECT_URIS
value: http://localhost:8080/auth-result/oidc
value: http://localhost:8081/auth-result/oidc
- name: TEST_USER
value: '{"SubjectId":"user","Username":"user","Password":"pwd"}'
ports:
Expand All @@ -33,6 +33,6 @@ spec:
selector:
app: oidc-server-mock
ports:
- port: 8081
- port: 8082
targetPort: 80
---
20 changes: 10 additions & 10 deletions docs/pages/1.getting-started/02.using-tweek.md
Expand Up @@ -10,7 +10,7 @@ After setting up our environment, we're going to create our first key.
Keys in tweek are the most basic building blocks and they represent a container for dynamic value that affect feature behaviors.
Our first key, will be a key that is responsible for the color of a "sign up" button.

- Open http://localhost:8080/login in browser.
- Open http://localhost:8081/login in browser.
- Login
- User Basic auth (user: admin-app, password: 8v/iUG0vTH4BtVgkSn3Tng==)
- Can also use OIDC mock server login button for testing OIDC (user: User, password: pwd)
Expand All @@ -31,9 +31,9 @@ More on [keys and paths](https://docs.tweek.fm/concepts/keys/keys-ands-paths)

Use curl/postman/chrome to fire GET Request:

- http://localhost:8080/api/v2/values/my_app/sign_button/color -> expected to be "red"
- http://localhost:8080/api/v2/values/my_app/sign_button/color?user.Country=canada -> expected to be "blue"
- http://localhost:8080/api/v2/values/my_app/sign_button/_?user.Country=canada -> expected to be {"color":"blue"}
- http://localhost:8081/api/v2/values/my_app/sign_button/color -> expected to be "red"
- http://localhost:8081/api/v2/values/my_app/sign_button/color?user.Country=canada -> expected to be "blue"
- http://localhost:8081/api/v2/values/my_app/sign_button/_?user.Country=canada -> expected to be {"color":"blue"}

Using the rest api, an application can query Tweek for getting the right set of values for each specific user.
More on Tweek [Rest api](https://docs.tweek.fm/api/rest-api).
Expand All @@ -50,11 +50,11 @@ Tweek provide UI and rest api for editing context.

After that, we can query Tweek API with:

- http://localhost:8080/api/v2/values/my_app/sign_button/color?user=john -> expected to be "blue"
- http://localhost:8081/api/v2/values/my_app/sign_button/color?user=john -> expected to be "blue"

You can also use the api for updating Tweek context:

- curl -X POST http://localhost:8080/api/v2/context/user/john \
- curl -X POST http://localhost:8081/api/v2/context/user/john \
-H 'content-type: application/json' \
-H 'x-client-id: admin-app' \
-H 'x-client-secret: 8v/iUG0vTH4BtVgkSn3Tng==' \
Expand All @@ -70,10 +70,10 @@ Create new key in the editor "my_app/sign_button/is_enabled" with value type "bo
Add new rule, remove all conditions, set the the rule value to gradual release with 50%.
Try querying configuration with different users and You'll have different results.

- http://localhost:8080/api/v2/values/my_app/sign_button/is_enabled?user=barny
- http://localhost:8080/api/v2/values/my_app/sign_button/is_enabled?user=robin
- http://localhost:8080/api/v2/values/my_app/sign_button/is_enabled?user=ted
- http://localhost:8080/api/v2/values/my_app/sign_button/is_enabled?user=lily
- http://localhost:8081/api/v2/values/my_app/sign_button/is_enabled?user=barny
- http://localhost:8081/api/v2/values/my_app/sign_button/is_enabled?user=robin
- http://localhost:8081/api/v2/values/my_app/sign_button/is_enabled?user=ted
- http://localhost:8081/api/v2/values/my_app/sign_button/is_enabled?user=lily
- etc...

More on how multi-variant keys work in Tweek. (link)
12 changes: 6 additions & 6 deletions docs/pages/2.concepts/02.context/intro-to-context.md
Expand Up @@ -19,8 +19,8 @@ For example, assuming we have a key `is_allowed_to_drive` with rule:
If we send these requests to Tweek:

```
GET http://localhost:8080/api/v2/values/is_allowed_to_drive -> false
GET http://localhost:8080/api/v2/values/is_allowed_to_drive?User.Age=20 -> true
GET http://localhost:8081/api/v2/values/is_allowed_to_drive -> false
GET http://localhost:8081/api/v2/values/is_allowed_to_drive?User.Age=20 -> true
```

In order to get the right values from Tweek, we need to provide Tweek the relevant context for the request.
Expand All @@ -31,13 +31,13 @@ While we can always pass context parameters in url, a different approach is to s
For example:

```
GET http://localhost:8080/api/v2/values/is_allowed_to_drive?User=john -> false
GET http://localhost:8081/api/v2/values/is_allowed_to_drive?User=john -> false
```

We've asked for the value of "is_allowed_to_drive" for user John, but Tweek doesn't know any facts about him, let's change it:

```
POST http://localhost:8080/api/v2/context/user/john
POST http://localhost:8081/api/v2/context/user/john
{
"Age": 20
}
Expand All @@ -46,15 +46,15 @@ POST http://localhost:8080/api/v2/context/user/john
After adding the data, let's retry our first request:

```
GET http://localhost:8080/api/v2/keys/is_allowed_to_drive?User=john -> true
GET http://localhost:8081/api/v2/keys/is_allowed_to_drive?User=john -> true
```

## Identities & Properties

You've noticed that we used "User.Age" and not simply "Age", the reason is that Tweek treat facts as properties on top of identities, for example:

```
GET http://localhost:8080/api/v2/keys/path/to/key?User=john&User.Country=england
GET http://localhost:8081/api/v2/keys/path/to/key?User=john&User.Country=england
```

1. Tweek understands that it need to get the values for identity user "john".
Expand Down
2 changes: 1 addition & 1 deletion e2e/integration/utils/client.js
Expand Up @@ -26,7 +26,7 @@ nconf
.argv()
.env()
.defaults({
GATEWAY_URL: 'http://localhost:8080',
GATEWAY_URL: 'http://localhost:8081',
CLIENT_ID: 'admin-app',
CLIENT_SECRET: '8v/iUG0vTH4BtVgkSn3Tng==',

Expand Down
4 changes: 2 additions & 2 deletions e2e/ui/utils/constants.js
Expand Up @@ -4,8 +4,8 @@ nconf
.argv()
.env()
.defaults({
GATEWAY_URL: 'http://localhost:8080',
EDITOR_URL: 'http://localhost:8080/',
GATEWAY_URL: 'http://localhost:8081',
EDITOR_URL: 'http://localhost:8081/',
});

const trimEnd = (str) => str.replace(/\/+$/, '');
Expand Down
2 changes: 1 addition & 1 deletion services/editor/Dockerfile
@@ -1,5 +1,5 @@
# ---- Deps ----
FROM node:10.15.0-alpine AS dependencies
FROM node:10.15.3-alpine AS dependencies
WORKDIR /opt/app/
COPY package.json yarn.lock ./
RUN yarn --production
Expand Down
2 changes: 1 addition & 1 deletion services/editor/debug.Dockerfile
Expand Up @@ -4,5 +4,5 @@ WORKDIR /app
COPY package.json yarn.lock ./
RUN yarn
COPY . /app
RUN yarn test
RUN CI=true yarn test
CMD [ "yarn", "start" ]
4 changes: 2 additions & 2 deletions services/editor/package.json
Expand Up @@ -11,12 +11,12 @@
"scripts": {
"start": "npm-run-all -l build:less -p -r start:watch:*",
"start:watch:less": "node-less-chokidar src/ -o src/ --watch --recursive",
"start:watch:app": "REACT_APP_GATEWAY_URL=http://localhost:8080 react-app-rewired start",
"start:watch:app": "REACT_APP_GATEWAY_URL= react-app-rewired start",
"start:full-env": "yarn docker-compose up -d gateway publishing && yarn start",
"build": "run-s -l build:*",
"build:less": "node-less-chokidar src/",
"build:app": "react-app-rewired build",
"test": "react-scripts test",
"test": "react-scripts test --no-watchman --watch=false --watchAll=false",
"test:e2e": "cd ../../ && yarn start:e2e gateway && EDITOR_URL=http://localhost:3000 yarn test:local:ui",
"eject": "react-scripts eject",
"teardown": "yarn docker-compose down --remove-orphans",
Expand Down
Expand Up @@ -3,7 +3,7 @@ package rules
default subject = { "user": null, "group": null }

subject = { "user": "admin-app", "group": "externalapps"} {
input.iss = "http://localhost:8081"
startswith(input.iss, "http://localhost:")
input.aud = "tweek-openid-mock-client"
} else = { "user": input.sub, "group": "default" } {
true
Expand Down

0 comments on commit 22baf53

Please sign in to comment.