Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 4 additions & 5 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,11 @@ COPY ./config/ ./config/
COPY --from=builder /tmp/requirements.txt ./
COPY pyproject.toml README.md ./
COPY ./project/ ./project/
COPY ./docker-entrypoint.sh ./

RUN set -ex && \
addgroup -S nonroot && \
adduser -S nonroot -G nonroot && \
addgroup nonroot && \
adduser nonroot -G nonroot -s /bin/sh -D && \
chown -R nonroot:nonroot /app

RUN set -ex && \
Expand All @@ -35,7 +36,5 @@ RUN set -ex && \
ENV PYTHONPATH=/app
ENV PYTHONUNBUFFERED=1

ENTRYPOINT [ "/usr/local/bin/python", "-m", "uvicorn", "project.main:app" ]
ENTRYPOINT [ "/app/docker-entrypoint.sh" ]
CMD [ "--host", "0.0.0.0", "--port", "8080", "--workers", "4" ]

USER nonroot
33 changes: 33 additions & 0 deletions docker-entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#!/bin/sh

print_info() {
printf "\033[1m[$0] [-]\033[0m %s\n" "$1"
}

print_error() {
printf "\033[31;1m[$0] [!]\033[0m %s\n" "$1"
}

if [ -n "${FORCE_UPDATE_CA_CERTIFICATES}" ];
then
if [ "$(id -u)" -ne "0" ];
then
print_error "update-ca-certificates requires to be run as root"
exit 1
fi

print_info "Provisioning additional certificates"

update-ca-certificates
rm /etc/ssl/cert.pem
ln -s /etc/ssl/certs/ca-certificates.crt /etc/ssl/cert.pem
fi

if [ "$(id -u)" -eq "0" ];
then
print_info "Dropping privileges"
su - nonroot
fi

print_info "$(printf "%s " "Running server with arguments:" "${@}")"
exec /usr/local/bin/python -m uvicorn project.main:app "${@}"