-
Notifications
You must be signed in to change notification settings - Fork 227
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 support for git tokens, to be used for python dependencies from private git repos, in the main python template. #292
Closed
CC007
wants to merge
2
commits into
openfaas:master
from
CodeQualIT:feature/private-git-dependency-support
Closed
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 |
---|---|---|
@@ -1,56 +1,87 @@ | ||
FROM --platform=${TARGETPLATFORM:-linux/amd64} ghcr.io/openfaas/classic-watchdog:0.2.0 as watchdog | ||
FROM --platform=${TARGETPLATFORM:-linux/amd64} python:3-alpine | ||
|
||
ARG TARGETPLATFORM | ||
ARG BUILDPLATFORM | ||
# Builder stage that allows you to use git modules from private repos | ||
FROM --platform=${TARGETPLATFORM:-linux/amd64} python:3-alpine as builder | ||
|
||
# Allows you to add additional packages via build-arg | ||
# Basic user, python and certificate setup | ||
ARG ADDITIONAL_PACKAGE | ||
|
||
COPY --from=watchdog /fwatchdog /usr/bin/fwatchdog | ||
RUN chmod +x /usr/bin/fwatchdog | ||
RUN apk --no-cache add ca-certificates ${ADDITIONAL_PACKAGE} | ||
RUN addgroup -S app && adduser app -S -G app | ||
WORKDIR /home/app/ | ||
RUN chown -R app /home/app && \ | ||
mkdir -p /home/app/python && chown -R app /home/app | ||
USER app | ||
ENV PATH=$PATH:/home/app/.local/bin:/home/app/python/bin/ | ||
ENV PYTHONPATH=$PYTHONPATH:/home/app/python | ||
|
||
# Token to be provided as argument | ||
ARG GIT_TOKEN=no_token_set | ||
|
||
# Add non root user | ||
RUN addgroup -S app && adduser app -S -G app | ||
# Install git and make the git token available as environment variable | ||
USER root | ||
RUN apk --no-cache add git | ||
|
||
# Install template requirements | ||
USER app | ||
WORKDIR /home/app/ | ||
|
||
COPY index.py . | ||
COPY requirements.txt . | ||
RUN GIT_TOKEN=${GIT_TOKEN} pip install -r requirements.txt --target=/home/app/python | ||
|
||
# Install function specific requirements | ||
RUN mkdir -p function | ||
WORKDIR /home/app/function/ | ||
COPY function/requirements.txt . | ||
RUN GIT_TOKEN=${GIT_TOKEN} pip install -r requirements.txt --target=/home/app/python | ||
|
||
FROM --platform=${TARGETPLATFORM:-linux/amd64} ghcr.io/openfaas/classic-watchdog:0.2.0 as watchdog | ||
|
||
# Actual image | ||
FROM --platform=${TARGETPLATFORM:-linux/amd64} python:3-alpine | ||
|
||
# Basic user, python and certificate setup | ||
ARG ADDITIONAL_PACKAGE | ||
RUN apk --no-cache add ca-certificates ${ADDITIONAL_PACKAGE} | ||
RUN addgroup -S app && adduser app -S -G app | ||
WORKDIR /home/app/ | ||
RUN chown -R app /home/app && \ | ||
mkdir -p /home/app/python && chown -R app /home/app | ||
mkdir -p /home/app/python && chown -R app /home/app | ||
USER app | ||
ENV PATH=$PATH:/home/app/.local/bin:/home/app/python/bin/ | ||
ENV PYTHONPATH=$PYTHONPATH:/home/app/python | ||
|
||
RUN pip install -r requirements.txt --target=/home/app/python | ||
# Copy over watchdog | ||
USER root | ||
COPY --from=watchdog /fwatchdog /usr/bin/fwatchdog | ||
RUN chmod +x /usr/bin/fwatchdog | ||
|
||
# Copy over template files | ||
USER app | ||
WORKDIR /home/app/ | ||
COPY index.py . | ||
COPY requirements.txt . | ||
|
||
# Mark the function dir as a module | ||
RUN mkdir -p function | ||
RUN touch ./function/__init__.py | ||
|
||
# Copy over the function specific requirements file | ||
WORKDIR /home/app/function/ | ||
COPY function/requirements.txt . | ||
|
||
RUN pip install -r requirements.txt --target=/home/app/python | ||
|
||
# Copy over resolved dependencies from builder stage | ||
WORKDIR /home/app/ | ||
COPY --from=builder /home/app/.cache /home/app/.cache | ||
COPY --from=builder /home/app/python /home/app/python | ||
|
||
# Copy over the specific function code | ||
USER root | ||
|
||
COPY function function | ||
|
||
# Allow any user-id for OpenShift users. | ||
RUN chown -R app:app ./ && \ | ||
chmod -R 777 /home/app/python | ||
chmod -R 777 /home/app/python | ||
|
||
# Prepare and run the watchdog | ||
USER app | ||
|
||
ENV fprocess="python3 index.py" | ||
EXPOSE 8080 | ||
|
||
HEALTHCHECK --interval=3s CMD [ -e /tmp/.lock ] || exit 1 | ||
|
||
CMD ["fwatchdog"] |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My concern would be whether any C/C++ libraries that were built or installed into the system are still available at this point such as numpy, pillow or pandas.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point. I'll see if I can test this. I believe
requests
also requires C/C++ libs.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Confirmed that numpy only installs to
/home/app/.cache
and/home/app/python
. I'll try pillow and pandas next.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pillow doesn't correctly install, due to a missing zlib dependency (and even when that is added, it is installed to
/lib
instead of/usr/lib
, so python still can't find it)See: link
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pandas seems to work fine too, only using those 2 folders