Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update docker-compose examples #6566

Merged
merged 7 commits into from Jul 29, 2020
Merged

Update docker-compose examples #6566

merged 7 commits into from Jul 29, 2020

Conversation

azrikahar
Copy link
Contributor

This PR only affects the documentation and is ready to be merged.

Description of what this PR changed:

  1. Changed volume for strapi in SQLite from ./:/srv/app to ./app:/srv/app

    Both the PostgreSQL and MongoDB strapi service binds to ./app instead of ./, so this feels more uniform. It's also better to keep strapi into the ./app folder and not mixed up with the docker-compose file here.

  2. Removed links option for strapi service in PostgreSQL and MongoDB

    Since docker-compose v3, the links option became a legacy feature and may eventually be removed, as mentioned in the official Docker docs over here. Since docker-compose joins services/containers into the same network, they can already communicate to each other, as quoted from the previous docker docs link:

    Links are not required to enable services to communicate - by default, any service can reach any other service at that service’s name.

    In addition, the docker compose examples for postgresql and mongodb in the strapi-docker repo also seems to be more up-to-date in terms of docker compose v3 format, so I do believe having more updated format over here will be more consistent overall.

  3. Add depends_on option for strapi service in PostgreSQL and MongoDB

    This option is also used in the postgresql & mongodb docker compose example in strapi-docker. Since Strapi also often mentions the database needs to be up beforehand, this option added does seem more fitting. Just in case the reviewer is not sure what depends_on does, basically docker-compose will recognize that "strapi" service depends on the "postgres" or "mongo" service, so it will wait until the database service start first before starting strapi (there are some caveats, but it's explained in the official docs). More info on this option in the official Docker docs here

  4. Changed volume for strapi in MongoDB from ./data/db:/data/db to ./db:/data/db

    Since based on other tabs, strapi resides on ./app of the base directory, postgres on ./data, I think it's also more uniform to have mongo to reside on ./db rather than nested in ./data/db. Once again this ./db approach is also used in the mongodb compose example in strapi-docker so it'll be more consistent as well.


The following changes are more for clarity in my personal opinion, so if you guys deem them not necessary, I can revert these changes if you guys want me to.

  1. Add POSTGRES_DB and MONGO_INITDB_DATABASE environment variables

    These are also used in the strapi-docker examples to show a database is initialized with the name "strapi", as seen here (postgres) and here (mongodb). This is just to match how for postgres, DATABASE_USERNAME corresponds to POSTGRES_USER and DATABASE_PASSWORD to POSTGRES_PASSWORD. Even though for the Postgres docker image it will automatically set POSTGRES_DB to the value of POSTGRES_USER if it's not set, but I feel like setting it here will be clearer rather than hoping the user know the postgres image does this under the hood.

  2. Remove exposed ports for databases

    Since the strapi service can already reach the database service, be it postgresql or mongodb, via the docker network, there is no need to expose the database port to the host machine. This is of course unless they have a database management application in their machine and wants to use localhost:5432 or localhost:27017 to access the database. However for security purpose and in case someone does use this compose file in production, I believe it's best to not expose it until they opt-in to do so. The postgres example in strapi-docker also doesn't expose the port, though the mongodb one does. I do plan to create a pull request at strapi-docker if all these are approved over here.


I have tested the updated compose file & there are no issues. If you guys wish to have the docker-compose logs for verification, do let me know so I can provide it, probably via pastebin since it's pretty lengthy. I do understand reviewing pull requests can be a long process, so I hope I gave sufficient details on what I changed and the reasoning behind the changes. Do let me know as well if you need any clarifications. Cheers

Changed volume bind mount from `./:/srv/app` to `./app:/srv/app` to match path used in PostgreSQL and MongoDB example

Signed-off-by: azrikahar <42867097+azrikahar@users.noreply.github.com>
Signed-off-by: azrikahar <42867097+azrikahar@users.noreply.github.com>
Signed-off-by: azrikahar <42867097+azrikahar@users.noreply.github.com>
Signed-off-by: azrikahar <42867097+azrikahar@users.noreply.github.com>
Signed-off-by: azrikahar <42867097+azrikahar@users.noreply.github.com>
Signed-off-by: azrikahar <42867097+azrikahar@users.noreply.github.com>
@codecov
Copy link

codecov bot commented Jun 5, 2020

Codecov Report

Merging #6566 into master will not change coverage.
The diff coverage is n/a.

Impacted file tree graph

@@           Coverage Diff           @@
##           master    #6566   +/-   ##
=======================================
  Coverage   19.85%   19.85%           
=======================================
  Files         857      857           
  Lines       12076    12076           
  Branches     1963     1963           
=======================================
  Hits         2398     2398           
  Misses       8093     8093           
  Partials     1585     1585           
Flag Coverage Δ
#front 14.66% <ø> (ø)
#unit 41.26% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.


Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update e22fb6c...1dcac52. Read the comment docs.

@alexandrebodin alexandrebodin added source: docs Documentation changes issue: enhancement Issue suggesting an enhancement to an existing feature labels Jul 16, 2020
@lauriejim
Copy link
Contributor

@alexandrebodin is the update correct? Because the update in on the code.

Copy link
Member

@alexandrebodin alexandrebodin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

a minor change :)

- ./data/db:/data/db
ports:
- '27017:27017'
- ./db:/data/db
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would use ./data so it is consistent between every examples :)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry for the late reply. Thank you for taking your time to change it. 👍

@alexandrebodin alexandrebodin mentioned this pull request Jul 29, 2020
Copy link
Member

@alexandrebodin alexandrebodin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM ! Thanks for your contribution :)

@alexandrebodin alexandrebodin merged commit 56e4426 into strapi:master Jul 29, 2020
@alexandrebodin alexandrebodin added this to the 3.1.2 milestone Jul 29, 2020
gilfernandes pushed a commit to onepointconsulting/strapi that referenced this pull request Aug 13, 2020
* Change volume for strapi in SQLite for consistency

Changed volume bind mount from `./:/srv/app` to `./app:/srv/app` to match path used in PostgreSQL and MongoDB example

Signed-off-by: azrikahar <42867097+azrikahar@users.noreply.github.com>

* Remove "links" option for PostgreSQL & MongoDB

Signed-off-by: azrikahar <42867097+azrikahar@users.noreply.github.com>

* Add "depends_on" option for PostgreSQL & MongoDB

Signed-off-by: azrikahar <42867097+azrikahar@users.noreply.github.com>

* Changed volume for strapi in MongoDB example

Signed-off-by: azrikahar <42867097+azrikahar@users.noreply.github.com>

* Add database init name environment variables

Signed-off-by: azrikahar <42867097+azrikahar@users.noreply.github.com>

* Remove exposed ports for databases

Signed-off-by: azrikahar <42867097+azrikahar@users.noreply.github.com>

* Update docker.md

Co-authored-by: Alexandre BODIN <alexandrebodin@users.noreply.github.com>
Signed-off-by: Gil Fernandes <gil.fernandes@onepointltd.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
issue: enhancement Issue suggesting an enhancement to an existing feature source: docs Documentation changes
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants