diff --git a/Dockerfile b/Dockerfile index c008718642df9e72cfd44f3b9207a8fc66a69a03..e281af8a422fc7480b63cdd9f055f7333fad09c1 100644 --- a/Dockerfile +++ b/Dockerfile @@ -18,9 +18,45 @@ RUN pip install --no-cache-dir -r requirements.txt # Copy application code COPY . . -# Make the wait-for script executable -COPY ./docker/wait-for.sh /wait-for.sh -RUN chmod +x /wait-for.sh +# Create wait-for.sh script directly in the Dockerfile +RUN echo '#!/bin/sh \n\ +# wait-for.sh \n\ +\n\ +set -e \n\ +\n\ +host="$1" \n\ +shift \n\ +\n\ +# Handle the -- separator if present \n\ +if [ "$1" = "--" ]; then \n\ + shift \n\ +fi \n\ +\n\ +cmd="$@" \n\ +\n\ +# Extract hostname from host:port format \n\ +hostname=$(echo "$host" | cut -d: -f1) \n\ +port=$(echo "$host" | cut -d: -f2) \n\ +\n\ +echo "Waiting for MySQL database at $hostname:$port..." \n\ +\n\ +# First wait for DNS resolution \n\ +until getent hosts "$hostname" || ping -c 1 "$hostname" >/dev/null 2>&1; do \n\ + echo "Waiting for DNS resolution of $hostname..." \n\ + sleep 3 \n\ +done \n\ +\n\ +echo "DNS resolution successful for $hostname" \n\ +\n\ +# Then wait for port to be available \n\ +until nc -z -v -w30 "$hostname" "$port"; do \n\ + echo "Waiting for MySQL database at $hostname:$port to start accepting connections..." \n\ + sleep 2 \n\ +done \n\ +\n\ +echo "MySQL database is up - executing command: $cmd" \n\ +exec $cmd' > /wait-for.sh \ + && chmod +x /wait-for.sh # Expose port 5000 for the Flask app EXPOSE 5000 diff --git a/docker/wait-for.sh b/docker/wait-for.sh deleted file mode 100644 index 59da49b995c9bcbd2409b060ed53e2798e4439c9..0000000000000000000000000000000000000000 --- a/docker/wait-for.sh +++ /dev/null @@ -1,37 +0,0 @@ -#!/bin/sh -# wait-for.sh - -set -e - -host="$1" -shift - -# Handle the -- separator if present -if [ "$1" = "--" ]; then - shift -fi - -cmd="$@" - -# Extract hostname from host:port format -hostname=$(echo "$host" | cut -d: -f1) -port=$(echo "$host" | cut -d: -f2) - -echo "Waiting for MySQL database at $hostname:$port..." - -# First wait for DNS resolution -until getent hosts "$hostname" || ping -c 1 "$hostname" >/dev/null 2>&1; do - echo "Waiting for DNS resolution of $hostname..." - sleep 3 -done - -echo "DNS resolution successful for $hostname" - -# Then wait for port to be available -until nc -z -v -w30 "$hostname" "$port"; do - echo "Waiting for MySQL database at $hostname:$port to start accepting connections..." - sleep 2 -done - -echo "MySQL database is up - executing command: $cmd" -exec $cmd \ No newline at end of file