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

Add docker-compose.healthcheck.yml #384

Merged
merged 1 commit into from
Oct 24, 2022
Merged

Conversation

rangerz
Copy link
Contributor

@rangerz rangerz commented Feb 1, 2021

According to the HEALTHCHECK for docker containers I mentioned in here

@markshust, please rebuild all of php (7.3, 7.4, 8.0) and elasticsearch(6.8, 7.6) images. Thanks 👍

In bin/status also can view all health status

magento2.test git:(master) ✗ ./bin/status                                                        git:(master|●4✚2…5
            Name                          Command                  State                         Ports
------------------------------------------------------------------------------------------------------------------------
magento2test_app_1             /docker-entrypoint.sh ngin ...   Up (healthy)   80/tcp, 0.0.0.0:80->8000/tcp,
                                                                               0.0.0.0:443->8443/tcp
magento2test_db_1              /docker-entrypoint.sh --ma ...   Up (healthy)   0.0.0.0:3306->3306/tcp
magento2test_elasticsearch_1   /usr/local/bin/docker-entr ...   Up (healthy)   0.0.0.0:9200->9200/tcp,
                                                                               0.0.0.0:9300->9300/tcp
magento2test_mailhog_1         MailHog                          Up (healthy)   0.0.0.0:55038->1025/tcp,
                                                                               0.0.0.0:8025->8025/tcp
magento2test_phpfpm_1          docker-php-entrypoint php-fpm    Up (healthy)   9000/tcp, 9001/tcp
magento2test_rabbitmq_1        docker-entrypoint.sh rabbi ...   Up (healthy)   15671/tcp, 0.0.0.0:15672->15672/tcp,
                                                                               25672/tcp, 4369/tcp, 5671/tcp,
                                                                               0.0.0.0:5672->5672/tcp
magento2test_redis_1           docker-entrypoint.sh redis ...   Up (healthy)   6379/tcp

Refs:
magento/magento-cloud-docker
sun-asterisk-research/docker-php

Copy link
Owner

@markshust markshust left a comment

Choose a reason for hiding this comment

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

Very cool, thanks for this. Some questions/comments posted.

--elasticsearch-host=$ES_HOST \
--elasticsearch-port=$ES_PORT \
--elasticsearch-host=elasticsearch \
--elasticsearch-port=9200 \
Copy link
Owner

Choose a reason for hiding this comment

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

We'll want to back out this update so a user can override the Elasticsearch host/port with env vars.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ok, I will recover this part.

But I think this setting is very common.
If someone need change Elasticsearch host/port, change here is not enough.

docker-compose.yml (just guess, not test yet)

elasticsearch:
    image: markoshust/magento-elasticsearch:7.6.2-2
    ports:
      - "9200:9200" # this also need to change
      - "9300:9300"
    environment:
      - "discovery.type=single-node"
      - ES_HOST=elasticsearch # add new value
      - ES_PORT=9200               # add new value

Copy link
Owner

Choose a reason for hiding this comment

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

Yep, I'd avoid the vars being set here though and set defaults within the bash file (see #384 (comment)). But, this is how & where someone would override these vars. This would be useful to add to the documentation.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think this push request (commit) should only keep changes about HEALTHCHECK.
For other environmental variables, I will create another one for it.

@@ -3,14 +3,10 @@ set -o errexit
source env/db.env
BASE_URL=${1:-magento2.test}

ES_HOST=elasticsearch
ES_PORT=9200
Copy link
Owner

Choose a reason for hiding this comment

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

Need to add these back in

Copy link
Owner

Choose a reason for hiding this comment

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

I think this is where we need updates. These settings are file, but need to pull in from envvar if it exists.

I didn't test but something like this pseudo code may work:

ES_HOST="${ES_HOST:=elasticsearch}"
ES_PORT="${ES_PORT:=9200}"

This way we don't need to define anything in the XML files.

Copy link
Owner

Choose a reason for hiding this comment

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

On second thought, maybe be better to create an env/elasticsearch.env file for these similar to https://github.com/markshust/docker-magento/blob/master/compose/env/db.env

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@markshust I think this push request (commit) should only keep changes about HEALTHCHECK.
For other environmental variables, I will create another one for it.

@@ -19,12 +19,27 @@ services:
- appdata:/var/www/html
- sockdata:/sock
- ssldata:/etc/nginx/certs
healthcheck:
test: 'curl --fail http://127.0.0.1:8000'
interval: 1m30s
Copy link
Owner

Choose a reason for hiding this comment

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

Why is the interval a different value from the docker-compose.dev.yml file?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think remove all interval, timeout, and start-period will be fine.
Using their default value may a better choice

The options that can appear before CMD are:

--interval=DURATION (default: 30s)
--timeout=DURATION (default: 30s)
--start-period=DURATION (default: 0s)
--retries=N (default: 3)

Copy link
Owner

Choose a reason for hiding this comment

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

Cool, definitely prefer the defaults 👍

healthcheck:
test: 'curl --fail http://127.0.0.1:8000'
interval: 1m30s
timeout: 10s
Copy link
Owner

Choose a reason for hiding this comment

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

Same with timeout, I would think these would be consistent between the files unless there was some other reason to do so (which should probably then be documented).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Remove all interval, timeout, and start-period, and use default value.

Copy link
Owner

Choose a reason for hiding this comment

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

👍

@@ -53,6 +78,11 @@ services:
- "5672:5672"
volumes:
- rabbitmqdata:/var/lib/rabbitmq
healthcheck:
test: 'rabbitmq-diagnostics -q ping'
interval: 30s
Copy link
Owner

Choose a reason for hiding this comment

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

The healthcheck params are repeated a few times, can we make this into a YAML anchor like volumes are done?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Remove all interval, timeout, and start-period, and use default value.

Copy link
Owner

Choose a reason for hiding this comment

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

👍

@markshust
Copy link
Owner

@rangerz this has been sitting here a long time. Should it be worked on & merged in? It's a bit invasive, I want to make sure we need this, as there seems to be many moving pieces to implement this. I've really never had a problem with my Docker containers being in an unhealthy state.

@rangerz
Copy link
Contributor Author

rangerz commented Oct 13, 2022

@markshust

Forget the above message

I added docker-compose.healthcheck.yml for bin/start without until statement in bash script

Please review it.

@rangerz rangerz changed the title Add healthcheck for all containers Add docker-compose.healthcheck.yml Oct 13, 2022
@markshust
Copy link
Owner

Hi @rangerz, all looks good! But I don't see any additions to bin/start. Did you want me to merge this for testing, or is this missing an update in bin/start?

I just merged your other big PR in for docker-compose/docker compose, so perhaps that needed to be merged in first?

@rangerz
Copy link
Contributor Author

rangerz commented Oct 20, 2022

@markshust Yes, here is waiting for the bin/docker-compose commit.

It's updated to put docker-compose.healthcheck.yml into bin/docker-compose and then remove until wait for RabbitMQ and Elasticsearch services

@markshust markshust merged commit ba7ec89 into markshust:master Oct 24, 2022
@markshust
Copy link
Owner

Awesome... this is sweet!!! 🧡🧡🧡

@rangerz rangerz deleted the healthcheck branch December 10, 2022 09:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants