Skip to content

Commit e9f804c

Browse files
dandimeodandimeonerpaula
authored
[DOC-562] Example Cache Override (#234)
* add OVERRIDE env var to toolchain docker compose * add override flag to arangoproxy * add OVERRIDE injection to start_arangoproxy script * add override flag to arangoproxy config, set the override flag in example struct creation * add override pipeline parameter to generate job * use whitespace as default override arg in circleci * [skip ci] Automatic commit of generated files from CircleCI * fix commit generate name chekc * [skip ci] Automatic commit of generated files from CircleCI * fix commit-generated workflow * use error wrapper in download artifacts for commit-generated * [skip ci] Automatic commit of generated files from CircleCI * extend override to use regexes * restore export OVERRIDE in circleci * fallback override * add override param explanation in CIRCLECI.md * adjust readme --------- Co-authored-by: dandimeo <daniele@arangodb.com> Co-authored-by: Paula <paula.mihu@arangodb.com>
1 parent 7fb48b7 commit e9f804c

File tree

13 files changed

+67
-8
lines changed

13 files changed

+67
-8
lines changed

.circleci/commit.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ async function commit_generated() {
2424

2525
let jobsData = await jobs.json();
2626
for (let job of jobsData.items) {
27-
if (job.name != "build-with-generated") continue
27+
if (job.name != "generate") continue
2828
let artifacts = await fetch('https://circleci.com/api/v2/project/gh/arangodb/docs-hugo/'+job.job_number+'/artifacts', {
2929
method: 'GET',
3030
headers: {'content-type': 'application/json', 'Circle-Token': process.env.CIRCLECI_API_TOKEN},

.circleci/config.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,10 @@ parameters:
1919
type: string
2020
default: ""
2121

22+
override:
23+
type: string
24+
default: ""
25+
2226
version:
2327
type: string
2428
default: ""

.circleci/generate_config.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -264,6 +264,7 @@ def workflow_generate_launch_command(config):
264264
export ENV=\"circleci\"\n \
265265
export HUGO_URL=https://<< pipeline.parameters.deploy-url >>--docs-hugo.netlify.app\n \
266266
export HUGO_ENV=examples\n \
267+
export OVERRIDE=<< pipeline.parameters.override >>\n \
267268
export GENERATORS='<< parameters.generators >>'\n"
268269

269270
for i in range(len(versions)):
@@ -321,10 +322,12 @@ def workflow_commit_generated_download_data(config):
321322
for i in range(len(versions)):
322323
version = versions[i]["name"]
323324
cmd = f"{cmd}\n\
325+
set +e\n\
324326
wget $base_url/{version}-generated.tar\n\
325327
tar -xf {version}-generated.tar -C docs-hugo/site/data/\n\
328+
set -e\n\
326329
"
327-
config["commands"]["store-generated-data"]["steps"][0]["run"]["command"] = cmd
330+
config["commands"]["download-generated-data"]["steps"][0]["run"]["command"] = cmd
328331

329332
return config
330333

CIRCLECI.md

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,33 @@ arguments are invoked:
9393
| `deploy-url` | `deploy-preview-{PR_NUMBER}` |
9494
| `commit-generated` | `true` |
9595

96+
### `cache override`
97+
98+
You can override the cache of an example with the `override` CircleCI parameter
99+
in the `generate` workflow.
100+
101+
The override parameter is a comma-separated string of regexes.
102+
103+
The comma will be replaced by `|` and creates an `OR` of all the regexes in the
104+
`override` parameter.
105+
106+
The example below overrides all examples having `http` or starting with `aql` in
107+
the example name. You can also specify the name of the example to override the
108+
cache for, i.e. `AqlDateTimeToLocal_3`.
109+
110+
Note that the override is valid for all versions that are specified using the
111+
`arangodb` parameters. You can override the example output for a single version
112+
or for multiple versions.
113+
114+
| Name | Value |
115+
|:-----|:------|
116+
| `workflow` | `generate` |
117+
| `arangodb-3_10` | `{string in PR Template at 3.10}` |
118+
| `arangodb-3_11` | `{string in PR Template at 3.11}` |
119+
| `generators` | `examples` |
120+
| `commit-generated` | `true` |
121+
| `override` | `http,^aql.*` |
122+
96123
## Release workflow (ArangoDB)
97124

98125
To run a release job for a new ArangoDB patch release (e.g. 3.11.4), follow the

site/data/3.11/cache.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2129,7 +2129,7 @@
21292129
},
21302130
"aqlDateTimeToLocal_3_single": {
21312131
"request": "LS0tCm5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gICAgXCJ0emRiXCIgOiBcIjIwMjNhXCIsIFxuICAgIFwiem9uZUluZm9cIiA6IHsgXG4gICAgICBcIm5hbWVcIiA6IFwiV0FUXCIsIFxuICAgICAgXCJiZWdpblwiIDogXCIxOTE5LTA4LTMxVDIzOjMwOjAwLjAwMFpcIiwgXG4gICAgICBcImVuZFwiIDogbnVsbCwgXG4gICAgICBcImRzdFwiIDogZmFsc2UsIFxuICAgICAgXCJvZmZzZXRcIiA6IDM2MDAgXG4gICAgfSBcbiAgfSBcbl0iLCJlcnJvciI6IiIsIm9wdGlvbnMiOnsiZGVzY3JpcHRpb24iOiIiLCJuYW1lIjoiYXFsRGF0ZVRpbWVUb0xvY2FsXzMiLCJ0eXBlIjoic2luZ2xlIiwicmVuZGVyIjoiaW5wdXQvb3V0cHV0In19Cg=="
21332133
},
21342134
"aqlDateTimeToUTC_1_single": {
21352135
"request": "LS0tCm5hbWU6IGFxbERhdGVUaW1lVG9VVENfMQpkZXNjcmlwdGlvbjogJycKLS0tClJFVFVSTiBbCiAgREFURV9MT0NBTFRPVVRDKCIyMDIwLTAzLTE1VDAwOjAwOjAwLjAwMCIsICJFdXJvcGUvQmVybGluIiksCiAgREFURV9MT0NBTFRPVVRDKCIyMDIwLTAzLTE1VDAwOjAwOjAwLjAwMCIsICJBbWVyaWNhL05ld19Zb3JrIiksCiAgREFURV9MT0NBTFRPVVRDKCIyMDIwLTAzLTE1VDAwOjAwOjAwLjAwMCIsICJVVEMiKQpd",

toolchain/arangoproxy/cmd/main.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,20 @@ import (
44
"flag"
55
"fmt"
66
"os"
7+
"strings"
78

89
"github.com/arangodb/docs/migration-tools/arangoproxy/internal"
910
"github.com/arangodb/docs/migration-tools/arangoproxy/internal/models"
1011
)
1112

1213
var configFile string
13-
var env string
14+
var env, override string
1415
var help, useServers bool
1516

1617
// Pre-Run Setup
1718
func init() {
1819
flag.StringVar(&configFile, "config", "./configs/local.yaml", "path of config file")
20+
flag.StringVar(&override, "override", " ", "override examples")
1921
flag.BoolVar(&help, "help", false, "Display help usage")
2022
flag.BoolVar(&useServers, "use-servers", false, "Enable communication with arangodb servers")
2123
flag.Parse()
@@ -25,6 +27,7 @@ func init() {
2527
fmt.Printf("Error loading config: %s\n, aborting...", err.Error())
2628
os.Exit(1)
2729
}
30+
models.Conf.Override = strings.ReplaceAll(override, ",", "|")
2831

2932
models.Logger.Printf(startupBanner)
3033
models.Logger.Printf("./arangoproxy -help for help usage\n\n")
@@ -34,6 +37,7 @@ func init() {
3437
models.Logger.Printf("Usage: ...\n")
3538
os.Exit(0)
3639
}
40+
models.Logger.Printf("Configuration:\n%v\n", models.Conf)
3741

3842
models.Logger.Printf("Setup Done\n---------\n")
3943

toolchain/arangoproxy/internal/models/config.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@ import (
99
type Config struct {
1010
Repositories []Repository `yaml:"repositories"` // ArangoDB instances
1111
Cache string `yaml:"cache"` // Cache configuration
12-
Datasets string `yaml:"datasetsFile"` // Logfile
12+
Datasets string `yaml:"datasetsFile"`
13+
Override string `yaml:"-"`
1314
}
1415

1516
var Conf Config

toolchain/arangoproxy/internal/models/example.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,11 @@ import (
88
"io/ioutil"
99
"net/http"
1010
"regexp"
11+
"strconv"
1112
"strings"
1213

14+
"github.com/arangodb/docs/migration-tools/arangoproxy/internal/utils"
15+
"github.com/dlclark/regexp2"
1316
"gopkg.in/yaml.v3"
1417
)
1518

@@ -89,6 +92,10 @@ func ParseExample(request io.Reader, headers http.Header) (Example, error) {
8992
optionsYaml.SaveCache = headers.Get("Cache")
9093
optionsYaml.Version = headers.Get("Version")
9194

95+
overrideRE := regexp2.MustCompile(Conf.Override, 0)
96+
97+
optionsYaml.SaveCache = strconv.FormatBool(utils.Regexp2StringHasMatch(overrideRE, optionsYaml.Name))
98+
9299
code := strings.Replace(string(decodedRequest), string(options), "", -1)
93100

94101
return Example{Type: "", Options: optionsYaml, Code: code, Base64Request: string(req)}, nil

toolchain/arangoproxy/internal/utils/utils.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,3 +50,11 @@ func Regexp2FindAllString(re *regexp2.Regexp, s string) []string {
5050
}
5151
return matches
5252
}
53+
54+
func Regexp2StringHasMatch(re *regexp2.Regexp, s string) bool {
55+
m, _ := re.FindStringMatch(s)
56+
if m != nil {
57+
return true
58+
}
59+
return false
60+
}

toolchain/docker/amd64/docker-compose.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ services:
1515
HUGO_URL: ${HUGO_URL:-http://localhost}
1616
HUGO_ENV: ${HUGO_ENV:-development}
1717
GENERATORS: ${GENERATORS}
18+
OVERRIDE: ${OVERRIDE}
1819
ARANGODB_SRC_3_10: ${ARANGODB_SRC_3_10}
1920
ARANGODB_SRC_3_11: ${ARANGODB_SRC_3_11}
2021
ARANGODB_SRC_3_12: ${ARANGODB_SRC_3_12}

toolchain/docker/arm64/docker-compose.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ services:
1515
HUGO_URL: ${HUGO_URL:-http://localhost}
1616
HUGO_ENV: ${HUGO_ENV:-development}
1717
GENERATORS: ${GENERATORS}
18+
OVERRIDE: ${OVERRIDE}
1819
ARANGODB_SRC_3_10: ${ARANGODB_SRC_3_10}
1920
ARANGODB_SRC_3_11: ${ARANGODB_SRC_3_11}
2021
ARANGODB_SRC_3_12: ${ARANGODB_SRC_3_12}

toolchain/scripts/start_arangoproxy.sh

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,10 @@ ARANGOPROXY_ARGS=""
1919
if [ "$HUGO_ENV" != "prod" ] && [ "$HUGO_ENV" != "frontend" ]; then
2020
# For each server in arangoproxy/cmd/configs/local.yaml filled by previous step, check the server is up and healthy
2121
ARANGOPROXY_ARGS="-use-servers"
22+
if [ "$OVERRIDE" != "" ] ; then
23+
ARANGOPROXY_ARGS="$ARANGOPROXY_ARGS -override $OVERRIDE"
24+
fi
25+
2226
mapfile servers < <(yq e -o=j -I=0 '.repositories.[]' /home/toolchain/arangoproxy/cmd/configs/local.yaml )
2327

2428
for server in "${servers[@]}"; do

toolchain/scripts/toolchain.sh

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -252,6 +252,7 @@ function run_arangoproxy_and_site() {
252252
-e ENV="$ENV" \
253253
-e HUGO_URL="$HUGO_URL" \
254254
-e HUGO_ENV="$HUGO_ENV" \
255+
-e OVERRIDE="$OVERRIDE" \
255256
-v arangosh:/arangosh \
256257
--volumes-from toolchain \
257258
--log-opt tag="{{.Name}}" \
@@ -268,7 +269,7 @@ function setup_arangoproxy() {
268269
setup_arangoproxy_arangosh "$image" "$version"
269270

270271
setup_arangoproxy_repositories "$version" "$container_name"
271-
272+
272273
log "[setup_arangoproxy] Done"
273274
}
274275

@@ -314,8 +315,6 @@ function setup_arangoproxy_repositories() {
314315
}
315316

316317

317-
318-
319318
##### SERVER FUNCTIONS
320319

321320
function process_server() {

0 commit comments

Comments
 (0)