Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

OONI Run v2 refactor #805

Closed
wants to merge 67 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
67 commits
Select commit Hold shift + click to select a range
88c281f
Copy OONI Run v2 into oonidatapi tree
hellais Feb 15, 2024
fee55cb
Port OONI Run v2 API over to fastapi
hellais Feb 15, 2024
49952fb
Port OONI Run v2 links over to postgresql
hellais Feb 15, 2024
01b310a
Init alembic setup
hellais Feb 15, 2024
80a7e35
Add alembic migration
hellais Feb 15, 2024
a045348
Align OONI Run v2 implementation to spec
hellais Feb 16, 2024
aca26b1
is_archived cannot be set during create
hellais Feb 23, 2024
c0b36bf
Fix type hints for edit request
hellais Feb 23, 2024
c8e3887
Bump version
hellais Feb 23, 2024
6a7c172
Enable docker build in oonirunv2 branch
hellais Feb 23, 2024
dddd500
Disable autobump
hellais Feb 23, 2024
8ac5f47
Fix reference to tf-actions WIP branch
hellais Feb 23, 2024
fbaf706
Set password
hellais Feb 23, 2024
f3c84e0
Remove check same thread option
hellais Feb 26, 2024
ed662d5
Upgrade to SQLAlchemy 2.x
hellais Feb 26, 2024
da5aea1
Fix broken tests
hellais Feb 26, 2024
8faf9b7
Add github workflow for running tests
hellais Feb 26, 2024
4c09256
Minimal docs update
hellais Feb 26, 2024
eff90a2
Add action triggers
hellais Feb 26, 2024
8f8012b
Remove coverage upload
hellais Feb 27, 2024
3ccae6b
Add pytest-cov
hellais Feb 27, 2024
6ad9f20
Address feedback from spec review: https://github.com/ooni/spec/pull/292
hellais Feb 27, 2024
64b48e5
More changes based on PR review
hellais Feb 27, 2024
66941e2
Add alembic db migration
hellais Feb 27, 2024
f403a00
Fix tests and some bugs related to expiration time
hellais Feb 27, 2024
a748463
Add more tests for expiration
hellais Feb 28, 2024
c1266dc
Add more tests for OONI Run v2
hellais Feb 28, 2024
daef567
Bump minor version number
hellais Feb 28, 2024
c8fc20f
Interpolate the OONI_PG_PASSWORD
hellais Feb 28, 2024
725da39
Fix getting of env var
hellais Feb 28, 2024
2c57b0c
Convert OONI Run link ID column to string
hellais Feb 28, 2024
56dec64
Handle the _intl fields being set to None
hellais Feb 28, 2024
8eff65a
Bump API version to 0.4.1
hellais Feb 28, 2024
35ade79
Add tests for filtering by only_latest
hellais Mar 1, 2024
f8e6129
Add click to dev deps
hellais Mar 1, 2024
6a99313
Fix types of oonirun_link_id
hellais Mar 1, 2024
ab60c44
Add a smoketest for oonirun v2
hellais Mar 1, 2024
a858df1
Add a smoketest stage before pushing the docker tags
hellais Mar 1, 2024
f54c38c
Fix typo in outputs name
hellais Mar 1, 2024
2280915
Rename test_new_api to test_legacy_ooniapi
hellais Mar 1, 2024
061858b
Move mypy tests into test_legacy_ooniapi
hellais Mar 1, 2024
faf0863
Set working directory for smoketests
hellais Mar 1, 2024
8080727
Fix port mapping
hellais Mar 1, 2024
02a3839
Run alembic migration before starting pg host
hellais Mar 1, 2024
bbaaa8d
Ensure poetry is setup
hellais Mar 1, 2024
d7842b0
Fix returning of empty list when descriptors are not found
hellais Mar 1, 2024
e02f6b8
Add checks for descriptors
hellais Mar 1, 2024
a9b8bc2
Rename list ooni run links endpoint
hellais Mar 1, 2024
21cb6b7
Fix tests based on API change
hellais Mar 1, 2024
8f5321f
Fix reference to postgresql
hellais Mar 1, 2024
09ff4fb
Fix smoke test
hellais Mar 1, 2024
8276587
Add wait function to start the smoketest
hellais Mar 1, 2024
f387c44
Provide more information about crash
hellais Mar 1, 2024
e853fd4
Temporarily disable the smoke test
hellais Mar 1, 2024
f0c4bfc
bump dataapi version
hellais Mar 1, 2024
622bf25
Temporarily enable all origins
hellais Mar 4, 2024
a2c5556
Bump version
hellais Mar 4, 2024
504454c
Add codebuild buildspec
hellais Mar 5, 2024
f04b10e
Add .coverage to gitignore
hellais Mar 5, 2024
82a0999
Fix path export
hellais Mar 5, 2024
d6751d8
Fix command
hellais Mar 5, 2024
572c0b6
Fixes to buildspec
hellais Mar 5, 2024
6d5b9dc
Add integration with ECR
hellais Mar 5, 2024
e598308
Fix ECR login
hellais Mar 5, 2024
d3014a2
Fix region name
hellais Mar 5, 2024
93aed8e
Push to dockerhub
hellais Mar 5, 2024
2171765
Write artifact to project root
hellais Mar 5, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
122 changes: 96 additions & 26 deletions .github/workflows/build_dataapi.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ on:
push:
branches:
- master
- oonirunv2
paths:
- "api/fastapi/**"
- ".github/workflows/build_dataapi.yml"
Expand All @@ -13,8 +14,28 @@ env:
IMAGE_NAME: ooni/dataapi

jobs:
test:
uses: ./.github/workflows/test_dataapi.yml

build_and_push:
name: Build and push
needs: [test]
runs-on: ubuntu-latest
services:
postgres:
image: postgres
env:
POSTGRES_USER: oonipg
POSTGRES_PASSWORD: oonipg
POSTGRES_DB: oonipg
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 5
ports:
- 5432:5432

steps:
- name: Checkout Repository
uses: actions/checkout@v2
Expand All @@ -36,6 +57,7 @@ jobs:
echo "version_number=$VERSION_NUMBER" >> "$GITHUB_OUTPUT"

- name: Build and Push Docker Image
id: dockerbuild
env:
DOCKERFILE_PATH: ${{ env.oonidataapi_dir }}
run: |
Expand All @@ -44,43 +66,91 @@ jobs:
TAG_BUILD_LABEL=$IMAGE_NAME:${{ steps.version.outputs.build_label }}
TAG_VERSION=$IMAGE_NAME:v${{ steps.version.outputs.version_number }}

echo "tag_latest=$TAG_LATEST" >> $GITHUB_OUTPUT
echo "tag_environment=$TAG_ENVIRONMENT" >> $GITHUB_OUTPUT
echo "tag_build_label=$TAG_BUILD_LABEL" >> $GITHUB_OUTPUT
echo "tag_version=$TAG_VERSION" >> $GITHUB_OUTPUT

# Build Docker image with multiple tags
docker build --build-arg BUILD_LABEL=${{ steps.version.outputs.build_label }} \
-t $TAG_BUILD_LABEL \
-t $TAG_ENVIRONMENT \
-t $TAG_LATEST \
-t $TAG_VERSION \
$DOCKERFILE_PATH
# Setup python
- name: Set up Python 3.11
uses: actions/setup-python@v4
with:
python-version: 3.11

# Push all tags
docker push $TAG_BUILD_LABEL
docker push $TAG_ENVIRONMENT
docker push $TAG_LATEST
docker push $TAG_VERSION
- name: Install poetry
run: |
curl -fsS https://install.python-poetry.org | python - --preview -y

- name: Checkout ooni/devops
uses: actions/checkout@v2
- name: Add poetry to PATH
run: echo "$HOME/.local/bin" >> $GITHUB_PATH

- name: Set up poetry cache
uses: actions/cache@v3
with:
repository: "ooni/devops" # Replace with your repository's name
ssh-key: ${{ secrets.OONI_DEVOPS_DEPLOYKEY }}
path: "ooni-devops"
ref: "tf-actions"
path: "$HOME/.cache/pypoetry/virtualenvs"
key: venv-${{ runner.os }}-${{ hashFiles('**/api/fastapi/poetry.lock') }}

- name: Bump version of dataapi
run: |
jq --arg value "v${{ steps.version.outputs.version_number }}" \
'(.ooni_service_config.dataapi_version) = $value' \
${BASE_DIR}/terraform.tfvars.json > ${BASE_DIR}/terraform.tfvars.json.tmp \
&& mv ${BASE_DIR}/terraform.tfvars.json.tmp ${BASE_DIR}/terraform.tfvars.json
- name: Install dependencies
run: poetry install
working-directory: ./api/fastapi/

# Configure database and docker
- name: Run alembic migrations
env:
BASE_DIR: "ooni-devops/tf/environments/production"
OONI_PG_PASSWORD: oonipg
OONI_PG_HOST: localhost
run: poetry run alembic upgrade head
working-directory: ./api/fastapi/oonidataapi/

- name: Start Docker container with PostgreSQL
run: |
docker run -d --name oonidataapi -p 8000:80 \
-e POSTGRESQL_URL="postgresql://oonipg:oonipg@localhost/oonipg" \
${{ steps.dockerbuild.outputs.tag_version }}

# Run smoke test
#- name: Run smoketest against the built docker image
# run: poetry run python oonidataapi/tests/run_smoketest.py --backend-base-url=http://localhost:8000/
# working-directory: ./api/fastapi/

- name: Commit changes
id: commit
- name: Push docker tags
run: |
cd ooni-devops
git config --global user.email "nothuman@ooni.org"
git config --global user.name "OONI Github Actions Bot"
git add .
git commit -m "auto: update oonidataapi package version to v${{ steps.version.outputs.version_number }}" || echo "No changes to commit"
git push origin
# Push all tags
docker push ${{ steps.dockerbuild.outputs.tag_latest }}
docker push ${{ steps.dockerbuild.outputs.tag_environment }}
docker push ${{ steps.dockerbuild.outputs.tag_build_label }}
docker push ${{ steps.dockerbuild.outputs.tag_version }}

#- name: Checkout ooni/devops
# uses: actions/checkout@v2
# with:
# repository: "ooni/devops" # Replace with your repository's name
# ssh-key: ${{ secrets.OONI_DEVOPS_DEPLOYKEY }}
# path: "ooni-devops"

#- name: Bump version of dataapi
# run: |
# jq --arg value "v${{ steps.version.outputs.version_number }}" \
# '(.ooni_service_config.dataapi_version) = $value' \
# ${BASE_DIR}/terraform.tfvars.json > ${BASE_DIR}/terraform.tfvars.json.tmp \
# && mv ${BASE_DIR}/terraform.tfvars.json.tmp ${BASE_DIR}/terraform.tfvars.json
# env:
# BASE_DIR: "ooni-devops/tf/environments/prod"

#- name: Commit changes
# id: commit
# run: |
# cd ooni-devops
# git config --global user.email "nothuman@ooni.org"
# git config --global user.name "OONI Github Actions Bot"
# git checkout -b bump-api
# git add .
# git commit -m "auto: update oonidataapi package version to v${{ steps.version.outputs.version_number }}" || echo "No changes to commit"
# git push origin
30 changes: 0 additions & 30 deletions .github/workflows/mypy.yml

This file was deleted.

42 changes: 42 additions & 0 deletions .github/workflows/test_dataapi.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
name: Tests
on:
push:
branches:
- main
pull_request:
branches:
- "*"
workflow_call:
jobs:
run_tests:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3

- name: Set up Python 3.11
uses: actions/setup-python@v4
with:
python-version: 3.11

- name: Install poetry
run: |
curl -fsS https://install.python-poetry.org | python - --preview -y

- name: Add poetry to PATH
run: echo "$HOME/.local/bin" >> $GITHUB_PATH

- name: Set up poetry cache
uses: actions/cache@v3
with:
path: "$HOME/.cache/pypoetry/virtualenvs"
key: venv-${{ runner.os }}-${{ hashFiles('**/api/fastapi/poetry.lock') }}

- name: Install dependencies
run: poetry install
working-directory: ./api/fastapi/

- name: Run all tests
env:
PYTHONUNBUFFERED: "1"
run: poetry run pytest -s --full-trace --log-level=INFO --log-cli-level=INFO -v --setup-show --cov=./ --cov-report=xml --cov-report=term oonidataapi/tests
working-directory: ./api/fastapi/
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Test API
name: Test Legacy API
on:
pull_request:
workflow_dispatch:
Expand All @@ -9,6 +9,29 @@
default: false

jobs:
mypy:
runs-on: ubuntu-latest
container: debian:11
steps:
- name: Check out repository code
uses: actions/checkout@v2

- name: Setup APT
run: |
apt-get update
apt-get install --no-install-recommends -y ca-certificates gnupg
echo "deb http://deb-ci.ooni.org unstable main" >> /etc/apt/sources.list
apt-key adv --verbose --keyserver hkp://keyserver.ubuntu.com --recv-keys "B5A08F01796E7F521861B449372D1FF271F2DD50"

- name: Install dependencies
run: |
apt-get update
apt-get install --no-install-recommends -qy mypy

- name: Run tests
# see the mypy.ini file
run: cd api && mypy **/*.py

integration_test:
runs-on: ubuntu-latest
steps:
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,4 @@ af/oometa/tsvdump.dir/
.tox/
af/fastpath/var/
af/fastpath/etc/
.coverage
14 changes: 13 additions & 1 deletion api/fastapi/Readme.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,18 @@
Running:
## OONI Data API

Setup:

```
poetry install
```

To run tests

```
poetry run pytests oonidataapi/tests
```

To run the backend:
```
poetry run uvicorn oonidataapi.main:app
```
55 changes: 55 additions & 0 deletions api/fastapi/buildspec.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
version: 0.2
env:
variables:
OONI_CODE_PATH: api/fastapi/
IMAGE_NAME: ooni/dataapi

phases:
install:
runtime-versions:
python: 3.11
commands:
- echo "Installing Poetry"
- curl -fsS https://install.python-poetry.org | python - --preview -y
- export PATH="$HOME/.local/bin:$PATH"

pre_build:
commands:
- aws --version
- echo "Logging in to ECR"
- aws secretsmanager get-secret-value --secret-id DOCKER_HUB_PASSWORD --query SecretString --output text | docker login --username ooni --password-stdin
- echo "Formatting version information..."
- DATE=$(date +'%Y%m%d')
- SHORT_SHA=$(echo $CODEBUILD_RESOLVED_SOURCE_VERSION | cut -c1-8)
- BUILD_LABEL="${DATE}-${SHORT_SHA}"
- VERSION_NUMBER=$(cat your_project_dir/pyproject.toml | grep 'version =' | awk -F '"' '{print $2}')

build:
commands:
- PROJECT_ROOT=$(pwd)
- cd $OONI_CODE_PATH
- echo "Installing project dependencies with poetry..."
- poetry install --no-root
- poetry run pytest -s --full-trace --log-level=INFO --log-cli-level=INFO -v --setup-show --cov=./ --cov-report=xml --cov-report=term oonidataapi/tests

- echo "Building and tagging Docker image..."
- |
docker build --build-arg BUILD_LABEL=${BUILD_LABEL} \
-t $IMAGE_NAME:$BUILD_LABEL \
-t $IMAGE_NAME:production \
-t $IMAGE_NAME:latest \
-t $IMAGE_NAME:v$VERSION_NUMBER \
.

post_build:
commands:
- echo "Build complete at $(date)"
- echo "Pushing Docker images..."
- docker push $IMAGE_NAME:$BUILD_LABEL
- docker push $IMAGE_NAME:production
- docker push $IMAGE_NAME:latest
- docker push $IMAGE_NAME:v$VERSION_NUMBER
- printf '[{"name":"ooni_dataapi","imageUri":"%s"}]' $IMAGE_NAME:$BUILD_LABEL > ${PROJECT_ROOT}/imagedefinitions.json

artifacts:
files: imagedefinitions.json
Loading
Loading