# syntax = docker/dockerfile:1
# DOCKER_BUILDKIT=1 docker build . -f firewall_filtering/Dockerfile -t firewall_filtering --secret id=ca.key,src=ca.key
FROM python

RUN mkdir /service
COPY protobufs/ /service/protobufs/
COPY firewall_filtering/ /service/firewall_filtering/
COPY ca.pem /service/firewall_filtering

WORKDIR /service/firewall_filtering
RUN python -m pip install --upgrade pip
RUN python -m pip install -r requirements.txt
RUN python -m grpc_tools.protoc -I ../protobufs --python_out=. --grpc_python_out=. ../protobufs/firewall_filter.proto
RUN openssl req -nodes -newkey rsa:4096 -subj /CN=firewall_filtering -keyout server.key -out server.csr
RUN --mount=type=secret,id=ca.key openssl x509 -req -in server.csr -CA ca.pem -CAkey /run/secrets/ca.key -set_serial 1 -out server.pem

EXPOSE 50051
ENTRYPOINT ["python", "firewall_filtering.py"]
