ID:FCLD-228;DONE:7;HOURS:7; system file gen test in builder

This commit is contained in:
Sameer Dev 2024-04-23 22:42:27 +05:30
commit 816b2cd2a1
4 changed files with 75 additions and 0 deletions

49
Dockerfile Normal file
View File

@ -0,0 +1,49 @@
### SYSTEM GENERATED FILE, MAKE CHANGES AS NEEDED ###
# Build a virtualenv using the appropriate Debian release
# * Install python3-venv for the built-in Python3 venv module (not installed by default)
# * Install gcc libpython3-dev to compile C Python modules
# * In the virtualenv: Update pip setuputils and wheel to support building new packages
FROM debian:11-slim AS build
RUN apt-get update && \
apt-get install --no-install-suggests --no-install-recommends --yes python3-venv gcc libpython3-dev && \
python3 -m venv /venv && \
/venv/bin/pip install --upgrade pip setuptools wheel
# Build the virtualenv as a separate step: Only re-execute this step when packages changes
FROM build AS build-venv
# Install flask for starting the web server
RUN /venv/bin/pip install -U Flask waitress gunicorn
### COMMENT AS NEEDED ###
# Check if requirements.txt exists before copying
# If the path exists, copy requirements.txt into the builder stage
# Using glob pattern so that build does not fail if requirements.txt does not exist
COPY requirements.tx[t] /requirements.txt
### DEFAULT BOOTSTRAP BUILD CODE, RUN LOCALLY TO GENERATE requirements.txt ###
# If requirements.txt exists and not empty, install the listed packages
# If it doesn't exist or is empty, print a message and skip the installation
RUN if [ -s requirements.txt ]; then \
/venv/bin/pip install --disable-pip-version-check -r /requirements.txt; \
else \
echo "No requirements.txt found, skipping installation"; \
fi
# Start a new stage with a distroless image for smaller image size and improved security
FROM gcr.io/distroless/python3-debian11
# Copy the /venv directory from the builder stage into the current stage
# This includes the application code and the dependencies
COPY --from=build-venv /venv /venv
# Copy the rest of the application code
COPY . /python-buildpack-func-sample
# Set /python-buildpack-func-sample as the working directory in the current stage
WORKDIR /python-buildpack-func-sample
# Set the command to run when the container starts
# This will start the application by running entrypoint file
ENTRYPOINT [ "/venv/bin/python3", "autogen_index.py" ]

15
fc.toml Normal file
View File

@ -0,0 +1,15 @@
app = "python-dockerfile-app-sample"
region = "asia-south1"
handler = ""
[build]
dockerfile = "Dockerfile"
ignorefile = ".gitignore"
[build.args]
foo = "bar"
[env]
FOO = "BAR"
[http_service]
internal_port = 3000

10
index.py Normal file
View File

@ -0,0 +1,10 @@
from flask import Flask
app = Flask(__name__)
@app.route('/')
def hello():
return 'Hello World!'
if __name__ == '__main__':
app.run(port=3000)

1
requirements.txt Normal file
View File

@ -0,0 +1 @@
Flask==3.0.3