Skip to content

Commit 7fe8c14

Browse files
authored
Merge branch 'main' into maintenance-css/T343644
2 parents 99f7a7b + ca4956c commit 7fe8c14

Some content is hidden

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

79 files changed

+1103
-191
lines changed

.gitattributes

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# Directory entries are not enough to encrypt fines beneath it
2+
# https://github.com/AGWA/git-crypt#gitattributes-file
3+
quarry/config-prod.yaml filter=git-crypt diff=git-crypt
4+
tofu/secrets.tf filter=git-crypt diff=git-crypt
5+
helm-quarry/prod-config.yaml filter=git-crypt diff=git-crypt
6+
secrets.sh filter=git-crypt diff=git-crypt

.github/workflows/blubber.yaml

Lines changed: 0 additions & 19 deletions
This file was deleted.
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
---
2+
3+
name: Build and Push quarry image
4+
5+
'on':
6+
pull_request_target:
7+
8+
jobs:
9+
build_and_push:
10+
runs-on: ubuntu-latest
11+
steps:
12+
- uses: actions/checkout@v4
13+
14+
- name: git fetch
15+
run: |
16+
git fetch
17+
- name: git checkout
18+
run: |
19+
git checkout ${{ github.head_ref }}
20+
21+
- name: Set up Docker Buildx
22+
uses: docker/setup-buildx-action@v3
23+
24+
- name: Login to Quay.io
25+
uses: docker/login-action@v3
26+
with:
27+
registry: quay.io
28+
username: ${{ secrets.QUAY_QUARRY_USER }}
29+
password: ${{ secrets.QUAY_QUARRY_PASSWORD }}
30+
31+
- name: Build and push
32+
id: docker_build
33+
uses: docker/build-push-action@v5
34+
with:
35+
push: true
36+
context: .
37+
tags: quay.io/wikimedia-quarry/quarry:pr-${{ github.event.number }}
38+
39+
- name: Image digest
40+
run: echo ${{ steps.docker_build.outputs.digest }}

.github/workflows/linter.yaml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
---
2+
3+
name: "linter"
4+
5+
'on':
6+
pull_request:
7+
8+
jobs:
9+
tox:
10+
runs-on: ubuntu-latest
11+
steps:
12+
- uses: actions/checkout@v2
13+
14+
- name: build tox container
15+
run: |
16+
docker build -f tests/tox/Dockerfile -t tox:01 .
17+
- name: run tox container
18+
run: |
19+
docker run tox:01
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
---
2+
3+
name: update container tags
4+
5+
'on':
6+
pull_request_target:
7+
8+
jobs:
9+
update-container-tags:
10+
runs-on: ubuntu-latest
11+
steps:
12+
- uses: actions/checkout@v2
13+
with:
14+
token: ${{ secrets.PERSONAL_ACCESS_TOKEN }}
15+
repository: ${{ github.event.pull_request.head.repo.full_name }}
16+
17+
- name: git fetch
18+
run: |
19+
git fetch
20+
- name: git checkout
21+
run: |
22+
git checkout ${{ github.head_ref }}
23+
24+
# compare to upstream main branch
25+
- name: git add remote
26+
run: |
27+
git remote add quarry https://github.com/toolforge/quarry.git
28+
- name: git remote update
29+
run: |
30+
git remote update
31+
32+
- name: update values.yaml
33+
run: |
34+
for i in web worker ; do
35+
sed -i "s/tag: .* # ${i} tag managed by github actions$/tag: pr-${{ github.event.number }} # ${i} tag managed by github actions/" helm-quarry/values.yaml
36+
done
37+
38+
- uses: EndBug/add-and-commit@v7
39+
with:
40+
add: 'helm-quarry/values.yaml'
41+
author_name: Github Action
42+
author_email: [email protected]
43+
branch: ${{ github.head_ref }}
44+
message: 'auto update of ${{ inputs.imagename }} tag'
45+
pull: --rebase --autostash

.gitignore

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,9 @@ config.yaml
1414
.python-version
1515
.tox/
1616
*.swp
17+
.vscode
18+
.tool-versions
19+
terraform.tfstate*
20+
.terraform*
21+
tofu/kube.config
22+
ansible/collections/*

Dockerfile

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,24 @@
11
# Use official python base image, small and debian edition
2-
FROM amd64/python:3.7.3-slim
3-
4-
ARG purpose=dev
5-
6-
# Update debian packages
7-
RUN apt-get update && \
8-
apt-get upgrade -y
2+
FROM amd64/python:3.7.16-slim
93

104
# Create Quarry user, create /results folder owned by this user,
11-
# to be mounted as volume to be shared between web and runner
5+
# to be mounted as volume to be shared between web and runner in dev setup
126
RUN useradd -r -m quarry && \
137
mkdir /results && \
148
chown -R quarry: /results
159

1610
WORKDIR /app
1711

1812
COPY requirements.txt /app
19-
# Install python or test dependencies
20-
RUN if [ ${purpose} = "test" ] ; then apt-get install -y tox redis-server; \
21-
else pip install --upgrade pip wheel && \
22-
pip install -r requirements.txt; fi
13+
# Install dependencies
14+
RUN pip install --upgrade pip wheel && \
15+
pip install -r requirements.txt
2316

2417
# Copy app code
2518
USER quarry
2619
COPY . /app
2720

28-
# Run web server
21+
# Expose port for web server
2922
EXPOSE 5000
30-
ENTRYPOINT ["python", "quarry.wsgi"]
23+
24+
# Entrypoint is set elsewhere, as it's different for web and worker

README.md

Lines changed: 60 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ queries against Wikipedia and sister projects databases.
44

55
## Setting up a local dev environment ##
66

7+
# docker-compose
78
Quarry uses [Docker](https://docs.docker.com/engine/install/) to set up a local
89
environment. You can set it up by:
910

@@ -18,43 +19,50 @@ will imediatelly be taken into account.
1819
A worker node is also created to execute your queries in the background (uses the
1920
same image). Finally, redis and two database instances are also started.
2021

21-
One database is your quarry database the other is a wikireplica-like database
22-
named `mywiki`. This (or `mywiki_p`) is the correct thing to enter in the
23-
database field on all local test queries.
24-
25-
In your local environment, you can query Quarry internal db itself. Use then
26-
"quarry" as database name.
27-
2822
To stop, run `docker-compose stop` or hit CTRL-C on the terminal your docker-compose
2923
is running in. After that, to start with code changes, you'll want to `docker-compose down`
3024
to clean up. Also, this creates a docker volume where sqlite versions of query
3125
results are found. That will not be cleaned up unless you run `docker-compose down -v`
3226

3327

28+
29+
# minikube
30+
It is possible to run a quarry system inside [minikube](https://minikube.sigs.k8s.io/docs/)!
31+
At this time, you need to set it up with a cluster version before 1.22, most likely.
32+
33+
First build the containers:
34+
```
35+
eval $(minikube docker-env)
36+
docker build . -t quarry:01
37+
cd docker-replica/
38+
docker build . -t mywiki:01
39+
```
40+
41+
You will need to install minikube (tested on minikube 1.23) and [helm](https://helm.sh) and kubectl on your system. When you are confident those are working, start minikube with:
42+
- `minikube start --kubernetes-version=v1.23.15`
43+
- `minikube addons enable ingress`
44+
- `kubectl create namespace quarry`
45+
- `helm -n quarry install quarry helm-quarry -f helm-quarry/dev-env.yaml`
46+
47+
The rest of the setup instructions will display on screen as long as the install is successful.
48+
49+
# local databases
50+
Both local setups will create two databases.
51+
52+
One database is your quarry database the other is a wikireplica-like database
53+
named `mywiki`. This (or `mywiki_p`) is the correct thing to enter in the
54+
database field on all local test queries.
55+
56+
The other database is the Quarry internal db. In your local environment, you can query Quarry internal db itself. Use then
57+
"quarry" as database name.
58+
3459
### Updating existing containers ###
3560

3661
If you had already run a dev environment (that is, ran `docker-compose up`) you might want to update
3762
the containers with the new dependencies by running `docker-compose build` before running
3863
`docker-compose up` again.
3964

4065

41-
## Running tests ##
42-
43-
1. Set up [Blubber](https://wikitech.wikimedia.org/wiki/Blubber) to run tests:
44-
https://wikitech.wikimedia.org/wiki/Blubber/Download
45-
```bash
46-
blubber() {
47-
if [ $# -lt 2 ]; then
48-
echo 'Usage: blubber config.yaml variant'
49-
return 1
50-
fi
51-
curl -s -H 'content-type: application/yaml' --data-binary @"$1" https://blubberoid.wikimedia.org/v1/"$2"
52-
}
53-
```
54-
2. Run tests:
55-
`blubber .pipeline/blubber.yaml quarry-test | docker build --tag blubber-quarry:01 --file - . ; docker run blubber-quarry:01`
56-
57-
5866
## Useful commands ##
5967

6068
To pre-compile nunjucks templates:
@@ -71,3 +79,31 @@ Bug: <ticket number>
7179

7280
For example:
7381
Bug: T317566
82+
83+
## git-crypt ##
84+
85+
git-crypt is used to encrypt the config.yaml file. To decrypt ask a maintainer for the decryption key and:
86+
```
87+
git clone https://github.com/toolforge/quarry.git
88+
cd quarry
89+
git-crypt unlock <path to decryption key>
90+
```
91+
92+
## Deploying to production ##
93+
From the quarry-bastion:
94+
`git clone https://github.com/toolforge/quarry.git`
95+
`cd quarry`
96+
`git checkout <branch>` If not deploying main
97+
`git-crypt unlock <path to key>`
98+
`bash deploy.sh`
99+
In horizon point the web proxy at the new cluster.
100+
101+
### Fresh deploy ###
102+
For a completely fresh deploy, and nfs server will need to be setup. Add its hostname to helm-quarry/prod-env.yaml.
103+
And an object store will need to be generated for the tofu state file. Named "tofu-state"
104+
And setup mysql:
105+
`mysql -uquarry -h <trove hostname created in by tofu> -p < schema.sql`
106+
107+
## troubleshooting ##
108+
If ansible doesn't detect a change for quarry helm the following can be run:
109+
`helm -n quarry upgrade --install quarry helm-quarry -f helm-quarry/prod-env.yaml`

ansible/ansible.cfg

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
[defaults]
2+
# Better error output
3+
stdout_callback=debug
4+
stderr_callback=debug
5+
6+
collections_path=./collections/ansible_collections
7+
8+
# we're only using localhost, no need for the warning.
9+
localhost_warning=False
10+
11+
[inventory]
12+
# Only using localhost, so no inventory
13+
inventory_unparsed_warning=False

ansible/quarry.yaml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
---
2+
3+
- name: Deploy quarry to k8s cluster
4+
gather_facts: false
5+
hosts: localhost
6+
tasks:
7+
- name: Deploy quarry
8+
kubernetes.core.helm:
9+
name: quarry
10+
chart_ref: ../helm-quarry
11+
release_namespace: "quarry"
12+
create_namespace: true
13+
values_files:
14+
- ../helm-quarry/prod-env.yaml

0 commit comments

Comments
 (0)