blabla1337 / skf-flask

Security Knowledge Framework (SKF) Python Flask / Angular project
https://www.securityknowledgeframework.org
Apache License 2.0
807 stars 308 forks source link

API Dockerfile Changes and Workers Refactor #747

Closed JOT85 closed 2 years ago

JOT85 commented 2 years ago

This is a prerequisite to the next PR (#748), it's just some small changes I made for quality of life when developing and a bit of tidying up.

Dockerfile layer order

The first main change is the reording of the layers in the skf-api Dockerfile. The new order adds the code add the end of the build meaning that, when the cache is used, only the last couple of layers need to be updated instead of the many that were updated before. This also makes pushing updated images much faster.

Exclude Angular2 directory

I also added a dockerignore file only for the skf-api build to exclude the Angular2 directory. To use Dockerfile specific dockerignore files, you need to set DOCKER_BUILDKIT=1, as explained in the comment at the bottom of the Dockerfile. The build still works without it, it just won't exclude the files which was the behaviour before.

Perhaps we should manually list the directories we want to include, instead of listing those to be excluded? That seems like the right way round to do this?

Remove duplicated code

The second change was to break out the deployment and deletion functions into a separate python file, so that they aren't duplicated.

JOT85 commented 2 years ago

In 9cac6c424b1822be2eac9b23752518a369903acc, the base image was changed to python:3.7-slim-stretch. Commit bf22f4ea446d62e17e9cec5b8c1bfd50994fecea fixed the error when using python:3.7-slim. I still think it's a good idea to explicitly mention the version though. We could switch to bullseye? Stretch is supported until June 30, 2022.

blabla1337 commented 2 years ago

Super awesome PR and many thanks for this, really appreciate it!