-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
2024 refactor part 2/3: fastapi refactor (#800)
* Create structure for fastapi based API * Refactor aggregation and measurement API to fastapi * Refactor aggregation and measurement API to fastapi * Add github workflow * Delete all unused imports * Remove dead code * Move unused variables into integ tests * Rename dataapi to oonidataapi * Move aggregation integration test into oonidataapi dir * Integrate aggregation integration tests * Add missing deps * Fix pkg_name * Port aggregation tests over to httpx * Run build on new branch name * Re-add parts lost in rebase * More missing pieces Thankyou linting
- Loading branch information
Showing
29 changed files
with
6,503 additions
and
1,592 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
name: Build and Deploy Docker Image for dataapi | ||
|
||
on: | ||
push: | ||
branches: | ||
- backend-v2024.2.0 | ||
#paths: | ||
# - "api/fastapi/**" | ||
|
||
env: | ||
IMAGE_NAME: ooni/dataapi | ||
DOCKERFILE_PATH: ./api/fastapi/ | ||
|
||
jobs: | ||
build_and_push: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout Repository | ||
uses: actions/checkout@v2 | ||
|
||
- name: Log in to Docker Hub | ||
uses: docker/login-action@v1 | ||
with: | ||
username: ${{ vars.DOCKERHUB_USERNAME }} | ||
password: ${{ secrets.DOCKERHUB_PASSWORD }} | ||
|
||
- name: Format version number | ||
id: version | ||
run: | | ||
DATE=$(date +'%Y%m%d') | ||
SHORT_SHA=$(echo ${{ github.sha }} | cut -c1-4) | ||
TAG="v${DATE}-${SHORT_SHA}" | ||
echo "tag=$TAG" >> "$GITHUB_OUTPUT" | ||
- name: Build and Push Docker Image | ||
run: | | ||
BUILD_LABEL=${{ steps.version.outputs.tag }} | ||
TAG_LATEST=$IMAGE_NAME:latest | ||
TAG_ENVIRONMENT=$IMAGE_NAME:production | ||
TAG_VERSION=$IMAGE_NAME:$BUILD_LABEL | ||
# Build Docker image with multiple tags | ||
docker build --build-arg BUILD_LABEL=$BUILD_LABEL -t $TAG_LATEST -t $TAG_VERSION -t $TAG_ENVIRONMENT $DOCKERFILE_PATH | ||
# Push all tags | ||
docker push $TAG_LATEST | ||
docker push $TAG_VERSION | ||
docker push $TAG_ENVIRONMENT |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
# Python builder | ||
# Produced a virtualenv with all the deps good to go | ||
|
||
# TODO(art): upgrade to bookworm (blocked by this | ||
# https://github.com/actions/setup-python/issues/721) or stop using debian to | ||
# have more recent base OS | ||
FROM python:3.11-bullseye as py-build | ||
ARG BUILD_LABEL=docker | ||
|
||
RUN apt-get update && export DEBIAN_FRONTEND=noninteractive \ | ||
&& apt-get -y install --no-install-recommends python3 python3-dev | ||
|
||
RUN curl -sSL https://install.python-poetry.org | POETRY_HOME=/opt/poetry python3 - | ||
|
||
COPY . /app | ||
WORKDIR /app | ||
ENV PATH=/opt/poetry/bin:$PATH | ||
RUN echo "$BUILD_LABEL" > /app/dataapi/BUILD_LABEL | ||
RUN poetry config virtualenvs.in-project true && poetry install --no-interaction --no-ansi | ||
|
||
### Actual image running on the host | ||
FROM python:3.11-bullseye | ||
|
||
ENV PYTHONDONTWRITEBYTECODE 1 | ||
ENV PYTHONUNBUFFERED 1 | ||
|
||
COPY --from=py-build /app /app | ||
WORKDIR /app | ||
CMD ["/app/.venv/bin/uvicorn", "dataapi.main:app", "--host", "0.0.0.0", "--port", "80"] | ||
EXPOSE 80 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
Running: | ||
|
||
``` | ||
poetry install | ||
poetry run uvicorn dataapi.main:app | ||
``` |
Oops, something went wrong.