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

Add production Dockerfile and ci image upload workflow #70

Draft
wants to merge 4 commits into
base: develop
Choose a base branch
from

Conversation

asuresh-code
Copy link
Contributor

@asuresh-code asuresh-code commented Nov 25, 2024

Description

Enter a description of the changes here

Testing instructions

Add a set up instructions describing how the reviewer should test the code

  • Review code
  • Check Actions build
  • Review changes to test coverage
  • {more steps here}

Agile board tracking

closes #5

@asuresh-code asuresh-code self-assigned this Nov 25, 2024
@asuresh-code asuresh-code marked this pull request as draft November 25, 2024 14:07
@asuresh-code asuresh-code added the docker Pull requests that update Docker code label Nov 25, 2024
@codecov-commenter
Copy link

codecov-commenter commented Nov 25, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 98.09%. Comparing base (005e416) to head (05a7082).

Additional details and impacted files
@@           Coverage Diff            @@
##           develop      #70   +/-   ##
========================================
  Coverage    98.09%   98.09%           
========================================
  Files           21       21           
  Lines          368      368           
========================================
  Hits           361      361           
  Misses           7        7           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Collaborator

@VKTB VKTB left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Still waiting on the Harbor project. The README will need to be updated at the end to include instructions.

file: ./Dockerfile.prod
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing newline at end of file

Suggested change
labels: ${{ steps.meta.outputs.labels }}
labels: ${{ steps.meta.outputs.labels }}

@@ -106,3 +106,34 @@ jobs:
- name: Output docker logs (minio)
if: failure()
run: docker logs object-storage-api-minio-1
docker:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you like the idea of pushing the image to Harbor only when the CI workflow is manually run then you might want to look at the CI workflow file in ral-facilities/scigateway-auth#134 and make those changes here.

@@ -0,0 +1,28 @@
FROM python:3.12.7-alpine3.20@sha256:edd1d8559c585e1e9a9b79de44ac27f8ac32cb0c7323e112ae6870ceeecd8dbf AS builder
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can probably get away with one stage as I don't think it would make a massive difference in this case.

COPY --from=builder /usr/local/lib/python3.12/site-packages /usr/local/lib/python3.12/site-packages
COPY --from=builder /usr/local/bin /usr/local/bin

COPY README.md ./
Copy link
Collaborator

@VKTB VKTB Dec 12, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copying the README is not needed.

RUN set -eux; \
\
# Create loging.ini from its .example file \
cp object_storage_api/logging.example.ini object_storage_api/logging.ini;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't do this in other projects. We have instructions to tell the user to create the file manually before building the image. I think we should stay consistent.

# Create loging.ini from its .example file \
cp object_storage_api/logging.example.ini object_storage_api/logging.ini;

USER nobody
Copy link
Collaborator

@VKTB VKTB Dec 12, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wasn't aware of this user. We manually create a non-root user and group in other projects. I will need to look into this a bit more because if we can just use nobody then it would save us from creating non-root users. Let me know if you did any research on this and what you found out.

Update:
I had a chat with Alan and we decided not to use the nobody user and group. We should continue to manually create a non-root user and group like is the case with some of our projects and many popular Docker images.


USER nobody

CMD ["uvicorn", "object_storage_api.main:app", "--app-dir", "/object-storage-api-run", "--host", "0.0.0.0", "--port", "8000"]
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We recently started using the FastAPI CLI CLI command line program, which internally uses a production-ready Uvicorn server, as that now seems to be the recommended way by FastAPI of running apps for, both, local development and production.

Copy link
Collaborator

@VKTB VKTB Dec 12, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You might want to look at the Dockerfile in ral-facilities/scigateway-auth#134 and what I did there. If you like what I did then it would be nice to keep things consistent (thoughts on it in that PR are welcome). It just means that we can have a single file with multiple stages/targets.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
docker Pull requests that update Docker code
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add production Dockerfile and upload images on CI
3 participants