From 6a1c10d3f703379c9ef69d07ea0e83e6b5440a74 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Karol=20S=C3=B3jko?= Date: Tue, 1 Sep 2020 16:16:40 +0200 Subject: [PATCH] fix: local docker-compose setup (#460) --- .dockerignore | 2 ++ .env.sample | 6 +++--- README.md | 49 ++++++++++++++++++++++++++++---------------- docker-compose.yml | 14 ++++++++++++- docker/entrypoint.sh | 15 ++++++++++++++ 5 files changed, 64 insertions(+), 22 deletions(-) diff --git a/.dockerignore b/.dockerignore index ea08119bd..3e3c9de48 100644 --- a/.dockerignore +++ b/.dockerignore @@ -1,3 +1,5 @@ # git .git/ .gitignore +node_modules +public/assets diff --git a/.env.sample b/.env.sample index bb5bdaf90..2c3e2f4ed 100644 --- a/.env.sample +++ b/.env.sample @@ -1,14 +1,14 @@ RAILS_ENV=development -PORT=3000 +PORT=3001 WEB_CONCURRENCY=0 RAILS_LOG_TO_STDOUT=true RAILS_SERVE_STATIC_FILES=true SECRET_KEY_BASE=test -APP_HOST=http://localhost:3000 +APP_HOST=http://localhost:3001 EXTENSIONS_MANAGER_LOCATION=extensions/extensions-manager/dist/index.html BATCH_MANAGER_LOCATION=extensions/batch-manager/dist/index.min.html -SF_DEFAULT_SERVER=http://localhost:3001 +SF_DEFAULT_SERVER=http://localhost:3000 # Datadog DATADOG_ENABLED=false diff --git a/README.md b/README.md index 6de3922de..3d403a04e 100644 --- a/README.md +++ b/README.md @@ -62,11 +62,25 @@ Questions? Find answers on our [Help page](https://standardnotes.org/help). --- -### Running with Docker image +### Docker setup -You can run the application by using our [official Docker image](https://hub.docker.com/r/standardnotes/web) +Docker is the quick and easy way to try out Standard Notes. We highly recommend using our official [Docker hub image](https://hub.docker.com/repository/docker/standardnotes/web). -Make sure you are using the appropriate tag for your use case. `develop` branch is tagged with `latest` and `master` branch is tagged with `stable`. +### Standalone instance + +Before you start make sure you have a `.env` file copied from the sample `env.sample` and configured with your parameters. + +If your intention is not contributing but just running the app we recommend using our official image from Docker hub like this: +``` +docker run -d -p 3001:3001 --env-file=your-env-file standardnotes/web:stable +``` + +Or if you want to use the `develop` branch that is in a work-in-progress state please use: +``` +docker run -d -p 3001:3001 --env-file=your-env-file standardnotes/web:latest +``` + +You can then access the app at `http://localhost:3001` (please check Docker container logs if the server has started already and is listening on connections). ### Running Locally @@ -83,21 +97,6 @@ This repo contains the core code used in the web app, as well as the Electron-ba Then open your browser to `http://localhost:3001`. -### Running Locally with Docker - -To run the app locally with Docker, first create a configuration file: - -``` -cp .env.sample .env -``` - -Adjust the configuration file if needed. Then start the application by typing: - -``` -docker-compose build -docker-compose up -``` - --- **Extensions Manager and Batch Manager:** @@ -124,3 +123,17 @@ SF_DEFAULT_SERVER=https://sync.myserver - Desktop app: https://github.com/standardnotes/desktop - Mobile (iOS & Android): https://github.com/standardnotes/mobile - Extensions: https://github.com/sn-extensions + +## Contributing + +For contributing we highly recommend you use our docker-compose setup that is provided in this repository. + +### Docker compose setup + +Use the included [docker-compose.yml](docker-compose.yml) file to build Standard Notes with `docker-compose`. Once your `.env` file has been copied and configured, simply run: + +``` +docker-compose up -d +``` + +This should load the app container and run the necessary scripts. You should then be able to reach the app at `http://localhost:3001` diff --git a/docker-compose.yml b/docker-compose.yml index ac5a3a4b3..a23046cbb 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,11 +1,23 @@ -version: '3' +version: '3.8' services: app: build: context: . + command: start-local env_file: .env restart: unless-stopped ports: - ${PORT}:3001 volumes: - .:/app + networks: + standardnotes_proxy: + aliases: + - web + web: {} + +networks: + web: + name: web + standardnotes_proxy: + name: standardnotes diff --git a/docker/entrypoint.sh b/docker/entrypoint.sh index 637b76ccb..8f809e47c 100755 --- a/docker/entrypoint.sh +++ b/docker/entrypoint.sh @@ -9,6 +9,21 @@ case "$1" in bundle exec rails s -b 0.0.0.0 ;; + 'start-local' ) + echo "Prestart Step 1/5 - Removing server lock" + rm -f /app/tmp/pids/server.pid + echo "Prestart Step 2/5 - Cleaning assets" + bundle exec rails assets:clobber + echo "Prestart Step 3/5 - Installing dependencies" + npm install + echo "Prestart Step 4/5 - Creating Webpack bundle" + npm run bundle + echo "Prestart Step 5/5 - Compiling assets" + bundle exec rails assets:precompile + echo "Starting Server..." + bundle exec rails s -b 0.0.0.0 + ;; + * ) echo "Unknown command" ;;