diff --git a/hosting/docker-compose.yml b/hosting/docker-compose.yml new file mode 100644 index 0000000000..1b1f608f91 --- /dev/null +++ b/hosting/docker-compose.yml @@ -0,0 +1,67 @@ +version: "3" + +services: + app-service: + build: ./server + volumes: + - ./server:/app + ports: + - "4001:4001" + environment: + MINIO_ACCESS_KEY: ${MINIO_ACCESS_KEY} + MINIO_SECRET_KEY: ${MINIO_SECRET_KEY} + SELF_HOSTED: ${SELF_HOSTED} + COUCH_DB_URL: http://${COUCH_DB_USER}:${COUCH_DB_PASSWORD}@couchdb-service:5984 + BUDIBASE_ENVIRONMENT: ${BUDIBASE_ENVIRONMENT} + depends_on: + - nginx-service + - minio-service + - couch-init + + minio-service: + image: minio/minio:RELEASE.2020-12-10T01-54-29Z + volumes: + - data1:/data + expose: + - "9000" + environment: + MINIO_ACCESS_KEY: ${MINIO_ACCESS_KEY} + MINIO_SECRET_KEY: ${MINIO_SECRET_KEY} + command: server /data + healthcheck: + test: ["CMD", "curl", "-f", "http://localhost:9000/minio/health/live"] + interval: 30s + timeout: 20s + retries: 3 + + nginx-service: + image: nginx:1.19.2-alpine + volumes: + - ./nginx.conf:/etc/nginx/nginx.conf:ro + ports: + - "9000:9000" + depends_on: + - minio-service + + couchdb-service: + image: apache/couchdb:3.0 + environment: + - COUCHDB_PASSWORD=${COUCH_DB_PASSWORD} + - COUCHDB_USER=${COUCH_DB_USER} + ports: + - "5984:5984" + - "4369:4369" + - "9100:9100" + volumes: + - couchdb_data:/couchdb + + couch-init: + image: curlimages/curl + depends_on: + - couchdb-service + command: ["sh","-c","sleep 10 && curl -u ${COUCH_DB_USER}:${COUCH_DB_PASSWORD} -X PUT couchdb-service:5984/_users && curl -u ${COUCH_DB_USER}:${COUCH_DB_PASSWORD} -X PUT couchdb-service:5984/_replicator; fg ; "] + +volumes: + couchdb_data: + driver: local + data1: diff --git a/hosting/hosting.properties b/hosting/hosting.properties index ce3ab326c9..cf818d0eb3 100644 --- a/hosting/hosting.properties +++ b/hosting/hosting.properties @@ -1,6 +1,6 @@ -minio_access_key=budibase -minio_secret_key=budibase -minio_port=9000 -# specify the following below settings if switching credentials -#minio_secret_key_old=minioadmin -#minio_access_key_old=minioadmin +SELF_HOSTED=1 +MINIO_ACCESS_KEY=budibase +MINIO_SECRET_KEY=budibase +COUCH_DB_PASSWORD=budibase +COUCH_DB_USER=budibase +BUDIBASE_ENVIRONMENT=PRODUCTION diff --git a/hosting/install-docker-compose.sh b/hosting/install-docker-compose.sh new file mode 100755 index 0000000000..6d466a7655 --- /dev/null +++ b/hosting/install-docker-compose.sh @@ -0,0 +1,4 @@ +#!/bin/bash +sudo curl -L "https://github.com/docker/compose/releases/download/1.27.4/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose +sudo chmod +x /usr/local/bin/docker-compose +sudo ln -s /usr/local/bin/docker-compose /usr/bin/docker-compose diff --git a/hosting/nginx.conf b/hosting/nginx.conf new file mode 100644 index 0000000000..9ca4f1d630 --- /dev/null +++ b/hosting/nginx.conf @@ -0,0 +1,65 @@ + +user nginx; +worker_processes auto; + +error_log /var/log/nginx/error.log warn; +pid /var/run/nginx.pid; + + +events { + worker_connections 1024; +} + + +http { + include /etc/nginx/mime.types; + default_type application/octet-stream; + + log_format main '$remote_addr - $remote_user [$time_local] "$request" ' + '$status $body_bytes_sent "$http_referer" ' + '"$http_user_agent" "$http_x_forwarded_for"'; + + access_log /var/log/nginx/access.log main; + + sendfile on; + #tcp_nopush on; + + keepalive_timeout 65; + + #gzip on; + + # include /etc/nginx/conf.d/*.conf; + + upstream minio { + server minio:9000; + } + + server { + listen 9000; + listen [::]:9000; + server_name localhost; + + # To allow special characters in headers + ignore_invalid_headers off; + # Allow any size file to be uploaded. + # Set to a value such as 1000m; to restrict file size to a specific value + client_max_body_size 0; + # To disable buffering + proxy_buffering off; + + location / { + proxy_set_header Host $http_host; + proxy_set_header X-Real-IP $remote_addr; + proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; + proxy_set_header X-Forwarded-Proto $scheme; + + proxy_connect_timeout 300; + # Default is HTTP/1, keepalive is only enabled in HTTP/1.1 + proxy_http_version 1.1; + proxy_set_header Connection ""; + chunked_transfer_encoding off; + + proxy_pass http://minio; + } + } +} diff --git a/hosting/server b/hosting/server new file mode 120000 index 0000000000..785f5d338c --- /dev/null +++ b/hosting/server @@ -0,0 +1 @@ +../packages/server/ \ No newline at end of file diff --git a/hosting/start.sh b/hosting/start.sh index 94f2fe8896..b32098a3b7 100755 --- a/hosting/start.sh +++ b/hosting/start.sh @@ -1,20 +1,2 @@ #!/bin/bash - -function dockerInstalled { - echo "Checking docker installation..." - if [ ! -x "$(command -v docker)" ]; then - echo "Please install docker to continue" - exit -1 - fi -} - -dockerInstalled - -source "${BASH_SOURCE%/*}/hosting.properties" - -opts="-e MINIO_ACCESS_KEY=$minio_access_key -e MINIO_SECRET_KEY=$minio_secret_key" -if [ -n "$minio_secret_key_old" ] && [ -n "$minio_access_key_old" ]; then - opts="$opts -e MINIO_SECRET_KEY_OLD=$minio_secret_key_old -e MINIO_ACCESS_KEY_OLD=$minio_access_key_old" -fi - -docker run -p $minio_port:$minio_port $opts -v /mnt/data:/data minio/minio server /data +docker-compose --env-file hosting.properties up diff --git a/hosting/utils/testing.sh b/hosting/utils/testing.sh new file mode 100755 index 0000000000..94f2fe8896 --- /dev/null +++ b/hosting/utils/testing.sh @@ -0,0 +1,20 @@ +#!/bin/bash + +function dockerInstalled { + echo "Checking docker installation..." + if [ ! -x "$(command -v docker)" ]; then + echo "Please install docker to continue" + exit -1 + fi +} + +dockerInstalled + +source "${BASH_SOURCE%/*}/hosting.properties" + +opts="-e MINIO_ACCESS_KEY=$minio_access_key -e MINIO_SECRET_KEY=$minio_secret_key" +if [ -n "$minio_secret_key_old" ] && [ -n "$minio_access_key_old" ]; then + opts="$opts -e MINIO_SECRET_KEY_OLD=$minio_secret_key_old -e MINIO_ACCESS_KEY_OLD=$minio_access_key_old" +fi + +docker run -p $minio_port:$minio_port $opts -v /mnt/data:/data minio/minio server /data diff --git a/packages/server/Dockerfile b/packages/server/Dockerfile index 96ae3b7a30..9a6b058a17 100644 --- a/packages/server/Dockerfile +++ b/packages/server/Dockerfile @@ -4,12 +4,16 @@ WORKDIR /app ENV CLOUD=1 ENV COUCH_DB_URL=https://couchdb.budi.live:5984 -env BUDIBASE_ENVIRONMENT=PRODUCTION +ENV BUDIBASE_ENVIRONMENT=PRODUCTION # copy files and install dependencies COPY . ./ -RUN yarn +RUN yarn EXPOSE 4001 +# have to add node environment production after install +# due to this causing yarn to stop installing dev dependencies +# which are actually needed to get this environment up and running +ENV NODE_ENV=production CMD ["yarn", "run:docker"]