Skip to content

Commit 912ae5f

Browse files
committed
WIP
1 parent a00f4f8 commit 912ae5f

Some content is hidden

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

47 files changed

+1197
-63
lines changed

.envrc.bak

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
export MINIKUBE_PROFILE=minikube-wbaas
2+
export MINIKUBE_MEMORY=max
3+
export MINIKUBE_CPUS=max
4+
export MINIKUBE_IN_STYLE=false
5+
6+
export USER_MAIL="dena@dena.dena"
7+
export USER_PASS="123qwe"
8+
9+
#export USER_WIKI_NAME="Local Test Wikiz"
10+
#export USER_WIKI_DOMAIN="local-test-wikiz.wbaas-local-test.de"
11+
#export USER_WIKI_ADMIN="Adminz"
12+
13+
export CYPRESS_TEST_WIKI_PASSWORD="SuperSecureHackathonPassword!"
14+
export CYPRESS_TEST_WIKI_USERNAME="Admin"
15+
export CYPRESS_TEST_USER="deniz.erdogan@wikimedia.de"
16+
export CYPRESS_TEST_PASSWORD="W*=6+U4=xU{Hs.bJ3Px!"

.gitmodules

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[submodule "ssl-test"]
2+
path = ssl-test
3+
url = git@github.com:deer-wmde/ssl-test.git

bin/local/README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,17 +30,17 @@ Creates a new wikibase with a local user account. The minikube tunnel needs to b
3030

3131
It does this in two steps:
3232
1. Obtaining an auth token
33-
- by `POST`ing to `http://api.wbaas.localhost/auth/login`
33+
- by `POST`ing to `http://api.wbaas-local-test.de/auth/login`
3434
2. Requesting a new wikibase
35-
- by `POST`ing to `http://api.wbaas.localhost/wiki/create`
35+
- by `POST`ing to `http://api.wbaas-local-test.de/wiki/create`
3636

3737
#### Default credentials
3838
You can use environment variables to overwrite the defaults:
3939
```bash
4040
USER_MAIL="${USER_MAIL:-jane.doe@wikimedia.de}"
4141
USER_PASS="${USER_PASS:-wikiwikiwiki}"
4242
USER_WIKI_NAME="${USER_WIKI_NAME:-Local Test Wiki}"
43-
USER_WIKI_DOMAIN="${USER_WIKI_DOMAIN:-local-test-wiki.wbaas.localhost}"
43+
USER_WIKI_DOMAIN="${USER_WIKI_DOMAIN:-local-test-wiki.wbaas-local-test.de}"
4444
USER_WIKI_ADMIN="${USER_WIKI_ADMIN:-Admin}"
4545
```
4646

bin/local/README.md.bak

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
# About this directory
2+
The purpose of the scripts in this directory is to improve and speed up the workflow with the local minikube setup. They are mostly quick and dirty hacks but serve the purpose.
3+
4+
## Scripts
5+
### [`new-local-cluster.sh`](./new-local-cluster.sh)
6+
Deletes and tries to re-initiate the local minikube cluster in an unattended fashion (no user input/prompt approval required) by applying our opentofu and helmfile configuration. It can take like ~20 minutes to finish. All data inside the local cluster will be lost. Please report if your cluster is not in a useable state after running this script, so we can improve it.
7+
8+
### [`create-local-user.sh`](./create-local-user.sh)
9+
Creates a local user account that can be used immediately. The minikube tunnel needs to be open for this to work (`make minikube-tunnel`).
10+
11+
It does this in three steps:
12+
1. Creates an invite code
13+
- by running `artisan wbs-invitation:create <code>`
14+
2. Registers a user account
15+
- by using `curl` to `POST` form data to the API endpoint `/user/register`
16+
3. Manually sets the account to verified
17+
- by flipping the `verified` field of the user in the database to 1
18+
- via a PHP snippet executed with artisan tinker (dirty)
19+
20+
#### Default credentials
21+
You can use environment variables to overwrite the defaults:
22+
```bash
23+
USER_CODE="${USER_CODE:-create-local-user}"
24+
USER_MAIL="${USER_MAIL:-jane.doe@wikimedia.de}"
25+
USER_PASS="${USER_PASS:-wikiwikiwiki}"
26+
```
27+
28+
### [`create-local-wiki.sh`](./create-local-wiki.sh)
29+
Creates a new wikibase with a local user account. The minikube tunnel needs to be open for this to work (`make minikube-tunnel`).
30+
31+
It does this in two steps:
32+
1. Obtaining an auth token
33+
- by `POST`ing to `http://api.wbaas-local-test.de/auth/login`
34+
2. Requesting a new wikibase
35+
- by `POST`ing to `http://api.wbaas-local-test.de/wiki/create`
36+
37+
#### Default credentials
38+
You can use environment variables to overwrite the defaults:
39+
```bash
40+
USER_MAIL="${USER_MAIL:-jane.doe@wikimedia.de}"
41+
USER_PASS="${USER_PASS:-wikiwikiwiki}"
42+
USER_WIKI_NAME="${USER_WIKI_NAME:-Local Test Wiki}"
43+
USER_WIKI_DOMAIN="${USER_WIKI_DOMAIN:-local-test-wiki.wbaas-local-test.de}"
44+
USER_WIKI_ADMIN="${USER_WIKI_ADMIN:-Admin}"
45+
```
46+
47+
## Adding new scripts
48+
### Fail safe
49+
All of these scripts should start with this failsafe snippet, to make sure they aren't doing anything at all when executed outside of the local minikube cluster context. If `kubectl` will be used in the script, it can be forced to use the local context with each call like this: `kubectl --context ${KUBE_CONTEXT}`.
50+
51+
```bash
52+
#!/bin/bash
53+
54+
### failsafe logic to exit in case we are not running in our local minikube context
55+
KUBE_CONTEXT=$(kubectl config current-context)
56+
57+
echo "Current kube context: '${KUBE_CONTEXT}'"
58+
59+
if [[ "${KUBE_CONTEXT}" != "minikube-wbaas" ]]; then
60+
echo "Error: wrong kube context. Use this script only within 'minikube-wbaas'!"
61+
exit 1
62+
fi
63+
#####################################################################################
64+
```
65+
66+
### Dependency checking
67+
To test if certain CLI tools are available, you can check for them (and exit in case they aren't available) like this:
68+
```bash
69+
# Check if `jq` and `jo` are available
70+
[[ $(type -P "jq") ]] || { echo "error: 'jq' is not installed." 1>&2; exit 1; }
71+
[[ $(type -P "jo") ]] || { echo "error: 'jo' is not installed." 1>&2; exit 1; }
72+
```

bin/local/create-local-wiki.sh

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,17 +19,17 @@ fi
1919
USER_MAIL="${USER_MAIL:-jane.doe@wikimedia.de}"
2020
USER_PASS="${USER_PASS:-wikiwikiwiki}"
2121
USER_WIKI_NAME="${USER_WIKI_NAME:-Local Test Wiki}"
22-
USER_WIKI_DOMAIN="${USER_WIKI_DOMAIN:-local-test-wiki.wbaas.localhost}"
22+
USER_WIKI_DOMAIN="${USER_WIKI_DOMAIN:-local-test-wiki.wbaas-local-test.de}"
2323
USER_WIKI_ADMIN="${USER_WIKI_ADMIN:-Admin}"
2424

25-
TEST_RESPONSE=$(curl -s http://api.wbaas.localhost/healthz)
25+
TEST_RESPONSE=$(curl -s http://api.wbaas-local-test.de/healthz)
2626
if [[ "${TEST_RESPONSE}" != "It's Alive" ]]; then
2727
echo "Error: local api is not available. Is the minikube tunnel open? ('make minikube-tunnel')"
2828
exit 2
2929
fi
3030

3131
LOGIN_JSON_DATA=$(jo email="${USER_MAIL}" password="${USER_PASS}")
32-
LOGIN_RESPONSE=$(curl -s 'http://api.wbaas.localhost/auth/login' \
32+
LOGIN_RESPONSE=$(curl -s 'http://api.wbaas-local-test.de/auth/login' \
3333
-X POST \
3434
-H 'Content-Type: application/json' \
3535
-H 'Accept: application/json' \
@@ -39,7 +39,7 @@ LOGIN_TOKEN=$(echo "${LOGIN_RESPONSE}" | jq -r '.token')
3939
[[ -n "$LOGIN_TOKEN" ]] || { echo "error: login failed." 1>&2; exit 1; }
4040

4141
CREATE_WIKI_JSON_DATA=$(jo domain="${USER_WIKI_DOMAIN}" sitename="${USER_WIKI_NAME}" username="${USER_WIKI_ADMIN}")
42-
CREATE_WIKI_RESPONSE=$(curl -s 'http://api.wbaas.localhost/wiki/create' \
42+
CREATE_WIKI_RESPONSE=$(curl -s 'http://api.wbaas-local-test.de/wiki/create' \
4343
-X POST \
4444
-H 'Content-Type: application/json' \
4545
-H 'Accept: application/json' \

bin/local/create-local-wiki.sh.bak

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
#!/bin/bash
2+
3+
### failsafe logic to exit in case we are not running in our local minikube context
4+
KUBE_CONTEXT=$(kubectl config current-context)
5+
6+
echo "Current kube context: '${KUBE_CONTEXT}'"
7+
8+
if [[ "${KUBE_CONTEXT}" != "minikube-wbaas" ]]; then
9+
echo "Error: wrong kube context. Use this script only within 'minikube-wbaas'!"
10+
exit 1
11+
fi
12+
#####################################################################################
13+
14+
[[ $(type -P "jq") ]] || { echo "error: 'jq' is not installed." 1>&2; exit 1; }
15+
[[ $(type -P "jo") ]] || { echo "error: 'jo' is not installed." 1>&2; exit 1; }
16+
17+
# This script should create a wiki for a user account on a local wbaas cluster with the credentials below. Do not use this in production!
18+
19+
USER_MAIL="${USER_MAIL:-jane.doe@wikimedia.de}"
20+
USER_PASS="${USER_PASS:-wikiwikiwiki}"
21+
USER_WIKI_NAME="${USER_WIKI_NAME:-Local Test Wiki}"
22+
USER_WIKI_DOMAIN="${USER_WIKI_DOMAIN:-local-test-wiki.wbaas-local-test.de}"
23+
USER_WIKI_ADMIN="${USER_WIKI_ADMIN:-Admin}"
24+
25+
TEST_RESPONSE=$(curl -s http://api.wbaas-local-test.de/healthz)
26+
if [[ "${TEST_RESPONSE}" != "It's Alive" ]]; then
27+
echo "Error: local api is not available. Is the minikube tunnel open? ('make minikube-tunnel')"
28+
exit 2
29+
fi
30+
31+
LOGIN_JSON_DATA=$(jo email="${USER_MAIL}" password="${USER_PASS}")
32+
LOGIN_RESPONSE=$(curl -s 'http://api.wbaas-local-test.de/auth/login' \
33+
-X POST \
34+
-H 'Content-Type: application/json' \
35+
-H 'Accept: application/json' \
36+
--data-raw "${LOGIN_JSON_DATA}")
37+
38+
LOGIN_TOKEN=$(echo "${LOGIN_RESPONSE}" | jq -r '.token')
39+
[[ -n "$LOGIN_TOKEN" ]] || { echo "error: login failed." 1>&2; exit 1; }
40+
41+
CREATE_WIKI_JSON_DATA=$(jo domain="${USER_WIKI_DOMAIN}" sitename="${USER_WIKI_NAME}" username="${USER_WIKI_ADMIN}")
42+
CREATE_WIKI_RESPONSE=$(curl -s 'http://api.wbaas-local-test.de/wiki/create' \
43+
-X POST \
44+
-H 'Content-Type: application/json' \
45+
-H 'Accept: application/json' \
46+
-H "Authorization: Bearer ${LOGIN_TOKEN}" \
47+
--data-raw "${CREATE_WIKI_JSON_DATA}")
48+
49+
echo "$CREATE_WIKI_RESPONSE"

doc/deployments/argocd.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ This GitHub workflow runs the script to check if the checked-in values files are
5252
1. Enable admin access by flipping `admin.enabled` to `true` in our values file (or manually in the ConfigMap `argocd-cm`)
5353
- this is enabled for local clusters by default
5454
2. Access the web interface and log in (username `admin`)
55-
- a) local - http://argo.wbaas.localhost/
55+
- a) local - http://argo.wbaas-local-test.de/
5656
- b) staging/production - https://localhost:8080/
5757
- Forward port `8080` of the deployment `argo-cd-base-argocd-server`
5858

doc/deployments/argocd.md.bak

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
# Argo CD
2+
## Overview
3+
### Deployment of Argo CD
4+
We deploy Argo CD via helmfile and the community helm charts: https://argoproj.github.io/argo-helm/
5+
- see [/k8s/helmfile/argo-cd.yaml](../../k8s/helmfile/argo-cd.yaml)
6+
7+
It's basic configuration lives in the values files `argo-cd-base.values.yaml.gotmpl` for each environment.
8+
- [production](../../k8s/helmfile/env/production/argo-cd-base.values.yaml.gotmpl)
9+
- [staging](../../k8s/helmfile/env/staging/argo-cd-base.values.yaml.gotmpl)
10+
- [local](../../k8s/helmfile/env/local/argo-cd-base.values.yaml.gotmpl)
11+
12+
Currently this means each environment gets it's own instance of Argo CD, which in turn always deploys to the cluster it lives in. We may want to change this in the future, if this prevents us from using certain features or workflows.
13+
14+
### Application configuration
15+
There are two more charts we use to configure our project & applications:
16+
- [argocd-config](../../charts/argocd-config/)
17+
- gets deployed by helmfile
18+
- defines the ["app-of-apps"](https://argo-cd.readthedocs.io/en/stable/operator-manual/cluster-bootstrapping/) `Application`
19+
- [argocd-apps](../../charts/argocd-apps/)
20+
- gets deployed by Argo CD
21+
- defines the `Application` resources for our actual helm releases
22+
23+
The values of the first chart get passed on to the second one, so we can infer which environment we are running in.
24+
25+
### Values files
26+
After trying out different ways of templating our way through this, we currently settled with a script to generate plain yaml files:
27+
- the bash script: [/bin/generate/values](../../bin/generate-values)
28+
- the values files: [/k8s/argocd/](../../k8s/argocd/)
29+
30+
These are generated by helmfile, which in turn reads the value files in [/k8s/helmfile/env/](../../k8s/helmfile/env/) like we are used to.
31+
32+
#### [/bin/generate/values](../../bin/generate-values)
33+
```
34+
$ ./bin/generate-values
35+
error: missing environment
36+
37+
usage: generate-values <environment> <release-name> [output-file-template]
38+
```
39+
The script can be run like `./bin/generate-values local ui` where `local` could be `staging` or `production` and `ui` any other helmfile release. The third parameter let's you define a different helmfile than `k8s/helmfile/helmfile.yaml`. This is needed for the CI script. Once we moved all components to Argo we could create a Makefile target that generates/updates all values files, for our convenience.
40+
41+
#### CI - [check-generated-values.yml](../../.github/workflows/check-generated-values.yml)
42+
This GitHub workflow runs the script to check if the checked-in values files are actually up to date. It does this by iterating over each generated values file that is present in `k8s/argocd/` and runs `generate-values` to compare it against.
43+
44+
### Self-Healing
45+
[Automatic Self-Healing](https://argo-cd.readthedocs.io/en/stable/user-guide/auto_sync/#automatic-self-healing) is currently disabled for the local environment. This way, we still can use skaffold to replace resources that get deployed by Argo CD. Otherwise Argo CD would immediately replace them again with the image that is configured in the values files.
46+
47+
## Admin access
48+
> Caution! Admin access should only happen in rare circumstances (testing/diagnosing, for example)
49+
> as we want to maintain the configuration for everything in git.
50+
51+
1. Reset the admin password by running `./bin/get-argocd-password`
52+
1. Enable admin access by flipping `admin.enabled` to `true` in our values file (or manually in the ConfigMap `argocd-cm`)
53+
- this is enabled for local clusters by default
54+
2. Access the web interface and log in (username `admin`)
55+
- a) local - http://argo.wbaas-local-test.de/
56+
- b) staging/production - https://localhost:8080/
57+
- Forward port `8080` of the deployment `argo-cd-base-argocd-server`
58+
59+
```
60+
make argo-port-forward
61+
```

doc/local-dev-env.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -178,15 +178,15 @@ minikube does not provision LoadBalancer service IP addresses as part of normal
178178
make minikube-tunnel
179179
```
180180

181-
You should now be able to access the ingress via http://www.wbaas.localhost. Most modern browsers will automatically resolve *.localhost to 127.0.0.1. If not, you'll need to edit your hosts file.
181+
You should now be able to access the ingress via http://www.wbaas-local-test.de. Most modern browsers will automatically resolve *.localhost to 127.0.0.1. If not, you'll need to edit your hosts file.
182182

183183
More detailed information on the load balancer can be found in [minikube-load-balancer.md](minikube-load-balancer.md).
184184

185185
## Mailhog / Local emails
186186

187187
For the local setup, [Mailhog](https://github.com/mailhog/MailHog) is used to capture outbound emails.
188188

189-
You can view those emails by going to http://mailhog.wbaas.localhost/
189+
You can view those emails by going to http://mailhog.wbaas-local-test.de/
190190

191191
## Mediawiki debugging
192192
### logging
@@ -215,10 +215,10 @@ Xdebug can be enabled in your minikube cluster if you use mediawiki image with `
215215
- You can use Xdebug on your VSCode IDE by following these steps:
216216
* Follow this tutorial in the section "Debug PHP using Xdebug and VS Code" https://php.tutorials24x7.com/blog/how-to-debug-php-using-xdebug-and-visual-studio-code-on-ubuntu
217217

218-
## Create an account on wbaas.localhost
218+
## Create an account on wbaas-local-test.de
219219
To use the local wbaas instance you have just setup, you will need to create an invitation code via the api which is needed when creating an account. Follow the [instructions](https://github.com/wbstack/api/blob/main/docs/invitation-codes.md) documented in the wbaas/api repo.
220220

221-
After creating the invitation code, you can visit http://wbaas.localhost/create-account (or click the create account link in the login form) and create an account. All outbound email is captured by Mailhog ([see above](#mailhog--local-emails)) so you can use a made up email address (e.g. `test@example.com`). Verify your email address via the "Account Creation Notificaiton" email captured by Mailhog.
221+
After creating the invitation code, you can visit http://wbaas-local-test.de/create-account (or click the create account link in the login form) and create an account. All outbound email is captured by Mailhog ([see above](#mailhog--local-emails)) so you can use a made up email address (e.g. `test@example.com`). Verify your email address via the "Account Creation Notificaiton" email captured by Mailhog.
222222

223223
## [Optional] setup bash completion
224224
Here is how to get tab completion working for common commands
@@ -275,7 +275,7 @@ Error: plugin "diff" exited with error
275275

276276
it is likely because `make diff-local` uses the `--skip-deps` option when executing `helmfile diff` which skips downloading chart dependencies. To force the fetching of dependencies run `make helmfile-deps` before `make diff-local`.
277277

278-
### **Why can't I access [wbaas.localhost](http://www.wbaas.localhost)?**
278+
### **Why can't I access [wbaas-local-test.de](http://www.wbaas-local-test.de)?**
279279
Here are a few things to try:
280280
- make sure minikube is running `make minikube-start`
281281
- make sure the minikube tunnel is running `make minikube-tunnel`

0 commit comments

Comments
 (0)