Skip to content

Commit

Permalink
Fix oppia#19121: better error outputs when running make run-offline (o…
Browse files Browse the repository at this point in the history
…ppia#19453)

* better error outputs when running make run-offline

* moved echo statements to start-devserver

* removed files due to previous bad commit

* changed docker compose file to pre-resolve version

* checking container health using healthcheck

* added copyright notice

* removed commented code and added few useful comments

* removed output to log file for testing
  • Loading branch information
Jayam Patel authored Feb 8, 2024
1 parent 41247f5 commit f7afa5f
Show file tree
Hide file tree
Showing 5 changed files with 76 additions and 8 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -69,3 +69,5 @@ dump.rdb
ui-debug.log
firebase-debug.log
debug.log
# development logs and status entries
.dev
27 changes: 21 additions & 6 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -46,15 +46,14 @@ run-devserver: ## Runs the dev-server
docker compose stop angular-build
docker compose up dev-server -d --no-deps
$(MAKE) update.requirements
$(MAKE) run-offline
$(MAKE) start-devserver

run-offline: ## Runs the dev-server in offline mode
## Users can pass this check by simply running `make start-devserver`
$(MAKE) check.dev-container-healthy
$(MAKE) start-devserver
@echo 'Please visit http://localhost:8181 to access the development server.'
@echo 'Check dev-server logs using "make logs.dev-server"'
@echo 'Stop the development server using "make stop"'

start-devserver: ## Starts the development server for the tests
start-devserver: ## Starts the development server
docker compose up dev-server -d
@printf 'Please wait while the development server starts...\n\n'
@while [[ $$(curl -s -o /tmp/status_code.txt -w '%{http_code}' http://localhost:8181) != "200" ]] || [[ $$(curl -s -o /tmp/status_code.txt -w '%{http_code}' http://localhost:8181/community-library) != "200" ]]; do \
Expand All @@ -65,7 +64,9 @@ start-devserver: ## Starts the development server for the tests
sleep 1; \
done
@printf '\n\n'
@echo 'Development server started at port 8181.'
@echo 'Please visit http://localhost:8181 to access the development server.'
@echo 'Check dev-server logs using "make logs.dev-server"'
@echo 'Stop the development server using "make stop"'

init: build run-devserver ## Initializes the build and runs dev-server.

Expand Down Expand Up @@ -95,6 +96,20 @@ update.package: ## Installs the npm requirements for the project
@echo 'yarn-path "../oppia_tools/yarn-1.22.15/bin/yarn"' > .yarnrc
@echo 'cache-folder "../yarn_cache"' >> .yarnrc

check.dev-container-healthy:
@run_devserver_prompt="Please, run \`make run-devserver\` (requires internet) once before running \`make run-offline\`"; \
if [ -f ".dev/containers-health.json" ]; then \
if jq -e ".devserver != true" ".dev/containers-health.json" > /dev/null; then \
echo "Container is unhealthy"; \
echo $$run_devserver_prompt; \
exit 1; \
fi \
else \
echo "Can't check container health!"; \
echo $$run_devserver_prompt; \
exit 1; \
fi

logs.%: ## Shows the logs of the given docker service. Example: make logs.datastore
docker compose logs -f $*

Expand Down
2 changes: 1 addition & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ services:
- firebase
- redis
healthcheck:
test: curl -f http://localhost:8181/ || exit 1
test: ["CMD", "bash", "docker/dev-server.healthcheck.sh"]
timeout: 10s
interval: 30s
retries: 5
Expand Down
3 changes: 2 additions & 1 deletion docker/Dockerfile.backend
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ RUN apt-get update -y && apt-get upgrade -y \
python2 \
python3-matplotlib \
unzip \
wget
wget \
jq
RUN curl -sL https://deb.nodesource.com/setup_16.x | bash -
RUN apt-get install -y nodejs

Expand Down
50 changes: 50 additions & 0 deletions docker/dev-server.healthcheck.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
#!/bin/bash
# Copyright 2023 The Oppia Authors. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS-IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

FILE=".dev/containers-health.json"

# Create parent directories if needed
DIR=$(dirname "$FILE")
if [ ! -d "$DIR" ]; then
mkdir -p "$DIR"
fi

# Check and create file
echo '{ "devserver": false }' > "$FILE"

# Check if devserver health is stored and reset it to false
key_to_check="devserver"
if jq -e "has(\"$key_to_check\")" "$FILE" > /dev/null; then
jq '.["devserver"] = false' "$FILE" > /tmp/status.json && mv /tmp/status.json "$FILE"
else
jq '. + { "devserver": false }' "$FILE" > /tmp/status.json && mv /tmp/status.json "$FILE"
fi

# Check container health
curl -f http://localhost:8181/
STATUS=$?

if [ $STATUS -eq 0 ]; then
# Healthy
jq '.["devserver"] = true' "$FILE" > /tmp/status.json && mv /tmp/status.json "$FILE"

exit 0

else
# Unhealthy
jq '.["devserver"] = false' "$FILE" > /tmp/status.json && mv /tmp/status.json "$FILE"

exit 1
fi

0 comments on commit f7afa5f

Please sign in to comment.