Docker Community Forums

Share and learn in the Docker community.

How to update path_prefix aws s3 for every organization in docker-compose

Hi everyone
I have a question about adding path_prefix in docker-compose for aws s3
I know how to add it in file_store.yml
so I use this configuration to save files from CANVAS LMS to dir-A directory :

development:
   storage: s3
   path_prefix: attachments/dir-A/

what I need it’s to change this path_prefix for every docker-compose to tell every organization where to save files in aws s3
for example :

Organization A =>  s3://bucket-name/account_1/attachments/dir-A/  
Organization B =>  s3://bucket-name/account_1/attachments/dir-B/  
Organization C =>  s3://bucket-name/account_1/attachments/dir-C/  

So like I said above, I know how to save files in from first organization to his directory dir-A, but I used by Dockerfile by building images with amazon_s3.yml and file_store.yml

And now I need to change just the path_prefix for every organization
is that possible and how please?

docker-compose used :
version: ‘3.5’

services:
  db:
    image: postgres:9.6
    environment:
      - POSTGRES_USER=foo
      - POSTGRES_PASSWORD=foo
      - POSTGRES_DB=foo
    volumes:
      - db:/var/lib/postgresql/data

  redis:
    image: redis:3.2.4
    command: redis-server --appendonly yes
    volumes:
      - ./.data/redis:/data

  app: &app
    image: registry/image:1.1
    command: bash -c "./wait-for-it.sh -t 40 db:5432 && /usr/src/entrypoint"
    environment:
      - RAILS_ENV=production
      - DB_DRIVER=postgresql
      - DB_HOST=db
      - DB_PORT=5432
      - DB_USERNAME=foo
      - DB_PASSWORD=foo
      - DB_NAME=foo
      - REDIS_SERVER=redis://redis:6379
      - MAIL_SERVER=in-v3.mailjet.com
      - MAIL_PORT=587
      - MAIL_USERNAME=foo
      - MAIL_PASSWORD=foo
      - MAIL_DOMAIN=in-v3.mailjet.com
      - MAIL_DEFAULT_SENDER_ADDRESS=************
      - MAIL_DEFAULT_SENDER_NAME=*******
      - DOMAIN=*******
      - DOMAIN_RCE=*******
      - PASSENGER_STARTUP_TIMEOUT=300
    depends_on:
      - db
      - redis
    volumes:
      - theme:/usr/src/app/public/dist/brandable_css
      - files:/usr/src/app/data/files
      - ./.data/tmp:/usr/src/app/tmp
  worker:
    <<: *app
    command: bundle exec script/delayed_job run


volumes:
  db:
    driver: local
  theme:
    driver: local
  files:
    driver: local

amazon_s3.yml :

development:
  bucket_name: MyBucket
  access_key_id: ******
  secret_access_key: ******
  region: eu-central-1

test:
  bucket_name: MyBucket
  access_key_id: ******
  secret_access_key: ******
  region: eu-central-1
  
production:
  bucket_name: MyBucket
  access_key_id: ******
  secret_access_key: ******
  region: eu-central-1

file_store.yml :

development:
  storage: s3
  path_prefix: attachments/dir-A/

test:
  storage: s3
  path_prefix: attachments/dir-A/
  
production:
  storage: s3
  path_prefix: attachments/dir-A/
## amazon storage example. requires valid amazon_s3.yml
#
# production:
#   storage: s3

Dockerfile :

FROM registry/image:1.1
ENV APP_HOME /usr/src/app
COPY --chown=docker:docker ./amazon_s3.yml ${APP_HOME}/config/amazon_s3.yml
COPY --chown=docker:docker ./file_store.yml ${APP_HOME}/config/file_store.yml

I found the solution;
So to make edit path_prefix in file_store.yml for every docker-compose

I add this ENV

production:
  storage: s3
  path_prefix: attachments/<%= ENV['HELLO_VARIABLE'] %>/

and in docker-compose.yml I add HELLO_VARIABLE to environment like:

  app: &app
    image: registry/images:1
    environment:
      - HELLO_VARIABLE=dir-A

and work perfectly when I upload now file to my canvas LMS platform
the files stored at

https://mybucket.s3.eu-central-1.amazonaws.com/account_1/attachments/dir-A/1/myFile.jpg