Skip to content
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 6 commits into from
Dec 3, 2018
Merged
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
71 changes: 71 additions & 0 deletions packaging/docker/Dockerfile
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 && \
Copy link
Contributor

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:

ARG FDB_VERSION_SHA256SUM 

and then running the check in the RUN block on line 35.

RUN wget $FDB_WEBSITE/downloads/$FDB_VERSION/linux/fdb_$FDB_VERSION.tar.gz && \
    echo "${FDB_VERSION_SHA256SUM} fdb_${FDB_VERSION}.tar.gz" > checksum && sha256sum -c checksum && \
    tar -xzf fdb_$FDB_VERSION.tar.gz --strip-components=1 && \

Then running:

docker build . -t fdb:latest --build-arg FDB_VERSION=5.2.5 --build-arg FDB_VERSION_SHA256SUM=275b9f541590d145136061cee6427103b347e1ff0e851b6556671e46102c1ad9

Just a "maybe nice to have".

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
71 changes: 71 additions & 0 deletions packaging/docker/README.md
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:

* `/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.
51 changes: 51 additions & 0 deletions packaging/docker/create_cluster_file.bash
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.

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
46 changes: 46 additions & 0 deletions packaging/docker/create_server_environment.bash
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
}
31 changes: 31 additions & 0 deletions packaging/docker/download_multiversion_libraries.bash
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
29 changes: 29 additions & 0 deletions packaging/docker/fdb.bash
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
20 changes: 20 additions & 0 deletions packaging/docker/samples/python/.env
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
41 changes: 41 additions & 0 deletions packaging/docker/samples/python/app/Dockerfile
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
21 changes: 21 additions & 0 deletions packaging/docker/samples/python/app/requirements.txt
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
Loading