-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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 an official dockerfile #887
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
6e076df
Adds a dockerfile for building an image to run FoundationDB.
brownleej ab60d94
Adds a sample docker-compose setup that uses the new docker image.
brownleej dac41b8
Adds support for basic locality information in the docker image.
brownleej 60908f7
Combine multiple run commands into one command in the dockerfile.
brownleej bbf7a44
Ensures that we set the cluster file contents in a consistent way in …
brownleej 82354e7
Moves the create_server_environment logic in the dockerfile into a so…
brownleej 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 |
---|---|---|
@@ -0,0 +1,71 @@ | ||
# Dockerfile | ||
# | ||
# This source file is part of the FoundationDB open source project | ||
# | ||
# Copyright 2013-2018 Apple Inc. and the FoundationDB project authors | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
# | ||
|
||
FROM ubuntu:18.04 | ||
|
||
# Install dependencies | ||
|
||
RUN apt-get update && \ | ||
apt-get install -y wget=1.19.4-1ubuntu2 \ | ||
dnsutils=1:9.11.3+dfsg-1ubuntu1.3 && \ | ||
rm -r /var/lib/apt/lists/* | ||
|
||
# Install FoundationDB Binaries | ||
|
||
ARG FDB_VERSION | ||
ARG FDB_WEBSITE=https://www.foundationdb.org | ||
|
||
WORKDIR /var/fdb/tmp | ||
RUN wget $FDB_WEBSITE/downloads/$FDB_VERSION/linux/fdb_$FDB_VERSION.tar.gz && \ | ||
tar -xzf fdb_$FDB_VERSION.tar.gz --strip-components=1 && \ | ||
rm fdb_$FDB_VERSION.tar.gz && \ | ||
chmod u+x fdb* && \ | ||
mv fdb* /usr/bin && \ | ||
rm -r /var/fdb/tmp | ||
|
||
WORKDIR /var/fdb | ||
|
||
# Install FoundationDB Client Libraries | ||
|
||
ARG FDB_ADDITIONAL_VERSIONS="5.1.7" | ||
|
||
COPY download_multiversion_libraries.bash scripts/ | ||
|
||
RUN wget $FDB_WEBSITE/downloads/$FDB_VERSION/linux/libfdb_c_$FDB_VERSION.so -O /usr/lib/libfdb_c.so && \ | ||
bash scripts/download_multiversion_libraries.bash $FDB_WEBSITE $FDB_ADDITIONAL_VERSIONS | ||
|
||
# Set Up Runtime Scripts and Directoris | ||
|
||
COPY fdb.bash scripts/ | ||
COPY create_server_environment.bash scripts/ | ||
COPY create_cluster_file.bash scripts/ | ||
RUN chmod u+x scripts/*.bash && \ | ||
mkdir -p logs | ||
VOLUME /var/fdb/data | ||
|
||
CMD /var/fdb/scripts/fdb.bash | ||
|
||
# Runtime Configuration Options | ||
|
||
ENV FDB_PORT 4500 | ||
ENV FDB_CLUSTER_FILE /var/fdb/fdb.cluster | ||
ENV FDB_NETWORKING_MODE container | ||
ENV FDB_COORDINATOR "" | ||
ENV FDB_CLUSTER_FILE_CONTENTS "" | ||
ENV FDB_PROCESS_CLASS unset |
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 |
---|---|---|
@@ -0,0 +1,71 @@ | ||
# Overview | ||
|
||
This directory provides a Docker image for running FoundationDB. | ||
|
||
The image in this directory is based on Ubuntu 18.04, but the commands and | ||
scripts used to build it should be suitable for most other distros with small | ||
tweaks to the installation of dependencies. | ||
|
||
The image relies on the following dependencies: | ||
|
||
* bash | ||
* wget | ||
* dig | ||
* glibc | ||
|
||
# Build Configuration | ||
|
||
This image supports several build arguments for build-time configuration. | ||
|
||
### FDB_VERSION | ||
|
||
The version of FoundationDB to install in the container. This is required. | ||
|
||
### FDB_WEBSITE | ||
|
||
The base URL for the FoundationDB website. The default is | ||
`https://www.foundationdb.org`. | ||
|
||
### FDB_ADDITIONAL_VERSIONS | ||
|
||
A list of additional client library versions to include in this image. These | ||
libraries will be in a special multiversion library folder. | ||
|
||
# Runtime Configuration | ||
|
||
This image supports several environment variables for run-time configuration. | ||
|
||
### FDB_PORT | ||
|
||
The port that FoundationDB should bind to. The default is 4500. | ||
|
||
### FDB_NETWORKING_MODE | ||
|
||
A networking mode that controls what address FoundationDB listens on. If this | ||
is `container` (the default), then the server will listen on its public IP | ||
within the docker network, and will only be accessible from other containers. | ||
|
||
If this is `host`, then the server will listen on `127.0.0.1`, and will not be | ||
accessible from other containers. You should use `host` networking mode if you | ||
want to access your container from your host machine, and you should also | ||
map the port to the same port on your host machine when you run the container. | ||
|
||
### FDB_COORDINATOR | ||
|
||
A name of another FDB instance to use as a coordinator process. This can be | ||
helpful when setting up a larger cluster inside a docker network, for instance | ||
when using Docker Compose. The name you provide must be resolvable through the | ||
DNS on the container you are running. | ||
|
||
# Copying Into Other Images | ||
|
||
You can also use this image to provide files for images that are clients of a | ||
FoundationDB cluster, by using the `from` argument of the `COPY` command. Some | ||
files you may want to copy are: | ||
alexmiller-apple marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
* `/usr/lib/libfdb_c.so`: The primary FoundationDB client library | ||
* `/usr/lib/fdb/multiversion/libfdb_*.so`: Additional versions of the client | ||
library, which you can use if you are setting up a multiversion client. | ||
* `/var/fdb/scripts/create_cluster_file.bash`: A script for setting up the | ||
cluster file based on an `FDB_COORDINATOR` environment variable. | ||
* `/usr/bin/fdbcli`: The FoundationDB CLI. |
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 |
---|---|---|
@@ -0,0 +1,51 @@ | ||
#! /bin/bash | ||
|
||
# | ||
# create_cluster_file.bash | ||
# | ||
# This source file is part of the FoundationDB open source project | ||
# | ||
# Copyright 2013-2018 Apple Inc. and the FoundationDB project authors | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
# | ||
|
||
# This script creates a cluster file for a server or client. | ||
# This takes the cluster file path from the FDB_CLUSTER_FILE | ||
# environment variable, with a default of /etc/foundationdb/fdb.cluster | ||
# | ||
# The name of the coordinator must be defined in the FDB_COORDINATOR environment | ||
# variable, and it must be a name that can be resolved through DNS. | ||
alexmiller-apple marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
function create_cluster_file() { | ||
FDB_CLUSTER_FILE=${FDB_CLUSTER_FILE:-/etc/foundationdb/fdb.cluster} | ||
mkdir -p $(dirname $FDB_CLUSTER_FILE) | ||
|
||
if [[ -n "$FDB_CLUSTER_FILE_CONTENTS" ]]; then | ||
echo "$FDB_CLUSTER_FILE_CONTENTS" > $FDB_CLUSTER_FILE | ||
elif [[ -n $FDB_COORDINATOR ]]; then | ||
coordinator_ip=$(dig +short $FDB_COORDINATOR) | ||
if [[ -z "$coordinator_ip" ]]; then | ||
echo "Failed to look up coordinator address for $FDB_COORDINATOR" 1>&2 | ||
exit 1 | ||
fi | ||
echo "docker:docker@$coordinator_ip:4500" > $FDB_CLUSTER_FILE | ||
else | ||
echo "FDB_COORDINATOR environment variable not defined" 1>&2 | ||
exit 1 | ||
fi | ||
} | ||
|
||
if [[ "${BASH_SOURCE[0]}" == "${0}" ]]; then | ||
create_cluster_file "$@" | ||
fi |
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 |
---|---|---|
@@ -0,0 +1,46 @@ | ||
#! /bin/bash | ||
|
||
# | ||
# create_server_environment.bash | ||
# | ||
# This source file is part of the FoundationDB open source project | ||
# | ||
# Copyright 2013-2018 Apple Inc. and the FoundationDB project authors | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
# | ||
|
||
source /var/fdb/scripts/create_cluster_file.bash | ||
|
||
function create_server_environment() { | ||
fdb_dir=/var/fdb | ||
env_file=$fdb_dir/.fdbenv | ||
|
||
: > $env_file | ||
|
||
if [[ "$FDB_NETWORKING_MODE" == "host" ]]; then | ||
public_ip=127.0.0.1 | ||
elif [[ "$FDB_NETWORKING_MODE" == "container" ]]; then | ||
public_ip=$(grep `hostname` /etc/hosts | sed -e "s/\s *`hostname`.*//") | ||
else | ||
echo "Unknown FDB Networking mode \"$FDB_NETWORKING_MODE\"" 1>&2 | ||
exit 1 | ||
fi | ||
|
||
echo "export PUBLIC_IP=$public_ip" >> $env_file | ||
if [[ -z $FDB_COORDINATOR ]]; then | ||
FDB_CLUSTER_FILE_CONTENTS="docker:docker@$public_ip:$FDB_PORT" | ||
fi | ||
|
||
create_cluster_file | ||
} |
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 |
---|---|---|
@@ -0,0 +1,31 @@ | ||
#! /bin/bash | ||
|
||
# | ||
# download_multiversion_libraries.bash | ||
# | ||
# This source file is part of the FoundationDB open source project | ||
# | ||
# Copyright 2013-2018 Apple Inc. and the FoundationDB project authors | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
# | ||
|
||
mkdir -p /usr/lib/fdb/multiversion | ||
website=$1 | ||
shift | ||
for version in $*; do | ||
origin=$website/downloads/$version/linux/libfdb_c_$version.so | ||
destination=/usr/lib/fdb/multiversion/libfdb_c_$version.so | ||
echo "Downloading $origin to $destination" | ||
wget $origin -o $destination | ||
done |
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 |
---|---|---|
@@ -0,0 +1,29 @@ | ||
#! /bin/bash | ||
|
||
# | ||
# fdb.bash | ||
# | ||
# This source file is part of the FoundationDB open source project | ||
# | ||
# Copyright 2013-2018 Apple Inc. and the FoundationDB project authors | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
# | ||
|
||
source /var/fdb/scripts/create_server_environment.bash | ||
create_server_environment | ||
source /var/fdb/.fdbenv | ||
echo "Starting FDB server on $PUBLIC_IP:4500" | ||
fdbserver --listen_address 0.0.0.0:$FDB_PORT --public_address $PUBLIC_IP:4500 \ | ||
--datadir /var/fdb/data --logdir /var/fdb/logs \ | ||
--locality_zoneid=`hostname` --locality_machineid=`hostname` --class $FDB_PROCESS_CLASS |
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 |
---|---|---|
@@ -0,0 +1,20 @@ | ||
# .env | ||
# | ||
# This source file is part of the FoundationDB open source project | ||
# | ||
# Copyright 2013-2018 Apple Inc. and the FoundationDB project authors | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
# | ||
|
||
COMPOSE_PROJECT_NAME=fdbpythonsample |
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 |
---|---|---|
@@ -0,0 +1,41 @@ | ||
# Dockerfile | ||
# | ||
# This source file is part of the FoundationDB open source project | ||
# | ||
# Copyright 2013-2018 Apple Inc. and the FoundationDB project authors | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
# | ||
|
||
FROM python:3.6 | ||
|
||
RUN apt-get update; apt-get install -y dnsutils | ||
|
||
RUN mkdir -p /app | ||
WORKDIR /app | ||
|
||
COPY --from=foundationdb:5.2.5 /usr/lib/libfdb_c.so /usr/lib | ||
COPY --from=foundationdb:5.2.5 /usr/bin/fdbcli /usr/bin/ | ||
COPY --from=foundationdb:5.2.5 /var/fdb/scripts/create_cluster_file.bash /app | ||
|
||
COPY requirements.txt /app | ||
RUN pip install -r requirements.txt | ||
|
||
COPY start.bash /app | ||
COPY server.py /app | ||
RUN chmod u+x /app/start.bash | ||
|
||
CMD /app/start.bash | ||
|
||
ENV FLASK_APP=server.py | ||
ENV FLASK_ENV=development |
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 |
---|---|---|
@@ -0,0 +1,21 @@ | ||
# requirements.txt | ||
# | ||
# This source file is part of the FoundationDB open source project | ||
# | ||
# Copyright 2013-2018 Apple Inc. and the FoundationDB project authors | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
# | ||
|
||
Flask==1.0.2 | ||
foundationdb==5.1.5 |
Oops, something went wrong.
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.
You may want to consider adding a SHA256 checksum check here. Adding another argument after line 31 like:
and then running the check in the RUN block on line 35.
Then running:
Just a "maybe nice to have".