From 1443bc4fa4ebebc8e1900b55d0f007aeba8e0f71 Mon Sep 17 00:00:00 2001 From: Zakaria Fatahi Date: Sun, 13 Nov 2022 22:31:08 +0100 Subject: [PATCH] Add more ENVs --- .env.example | 66 +++++++++++++++++++++++++++++++++++----------- Dockerfile | 4 ++- docker-compose.yml | 6 ++--- 3 files changed, 57 insertions(+), 19 deletions(-) diff --git a/.env.example b/.env.example index 94d8a3d..63d6198 100644 --- a/.env.example +++ b/.env.example @@ -3,23 +3,62 @@ export COMPOSE_PROJECT_NAME=baseapp # Which environment is running? These should be "development" or "production". -#export RAILS_ENV=production -#export NODE_ENV=production -export RAILS_ENV=development -export NODE_ENV=development - -## Secret keys -# You can use `rails secret` command to generate a secret key -export SECRET_KEY_BASE=insecure-key -export DEVISE_JWT_SECRET_KEY=my-jwt-secret-key +# About COMPOSE_PROFILES: https://docs.docker.com/compose/profiles/ # In development we want all services to start but in production you don't # need the asset watchers to run since assets get built into the image. # # You can even choose not to run postgres and redis in prod if you plan to use # managed cloud services. Everything "just works", even optional depends_on! -#export COMPOSE_PROFILES=postgres,redis,web,worker,cable +export RAILS_ENV=development +export NODE_ENV=development export COMPOSE_PROFILES=postgres,redis,assets,web,worker,cable +#export RAILS_ENV=production +#export NODE_ENV=production +#export COMPOSE_PROFILES=postgres,redis,web,worker,cable + +# What volume path should be used? In dev we want to volume mount everything +# so that we can develop our code without rebuilding our Docker images. +export DOCKER_WEB_VOLUME=.:/app +#export DOCKER_WEB_VOLUME=./public:/app/public + +# Should Docker restart your containers if they go down in unexpected ways? +#export DOCKER_RESTART_POLICY=unless-stopped +export DOCKER_RESTART_POLICY=no + +# What ip:port should be published back to the Docker host for the app server? +# If you're using Docker Toolbox or a custom VM you can't use 127.0.0.1. This +# is being overwritten in dev to be compatible with more dev environments. +# +# If you have a port conflict because something else is using 3000 then you +# can either stop that process or change 3000 to be something else. +# +# Use the default in production to avoid having puma directly accessible to +# the internet since it'll very likely be behind nginx or a load balancer. +#export DOCKER_WEB_PORT_FORWARD=127.0.0.1:3000 +export DOCKER_WEB_PORT_FORWARD=3000 + +# This is the same as above except for Action Cable. +#export DOCKER_CABLE_PORT_FORWARD=127.0.0.1:28080 +export DOCKER_CABLE_PORT_FORWARD=28080 + +# What CPU and memory constraints will be added to your services? When left at +# 0 they will happily use as much as needed. +# export DOCKER_POSTGRES_CPUS=0 +# export DOCKER_POSTGRES_MEMORY=0 +# export DOCKER_REDIS_CPUS=0 +# export DOCKER_REDIS_MEMORY=0 +# export DOCKER_WEB_CPUS=0 +# export DOCKER_WEB_MEMORY=0 +# export DOCKER_WORKER_CPUS=0 +# export DOCKER_WORKER_MEMORY=0 +# export DOCKER_CABLE_CPUS=0 +# export DOCKER_CABLE_MEMORY=0 + +## Secret keys +# You can use `rails secret` command to generate a secret key +export SECRET_KEY_BASE=insecure-key +export DEVISE_JWT_SECRET_KEY=my-jwt-secret-key ## Host export DEFAULT_HOST=example.com @@ -32,8 +71,8 @@ export DEFAULT_HOST=example.com # export RAILS_MIN_THREADS=5 ## Postgres -# export POSTGRES_HOST=postgres -# export POSTGRES_PORT=5432 +export POSTGRES_HOST=postgres +export POSTGRES_PORT=5432 export POSTGRES_USER=baseapp export POSTGRES_PASSWORD=123456 export POSTGRES_DB=baseapp @@ -53,8 +92,5 @@ export POSTGRES_DB=baseapp # export SIDEKIQ_WEB_USERNAME=sidekiq-web-dashboard # export SIDEKIQ_WEB_PASSWORD=sidekiq-web-123 -## Vite -export VITE_RUBY_HOST=0.0.0.0 - # frontend config VITE_API_URL=http://localhost:3000 diff --git a/Dockerfile b/Dockerfile index c79e746..681d189 100644 --- a/Dockerfile +++ b/Dockerfile @@ -13,6 +13,8 @@ RUN apk add --update \ nodejs=$NODE_VERSION \ yarn=$YARN_VERSION +###################################################################### + # This stage will be responsible for installing gems and npm packages FROM base AS dependencies @@ -36,7 +38,7 @@ COPY package.json yarn.lock ./ # Install npm packages RUN yarn install --frozen-lockfile -############################################################################### +###################################################################### # We're back at the base stage FROM base AS app diff --git a/docker-compose.yml b/docker-compose.yml index 28c5e14..01b0336 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -28,11 +28,11 @@ services: POSTGRES_PASSWORD: "${POSTGRES_PASSWORD}" # POSTGRES_DB: "${POSTGRES_DB}" image: "postgres:15.0-alpine" - profiles: ["postgres"] restart: "${DOCKER_RESTART_POLICY:-unless-stopped}" stop_grace_period: "3s" volumes: - "postgres:/var/lib/postgresql/data" + profiles: ["postgres"] redis: deploy: @@ -41,11 +41,11 @@ services: cpus: "${DOCKER_REDIS_CPUS:-0}" memory: "${DOCKER_REDIS_MEMORY:-0}" image: "redis:7.0.5-alpine" - profiles: ["redis"] restart: "${DOCKER_RESTART_POLICY:-unless-stopped}" stop_grace_period: "3s" volumes: - "redis:/data" + profiles: ["redis"] web: <<: *default-app @@ -95,7 +95,6 @@ services: vite: <<: *default-app - profiles: ["assets"] restart: "${DOCKER_RESTART_POLICY:-unless-stopped}" stop_grace_period: "3s" tty: true @@ -107,6 +106,7 @@ services: - .:/app environment: VITE_RUBY_HOST: 0.0.0.0 + profiles: ["assets"] volumes: postgres: {}