Update build environments
This commit is contained in:
parent
c4d7850228
commit
4f05fde794
24 changed files with 164 additions and 400 deletions
14
Makefile
14
Makefile
|
@ -2,8 +2,6 @@ export GO111MODULE=on
|
|||
GOIMPORTS=goimports
|
||||
BINARY_NAME=photoprism
|
||||
DOCKER_TAG=`date -u +%Y%m%d`
|
||||
TIDB_VERSION=2.1.11
|
||||
TF_VERSION=1.14.0
|
||||
|
||||
HASRICHGO := $(shell which richgo)
|
||||
ifdef HASRICHGO
|
||||
|
@ -75,6 +73,12 @@ build-go:
|
|||
build-static:
|
||||
rm -f $(BINARY_NAME)
|
||||
scripts/build.sh static $(BINARY_NAME)
|
||||
build-tensorflow:
|
||||
docker build -t photoprism/tensorflow:build docker/tensorflow
|
||||
docker run -ti photoprism/tensorflow:build bash
|
||||
build-tensorflow-arm64:
|
||||
docker build -t photoprism/tensorflow:arm64 docker/tensorflow/arm64
|
||||
docker run -ti photoprism/tensorflow:arm64 bash
|
||||
watch-js:
|
||||
(cd frontend && env NODE_ENV=development npm run watch)
|
||||
test-js:
|
||||
|
@ -125,12 +129,6 @@ docker-photoprism-arm64:
|
|||
docker-demo:
|
||||
scripts/docker-build.sh demo $(DOCKER_TAG)
|
||||
scripts/docker-push.sh demo $(DOCKER_TAG)
|
||||
docker-tensorflow:
|
||||
scripts/docker-build.sh tensorflow $(TF_VERSION)
|
||||
scripts/docker-push.sh tensorflow $(TF_VERSION)
|
||||
docker-tidb:
|
||||
scripts/docker-build.sh tidb $(TIDB_VERSION)
|
||||
scripts/docker-push.sh tidb $(TIDB_VERSION)
|
||||
docker-webdav:
|
||||
scripts/docker-build.sh webdav $(DOCKER_TAG)
|
||||
scripts/docker-push.sh webdav $(DOCKER_TAG)
|
||||
|
|
|
@ -94,7 +94,7 @@ RUN wget "https://dl.photoprism.org/tensorflow/nasnet.zip?${BUILD_TAG}" -O /tmp/
|
|||
|
||||
# Set up project directory
|
||||
WORKDIR "/go/src/github.com/photoprism/photoprism"
|
||||
COPY . .
|
||||
COPY ../../photoprism-arm64 .
|
||||
|
||||
# Build PhotoPrism
|
||||
RUN make dep build-js install
|
4
docker/tensorflow/.gitignore
vendored
Normal file
4
docker/tensorflow/.gitignore
vendored
Normal file
|
@ -0,0 +1,4 @@
|
|||
tensorflow-*
|
||||
v1*
|
||||
v2*
|
||||
!.gitignore
|
|
@ -5,6 +5,10 @@ TF_VERSION=1.15.2
|
|||
all: libtensorflow libtensorflow-avx libtensorflow-avx2
|
||||
patch:
|
||||
git apply tensorflow-$(TF_VERSION).diff
|
||||
download:
|
||||
wget https://github.com/tensorflow/tensorflow/archive/v$(TF_VERSION).tar.gz
|
||||
tar -xzf v$(TF_VERSION).tar.gz
|
||||
cp .tf_configure.bazelrc Makefile *.sh tensorflow-$(TF_VERSION)
|
||||
libtensorflow:
|
||||
bazel build --jobs 2 --config=opt //tensorflow:libtensorflow.so
|
||||
./create_archive.sh linux-cpu $(TF_VERSION)
|
||||
|
@ -14,7 +18,3 @@ libtensorflow-avx:
|
|||
libtensorflow-avx2:
|
||||
bazel build --jobs 2 --config=opt //tensorflow:libtensorflow.so --copt=-march=core-avx2 --host_copt=-march=core-avx2
|
||||
./create_archive.sh linux-avx2 $(TF_VERSION)
|
||||
static-avx:
|
||||
env JOB_COUNT=2 ARCH=core-avx-i ./build_static.sh
|
||||
static-avx2:
|
||||
env JOB_COUNT=2 ARCH=core-avx2 ./build_static.sh
|
||||
|
|
|
@ -1,21 +0,0 @@
|
|||
TF_VERSION=1.15.2
|
||||
|
||||
all: libtensorflow static archive
|
||||
patch:
|
||||
git apply tensorflow-$(TF_VERSION).diff
|
||||
libtensorflow:
|
||||
bazel build --jobs 2 --config=opt //tensorflow:libtensorflow.so
|
||||
static:
|
||||
env JOB_COUNT=2 ARCH=armv8-a ./build_static.sh
|
||||
archive:
|
||||
rm -rf tmp
|
||||
mkdir -p tmp/lib/
|
||||
mkdir -p tmp/include/tensorflow/c/eager/
|
||||
cp bazel-bin/tensorflow/libtensorflow.so.$(TF_VERSION) tmp/lib/libtensorflow.so
|
||||
cp bazel-bin/tensorflow/libtensorflow_framework.so.$(TF_VERSION) tmp/lib/libtensorflow_framework.so
|
||||
cp tensorflow/c/eager/c_api.h tmp/include/tensorflow/c/eager/
|
||||
cp tensorflow/c/c_api.h tensorflow/c/c_api_experimental.h LICENSE tmp/include/tensorflow/c/
|
||||
#(cd tmp && tar -czf ../libtensorflow-nvidia-jetson-nano-$(TF_VERSION).tar.gz .)
|
||||
#du -h libtensorflow-nvidia-jetson-nano-$(TF_VERSION).tar.gz
|
||||
guy@golem4:/tmp/photoprism/docker/tensorflow$
|
||||
|
4
docker/tensorflow/arm64/.gitignore
vendored
Normal file
4
docker/tensorflow/arm64/.gitignore
vendored
Normal file
|
@ -0,0 +1,4 @@
|
|||
tensorflow-*
|
||||
v1*
|
||||
v2*
|
||||
!.gitignore
|
27
docker/tensorflow/arm64/.tf_configure.bazelrc
Normal file
27
docker/tensorflow/arm64/.tf_configure.bazelrc
Normal file
|
@ -0,0 +1,27 @@
|
|||
build --action_env PYTHON_BIN_PATH="/usr/bin/python3"
|
||||
build --action_env PYTHON_LIB_PATH="/usr/lib/python3/dist-packages"
|
||||
build --python_path="/usr/bin/python3"
|
||||
build --action_env TF_NEED_OPENCL_SYCL="0"
|
||||
build --action_env TF_NEED_ROCM="0"
|
||||
build --action_env TF_NEED_CUDA="0"
|
||||
build --action_env TF_NEED_TENSORRT="0"
|
||||
build --action_env CUDA_TOOLKIT_PATH="/usr/local/cuda"
|
||||
build --action_env TF_CUDA_COMPUTE_CAPABILITIES="5.3"
|
||||
build --action_env TF_CUDA_CLANG="0"
|
||||
build --action_env TF_CUDA_VERSION="10"
|
||||
build --action_env GCC_HOST_COMPILER_PATH="/usr/bin/gcc-4.8"
|
||||
build --verbose_failures
|
||||
build:opt --copt=-Wno-sign-compare
|
||||
build:opt --conlyopt=-std=c11
|
||||
build:opt --cxxopt="-D_GLIBCXX_USE_CXX11_ABI=0"
|
||||
build:opt --host_conlyopt=-std=c11
|
||||
build:opt --host_cxxopt="-D_GLIBCXX_USE_CXX11_ABI=0"
|
||||
build:opt --host_copt=-Wno-sign-compare
|
||||
build:opt --define with_default_optimizations=true
|
||||
build:v2 --define=tf_api_version=2
|
||||
build:xla --define with_xla_support=true
|
||||
test --flaky_test_attempts=3
|
||||
test --test_size_filters=small,medium
|
||||
test --test_tag_filters=-benchmark-test,-no_oss,-oss_serial
|
||||
test --build_tag_filters=-benchmark-test,-no_oss
|
||||
build --action_env TF_CONFIGURE_IOS="0"
|
|
@ -58,8 +58,8 @@ RUN mv bazel-0.24.1-aarch64 /usr/local/bin/bazel && chmod 755 /usr/local/bin/baz
|
|||
|
||||
# Configure TensorFlow
|
||||
WORKDIR "/home/tensorflow/tensorflow-1.15.2"
|
||||
COPY ./*.sh ./
|
||||
COPY ../*.sh ./
|
||||
COPY ./*.diff ./
|
||||
COPY ./tf_configure.bazelrc .tf_configure.bazelrc
|
||||
COPY ./Makefile.aarch64 Makefile
|
||||
COPY ./Makefile Makefile
|
||||
|
10
docker/tensorflow/arm64/Makefile
Normal file
10
docker/tensorflow/arm64/Makefile
Normal file
|
@ -0,0 +1,10 @@
|
|||
TF_VERSION=1.15.2
|
||||
|
||||
# -march see https://gcc.gnu.org/onlinedocs/gcc-4.8.5/gcc/i386-and-x86-64-Options.html
|
||||
|
||||
all: libtensorflow
|
||||
patch:
|
||||
git apply tensorflow-$(TF_VERSION).diff
|
||||
libtensorflow:
|
||||
bazel build --jobs 2 --config=opt //tensorflow:libtensorflow.so --copt=-march=armv8-a --host_copt=-march=armv8-a
|
||||
./create_archive.sh arm64 $(TF_VERSION)
|
|
@ -1,3 +0,0 @@
|
|||
#!/bin/bash
|
||||
time bazel build --jobs 2 --config=opt //tensorflow:libtensorflow.so
|
||||
|
|
@ -1,53 +0,0 @@
|
|||
#!/usr/bin/env bash
|
||||
# Copyright 2016 The TensorFlow Authors. All Rights Reserved.
|
||||
#
|
||||
# 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.
|
||||
# ==============================================================================
|
||||
# Downloads and builds all of TensorFlow's dependencies for Linux, and compiles
|
||||
# the TensorFlow library itself. Supported on Ubuntu 14.04 and 16.04.
|
||||
|
||||
set -e
|
||||
|
||||
SCRIPT_DIR="tensorflow/contrib/makefile"
|
||||
|
||||
source "${SCRIPT_DIR}/build_helper.subr"
|
||||
|
||||
# Note: Limit the number of jobs to 1 on ARM64 to prevent the build from being killed
|
||||
JOB_COUNT="${JOB_COUNT:-$(get_job_count)}"
|
||||
|
||||
# Set CPU architecture e.g. core-avx-i, haswell or armv8-a
|
||||
# See https://gcc.gnu.org/onlinedocs/gcc/x86-Options.html
|
||||
# and https://gcc.gnu.org/onlinedocs/gcc/AArch64-Options.html
|
||||
ARCH=${ARCH:-core-avx-i}
|
||||
|
||||
# Remove any old files first.
|
||||
make -f tensorflow/contrib/makefile/Makefile clean
|
||||
rm -rf tensorflow/contrib/makefile/downloads
|
||||
|
||||
# Pull down the required versions of the frameworks we need.
|
||||
tensorflow/contrib/makefile/download_dependencies.sh
|
||||
|
||||
# Compile nsync.
|
||||
# Don't use export var=`something` syntax; it swallows the exit status.
|
||||
HOST_NSYNC_LIB=`tensorflow/contrib/makefile/compile_nsync.sh`
|
||||
TARGET_NSYNC_LIB="$HOST_NSYNC_LIB"
|
||||
export HOST_NSYNC_LIB TARGET_NSYNC_LIB
|
||||
|
||||
# Compile protobuf.
|
||||
tensorflow/contrib/makefile/compile_linux_protobuf.sh
|
||||
|
||||
# Build TensorFlow for ARCH.
|
||||
make -j"${JOB_COUNT}" -f tensorflow/contrib/makefile/Makefile \
|
||||
OPTFLAGS="-O3 -march=${ARCH}" \
|
||||
HOST_CXXFLAGS="--std=c++11 -march=${ARCH}" \
|
||||
MAKEFILE_DIR="${SCRIPT_DIR}"
|
|
@ -1,14 +0,0 @@
|
|||
version: '3.6'
|
||||
|
||||
services:
|
||||
build:
|
||||
build:
|
||||
context: .
|
||||
dockerfile: Dockerfile.aarch64
|
||||
container_name: tensorflow-build
|
||||
tty: true
|
||||
restart: always
|
||||
volumes:
|
||||
- ./out:/output
|
||||
|
||||
|
4
docker/tensorflow/jetson-nano/.gitignore
vendored
Normal file
4
docker/tensorflow/jetson-nano/.gitignore
vendored
Normal file
|
@ -0,0 +1,4 @@
|
|||
tensorflow-*
|
||||
v1*
|
||||
v2*
|
||||
!.gitignore
|
36
docker/tensorflow/jetson-nano/.tf_configure.bazelrc
Normal file
36
docker/tensorflow/jetson-nano/.tf_configure.bazelrc
Normal file
|
@ -0,0 +1,36 @@
|
|||
build --action_env PYTHON_BIN_PATH="/usr/bin/python"
|
||||
build --action_env PYTHON_LIB_PATH="/usr/lib/python2.7/dist-packages"
|
||||
build --python_path="/usr/bin/python"
|
||||
build --action_env TF_NEED_OPENCL_SYCL="0"
|
||||
build --action_env TF_NEED_ROCM="0"
|
||||
build --action_env TF_NEED_CUDA="1"
|
||||
build --action_env TF_NEED_TENSORRT="1"
|
||||
build --action_env CUDA_TOOLKIT_PATH="/usr/local/cuda"
|
||||
build --action_env TF_CUDA_COMPUTE_CAPABILITIES="5.3"
|
||||
build --action_env TF_CUDA_CLANG="0"
|
||||
build --action_env TF_CUDA_VERSION="10"
|
||||
build --action_env GCC_HOST_COMPILER_PATH="/usr/bin/gcc"
|
||||
build --config=cuda
|
||||
build --config=nonccl
|
||||
build --verbose_failures
|
||||
build --jobs 2
|
||||
build:opt --copt=-march=armv8-a
|
||||
build:opt --copt=-Wno-sign-compare
|
||||
build:opt --conlyopt=-std=c11
|
||||
build:opt --conlyopt=-D_XOPEN_SOURCE=600
|
||||
build:opt --cxxopt="-D_GLIBCXX_USE_CXX11_ABI=0"
|
||||
build:opt --host_copt=-march=armv8-a
|
||||
build:opt --host_conlyopt=-std=c11
|
||||
build:opt --host_conlyopt=-D_XOPEN_SOURCE=600
|
||||
build:opt --host_cxxopt="-D_GLIBCXX_USE_CXX11_ABI=0"
|
||||
build:opt --host_copt=-Wno-sign-compare
|
||||
build:opt --define with_default_optimizations=true
|
||||
build:v2 --define=tf_api_version=2
|
||||
build:xla --define with_xla_support=true
|
||||
test --flaky_test_attempts=3
|
||||
test --test_size_filters=small,medium
|
||||
test --test_tag_filters=-benchmark-test,-no_oss,-oss_serial
|
||||
test --build_tag_filters=-benchmark-test,-no_oss
|
||||
test --test_tag_filters=-gpu
|
||||
test --build_tag_filters=-gpu
|
||||
build --action_env TF_CONFIGURE_IOS="0"
|
14
docker/tensorflow/jetson-nano/Makefile
Normal file
14
docker/tensorflow/jetson-nano/Makefile
Normal file
|
@ -0,0 +1,14 @@
|
|||
TF_VERSION=1.15.2
|
||||
|
||||
# -march see https://gcc.gnu.org/onlinedocs/gcc-4.8.5/gcc/i386-and-x86-64-Options.html
|
||||
|
||||
all: libtensorflow
|
||||
patch:
|
||||
git apply tensorflow-$(TF_VERSION).diff
|
||||
download:
|
||||
wget https://github.com/tensorflow/tensorflow/archive/v$(TF_VERSION).tar.gz
|
||||
tar -xzf v$(TF_VERSION).tar.gz
|
||||
cp .tf_configure.bazelrc Makefile ../*.sh tensorflow-$(TF_VERSION)
|
||||
libtensorflow:
|
||||
bazel build --jobs 2 --config=opt //tensorflow:libtensorflow.so
|
||||
./create_archive.sh jetson-nano $(TF_VERSION)
|
4
docker/tensorflow/osx/.gitignore
vendored
Normal file
4
docker/tensorflow/osx/.gitignore
vendored
Normal file
|
@ -0,0 +1,4 @@
|
|||
tensorflow-*
|
||||
v1*
|
||||
v2*
|
||||
!.gitignore
|
27
docker/tensorflow/osx/.tf_configure.bazelrc
Normal file
27
docker/tensorflow/osx/.tf_configure.bazelrc
Normal file
|
@ -0,0 +1,27 @@
|
|||
build --action_env PYTHON_BIN_PATH="/usr/local/bin/python3"
|
||||
build --action_env PYTHON_LIB_PATH="/usr/local/lib/python3.7/site-packages"
|
||||
build --python_path="/usr/local/bin/python3"
|
||||
build --action_env TF_NEED_OPENCL_SYCL="0"
|
||||
build --action_env TF_NEED_ROCM="0"
|
||||
build --action_env TF_NEED_CUDA="0"
|
||||
build --action_env TF_NEED_TENSORRT="0"
|
||||
build --action_env CUDA_TOOLKIT_PATH="/usr/local/cuda"
|
||||
build --action_env TF_CUDA_COMPUTE_CAPABILITIES="5.3"
|
||||
build --action_env TF_CUDA_CLANG="0"
|
||||
build --action_env TF_CUDA_VERSION="10"
|
||||
build --action_env GCC_HOST_COMPILER_PATH="/usr/bin/gcc"
|
||||
build --verbose_failures
|
||||
build:opt --copt=-Wno-sign-compare
|
||||
build:opt --conlyopt=-std=c11
|
||||
build:opt --cxxopt="-D_GLIBCXX_USE_CXX11_ABI=0"
|
||||
build:opt --host_conlyopt=-std=c11
|
||||
build:opt --host_cxxopt="-D_GLIBCXX_USE_CXX11_ABI=0"
|
||||
build:opt --host_copt=-Wno-sign-compare
|
||||
build:opt --define with_default_optimizations=true
|
||||
build:v2 --define=tf_api_version=2
|
||||
build:xla --define with_xla_support=true
|
||||
test --flaky_test_attempts=3
|
||||
test --test_size_filters=small,medium
|
||||
test --test_tag_filters=-benchmark-test,-no_oss,-oss_serial
|
||||
test --build_tag_filters=-benchmark-test,-no_oss
|
||||
build --action_env TF_CONFIGURE_IOS="0"
|
20
docker/tensorflow/osx/Makefile
Normal file
20
docker/tensorflow/osx/Makefile
Normal file
|
@ -0,0 +1,20 @@
|
|||
TF_VERSION=1.15.2
|
||||
|
||||
# -march see https://gcc.gnu.org/onlinedocs/gcc-4.8.5/gcc/i386-and-x86-64-Options.html
|
||||
|
||||
all: libtensorflow libtensorflow-avx libtensorflow-avx2
|
||||
patch:
|
||||
git apply tensorflow-$(TF_VERSION).diff
|
||||
download:
|
||||
wget https://github.com/tensorflow/tensorflow/archive/v$(TF_VERSION).tar.gz
|
||||
tar -xzf v$(TF_VERSION).tar.gz
|
||||
cp .tf_configure.bazelrc Makefile ../*.sh tensorflow-$(TF_VERSION)
|
||||
libtensorflow:
|
||||
bazel build --jobs 2 --config=opt //tensorflow:libtensorflow.so
|
||||
./create_archive.sh osx-cpu $(TF_VERSION)
|
||||
libtensorflow-avx:
|
||||
bazel build --jobs 2 --config=opt //tensorflow:libtensorflow.so --copt=-march=core-avx-i --host_copt=-march=core-avx-i
|
||||
./create_archive.sh osx-avx $(TF_VERSION)
|
||||
libtensorflow-avx2:
|
||||
bazel build --jobs 2 --config=opt //tensorflow:libtensorflow.so --copt=-march=core-avx2 --host_copt=-march=core-avx2
|
||||
./create_archive.sh osx-avx2 $(TF_VERSION)
|
|
@ -1,36 +0,0 @@
|
|||
diff --git a/third_party/gif.BUILD b/third_party/gif.BUILD
|
||||
index cbe730fe10..9b6881891d 100644
|
||||
--- a/third_party/gif.BUILD
|
||||
+++ b/third_party/gif.BUILD
|
||||
@@ -20,14 +20,11 @@ cc_library(
|
||||
"lib/quantize.c",
|
||||
],
|
||||
hdrs = ["lib/gif_lib.h"],
|
||||
- defines = select({
|
||||
- ":android": [
|
||||
- "S_IREAD=S_IRUSR",
|
||||
- "S_IWRITE=S_IWUSR",
|
||||
- "S_IEXEC=S_IXUSR",
|
||||
- ],
|
||||
- "//conditions:default": [],
|
||||
- }),
|
||||
+ defines = [
|
||||
+ "S_IREAD=S_IRUSR",
|
||||
+ "S_IWRITE=S_IWUSR",
|
||||
+ "S_IEXEC=S_IXUSR"
|
||||
+ ],
|
||||
includes = ["lib/."],
|
||||
visibility = ["//visibility:public"],
|
||||
deps = select({
|
||||
diff --git a/third_party/gpus/crosstool/BUILD.tpl b/third_party/gpus/crosstool/BUILD.tpl
|
||||
index f94be6de83..f16f87a2df 100644
|
||||
--- a/third_party/gpus/crosstool/BUILD.tpl
|
||||
+++ b/third_party/gpus/crosstool/BUILD.tpl
|
||||
@@ -28,6 +28,7 @@ cc_toolchain_suite(
|
||||
"darwin|compiler": ":cc-compiler-darwin",
|
||||
"x64_windows|msvc-cl": ":cc-compiler-windows",
|
||||
"x64_windows": ":cc-compiler-windows",
|
||||
+ "aarch64": ":cc-compiler-local",
|
||||
"arm": ":cc-compiler-local",
|
||||
"k8": ":cc-compiler-local",
|
||||
"piii": ":cc-compiler-local",
|
|
@ -1,40 +0,0 @@
|
|||
# Builder image
|
||||
FROM golang:1.12.4-alpine as builder
|
||||
|
||||
ENV TIDB_VERSION 2.1.8
|
||||
|
||||
RUN apk add --no-cache \
|
||||
wget \
|
||||
make \
|
||||
git \
|
||||
g++ \
|
||||
gcc
|
||||
|
||||
RUN git clone https://github.com/pingcap/tidb.git /go/src/github.com/pingcap/tidb
|
||||
|
||||
WORKDIR /go/src/github.com/pingcap/tidb/
|
||||
|
||||
RUN git checkout tags/v$TIDB_VERSION && rm go.sum && GO111MODULE=on go mod tidy && make
|
||||
|
||||
# Executable image
|
||||
FROM alpine:3.9
|
||||
|
||||
COPY --from=builder /go/src/github.com/pingcap/tidb/bin/tidb-server /usr/local/bin/tidb-server
|
||||
|
||||
RUN apk add --no-cache \
|
||||
mysql-client \
|
||||
gnupg \
|
||||
openssl \
|
||||
pwgen \
|
||||
bash \
|
||||
tzdata
|
||||
|
||||
COPY /docker/tidb/entrypoint.sh /usr/local/bin/entrypoint.sh
|
||||
|
||||
WORKDIR /
|
||||
|
||||
EXPOSE 4000
|
||||
|
||||
ENTRYPOINT ["/usr/local/bin/entrypoint.sh"]
|
||||
|
||||
CMD ["/usr/local/bin/tidb-server"]
|
|
@ -1,217 +0,0 @@
|
|||
#!/bin/bash
|
||||
set -eo pipefail
|
||||
shopt -s nullglob
|
||||
|
||||
# if command starts with an option, prepend tidb-server
|
||||
if [ "${1:0:1}" = '-' ]; then
|
||||
set -- tidb-server "$@"
|
||||
fi
|
||||
|
||||
# skip setup if they want an option that stops tidb-server
|
||||
wantHelp=
|
||||
for arg; do
|
||||
case "$arg" in
|
||||
-'?'|--help|--print-defaults|-V|--version)
|
||||
wantHelp=1
|
||||
break
|
||||
;;
|
||||
esac
|
||||
done
|
||||
|
||||
# usage: file_env VAR [DEFAULT]
|
||||
# ie: file_env 'XYZ_DB_PASSWORD' 'example'
|
||||
# (will allow for "$XYZ_DB_PASSWORD_FILE" to fill in the value of
|
||||
# "$XYZ_DB_PASSWORD" from a file, especially for Docker's secrets feature)
|
||||
file_env() {
|
||||
local var="$1"
|
||||
local fileVar="${var}_FILE"
|
||||
local def="${2:-}"
|
||||
if [ "${!var:-}" ] && [ "${!fileVar:-}" ]; then
|
||||
echo >&2 "error: both $var and $fileVar are set (but are exclusive)"
|
||||
exit 1
|
||||
fi
|
||||
local val="$def"
|
||||
if [ "${!var:-}" ]; then
|
||||
val="${!var}"
|
||||
elif [ "${!fileVar:-}" ]; then
|
||||
val="$(< "${!fileVar}")"
|
||||
fi
|
||||
export "$var"="$val"
|
||||
unset "$fileVar"
|
||||
}
|
||||
|
||||
# usage: process_init_file FILENAME MYSQLCOMMAND...
|
||||
# ie: process_init_file foo.sh mysql -uroot
|
||||
# (process a single initializer file, based on its extension. we define this
|
||||
# function here, so that initializer scripts (*.sh) can use the same logic,
|
||||
# potentially recursively, or override the logic used in subsequent calls)
|
||||
process_init_file() {
|
||||
local f="$1"; shift
|
||||
local mysql=( "$@" )
|
||||
|
||||
case "$f" in
|
||||
*.sh) echo "$0: running $f"; . "$f" ;;
|
||||
*.sql) echo "$0: running $f"; "${mysql[@]}" < "$f"; echo ;;
|
||||
*.sql.gz) echo "$0: running $f"; gunzip -c "$f" | "${mysql[@]}"; echo ;;
|
||||
*) echo "$0: ignoring $f" ;;
|
||||
esac
|
||||
echo
|
||||
}
|
||||
|
||||
_check_config() {
|
||||
toRun=( "$@" --verbose --help )
|
||||
if ! errors="$("${toRun[@]}" 2>&1 >/dev/null)"; then
|
||||
cat >&2 <<-EOM
|
||||
|
||||
ERROR: tidb-server failed while attempting to check config
|
||||
command was: "${toRun[*]}"
|
||||
|
||||
$errors
|
||||
EOM
|
||||
exit 1
|
||||
fi
|
||||
}
|
||||
|
||||
# Fetch value from server config
|
||||
# We use tidb-server --verbose --help instead of my_print_defaults because the
|
||||
# latter only show values present in config files, and not server defaults
|
||||
_get_config() {
|
||||
local conf="$1"; shift
|
||||
"$@" --verbose --help --log-bin-index="$(mktemp -u)" 2>/dev/null \
|
||||
| awk '$1 == "'"$conf"'" && /^[^ \t]/ { sub(/^[^ \t]+[ \t]+/, ""); print; exit }'
|
||||
# match "datadir /some/path with/spaces in/it here" but not "--xyz=abc\n datadir (xyz)"
|
||||
}
|
||||
|
||||
# allow the container to be started with `--user`
|
||||
if [ "$1" = 'tidb-server' -a -z "$wantHelp" -a "$(id -u)" = '0' ]; then
|
||||
_check_config "$@"
|
||||
DATADIR="$(_get_config 'datadir' "$@")"
|
||||
mkdir -p "$DATADIR"
|
||||
chown -R mysql:mysql "$DATADIR"
|
||||
exec mysql "$BASH_SOURCE" "$@"
|
||||
fi
|
||||
|
||||
if [ "$1" = 'tidb-server' -a -z "$wantHelp" ]; then
|
||||
# still need to check config, container may have started with --user
|
||||
_check_config "$@"
|
||||
# Get config
|
||||
DATADIR="$(_get_config 'datadir' "$@")"
|
||||
|
||||
if [ ! -d "$DATADIR/mysql" ]; then
|
||||
file_env 'TIDB_ROOT_PASSWORD'
|
||||
if [ -z "$TIDB_ROOT_PASSWORD" -a -z "$TIDB_ALLOW_EMPTY_PASSWORD" -a -z "$TIDB_RANDOM_ROOT_PASSWORD" ]; then
|
||||
echo >&2 'error: database is uninitialized and password option is not specified '
|
||||
echo >&2 ' You need to specify one of TIDB_ROOT_PASSWORD, TIDB_ALLOW_EMPTY_PASSWORD and TIDB_RANDOM_ROOT_PASSWORD'
|
||||
exit 1
|
||||
fi
|
||||
|
||||
mkdir -p "$DATADIR"
|
||||
|
||||
echo 'Initializing database'
|
||||
"$@" --initialize-insecure
|
||||
echo 'Database initialized'
|
||||
|
||||
if command -v mysql_ssl_rsa_setup > /dev/null && [ ! -e "$DATADIR/server-key.pem" ]; then
|
||||
# https://github.com/mysql/mysql-server/blob/23032807537d8dd8ee4ec1c4d40f0633cd4e12f9/packaging/deb-in/extra/mysql-systemd-start#L81-L84
|
||||
echo 'Initializing certificates'
|
||||
mysql_ssl_rsa_setup --datadir="$DATADIR"
|
||||
echo 'Certificates initialized'
|
||||
fi
|
||||
|
||||
SOCKET="$(_get_config 'socket' "$@")"
|
||||
"$@" --socket="${SOCKET}" &
|
||||
pid="$!"
|
||||
|
||||
mysql=( mysql --protocol=socket -uroot -hlocalhost --socket="${SOCKET}" )
|
||||
|
||||
for i in {30..0}; do
|
||||
if echo 'SELECT 1' | "${mysql[@]}" &> /dev/null; then
|
||||
break
|
||||
fi
|
||||
echo 'MySQL init process in progress...'
|
||||
sleep 1
|
||||
done
|
||||
if [ "$i" = 0 ]; then
|
||||
echo >&2 'MySQL init process failed.'
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if [ -z "$TIDB_INITDB_SKIP_TZINFO" ]; then
|
||||
# sed is for https://bugs.mysql.com/bug.php?id=20545
|
||||
mysql_tzinfo_to_sql /usr/share/zoneinfo | sed 's/Local time zone must be set--see zic manual page/FCTY/' | "${mysql[@]}" mysql
|
||||
fi
|
||||
|
||||
if [ ! -z "$TIDB_RANDOM_ROOT_PASSWORD" ]; then
|
||||
export TIDB_ROOT_PASSWORD="$(pwgen -1 32)"
|
||||
echo "GENERATED ROOT PASSWORD: $TIDB_ROOT_PASSWORD"
|
||||
fi
|
||||
|
||||
rootCreate=
|
||||
# default root to listen for connections from anywhere
|
||||
file_env 'TIDB_ROOT_HOST' '%'
|
||||
if [ ! -z "$TIDB_ROOT_HOST" -a "$TIDB_ROOT_HOST" != 'localhost' ]; then
|
||||
# no, we don't care if read finds a terminating character in this heredoc
|
||||
# https://unix.stackexchange.com/questions/265149/why-is-set-o-errexit-breaking-this-read-heredoc-expression/265151#265151
|
||||
read -r -d '' rootCreate <<-EOSQL || true
|
||||
CREATE USER 'root'@'${TIDB_ROOT_HOST}' IDENTIFIED BY '${TIDB_ROOT_PASSWORD}' ;
|
||||
GRANT ALL ON *.* TO 'root'@'${TIDB_ROOT_HOST}' WITH GRANT OPTION ;
|
||||
EOSQL
|
||||
fi
|
||||
|
||||
"${mysql[@]}" <<-EOSQL
|
||||
-- What's done in this file shouldn't be replicated
|
||||
-- or products like mysql-fabric won't work
|
||||
SET @@SESSION.SQL_LOG_BIN=0;
|
||||
|
||||
ALTER USER 'root'@'localhost' IDENTIFIED BY '${TIDB_ROOT_PASSWORD}' ;
|
||||
GRANT ALL ON *.* TO 'root'@'localhost' WITH GRANT OPTION ;
|
||||
${rootCreate}
|
||||
DROP DATABASE IF EXISTS test ;
|
||||
FLUSH PRIVILEGES ;
|
||||
EOSQL
|
||||
|
||||
if [ ! -z "$TIDB_ROOT_PASSWORD" ]; then
|
||||
mysql+=( -p"${TIDB_ROOT_PASSWORD}" )
|
||||
fi
|
||||
|
||||
file_env 'TIDB_DATABASE'
|
||||
if [ "$TIDB_DATABASE" ]; then
|
||||
echo "CREATE DATABASE IF NOT EXISTS \`$TIDB_DATABASE\` ;" | "${mysql[@]}"
|
||||
mysql+=( "$TIDB_DATABASE" )
|
||||
fi
|
||||
|
||||
file_env 'TIDB_USER'
|
||||
file_env 'TIDB_PASSWORD'
|
||||
if [ "$TIDB_USER" -a "$TIDB_PASSWORD" ]; then
|
||||
echo "CREATE USER '$TIDB_USER'@'%' IDENTIFIED BY '$TIDB_PASSWORD' ;" | "${mysql[@]}"
|
||||
|
||||
if [ "$TIDB_DATABASE" ]; then
|
||||
echo "GRANT ALL ON \`$TIDB_DATABASE\`.* TO '$TIDB_USER'@'%' ;" | "${mysql[@]}"
|
||||
fi
|
||||
|
||||
echo 'FLUSH PRIVILEGES ;' | "${mysql[@]}"
|
||||
fi
|
||||
|
||||
echo
|
||||
ls /docker-entrypoint-initdb.d/ > /dev/null
|
||||
for f in /docker-entrypoint-initdb.d/*; do
|
||||
process_init_file "$f" "${mysql[@]}"
|
||||
done
|
||||
|
||||
if [ ! -z "$TIDB_ONETIME_PASSWORD" ]; then
|
||||
"${mysql[@]}" <<-EOSQL
|
||||
ALTER USER 'root'@'%' PASSWORD EXPIRE;
|
||||
EOSQL
|
||||
fi
|
||||
if ! kill -s TERM "$pid" || ! wait "$pid"; then
|
||||
echo >&2 'MySQL init process failed.'
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo
|
||||
echo 'MySQL init process done. Ready for start up.'
|
||||
echo
|
||||
fi
|
||||
fi
|
||||
|
||||
exec "$@"
|
|
@ -5,6 +5,6 @@ if [[ -z $1 ]] || [[ -z $2 ]]; then
|
|||
exit 1
|
||||
else
|
||||
echo "Building 'photoprism/$1:$2'...";
|
||||
docker build --no-cache --build-arg BUILD_TAG=$2 -t photoprism/$1:latest -t photoprism/$1:$2 -f docker/$1/Dockerfile .
|
||||
docker build --no-cache --build-arg BUILD_TAG=$2 -t photoprism/$1:latest -t photoprism/$1:$2 -f docker/${1/-//}/Dockerfile .
|
||||
echo "Done"
|
||||
fi
|
||||
|
|
Loading…
Reference in a new issue