Skip to content

Commit ed79701

Browse files
committed
Use run.sh and add tests
1 parent 060c1bf commit ed79701

File tree

9 files changed

+701
-172
lines changed

9 files changed

+701
-172
lines changed

.github/workflows/publish.yaml

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -254,3 +254,58 @@ jobs:
254254
webhook-type: incoming-webhook
255255
payload: |
256256
text: "⚠️ Build of ${{ env.GAR_IMAGE_NAME }}:${{ env.LATEST_TAG }} failed. Please review logs and correct issues."
257+
258+
git_reader_container:
259+
env:
260+
GAR_IMAGE_NAME: remote-settings-git-reader
261+
LATEST_TAG: "" # Set after checkout step
262+
runs-on: ubuntu-latest
263+
environment: build
264+
steps:
265+
- name: Checkout code
266+
uses: actions/checkout@v5
267+
with:
268+
fetch-depth: 0
269+
- name: Set tag version
270+
run: echo "LATEST_TAG=$(git describe --tags --abbrev=4)" >> "$GITHUB_ENV"
271+
- name: Extract metadata (tags, labels) for Docker
272+
id: meta
273+
uses: docker/metadata-action@v5
274+
with:
275+
images: ${{ env.GAR_LOCATION }}-docker.pkg.dev/${{ env.GCP_PROJECT_ID }}/${{ env.GAR_REPOSITORY }}/${{ env.GAR_IMAGE_NAME }}
276+
tags: |
277+
type=raw,value=${{ env.LATEST_TAG }}
278+
type=raw,value=latest
279+
- name: Set up Docker Buildx
280+
uses: docker/setup-buildx-action@v3
281+
- name: Authenticate on GCP
282+
id: gcp_auth
283+
uses: google-github-actions/auth@v3
284+
with:
285+
token_format: access_token
286+
service_account: artifact-writer@${{ env.GCP_PROJECT_ID }}.iam.gserviceaccount.com
287+
workload_identity_provider: ${{ vars.GCPV2_GITHUB_WORKLOAD_IDENTITY_PROVIDER }}
288+
- name: Login to GAR
289+
if: ${{ github.event_name == 'push' }}
290+
uses: docker/login-action@v3
291+
with:
292+
registry: ${{ env.GAR_LOCATION }}-docker.pkg.dev
293+
username: oauth2accesstoken
294+
password: ${{ steps.gcp_auth.outputs.access_token }}
295+
- name: Build and push
296+
uses: docker/build-push-action@v6
297+
with:
298+
context: git-reader/
299+
push: ${{ github.event_name == 'push' }}
300+
tags: ${{ steps.meta.outputs.tags }}
301+
labels: ${{ steps.meta.outputs.labels }}
302+
cache-from: type=gha # Load cache from GitHub Actions
303+
cache-to: type=gha,mode=max # Save cache to GitHub Actions
304+
- name: Notify DEVs of build failure
305+
if: failure()
306+
uses: slackapi/slack-github-action@v2.1.1
307+
with:
308+
webhook: ${{ secrets.SLACK_WEBHOOK_URL }}
309+
webhook-type: incoming-webhook
310+
payload: |
311+
text: "⚠️ Build of ${{ env.GAR_IMAGE_NAME }}:${{ env.LATEST_TAG }} failed. Please review logs and correct issues."

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ lint: $(INSTALL_STAMP) ## Analyze code base
4545
$(VENV)/bin/python bin/repo-python-versions.py
4646

4747
test: $(INSTALL_STAMP) ## Run unit tests
48-
PYTHONPATH=. $(VENV)/bin/coverage run -m pytest kinto-remote-settings cronjobs
48+
PYTHONPATH=. $(VENV)/bin/coverage run -m pytest kinto-remote-settings cronjobs git-reader
4949
$(VENV)/bin/coverage report -m --fail-under 99
5050

5151
browser-test: ## Run browser tests using Docker

git-reader/Dockerfile

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,29 +3,33 @@ FROM python:3.13.2-slim-bullseye
33
# Install uv.
44
COPY --from=ghcr.io/astral-sh/uv:latest /uv /bin/uv
55

6-
RUN apt-get update && apt-get -y install git git-lfs
6+
RUN apt-get update && apt-get -y install git git-lfs rsync util-linux
77

88
WORKDIR /app
99

1010
RUN chown 10001:10001 /app && \
1111
groupadd --gid 10001 app && \
1212
useradd --no-create-home --uid 10001 --gid 10001 --home-dir /app app
1313

14+
RUN mkdir /app/.ssh && \
15+
ssh-keyscan github.com >> /app/.ssh/known_hosts && \
16+
chown -R app:app /app/.ssh
17+
1418
COPY --chown=app:app pyproject.toml .
1519
COPY --chown=app:app uv.lock .
1620

1721
RUN uv sync --locked --no-cache
1822

23+
COPY --chown=app:app run.sh .
24+
RUN chmod +x run.sh
1925
COPY --chown=app:app main.py .
2026

21-
RUN mkdir /app/.ssh && \
22-
ssh-keyscan github.com >> /app/.ssh/known_hosts && \
23-
chown -R app:app /app/.ssh
24-
2527
USER app
2628

27-
ENV GIT_REPO_PATH=/mnt/data
29+
ENV GIT_REPO_PATH=/mnt/data/latest
2830
ENV SELF_CONTAINED=false
2931

3032
EXPOSE 8000
31-
CMD ["uv", "run", "uvicorn", "main:app", "--host", "0.0.0.0", "--port", "8000"]
33+
34+
ENTRYPOINT [ "/app/run.sh" ]
35+
CMD [ "web" ]

git-reader/README.md

Lines changed: 45 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,45 @@
11
# Remote Settings Over Git
22

3-
## Getting Started
4-
5-
Clone a Remote Settings data repository into a folder:
3+
## Building the Docker image
64

75
```bash
8-
git clone git@github.com:leplatrem/remote-settings-data.git /mnt/git/remote-settings-data
6+
docker build -t remote-settings-git-reader .
97
```
108

11-
If the container is configured to serve attachments (see `SELF_CONTAINED` below), make sure to install Git LFS and pull the LFS files:
9+
## Settings
10+
11+
- ``GIT_REPO_PATH``: the path to the Git repository to use.
12+
- ``SELF_CONTAINED`` (default: `false`): if set to `true`, the application will serve all necessary content from the Git repository, including
13+
attachments and certificates chains.
14+
- ``ATTACHMENTS_BASE_URL`` (default: `None`): this URL will be used as the base URL for attachments. If `SELF_CONTAINED` is `false`, this URL is required. With self-contained, the current domain will be used by default (`Host` request header) if not set.
1215

13-
```bash
14-
git lfs install
15-
git lfs pull
16-
git lfs fsck
17-
```
1816

19-
Build the container:
17+
## Running the application
18+
19+
The application needs access to a Git repository containing Remote Settings data (read-only);
2020

2121
```bash
22-
docker build -t remote-settings-git-reader .
22+
docker run --rm -p 8000:8000 \
23+
-e GIT_REPO_PATH=/mnt/data/latest \
24+
-e SELF_CONTAINED=true \
25+
-v /mnt/git/remote-settings-data:/mnt/data:ro \
26+
remote-settings-git-reader
2327
```
2428

25-
Then you can start the application with:
29+
But first, we will initialize the folder structure required to execute Git updates atomically.
30+
Use the ``init`` command and the ``GIT_REPO_URL`` environment variable to specify the repository to clone:
2631

2732
```bash
28-
docker run --rm -p 8000:8000 \
29-
-e GIT_REPO_PATH=/mnt/data \
33+
docker run --rm \
34+
-e GIT_REPO_URL=git@github.com:mozilla/remote-settings-data.git \
35+
-e GIT_REPO_PATH=/mnt/data/latest \
3036
-e SELF_CONTAINED=true \
3137
-v /mnt/git/remote-settings-data:/mnt/data \
32-
remote-settings-git-reader
38+
remote-settings-git-reader init
3339
```
3440

41+
Unless you used an anonymous clone, this is likely to fail, as the container needs access to the Git repository via SSH.
42+
3543
### Using SSH keys
3644

3745
When cloning the repository anonymously (from `https://...`) the Git LFS is rate-limited and it is very likely that you will hit the limit when pulling the LFS files.
@@ -45,13 +53,13 @@ Since the container is going to regularly run Git fetch commands to keep the rep
4553
This requires to have a SSH agent working on the host. It has the advantage of not requiring the container to have access to the actual key and passphrase (if any).
4654

4755
```bash
48-
docker run --rm -p 8000:8000 \
49-
-e GIT_REPO_PATH=/mnt/data \
56+
docker run --rm \
57+
-e GIT_REPO_PATH=/mnt/data/latest \
5058
-e SELF_CONTAINED=true \
5159
-v /mnt/git/remote-settings-data:/mnt/data \
5260
-e SSH_AUTH_SOCK=/app/ssh-agent \
5361
-v $SSH_AUTH_SOCK:/app/ssh-agent \
54-
remote-settings-git-reader
62+
remote-settings-git-reader init
5563
```
5664

5765
2. Or pass the private key file into the container.
@@ -73,12 +81,12 @@ EOF
7381
And then mount the SSH material directory into the container:
7482

7583
```bash
76-
docker run --rm -p 8000:8000 \
77-
-e GIT_REPO_PATH=/mnt/data \
84+
docker run --rm \
85+
-e GIT_REPO_PATH=/mnt/data/latest \
7886
-e SELF_CONTAINED=true \
7987
-v /mnt/git/remote-settings-data:/mnt/data \
8088
-v `pwd`/ssh-material:/app/.ssh \
81-
remote-settings-git-reader
89+
remote-settings-git-reader init
8290
```
8391

8492
You can test your SSH setup:
@@ -92,9 +100,19 @@ docker run \
92100
Hi <username>! You've successfully authenticated, but GitHub does not provide shell access.
93101
```
94102
95-
## Settings
103+
## Updating the repository
96104
97-
- ``GIT_REPO_PATH``: the path to the Git repository to use.
98-
- ``SELF_CONTAINED`` (default: `false`): if set to `true`, the application will serve all necessary content from the Git repository, including
99-
attachments and certificates chains.
100-
- ``ATTACHMENTS_BASE_URL`` (default: `None`): this URL will be used as the base URL for attachments. If `SELF_CONTAINED` is `false`, this URL is mandatory, otherwise the current domain will be used by default (`Host` request header).
105+
The container can be used to update the Git repository, by running the `update` command:
106+
107+
```bash
108+
docker run --rm \
109+
-e GIT_REPO_PATH=/mnt/data/latest \
110+
-e SELF_CONTAINED=true \
111+
-v /mnt/git/remote-settings-data:/mnt/data \
112+
remote-settings-git-reader update
113+
```
114+
This command can be run periodically (e.g., via a cron job) to keep the repository up to date. For example, every 5 minutes:
115+
116+
```bash
117+
*/5 * * * * docker run ...
118+
```

0 commit comments

Comments
 (0)