|
| 1 | +#!/bin/bash |
| 2 | + |
| 3 | +# |
| 4 | +# fdb-build.sh |
| 5 | +# |
| 6 | +# This source file is part of the FoundationDB open source project |
| 7 | +# |
| 8 | +# Copyright 2015-2022 Apple Inc. and the FoundationDB project authors |
| 9 | +# |
| 10 | +# Licensed under the Apache License, Version 2.0 (the "License"); |
| 11 | +# you may not use this file except in compliance with the License. |
| 12 | +# You may obtain a copy of the License at |
| 13 | +# |
| 14 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 15 | +# |
| 16 | +# Unless required by applicable law or agreed to in writing, software |
| 17 | +# distributed under the License is distributed on an "AS IS" BASIS, |
| 18 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 19 | +# See the License for the specific language governing permissions and |
| 20 | +# limitations under the License. |
| 21 | +# |
| 22 | + |
| 23 | +# |
| 24 | +# This script builds a local version of FDB to be used by record layer when in need of a pre-release build, or any other |
| 25 | +# build that is not available through the artifact repository |
| 26 | +# |
| 27 | +# Environment variables: |
| 28 | +# FDB_VERSION (Optional, defaults to 7.1.25): The FDB version that the code is on |
| 29 | +# OKTETO_USERNAME (Optional, defaults to <username>-dev): The okteto development environment name (this would determine your custom image names) |
| 30 | +# JAVA_HOME (Required): Java SDK home |
| 31 | +# MVN_HOME (Optional, defaults to /opt/brew/Cellar/maven\@3.5/3.5.4_1/bin): location where maven is instaled |
| 32 | +# FOUNDATIONDB_HOME (Required): Top level directory of the FDB that the script is building |
| 33 | +# RECORD_LAYER_HOME (Optional, defaults to ..): The top level directory of record layer |
| 34 | +# FDB_BUILD_HOME (Required): Local build artifact location |
| 35 | +# CMAKE_PREFIX_PATH (Required for Intel Macs): CMAKE search path for libraries. Set to /opt/brew for Intel |
| 36 | +# |
| 37 | +# This script assumes that the FDB images are available through AWS ECR. The script constructs an expected image name |
| 38 | +# and tries to use it. See fdb's build-images.sh for info on how to build and upload FDB images |
| 39 | +# |
| 40 | + |
| 41 | +set -e |
| 42 | + |
| 43 | +# Set environment variables |
| 44 | +ROOTDIR=$(cd $(dirname $0)/.. && pwd) |
| 45 | +FDB_VERSION="${FDB_VERSION:-7.1.25}" |
| 46 | +OKTETO_USERNAME="${OKTETO_USERNAME:-`whoami`-dev}" |
| 47 | +RECORD_LAYER_HOME="${RECORD_LAYER_HOME:-$ROOTDIR}" |
| 48 | +MVN_HOME="${MVN_HOME:-/opt/brew/Cellar/maven@3.5/3.5.4_1/bin}" |
| 49 | + |
| 50 | +if [ -z "$JAVA_HOME" ] |
| 51 | +then |
| 52 | + echo "JAVA_HOME environment variable not set" |
| 53 | + exit 1 |
| 54 | +fi |
| 55 | +if [ -z "$FOUNDATIONDB_HOME" ] |
| 56 | +then |
| 57 | + echo "FOUNDATIONDB_HOME environment variable not set" |
| 58 | + exit 1 |
| 59 | +fi |
| 60 | +if [ -z "$FDB_BUILD_HOME" ] |
| 61 | +then |
| 62 | + echo "FDB_BUILD_HOME environment variable not set" |
| 63 | + exit 1 |
| 64 | +fi |
| 65 | + |
| 66 | +echo "Environment setup:" |
| 67 | +echo "------------------" |
| 68 | +echo "FDB_VERSION=$FDB_VERSION" |
| 69 | +echo "OKTETO_USERNAME=$OKTETO_USERNAME" |
| 70 | +echo "MVN_HOME=$MVN_HOME" |
| 71 | +echo "JAVA_HOME=$JAVA_HOME" |
| 72 | +echo "FOUNDATIONDB_HOME=$FOUNDATIONDB_HOME" |
| 73 | +echo "RECORD_LAYER_HOME=$RECORD_LAYER_HOME" |
| 74 | +echo "FDB_BUILD_HOME=$FDB_BUILD_HOME" |
| 75 | +sleep 1 |
| 76 | + |
| 77 | +if [ "$1" == "clean" ] |
| 78 | +then |
| 79 | + echo |
| 80 | + echo "CAUTION" |
| 81 | + echo "Removing everything under $FDB_BUILD_HOME" |
| 82 | + rm -rIf $FDB_BUILD_HOME/* |
| 83 | +fi |
| 84 | + |
| 85 | +echo "-----------------------------------------------------" |
| 86 | +echo "Building local FDB from source. This may take a while" |
| 87 | +cd ${FDB_BUILD_HOME} |
| 88 | +cmake -D OPENSSL_ROOT_DIR=/opt/brew/opt/openssl -G Ninja ${FOUNDATIONDB_HOME} |
| 89 | +ninja |
| 90 | + |
| 91 | +echo "-----------------------------------------------------" |
| 92 | +echo "Copying library artifacts" |
| 93 | +cp ${FDB_BUILD_HOME}/packages/bin/fdbcli ${RECORD_LAYER_HOME}/run/fdbcli_${FDB_VERSION}-${OKTETO_USERNAME} |
| 94 | +cp ${FDB_BUILD_HOME}/packages/lib/libfdb_c.dylib ${RECORD_LAYER_HOME}/run/libfdb_c_${FDB_VERSION}-${OKTETO_USERNAME}.dylib |
| 95 | + |
| 96 | +echo "-----------------------------------------------------" |
| 97 | +echo "Deploying java bindings to local maven repo" |
| 98 | +$MVN_HOME/mvn install:install-file \ |
| 99 | + -Dfile=${FDB_BUILD_HOME}/packages/fdb-java-${FDB_VERSION}-SNAPSHOT.jar \ |
| 100 | + -DgroupId=org.foundationdb \ |
| 101 | + -DartifactId=fdb-java \ |
| 102 | + -Dversion=${FDB_VERSION}-SNAPSHOT \ |
| 103 | + -Dpackaging=jar \ |
| 104 | + -DgeneratePom=true |
| 105 | + |
| 106 | +echo "-----------------------------------------------------" |
| 107 | +echo "Downloading images from AWS" |
| 108 | +aws_account_id=$(aws --output text sts get-caller-identity --query 'Account') |
| 109 | +aws_region=us-west-2 |
| 110 | +registry="${aws_account_id}.dkr.ecr.${aws_region}.amazonaws.com" |
| 111 | +aws ecr get-login-password | docker login --username AWS --password-stdin ${registry} |
| 112 | +docker pull ${registry}/foundationdb/foundationdb:${FDB_VERSION}-${OKTETO_USERNAME} |
| 113 | +docker tag ${registry}/foundationdb/foundationdb:${FDB_VERSION}-${OKTETO_USERNAME} foundationdb/foundationdb:${FDB_VERSION}-${OKTETO_USERNAME} |
| 114 | + |
| 115 | +echo "-----------------------------------------------------" |
| 116 | +echo "Done building. Start docker image by issuing the command: " FDB_VERSION=${FDB_VERSION}-${OKTETO_USERNAME} ./start.sh |
0 commit comments