commit 816b2cd2a1704cc32738c49b5e43e14921ccbc26 Author: Sameer Dev Date: Tue Apr 23 22:42:27 2024 +0530 ID:FCLD-228;DONE:7;HOURS:7; system file gen test in builder diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..b68b8fe --- /dev/null +++ b/Dockerfile @@ -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" ] \ No newline at end of file diff --git a/fc.toml b/fc.toml new file mode 100644 index 0000000..fe37752 --- /dev/null +++ b/fc.toml @@ -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 diff --git a/index.py b/index.py new file mode 100644 index 0000000..1934239 --- /dev/null +++ b/index.py @@ -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) diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..95fef4e --- /dev/null +++ b/requirements.txt @@ -0,0 +1 @@ +Flask==3.0.3