Skip to content
This repository has been archived by the owner on Nov 30, 2022. It is now read-only.

Adds fidesops worker command to start the Celery worker [#663] #673

Merged
merged 16 commits into from
Jun 28, 2022
Merged
File renamed without changes.
53 changes: 53 additions & 0 deletions Dockerfile.worker
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
FROM node:16 as frontend

FROM --platform=linux/amd64 python:3.9.13-slim-buster as backend

ARG MSSQL_REQUIRED

# Install auxiliary software
RUN apt-get update && \
apt-get install -y \
git \
make \
ipython \
vim \
curl \
g++ \
gnupg \
gcc
seanpreston marked this conversation as resolved.
Show resolved Hide resolved


RUN echo "Building fidesops celery worker"
RUN echo "ENVIRONMENT VAR: $MSSQL_REQUIRED"

# SQL Server (MS SQL)
# https://docs.microsoft.com/en-us/sql/connect/odbc/linux-mac/installing-the-microsoft-odbc-driver-for-sql-server?view=sql-server-ver15
RUN if [ "$MSSQL_REQUIRED" = "true" ] ; then apt-get install apt-transport-https ; fi
RUN if [ "$MSSQL_REQUIRED" = "true" ] ; then curl https://packages.microsoft.com/keys/microsoft.asc | apt-key add - ; fi
RUN if [ "$MSSQL_REQUIRED" = "true" ] ; then curl https://packages.microsoft.com/config/debian/10/prod.list | tee /etc/apt/sources.list.d/msprod.list ; fi
RUN if [ "$MSSQL_REQUIRED" = "true" ] ; then apt-get update ; fi
ENV ACCEPT_EULA=y DEBIAN_FRONTEND=noninteractive
RUN if [ "$MSSQL_REQUIRED" = "true" ] ; then apt-get -y install \
unixodbc-dev \
msodbcsql17 \
mssql-tools ; fi
seanpreston marked this conversation as resolved.
Show resolved Hide resolved

# Update pip and install requirements
COPY requirements.txt dev-requirements.txt mssql-requirements.txt ./
RUN pip install -U pip \
&& pip install 'cryptography~=3.4.8' \
&& pip install snowflake-connector-python --no-use-pep517 \
&& pip install -r requirements.txt -r dev-requirements.txt

RUN if [ "$MSSQL_REQUIRED" = "true" ] ; then pip install -U pip -r mssql-requirements.txt ; fi
seanpreston marked this conversation as resolved.
Show resolved Hide resolved


# Copy in the application files and install it locally
COPY . /fidesops
WORKDIR /fidesops
RUN pip install -e .

# Enable detection of running within Docker
ENV RUNNING_IN_DOCKER=true

CMD [ "fidesops", "worker" ]
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
REGISTRY := ethyca
IMAGE_TAG := $(shell git fetch --force --tags && git describe --tags --dirty --always)

IMAGE_NAME := fidesops
IMAGE_NAME := webserver
sanders41 marked this conversation as resolved.
Show resolved Hide resolved
IMAGE := $(REGISTRY)/$(IMAGE_NAME):$(IMAGE_TAG)
IMAGE_LATEST := $(REGISTRY)/$(IMAGE_NAME):latest

Expand Down
2 changes: 1 addition & 1 deletion docker-compose.integration-mariadb.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
services:
fidesops:
webserver:
depends_on:
- mariadb_example

Expand Down
2 changes: 1 addition & 1 deletion docker-compose.integration-mongodb.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
services:
fidesops:
webserver:
depends_on:
- mongodb_example

Expand Down
2 changes: 1 addition & 1 deletion docker-compose.integration-mssql.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
services:
fidesops:
webserver:
depends_on:
- mssql_example

Expand Down
2 changes: 1 addition & 1 deletion docker-compose.integration-mysql.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
services:
fidesops:
webserver:
depends_on:
- mysql_example

Expand Down
2 changes: 1 addition & 1 deletion docker-compose.integration-postgres.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
services:
fidesops:
webserver:
depends_on:
- postgres_example

Expand Down
7 changes: 3 additions & 4 deletions docker-compose.no-db.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
services:
fidesops:
container_name: fidesops
webserver:
build:
context: .
dockerfile: Dockerfile
dockerfile: Dockerfile.app
expose:
- 8080
healthcheck:
Expand All @@ -29,7 +28,7 @@ services:
docs:
build:
context: docs/fidesops/
dockerfile: Dockerfile
dockerfile: Dockerfile.docs
volumes:
- ./docs/fidesops:/docs
expose:
Expand Down
15 changes: 7 additions & 8 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
services:
fidesops:
container_name: fidesops
webserver:
build:
context: .
dockerfile: Dockerfile
dockerfile: Dockerfile.app
depends_on:
- celery
- worker
- db
- redis
expose:
Expand Down Expand Up @@ -59,11 +58,11 @@ services:
ports:
- "0.0.0.0:6379:6379"

celery:
worker:
build:
context: .
dockerfile: Dockerfile
command: celery -A fidesops.tasks.celery_app worker --loglevel=info
dockerfile: Dockerfile.worker
command: fidesops worker
depends_on:
redis:
condition: service_started
Expand All @@ -77,7 +76,7 @@ services:
docs:
build:
context: docs/fidesops/
dockerfile: Dockerfile
dockerfile: Dockerfile.docs
volumes:
- ./docs/fidesops:/docs
expose:
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion run_infrastructure.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
"bigquery": ["BIGQUERY_KEYFILE_CREDS", "BIGQUERY_DATASET"],
}
EXTERNAL_DATASTORES = list(EXTERNAL_DATASTORE_CONFIG.keys())
IMAGE_NAME = "fidesops"
IMAGE_NAME = "webserver"


def run_infrastructure(
Expand Down
11 changes: 11 additions & 0 deletions src/fidesops/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import click

from fidesops.main import start_webserver
from fidesops.tasks import start_worker


@click.group()
Expand All @@ -18,3 +19,13 @@ def webserver(ctx: click.Context) -> None:
Runs any pending DB migrations and starts the webserver.
"""
start_webserver()


@cli.command()
@click.pass_context
def worker(ctx: click.Context) -> None:
"""
Starts a Celery worker
"""
celery_args = ["worker", "--loglevel=info"]
seanpreston marked this conversation as resolved.
Show resolved Hide resolved
start_worker(celery_args)
10 changes: 8 additions & 2 deletions src/fidesops/tasks/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from typing import List, Optional

from celery import Celery
from celery.utils.log import get_task_logger

Expand Down Expand Up @@ -28,6 +30,10 @@ def _create_celery() -> Celery:
celery_app = _create_celery()


if __name__ == "__main__":
def start_worker(argv: Optional[List[str]] = None) -> None:
logger.info("Running Celery worker...")
celery_app.worker_main()
celery_app.worker_main(argv)
seanpreston marked this conversation as resolved.
Show resolved Hide resolved


if __name__ == "__main__":
start_worker()