Skip to content

doc: describe how to create a Docker image #212

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

Merged
merged 1 commit into from
Feb 3, 2021
Merged
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
49 changes: 48 additions & 1 deletion google/cloud/functions/quickstart/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ git clone https://github.com/microsoft/vcpkg
(cd vcpkg && ./bootstrap.sh)
```

### Compiling a function

Once vcpkg is compiled you can build the quickstart example using:

> :warning: the first time you build the framework it might take several
Expand All @@ -39,15 +41,18 @@ Once vcpkg is compiled you can build the quickstart example using:
```shell
cd $HOME/functions-framework-cpp/google/cloud/functions/quickstart
cmake -H. -B.build -DCMAKE_TOOLCHAIN_FILE=$HOME/vcpkg/scripts/buildsystems/vcpkg.cmake
cmake --build .build
```

### Running the function locally

This will produce a standalone HTTP server, which you can run locally using:

```shell
.build/quickstart --port 8080
```

Test this program using `curl`. In a separate shell run:
Test this program using `curl`. In a separate terminal window run:

```shell
curl http://localhost:8080
Expand All @@ -58,3 +63,45 @@ And terminate the program gracefully using:
```shell
curl http://localhost:8080/quit/program/0
```

## How-to Guide: Running your function as Docker container

1. Install [Docker](https://store.docker.com/search?type=edition&offering=community) and
the [`pack` tool](https://buildpacks.io/docs/install-pack/).

1. Create the `pack` builder for C++. The first time your run this it can take
several minutes, maybe as long as an hour, depending on the capabilities of
your workstation.
```shell
cd $HOME/functions-framework-cpp
docker build -t gcf-cpp-runtime --target gcf-cpp-runtime -f build_scripts/Dockerfile .
docker build -t gcf-cpp-develop --target gcf-cpp-develop -f build_scripts/Dockerfile .
pack create-builder cpp-builder:bionic --config pack/builder.toml
pack trust-builder cpp-builder:bionic
```

1. Build a Docker image from your function using this buildpack:
```shell
pack build \
--builder cpp-builder:bionic \
--env FUNCTION_SIGNATURE_TYPE=http \
--env TARGET_FUNCTION=HelloWorld \
--path google/cloud/functions/quickstart/hello_function \
gcf-cpp-quickstart
```

1. Start a Docker container in the background with this image:
```shell
ID=$(docker run --detach --rm -p 8080:8080 gcf-cpp-quickstart)
```

1. Send requests to this function using `curl`:
```shell
curl http://localhost:8080
# Output: Hello, World!
```

1. Stop the background container:
```shell
docker kill "${ID}"
```