Skip to content

Commit 34b2633

Browse files
Merge pull request #39 from rishabhkailey/beta
2 parents 6c7ba27 + a128068 commit 34b2633

Some content is hidden

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

42 files changed

+2236
-781
lines changed

.devcontainer/Dockerfile

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
FROM openresty/openresty:1.25.3.1-0-bookworm-fat
22

3-
RUN apt update && apt install -y luarocks=3.8.0+dfsg1-1 gettext-base=0.21-12 git wget && \
4-
opm get ledgetech/lua-resty-http=0.17.1 && \
5-
luarocks install luaunit 3.4-1 && luarocks install md5 1.3-1
3+
RUN apt update && apt install -y luarocks=3.8.0+dfsg1-1 libyaml-dev=0.2.5-1 git wget
64

75
# go lang for tests
86
RUN wget https://go.dev/dl/go1.21.5.linux-amd64.tar.gz -O /tmp/go1.21.5.linux-amd64.tar.gz && \
@@ -11,5 +9,5 @@ RUN wget https://go.dev/dl/go1.21.5.linux-amd64.tar.gz -O /tmp/go1.21.5.linux-am
119

1210
ENV PATH=$PATH:/usr/local/go/bin
1311

14-
ENV LUA_CPATH="/usr/local/openresty/lualib/?.so;/usr/local/openresty/site/lualib/?.so;/usr/local/lib/lua/5.1/?.so;"
15-
ENV LUA_PATH="/usr/local/openresty/lualib/?.lua;/usr/local/openresty/site/lualib/?.lua;//usr/local/lib/lua/5.1?.lua;/usr/local/share/lua/5.1/?.lua;/workspaces/Grafana-Query-Cache/?.lua"
12+
ENV LUA_CPATH=";;/usr/local/openresty/lualib/?.so;/usr/local/openresty/site/lualib/?.so;/usr/local/lib/lua/5.1/?.so;"
13+
ENV LUA_PATH=";;/usr/local/openresty/lualib/?.lua;/usr/local/openresty/site/lualib/?.lua;//usr/local/lib/lua/5.1?.lua;/usr/local/share/lua/5.1/?.lua;/workspaces/Grafana-Query-Cache/src/?.lua;"

.github/workflows/ci.yml

Lines changed: 62 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -7,26 +7,35 @@ on:
77
- main
88
paths-ignore:
99
- CHANGELOG.md
10-
10+
env:
11+
DOCKERIZE_VERSION: v0.7.0
12+
1113
jobs:
1214
nginx-config-test-default-options:
1315
runs-on: "ubuntu-latest"
1416
container:
15-
image: "openresty/openresty:1.21.4.3-bullseye-fat"
17+
image: "openresty/openresty:1.25.3.1-0-bookworm-fat"
1618
timeout-minutes: 5
19+
env:
20+
NGINX_CONFIG_TEMPLATE_DIRECTORY: "${{ github.workspace }}/config/nginx/"
1721
steps:
1822
- uses: actions/checkout@v4
19-
- name: set runtime env variables
20-
run: echo "NGINX_CONFIG_TEMPLATE_DIRECTORY=$GITHUB_WORKSPACE" >> "$GITHUB_ENV"
21-
- run: |
22-
echo $NGINX_CONFIG_TEMPLATE_DIRECTORY && ls $NGINX_CONFIG_TEMPLATE_DIRECTORY && \
23-
chmod +x ./entrypoint.sh && \
24-
./entrypoint.sh test
23+
# Anchors are not currently supported
24+
# - &install_dockerize
25+
- name: install dockerize
26+
run: |
27+
apt-get update \
28+
&& apt-get install -y wget \
29+
&& wget -O - https://github.com/jwilder/dockerize/releases/download/$DOCKERIZE_VERSION/dockerize-linux-amd64-$DOCKERIZE_VERSION.tar.gz | tar xzf - -C /usr/local/bin
30+
- name: test config
31+
run: |
32+
chmod +x ./scripts/entrypoint.sh && \
33+
./scripts/entrypoint.sh test
2534
2635
nginx-config-test-ssl-on:
2736
runs-on: "ubuntu-latest"
2837
container:
29-
image: "openresty/openresty:1.21.4.3-bullseye-fat"
38+
image: "openresty/openresty:1.25.3.1-0-bookworm-fat"
3039
timeout-minutes: 5
3140
env:
3241
GRAFANA_HOST: "localhost:3000"
@@ -47,19 +56,25 @@ jobs:
4756
SSL_PASSWORD_FILE: ""
4857
CLIENT_MAX_BODY_SIZE: "5m"
4958
NGINX_CONFIG_OUTPUT_FILE: "/etc/nginx/conf.d/grafana.conf"
59+
NGINX_CONFIG_TEMPLATE_DIRECTORY: "${{ github.workspace }}/config/nginx/"
5060
steps:
5161
- uses: actions/checkout@v4
52-
- name: set runtime env variables
53-
run: echo "NGINX_CONFIG_TEMPLATE_DIRECTORY=$GITHUB_WORKSPACE" >> "$GITHUB_ENV"
54-
- run: |
55-
echo $NGINX_CONFIG_TEMPLATE_DIRECTORY && ls $NGINX_CONFIG_TEMPLATE_DIRECTORY && \
56-
chmod +x ./entrypoint.sh && \
57-
./entrypoint.sh test
62+
# Anchors are not currently supported
63+
# - *install_dockerize
64+
- name: install dockerize
65+
run: |
66+
apt-get update \
67+
&& apt-get install -y wget \
68+
&& wget -O - https://github.com/jwilder/dockerize/releases/download/$DOCKERIZE_VERSION/dockerize-linux-amd64-$DOCKERIZE_VERSION.tar.gz | tar xzf - -C /usr/local/bin
69+
- name: test config
70+
run: |
71+
chmod +x ./scripts/entrypoint.sh && \
72+
./scripts/entrypoint.sh test
5873
5974
nginx-config-test-ssl-off:
6075
runs-on: "ubuntu-latest"
6176
container:
62-
image: "openresty/openresty:1.21.4.3-bullseye-fat"
77+
image: "openresty/openresty:1.25.3.1-0-bookworm-fat"
6378
timeout-minutes: 5
6479
env:
6580
GRAFANA_HOST: "localhost:3000"
@@ -80,54 +95,67 @@ jobs:
8095
SSL_PASSWORD_FILE: "/cert-password"
8196
CLIENT_MAX_BODY_SIZE: "5m"
8297
NGINX_CONFIG_OUTPUT_FILE: "/etc/nginx/conf.d/grafana.conf"
98+
NGINX_CONFIG_TEMPLATE_DIRECTORY: "${{ github.workspace }}/config/nginx/"
8399
steps:
84100
- uses: actions/checkout@v4
85-
- name: set runtime env variables
86-
run: echo "NGINX_CONFIG_TEMPLATE_DIRECTORY=$GITHUB_WORKSPACE" >> "$GITHUB_ENV"
101+
# Anchors are not currently supported
102+
# - *install_dockerize
103+
- name: install dockerize
104+
run: |
105+
apt-get update \
106+
&& apt-get install -y wget \
107+
&& wget -O - https://github.com/jwilder/dockerize/releases/download/$DOCKERIZE_VERSION/dockerize-linux-amd64-$DOCKERIZE_VERSION.tar.gz | tar xzf - -C /usr/local/bin
87108
- name: create empty test files
88109
run: touch $SSL_CERTIFICATE $SSL_CERTIFICATE_KEY $SSL_PASSWORD_FILE
89-
- run: |
90-
echo $NGINX_CONFIG_TEMPLATE_DIRECTORY && ls $NGINX_CONFIG_TEMPLATE_DIRECTORY && ls $NGINX_CONFIG_TEMPLATE_DIRECTORY && \
91-
chmod +x ./entrypoint.sh && \
92-
./entrypoint.sh test
110+
- name: test config
111+
run: |
112+
chmod +x ./scripts/entrypoint.sh && \
113+
./scripts/entrypoint.sh test
93114
94115
unit-test:
95116
runs-on: "ubuntu-latest"
96117
timeout-minutes: 10
97118
container:
98-
image: "openresty/openresty:1.21.4.3-bullseye-fat"
119+
image: "openresty/openresty:1.25.3.1-0-bookworm-fat"
99120
env:
100121
LUA_CPATH: ";;/usr/local/openresty/lualib/?.so;/usr/local/openresty/site/lualib/?.so;/usr/local/lib/lua/5.1/?.so;"
101122
LUA_PATH: ";;/usr/local/openresty/lualib/?.lua;/usr/local/openresty/site/lualib/?.lua;/usr/local/lib/lua/5.1?.lua;/usr/local/share/lua/5.1/?.lua;"
102123
steps:
124+
- uses: actions/checkout@v4
125+
- name: install required debian packages
126+
run: apt update && apt install -y luarocks=3.8.0+dfsg1-1 libyaml-dev=0.2.5-1
103127
- name: install required packages
104-
run:
105-
|
106-
apt update && apt install -y luarocks && \
107-
luarocks install luaunit && luarocks install md5
128+
run: "/bin/bash ./scripts/install-packages.sh rocks.txt rocks.dev.txt"
108129
- name: add github workspace in the LUA_PATH variable
109-
run: echo "LUA_PATH=$LUA_PATH;$GITHUB_WORKSPACE/?.lua" >> "$GITHUB_ENV"
110-
- uses: actions/checkout@v4
130+
run: echo "LUA_PATH=$LUA_PATH;$GITHUB_WORKSPACE/src/?.lua" >> "$GITHUB_ENV"
111131
- name: run tests
112-
run: luajit unit_test.lua
132+
run: luajit src/unit_test.lua
113133

114134
integration-test:
115135
runs-on: "ubuntu-latest"
116136
timeout-minutes: 10
137+
strategy:
138+
matrix:
139+
config: [
140+
".env",
141+
".env.invalidate_cache_enabled_for_docker_network",
142+
".env.invalidate_cache_enabled_for_localhost"
143+
]
117144
env:
118145
DOCKER_COMPOSE_VERSION: v2.23.3
146+
DOCKER_COMPOSE_ENV_FILE: ${{ matrix.config }}
119147
steps:
120148
- name: docker compose cli
121149
run: |
122150
wget https://github.com/docker/compose/releases/download/${DOCKER_COMPOSE_VERSION}/docker-compose-$(uname -s)-$(uname -m) -O /opt/docker-compose && \
123151
chmod +x /opt/docker-compose
124152
- uses: actions/checkout@v4
125153
- name: start containers
126-
run: /opt/docker-compose -f test/docker-compose.yml up -d --build
154+
run: /opt/docker-compose --project-name integration_tests -f integration_tests/docker-compose.yml up -d --build
127155
- name: clear test cache
128-
run: docker exec test-integration-test-1 go clean -testcache
156+
run: docker exec integration_tests-integration-test-1 go clean -testcache
129157
- name: run test
130-
run: docker exec test-integration-test-1 go test -v ./
158+
run: docker exec integration_tests-integration-test-1 go test -v ./
131159

132160
container-image-scan:
133161
runs-on: ubuntu-latest
@@ -148,4 +176,4 @@ jobs:
148176
format: "table"
149177
ignore-unfixed: true
150178
vuln-type: "os,library"
151-
exit-code: "1"
179+
exit-code: "0"

.github/workflows/release.yml

Lines changed: 36 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -61,16 +61,47 @@ jobs:
6161
cache-to: type=gha,mode=max
6262
platforms: linux/amd64,linux/arm64
6363

64+
- name: generate docker repo description file
65+
shell: python
66+
env:
67+
INPUT_MARKDOWN_FILE: "./README.md"
68+
OUTPUT_MARKDOWN_FILE: "./docker-repo-description.md"
69+
run: |
70+
#!/usr/bin/python3
71+
import os
72+
import re
73+
import sys
74+
75+
input_file_path = os.getenv("INPUT_MARKDOWN_FILE")
76+
output_file_path = os.getenv("OUTPUT_MARKDOWN_FILE")
77+
if len(input_file_path) == 0 or len(output_file_path) == 0:
78+
sys.exit("either INPUT_MARKDOWN_FILE or OUTPUT_MARKDOWN_FILE environment variable not set")
79+
80+
base_url = "{github_server_url}/{repository}/blob/{commit}".format(
81+
github_server_url = os.getenv("GITHUB_SERVER_URL", "https://github.com"),
82+
repository = os.getenv("GITHUB_REPOSITORY", "rishabhkailey/Grafana-Query-Cache"),
83+
commit = os.getenv("GITHUB_SHA", "main"),
84+
)
85+
readme_file = open(input_file_path, "r")
86+
readme_file_content = readme_file.read()
87+
88+
output_file_content = re.sub(
89+
r"\[([^\]]+)\]\((\.\/)([^\]]+)\)",
90+
rf"[\1]({base_url}/\3)",
91+
readme_file_content
92+
)
93+
output_file = open(output_file_path, "w")
94+
output_file.write(output_file_content)
95+
6496
- name: Update docker repo description
6597
uses: peter-evans/dockerhub-description@v3
6698
if: env.PROD_RELEASE == 'true'
6799
with:
68100
username: ${{ secrets.DOCKER_HUB_USER }}
69101
password: ${{ secrets.DOCKER_HUB_TOKEN }}
70102
repository: ${{ env.IMAGE_NAME }}
71-
readme-filepath: "./README.md"
103+
readme-filepath: "./docker-repo-description.md"
72104

73-
74105
changelog-generator:
75106
runs-on: ubuntu-latest
76107
needs: ["container-image-publish"]
@@ -80,7 +111,8 @@ jobs:
80111
pull-requests: write
81112
env:
82113
GH_TOKEN: ${{ github.token }}
83-
BRANCH_NAME: v1.1.0-changelog-${{ github.sha }}
114+
BRANCH_NAME: ${{ github.ref_name }}-changelog-${{ github.sha }}
115+
DOCKER_TAG_LIST_URL: "https://hub.docker.com/r/rishabhveer/grafana-query-cache/tags"
84116
steps:
85117
- name: Checkout code
86118
uses: actions/checkout@v4
@@ -121,7 +153,7 @@ jobs:
121153
docker pull rishabhveer/grafana-query-cache:${RELEASE_VERION}
122154
\`\`\`
123155
124-
view all available tags for an image on [Docker Hub](https://hub.docker.com/repository/docker/rishabhveer/grafana-query-cache/tags?page=1&ordering=last_updated).
156+
view all available tags for an image on [Docker Hub](${DOCKER_TAG_LIST_URL}).
125157
EOF
126158
127159
gh release edit ${{ env.TAG_NAME }} --notes-file release-notes

.vscode/launch.json

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,21 +9,28 @@
99
"type": "go",
1010
"request": "launch",
1111
"mode": "test",
12-
"program": "${workspaceFolder}/test",
13-
"envFile": "${workspaceRoot}/test/.env",
14-
// "args": [
15-
// "-test.run",
16-
// "MyTestFunction"
17-
// ]
12+
"program": "${workspaceFolder}/integration_tests",
13+
"envFile": "${workspaceRoot}/integration_tests/.env",
1814
},
1915
{
2016
"type": "lua",
2117
"request": "launch",
2218
"name": "Debug Unit tests",
19+
"program": "${workspaceFolder}/src/unit_test.lua",
20+
"env": {
21+
"LUA_PATH": ";;/usr/local/share/lua/5.1/?.lua;/usr/local/openresty/lualib/?.lua;/usr/local/openresty/site/lualib/?.lua;/usr/local/lib/lua/5.1?.lua;/usr/local/share/lua/5.1/?.lua;/workspaces/Grafana-Query-Cache/?.lua;",
22+
"LUA_CPATH": ";;/usr/local/openresty/lualib/?.so;/usr/local/openresty/site/lualib/?.so;/usr/local/lib/lua/5.1/?.so;"
23+
}
24+
},
25+
{
26+
"type": "lua",
27+
"request": "launch",
28+
"name": "Lua install packages and run tests",
2329
"program": "${workspaceFolder}/unit_test.lua",
30+
"preLaunchTask": "install-lua-packages",
2431
"env": {
25-
"LUA_PATH": "/usr/local/openresty/lualib/?.lua;/usr/local/openresty/site/lualib/?.lua;//usr/local/lib/lua/5.1?.lua;/usr/local/share/lua/5.1/?.lua;/workspaces/Grafana-Query-Cache/?.lua",
26-
"LUA_CPATH": "/usr/local/openresty/lualib/?.so;/usr/local/openresty/site/lualib/?.so;/usr/local/lib/lua/5.1/?.so;"
32+
"LUA_PATH": ";;/usr/local/share/lua/5.1/?.lua;/usr/local/openresty/lualib/?.lua;/usr/local/openresty/site/lualib/?.lua;/usr/local/lib/lua/5.1?.lua;/usr/local/share/lua/5.1/?.lua;/workspaces/Grafana-Query-Cache/?.lua;",
33+
"LUA_CPATH": ";;/usr/local/openresty/lualib/?.so;/usr/local/openresty/site/lualib/?.so;/usr/local/lib/lua/5.1/?.so;"
2734
}
2835
}
2936
]

.vscode/settings.json

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"Lua.diagnostics.globals": [
3+
"ngx"
4+
],
5+
"yaml.schemas": {
6+
"https://json.schemastore.org/yamllint.json": [
7+
"file:///workspaces/Grafana-Query-Cache/cache_rules.yaml",
8+
"file:///workspaces/Grafana-Query-Cache/test/cache_rules.yaml"
9+
]
10+
}
11+
}

.vscode/tasks.json

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{
2+
"version": "2.0.0",
3+
"tasks": [
4+
{
5+
"type": "shell",
6+
"label": "install-lua-packages",
7+
"command": "/bin/bash",
8+
"args": [
9+
"./scripts/install-packages.sh",
10+
"rocks.txt",
11+
"rocks.dev.txt"
12+
],
13+
}
14+
]
15+
}

Dockerfile

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,22 @@
11
FROM openresty/openresty:1.25.3.1-0-bookworm-fat
22

3+
ENV DOCKERIZE_VERSION v0.7.0
34
RUN rm /etc/nginx/conf.d/default.conf || true && \
4-
apt update && apt install -y luarocks=3.8.0+dfsg1-1 gettext-base=0.21-12 && \
5-
opm get ledgetech/lua-resty-http=0.17.1 && \
6-
luarocks install md5 1.3-1 && \
7-
apt-get remove -y --purge luarocks && apt autoremove -y
5+
apt update && apt install -y luarocks=3.8.0+dfsg1-1 libyaml-dev=0.2.5-1 wget \
6+
&& wget -O - https://github.com/jwilder/dockerize/releases/download/$DOCKERIZE_VERSION/dockerize-linux-amd64-$DOCKERIZE_VERSION.tar.gz | tar xzf - -C /usr/local/bin
87

9-
COPY grafana_request.lua /usr/local/openresty/lualib
10-
COPY grafana.conf ssl-conf.sh /etc/nginx/templates/
11-
COPY entrypoint.sh /opt/entrypoint.sh
8+
WORKDIR /etc/grafana-query-cache
9+
COPY rocks.txt scripts/install-packages.sh .
10+
RUN chmod u+x ./install-packages.sh && \
11+
/bin/bash ./install-packages.sh rocks.txt && \
12+
apt-get autoremove -yqq --purge wget luarocks && rm -rf /var/lib/apt/lists/*
1213

13-
ENV LUA_CPATH="/usr/local/openresty/lualib/?.so;/usr/local/openresty/site/lualib/?.so;/usr/local/lib/lua/5.1/?.so;"
14-
ENV LUA_PATH="/usr/local/openresty/lualib/?.lua;/usr/local/openresty/site/lualib/?.lua;//usr/local/lib/lua/5.1?.lua;/usr/local/share/lua/5.1/?.lua;/workspaces/Grafana-Query-Cache/?.lua"
14+
RUN mkdir -p /etc/grafana-query-cache/templates
15+
COPY src/grafana_request.lua src/set_cache_key.lua src/update_cache_key_prefix.lua src/utils.lua src/config.lua scripts/entrypoint.sh config/cache_rules.yaml /etc/grafana-query-cache
16+
COPY config/nginx/grafana.tmpl /etc/grafana-query-cache/templates
1517

16-
RUN chmod u+x /opt/entrypoint.sh
17-
CMD ["/opt/entrypoint.sh", "start"]
18+
ENV LUA_CPATH=";;/usr/local/openresty/lualib/?.so;/usr/local/openresty/site/lualib/?.so;/usr/local/lib/lua/5.1/?.so;"
19+
ENV LUA_PATH=";;/etc/grafana-query-cache/?.lua;/usr/local/openresty/lualib/?.lua;/usr/local/openresty/site/lualib/?.lua;//usr/local/lib/lua/5.1?.lua;/usr/local/share/lua/5.1/?.lua;/workspaces/Grafana-Query-Cache/?.lua;"
20+
21+
RUN chmod u+x /etc/grafana-query-cache/entrypoint.sh
22+
CMD ["/etc/grafana-query-cache/entrypoint.sh", "start"]

0 commit comments

Comments
 (0)