From b75138de9ec2dc2a721a116fdcb416e533561fb8 Mon Sep 17 00:00:00 2001 From: Leo Correa Date: Fri, 18 Aug 2023 23:25:08 -0400 Subject: [PATCH 1/4] Setup entire application using docker compose --- README.md | 24 ++++++++++- backend/Dockerfile | 23 +++++++++++ backend/config/database.yml | 2 +- backend/config/mongoid.yml | 2 +- docker-compose.yml | 82 ++++++++++++++++++++++++++++++++----- frontend/Dockerfile | 17 ++++++++ frontend/README.md | 3 +- 7 files changed, 136 insertions(+), 17 deletions(-) create mode 100644 backend/Dockerfile create mode 100644 frontend/Dockerfile diff --git a/README.md b/README.md index 149f12f70..be85c9698 100644 --- a/README.md +++ b/README.md @@ -15,8 +15,15 @@ Help would be appreciated! Please join us in [slack #flaredown](https://rubyforg * Redis 6.2.3 * Ruby 3.0.6 (see [RVM](https://rvm.io/) also) * Node 12.22.6 + ## Installation +All dependencies are dockerized, including the application and can be run using `docker compose` so there's no dependencies to install other than docker. + +If you want to run the application on your own machine see the next sections on dependency installations + +### Mac + _If you are running on an M1 mac, run the following command before you start the installation process:_ ```bash $env /usr/bin/arch -arm64 /bin/zsh ---login @@ -54,7 +61,22 @@ npm install ## Running / Development +### Docker + From the project root: + +```bash +docker compose --profile dev up +``` + +This will build and run all the containers necessary to run the application locally. + +Visit your app at [http://localhost:4300](http://localhost:4300) + +### Local Machine Installation + +From the project root: + ```bash docker compose up ``` @@ -63,8 +85,6 @@ docker compose up rake run ``` -Visit your app at [http://localhost:4300](http://localhost:4300) - ## CI Several checks are configured to run on all commits using Github Actions, including lint, build and test steps. Definitions can be found in [./github/workflows](./github/workflows). Those checks which always run are required to be successful for PRs to be mergable. diff --git a/backend/Dockerfile b/backend/Dockerfile new file mode 100644 index 000000000..b0aacb5c5 --- /dev/null +++ b/backend/Dockerfile @@ -0,0 +1,23 @@ +FROM ruby:3.0 + +# set working directory +WORKDIR /app + +# install dependencies +RUN apt-get update -qq && \ + apt-get install -y nodejs postgresql-client + +# install bundler +RUN gem install bundler:2.1.4 + +# copy the Gemfile and Gemfile.lock to the container +COPY Gemfile Gemfile.lock ./ + +# install the gems +RUN bundle install + +# copy the rest of the application files to the container +COPY . . + +# start the server +CMD ["bundle", "exec", "puma", "-C", "config/puma.rb"] diff --git a/backend/config/database.yml b/backend/config/database.yml index 14a1979ce..42fe57ac5 100644 --- a/backend/config/database.yml +++ b/backend/config/database.yml @@ -1,7 +1,7 @@ default: &default adapter: postgresql encoding: unicode - host: localhost + host: <%= ENV.fetch('PG_DATABASE_HOST') { 'localhost' } %> database: flaredown_development username: postgres password: password diff --git a/backend/config/mongoid.yml b/backend/config/mongoid.yml index 0fdae284c..dd6ced106 100644 --- a/backend/config/mongoid.yml +++ b/backend/config/mongoid.yml @@ -9,7 +9,7 @@ development: # Provides the hosts the default client can connect to. Must be an array # of host:port pairs. (required) hosts: - - localhost:27017 + - <%= ENV['MONGODB_HOST'] || "localhost" %>:27017 options: # Change the default write concern. (default = { w: 1 }) # write: diff --git a/docker-compose.yml b/docker-compose.yml index af7157d44..aa9f722ae 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,27 +1,87 @@ -version: '3' -volumes: - postgres: - mongodb: - redis: +version: '3.8' +x-backend-services-hosts: + &backend-services-hosts + MONGODB_HOST: mongodb + REDIS_URL: redis://redis:6379 + PG_DATABASE_HOST: postgres + services: + backend: + build: backend + depends_on: + - postgres + - mongodb + - redis + ports: + - 3000:3000 + volumes: + - ./backend:/app + environment: *backend-services-hosts + profiles: + - dev + workers: + build: backend + command: bundle exec sidekiq -C config/sidekiq.yml + depends_on: + - redis + - mongodb + - postgres + volumes: + - ./backend:/app + environment: *backend-services-hosts + profiles: + - dev + tunnel: + build: backend + command: bundle exec bin/localtunnel + depends_on: + - backend + volumes: + - ./backend:/app + profiles: + - tunnel + frontend: + build: frontend + depends_on: + - backend + ports: + - 4300:4300 + volumes: + - ./frontend:/app + command: sh -c "cd /app && rm -rfd ./dist && ./node_modules/.bin/ember serve --port 4300 --proxy http://localhost:3000" + profiles: + - dev + app-setup: + build: backend + command: bundle exec rails app:setup + depends_on: + - postgres + environment: *backend-services-hosts + profiles: + - tools postgres: image: postgres:12.8-alpine + restart: always environment: POSTGRES_PASSWORD: password PGDATA: /data volumes: - postgres:/data - ports: - - 5432:5432 + expose: + - 5432 mongodb: image: mongo:4.4.9 volumes: - mongodb:/data/db - ports: - - 27017:27017 + expose: + - 27017 redis: image: redis:6.2.3-alpine volumes: - redis:/data - ports: - - 6379:6379 + expose: + - 6379 +volumes: + postgres: + mongodb: + redis: diff --git a/frontend/Dockerfile b/frontend/Dockerfile new file mode 100644 index 000000000..5b436fd9c --- /dev/null +++ b/frontend/Dockerfile @@ -0,0 +1,17 @@ +FROM node:12.22.6 + +# Force npm version 7 +RUN npm i -g npm@7 + +WORKDIR /app + +COPY package*.json node_modules bower.json .bowerrc .npmrc ./ + +RUN npm install + +COPY . . + +# Rebuild node-sass for the current environment +RUN npm rebuild node-sass + +CMD ["npm", "start"] diff --git a/frontend/README.md b/frontend/README.md index d8d740dde..be4431d9c 100644 --- a/frontend/README.md +++ b/frontend/README.md @@ -23,7 +23,7 @@ You will need the following things properly installed on your computer. ## Running / Development * `ember serve` -* Visit your app at [http://localhost:4200](http://localhost:4200). +* Visit your app at [http://localhost:4300](http://localhost:4300). ## Running / Development via Fastboot server @@ -54,4 +54,3 @@ Specify what it takes to deploy your app. * Development Browser Extensions * [ember inspector for chrome](https://chrome.google.com/webstore/detail/ember-inspector/bmdblncegkenkacieihfhpjfppoconhi) * [ember inspector for firefox](https://addons.mozilla.org/en-US/firefox/addon/ember-inspector/) - From 36a201e857d4faf42bcafc50f4dc2703064397b7 Mon Sep 17 00:00:00 2001 From: Leo Correa Date: Fri, 18 Aug 2023 23:59:16 -0400 Subject: [PATCH 2/4] No need to include node_modules in the app image These are installed by npm install --- frontend/Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frontend/Dockerfile b/frontend/Dockerfile index 5b436fd9c..e0d6bf77c 100644 --- a/frontend/Dockerfile +++ b/frontend/Dockerfile @@ -5,7 +5,7 @@ RUN npm i -g npm@7 WORKDIR /app -COPY package*.json node_modules bower.json .bowerrc .npmrc ./ +COPY package*.json bower.json .bowerrc .npmrc ./ RUN npm install From 480d59697af69e71b97489bc1205d5e15aca6021 Mon Sep 17 00:00:00 2001 From: Leo Correa Date: Sat, 19 Aug 2023 00:00:45 -0400 Subject: [PATCH 3/4] Reduce build context size by ignoring unneeded deps --- frontend/.dockerignore | 8 ++++++++ 1 file changed, 8 insertions(+) create mode 100644 frontend/.dockerignore diff --git a/frontend/.dockerignore b/frontend/.dockerignore new file mode 100644 index 000000000..177477ae3 --- /dev/null +++ b/frontend/.dockerignore @@ -0,0 +1,8 @@ +bower_components +node_modules +dist +tmp +.git +README.md +LICENSE +.gitignore From cb7ca859e98d72dcb22c43cb97ab3f39fc9bf2d5 Mon Sep 17 00:00:00 2001 From: Leo Correa Date: Sat, 19 Aug 2023 00:10:17 -0400 Subject: [PATCH 4/4] No need to rebuild node-sass since we're not copying node_modules --- frontend/Dockerfile | 3 --- 1 file changed, 3 deletions(-) diff --git a/frontend/Dockerfile b/frontend/Dockerfile index e0d6bf77c..d8fcec613 100644 --- a/frontend/Dockerfile +++ b/frontend/Dockerfile @@ -11,7 +11,4 @@ RUN npm install COPY . . -# Rebuild node-sass for the current environment -RUN npm rebuild node-sass - CMD ["npm", "start"]