diff --git a/hosting/bbcouch/Dockerfile b/hosting/couchdb/Dockerfile similarity index 64% rename from hosting/bbcouch/Dockerfile rename to hosting/couchdb/Dockerfile index 7f2f4815d5..11fab7129f 100644 --- a/hosting/bbcouch/Dockerfile +++ b/hosting/couchdb/Dockerfile @@ -4,9 +4,10 @@ ENV COUCHDB_USER admin ENV COUCHDB_PASSWORD admin EXPOSE 5984 -RUN apt-get update && apt-get install -y software-properties-common wget unzip curl && \ +RUN apt-get update && apt-get install -y --no-install-recommends software-properties-common wget unzip curl && \ apt-add-repository 'deb http://security.debian.org/debian-security stretch/updates main' && \ - apt-get update && apt-get install -y openjdk-8-jdk + apt-get update && apt-get install -y --no-install-recommends openjdk-8-jre && \ + rm -rf /var/lib/apt/lists/ # setup clouseau WORKDIR / @@ -19,13 +20,13 @@ WORKDIR /opt/clouseau RUN mkdir ./bin ADD clouseau/clouseau ./bin/ ADD clouseau/log4j.properties clouseau/clouseau.ini ./ -RUN chmod +x ./bin/clouseau # setup CouchDB WORKDIR /opt/couchdb ADD couch/vm.args couch/local.ini ./etc/ WORKDIR / +ADD build-target-paths.sh . ADD runner.sh ./bbcouch-runner.sh -RUN chmod +x ./bbcouch-runner.sh -ENTRYPOINT ["./bbcouch-runner.sh"] +RUN chmod +x ./bbcouch-runner.sh /opt/clouseau/bin/clouseau ./build-target-paths.sh +CMD ["./bbcouch-runner.sh"] diff --git a/hosting/couchdb/build-target-paths.sh b/hosting/couchdb/build-target-paths.sh new file mode 100644 index 0000000000..67e1765ca8 --- /dev/null +++ b/hosting/couchdb/build-target-paths.sh @@ -0,0 +1,24 @@ +#!/bin/bash + +echo ${TARGETBUILD} > /buildtarget.txt +if [[ "${TARGETBUILD}" = "aas" ]]; then + # Azure AppService uses /home for persisent data & SSH on port 2222 + DATA_DIR=/home + WEBSITES_ENABLE_APP_SERVICE_STORAGE=true + mkdir -p $DATA_DIR/{search,minio,couch} + mkdir -p $DATA_DIR/couch/{dbs,views} + chown -R couchdb:couchdb $DATA_DIR/couch/ + apt update + apt-get install -y openssh-server + echo "root:Docker!" | chpasswd + mkdir -p /tmp + chmod +x /tmp/ssh_setup.sh \ + && (sleep 1;/tmp/ssh_setup.sh 2>&1 > /dev/null) + cp /etc/sshd_config /etc/ssh/sshd_config + /etc/init.d/ssh restart + sed -i "s#DATA_DIR#/home#g" /opt/clouseau/clouseau.ini + sed -i "s#DATA_DIR#/home#g" /opt/couchdb/etc/local.ini +else + sed -i "s#DATA_DIR#/data#g" /opt/clouseau/clouseau.ini + sed -i "s#DATA_DIR#/data#g" /opt/couchdb/etc/local.ini +fi \ No newline at end of file diff --git a/hosting/bbcouch/clouseau/clouseau b/hosting/couchdb/clouseau/clouseau similarity index 100% rename from hosting/bbcouch/clouseau/clouseau rename to hosting/couchdb/clouseau/clouseau diff --git a/hosting/bbcouch/clouseau/clouseau.ini b/hosting/couchdb/clouseau/clouseau.ini similarity index 100% rename from hosting/bbcouch/clouseau/clouseau.ini rename to hosting/couchdb/clouseau/clouseau.ini diff --git a/hosting/bbcouch/clouseau/log4j.properties b/hosting/couchdb/clouseau/log4j.properties similarity index 100% rename from hosting/bbcouch/clouseau/log4j.properties rename to hosting/couchdb/clouseau/log4j.properties diff --git a/hosting/bbcouch/couch/local.ini b/hosting/couchdb/couch/local.ini similarity index 100% rename from hosting/bbcouch/couch/local.ini rename to hosting/couchdb/couch/local.ini diff --git a/hosting/bbcouch/couch/vm.args b/hosting/couchdb/couch/vm.args similarity index 100% rename from hosting/bbcouch/couch/vm.args rename to hosting/couchdb/couch/vm.args diff --git a/hosting/bbcouch/runner.sh b/hosting/couchdb/runner.sh similarity index 53% rename from hosting/bbcouch/runner.sh rename to hosting/couchdb/runner.sh index 01b4aee3dc..ad366ccb3d 100644 --- a/hosting/bbcouch/runner.sh +++ b/hosting/couchdb/runner.sh @@ -1,5 +1,11 @@ #!/bin/bash +DATA_DIR=${DATA_DIR:-/data} +mkdir -p ${DATA_DIR} +mkdir -p ${DATA_DIR}/couch/{dbs,views} +mkdir -p ${DATA_DIR}/search +chown -R couchdb:couchdb ${DATA_DIR}/couch +/build-target-paths.sh /docker-entrypoint.sh /opt/couchdb/bin/couchdb & sleep 10 curl -X PUT http://${COUCHDB_USER}:${COUCHDB_PASSWORD}@localhost:5984/_users diff --git a/hosting/single/Dockerfile b/hosting/single/Dockerfile index 58796f0362..eef5dab077 100644 --- a/hosting/single/Dockerfile +++ b/hosting/single/Dockerfile @@ -18,7 +18,7 @@ WORKDIR /worker ADD packages/worker . RUN node /pinVersions.js && yarn && yarn build && /cleanup.sh -FROM couchdb:3.2.1 +FROM budibase-couchdb ARG TARGETARCH ENV TARGETARCH $TARGETARCH #TARGETBUILD can be set to single (for single docker image) or aas (for azure app service) @@ -29,23 +29,9 @@ ENV TARGETBUILD $TARGETBUILD COPY --from=build /app /app COPY --from=build /worker /worker -# ENV CUSTOM_DOMAIN=budi001.custom.com \ -# See runner.sh for Env Vars -# These secret env variables are generated by the runner at startup -# their values can be overriden by the user, they will be written -# to the .env file in the /data directory for use later on -# REDIS_PASSWORD=budibase \ -# COUCHDB_PASSWORD=budibase \ -# COUCHDB_USER=budibase \ -# COUCH_DB_URL=http://budibase:budibase@localhost:5984 \ -# INTERNAL_API_KEY=budibase \ -# JWT_SECRET=testsecret \ -# MINIO_ACCESS_KEY=budibase \ -# MINIO_SECRET_KEY=budibase \ - # install base dependencies RUN apt-get update && \ - apt-get install -y software-properties-common wget nginx uuid-runtime && \ + apt-get install -y --no-install-recommends software-properties-common nginx uuid-runtime redis-server && \ apt-add-repository 'deb http://security.debian.org/debian-security stretch/updates main' && \ apt-get update @@ -53,7 +39,7 @@ RUN apt-get update && \ WORKDIR /nodejs RUN curl -sL https://deb.nodesource.com/setup_16.x -o /tmp/nodesource_setup.sh && \ bash /tmp/nodesource_setup.sh && \ - apt-get install -y libaio1 nodejs nginx openjdk-8-jdk redis-server unzip && \ + apt-get install -y --no-install-recommends libaio1 nodejs && \ npm install --global yarn pm2 # setup nginx @@ -68,23 +54,6 @@ RUN mkdir -p scripts/integrations/oracle ADD packages/server/scripts/integrations/oracle scripts/integrations/oracle RUN /bin/bash -e ./scripts/integrations/oracle/instantclient/linux/install.sh -# setup clouseau -WORKDIR / -RUN wget https://github.com/cloudant-labs/clouseau/releases/download/2.21.0/clouseau-2.21.0-dist.zip && \ - unzip clouseau-2.21.0-dist.zip && \ - mv clouseau-2.21.0 /opt/clouseau && \ - rm clouseau-2.21.0-dist.zip - -WORKDIR /opt/clouseau -RUN mkdir ./bin -ADD hosting/single/clouseau/clouseau ./bin/ -ADD hosting/single/clouseau/log4j.properties hosting/single/clouseau/clouseau.ini ./ -RUN chmod +x ./bin/clouseau - -# setup CouchDB -WORKDIR /opt/couchdb -ADD hosting/single/couch/vm.args hosting/single/couch/local.ini ./etc/ - # setup minio WORKDIR /minio ADD scripts/install-minio.sh ./install.sh @@ -97,9 +66,6 @@ RUN chmod +x ./runner.sh ADD hosting/single/healthcheck.sh . RUN chmod +x ./healthcheck.sh -ADD hosting/scripts/build-target-paths.sh . -RUN chmod +x ./build-target-paths.sh - # Script below sets the path for storing data based on $DATA_DIR # For Azure App Service install SSH & point data locations to /home ADD hosting/single/ssh/sshd_config /etc/ diff --git a/hosting/single/clouseau/clouseau b/hosting/single/clouseau/clouseau deleted file mode 100644 index 1095ea24cb..0000000000 --- a/hosting/single/clouseau/clouseau +++ /dev/null @@ -1,12 +0,0 @@ -#!/bin/sh -/usr/bin/java -server \ - -Xmx2G \ - -Dsun.net.inetaddr.ttl=30 \ - -Dsun.net.inetaddr.negative.ttl=30 \ - -Dlog4j.configuration=file:/opt/clouseau/log4j.properties \ - -XX:OnOutOfMemoryError="kill -9 %p" \ - -XX:+UseConcMarkSweepGC \ - -XX:+CMSParallelRemarkEnabled \ - -classpath '/opt/clouseau/*' \ - com.cloudant.clouseau.Main \ - /opt/clouseau/clouseau.ini \ No newline at end of file diff --git a/hosting/single/clouseau/clouseau.ini b/hosting/single/clouseau/clouseau.ini deleted file mode 100644 index 578a5acafa..0000000000 --- a/hosting/single/clouseau/clouseau.ini +++ /dev/null @@ -1,13 +0,0 @@ -[clouseau] - -; the name of the Erlang node created by the service, leave this unchanged -name=clouseau@127.0.0.1 - -; set this to the same distributed Erlang cookie used by the CouchDB nodes -cookie=monster - -; the path where you would like to store the search index files -dir=DATA_DIR/search - -; the number of search indexes that can be open simultaneously -max_indexes_open=500 diff --git a/hosting/single/clouseau/log4j.properties b/hosting/single/clouseau/log4j.properties deleted file mode 100644 index 9d4d9311bc..0000000000 --- a/hosting/single/clouseau/log4j.properties +++ /dev/null @@ -1,4 +0,0 @@ -log4j.rootLogger=debug, CONSOLE -log4j.appender.CONSOLE=org.apache.log4j.ConsoleAppender -log4j.appender.CONSOLE.layout=org.apache.log4j.PatternLayout -log4j.appender.CONSOLE.layout.ConversionPattern=%d{ISO8601} %c [%p] %m%n \ No newline at end of file diff --git a/hosting/single/couch/local.ini b/hosting/single/couch/local.ini deleted file mode 100644 index 266c0d4b60..0000000000 --- a/hosting/single/couch/local.ini +++ /dev/null @@ -1,5 +0,0 @@ -; CouchDB Configuration Settings - -[couchdb] -database_dir = DATA_DIR/couch/dbs -view_index_dir = DATA_DIR/couch/views diff --git a/hosting/single/couch/vm.args b/hosting/single/couch/vm.args deleted file mode 100644 index e9e4416863..0000000000 --- a/hosting/single/couch/vm.args +++ /dev/null @@ -1,32 +0,0 @@ -# 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. - -# erlang cookie for clouseau security --name couchdb@127.0.0.1 --setcookie monster - -# Ensure that the Erlang VM listens on a known port --kernel inet_dist_listen_min 9100 --kernel inet_dist_listen_max 9100 - -# Tell kernel and SASL not to log anything --kernel error_logger silent --sasl sasl_error_logger false - -# Use kernel poll functionality if supported by emulator -+K true - -# Start a pool of asynchronous IO threads -+A 16 - -# Comment this line out to enable the interactive Erlang shell on startup -+Bd -noinput diff --git a/hosting/single/runner.sh b/hosting/single/runner.sh index ea825131db..e4793d5492 100644 --- a/hosting/single/runner.sh +++ b/hosting/single/runner.sh @@ -72,14 +72,11 @@ for LINE in $(cat ${DATA_DIR}/.env); do export $LINE; done ln -s ${DATA_DIR}/.env /app/.env ln -s ${DATA_DIR}/.env /worker/.env # make these directories in runner, incase of mount -mkdir -p ${DATA_DIR}/couch/{dbs,views} mkdir -p ${DATA_DIR}/minio -mkdir -p ${DATA_DIR}/search chown -R couchdb:couchdb ${DATA_DIR}/couch redis-server --requirepass $REDIS_PASSWORD > /dev/stdout 2>&1 & -/opt/clouseau/bin/clouseau > /dev/stdout 2>&1 & +/bbcouch-runner.sh & /minio/minio server ${DATA_DIR}/minio > /dev/stdout 2>&1 & -/docker-entrypoint.sh /opt/couchdb/bin/couchdb & /etc/init.d/nginx restart if [[ ! -z "${CUSTOM_DOMAIN}" ]]; then # Add monthly cron job to renew certbot certificate @@ -90,15 +87,14 @@ if [[ ! -z "${CUSTOM_DOMAIN}" ]]; then /etc/init.d/nginx restart fi +# wait for backend services to start +sleep 10 + pushd app pm2 start -l /dev/stdout --name app "yarn run:docker" popd pushd worker pm2 start -l /dev/stdout --name worker "yarn run:docker" popd -sleep 10 -echo "curl to couchdb endpoints" -curl -X PUT ${COUCH_DB_URL}/_users -curl -X PUT ${COUCH_DB_URL}/_replicator echo "end of runner.sh, sleeping ..." sleep infinity diff --git a/package.json b/package.json index 6c147698ad..ff9185ae93 100644 --- a/package.json +++ b/package.json @@ -69,6 +69,7 @@ "build:docker:single:multiarch": "docker buildx build --platform linux/arm64,linux/amd64 -f hosting/single/Dockerfile -t budibase:latest .", "build:docker:single:image": "docker build -f hosting/single/Dockerfile -t budibase:latest .", "build:docker:single": "npm run build:docker:pre && npm run build:docker:single:image", + "build:docker:couch": "docker build -f hosting/couchdb/Dockerfile -t budibase-couchdb:latest ./hosting/couchdb", "build:docs": "lerna run build:docs", "release:helm": "node scripts/releaseHelmChart", "env:multi:enable": "lerna run env:multi:enable",