-
-
Notifications
You must be signed in to change notification settings - Fork 1k
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
workflow which ensures that talawa Api app starts in docker #2759
Changes from 56 commits
64bee20
4fa5812
6ca6131
57ae541
cfec867
1544502
0b6ef08
d8db396
4adec1f
45b7fcc
338a7b8
bb63fc2
d540981
5c54d6a
c942e2c
fbbb7ea
798b4f7
05f9c97
006092e
1c57fba
08c8d16
548e83b
a228c07
4c7280c
67baf1b
04ba4b2
a22e41d
e455a7c
01e8d37
22e66be
31a7dff
1a53bab
d62920f
5d8cdd9
cfcd134
a1425e0
cd44d42
9b300e1
94fad12
baaa36d
a8a121d
5cf642a
ef036d7
5e6a5e9
8c9d690
481b979
717ad62
5ccabab
4457277
0dc1c72
6cc3161
626991c
75939ab
e86129c
18d47a8
a73ab60
577175f
78fab42
89f67dd
4cfccd0
6841b72
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -312,6 +312,130 @@ jobs: | |
with: | ||
path: './coverage/lcov.info' | ||
min_coverage: 95.0 | ||
|
||
Docker-Check: | ||
name: Docker Check | ||
needs: Test-Application | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- name: Checkout repository | ||
uses: actions/checkout@v4 | ||
|
||
- name: Set up Node.js | ||
uses: actions/setup-node@v4 | ||
with: | ||
node-version: '22.x' | ||
|
||
- name: Cache Node.js dependencies | ||
uses: actions/cache@v4 | ||
with: | ||
path: | | ||
~/.npm | ||
node_modules | ||
key: ${{ runner.os }}-docker-check-${{ hashFiles('**/package-lock.json') }} | ||
restore-keys: | | ||
${{ runner.os }}-docker-check- | ||
|
||
- name: Install Docker Compose | ||
run: | | ||
sudo apt-get update | ||
sudo apt-get install -y docker-compose | ||
|
||
- name: Check if Talawa API starts in Docker | ||
run: | | ||
# Ensure no containers are running | ||
docker-compose -f docker-compose.dev.yaml down -v || true | ||
|
||
# Verify docker-compose file exists | ||
chmod +x .github/workflows/scripts/docker_file_check.sh | ||
./.github/workflows/scripts/docker_file_check.sh | ||
|
||
# Start containers | ||
if ! timeout 300 docker-compose -f docker-compose.dev.yaml up -d --build; then | ||
echo "Failed to start containers" | ||
docker-compose -f docker-compose.dev.yaml logs | ||
exit 1 | ||
fi | ||
|
||
# Wait for MongoDB and Redis to be ready | ||
echo "Waiting for MongoDB..." | ||
timeout=30 | ||
until docker-compose -f docker-compose.dev.yaml exec -T mongo mongosh --eval "db.runCommand({ ping: 1 }).ok">/dev/null 2>&1 || [ $timeout -eq 0 ]; do | ||
echo "Waiting for MongoDB to be ready..." | ||
sleep 1 | ||
((timeout--)) | ||
done | ||
if [ $timeout -eq 0 ]; then | ||
echo "Error: MongoDB failed to start within timeout" | ||
echo "Fetching MongoDB logs..." | ||
docker-compose -f docker-compose.dev.yaml logs mongodb | ||
echo "Shutting down MongoDB..." | ||
docker-compose -f docker-compose.dev.yaml down -v | ||
exit 1 | ||
else | ||
echo "MongoDB is ready!" | ||
fi | ||
prayanshchh marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
echo "Waiting for Redis..." | ||
timeout=30 | ||
until docker-compose -f docker-compose.dev.yaml exec -T redis-stack-server redis-cli ping >/dev/null 2>&1 || [ $timeout -eq 0 ]; do | ||
sleep 1 | ||
((timeout--)) | ||
done | ||
if [ $timeout -eq 0 ]; then | ||
echo "Error: Redis failed to start within timeout" | ||
echo "Fetching Redis logs..." | ||
docker-compose -f docker-compose.dev.yaml logs redis-stack-server | ||
echo "Shutting down Redis..." | ||
docker-compose -f docker-compose.dev.yaml down -v | ||
exit 1 | ||
else | ||
echo "Redis is ready!" | ||
fi | ||
|
||
# Wait for TALAWA API to be healthy | ||
timeout=60 | ||
until docker-compose -f docker-compose.dev.yaml exec -T talawa-api-dev curl -v -X OPTIONS "http://talawa-api-dev:4000/graphql" 2>&1 || [ $timeout -eq 0 ]; do | ||
echo "Waiting for API to start... ($timeout seconds remaining)" | ||
sleep 1 | ||
((timeout--)) | ||
done | ||
|
||
if [ $timeout -eq 0 ]; then | ||
echo "Error: API failed to start within timeout" | ||
docker-compose -f docker-compose.dev.yaml logs | ||
docker-compose -f docker-compose.dev.yaml down -v | ||
exit 1 | ||
fi | ||
prayanshchh marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
echo "API started successfully" | ||
|
||
# Ensure cleanup runs even if the script fails | ||
cleanup() { | ||
local exit_code=$? | ||
echo "Cleaning up containers..." | ||
if ! docker-compose -f docker-compose.dev.yaml down -v; then | ||
echo "Warning: Failed to cleanup containers" | ||
fi | ||
exit $exit_code | ||
} | ||
trap cleanup EXIT | ||
env: | ||
HEALTH_CHECK_URL: http://localhost:4000 | ||
COMPOSE_PROJECT_NAME: pr-${{ github.event.pull_request.number }} | ||
MONGO_DB_URL: mongodb://mongo:27017?replicaSet=rs0 | ||
REDIS_HOST: redis-stack-server | ||
REDIS_PORT: 6379 | ||
ACCESS_TOKEN_SECRET: ${{ secrets.GITHUB_TOKEN }}_${{ github.run_id }}_${{ github.run_number }} | ||
REFRESH_TOKEN_SECRET: ${{ secrets.GITHUB_TOKEN }}_${{ github.run_id }}_${{ github.run_attempt }} | ||
LAST_RESORT_SUPERADMIN_EMAIL: "[email protected]" | ||
COLORIZE_LOGS: "true" | ||
LOG_LEVEL: "info" | ||
RECAPTCHA_SITE_KEY: ${{secrets.RECAPTCHA_SITE_KEY}} | ||
RECAPTCHA_SECRET_KEY: ${{secrets.RECAPTCHA_SECRET_KEY}} | ||
MAIL_USERNAME: ${{secrets.MAIL_USERNAME}} | ||
MAIL_PASSWORD: ${{secrets.MAIL_PASSWORD}} | ||
|
||
Test-Builds: | ||
name: Test Development and Production Builds | ||
|
@@ -346,7 +470,7 @@ jobs: | |
LAST_RESORT_SUPERADMIN_EMAIL: "[email protected]" | ||
COLORIZE_LOGS: "true" | ||
LOG_LEVEL: "info" | ||
|
||
steps: | ||
- name: Checkout repository | ||
uses: actions/checkout@v4 | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
#!/bin/bash | ||
REPO_ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/../.." && pwd)" | ||
|
||
if ! command -v docker-compose &> /dev/null; then | ||
echo "Error: docker-compose is not installed" | ||
exit 1 | ||
fi | ||
|
||
docker-compose -f "${REPO_ROOT}/docker-compose.dev.yaml" down -v || { | ||
echo "Warning: Failed to stop containers. Continuing anyway..." | ||
} | ||
|
||
echo "docker-compose.dev.yaml file found. Ready to proceed." |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
#!/bin/bash | ||
set -e | ||
|
||
# Handle cleanup on script exit | ||
cleanup() { | ||
echo "Shutting down MongoDB..." | ||
mongod --shutdown | ||
exit 0 | ||
} | ||
trap cleanup SIGTERM SIGINT | ||
|
||
mongod --replSet rs0 --bind_ip_all --dbpath /data/db & | ||
MONGOD_PID=$! | ||
prayanshchh marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
# Wait for MongoDB to be ready | ||
MAX_TRIES=30 | ||
COUNTER=0 | ||
echo "Waiting for MongoDB to start..." | ||
until mongosh --eval "db.adminCommand('ping')" >/dev/null 2>&1; do | ||
if [ $COUNTER -gt $MAX_TRIES ]; then | ||
echo "Error: MongoDB failed to start" | ||
exit 1 | ||
fi | ||
let COUNTER=COUNTER+1 | ||
sleep 1 | ||
done | ||
|
||
# Initialize the replica set | ||
mongosh --eval ' | ||
config = { | ||
"_id" : "rs0", | ||
"members" : [ | ||
{ | ||
"_id" : 0, | ||
"host" : "mongo:27017", | ||
"priority": 1 | ||
} | ||
] | ||
}; | ||
|
||
while (true) { | ||
try { | ||
rs.initiate(config); | ||
break; | ||
} catch (err) { | ||
print("Failed to initiate replica set, retrying in 5 seconds..."); | ||
sleep(5000); | ||
} | ||
} | ||
' | ||
|
||
# Keep container running | ||
wait $MONGOD_PID |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1015,25 +1015,36 @@ async function main(): Promise<void> { | |
const REDIS_PASSWORD = ""; | ||
const MINIO_ENDPOINT = "http://minio:9000"; | ||
|
||
const { pwdVariable } = await inquirer.prompt({ | ||
type: "input", | ||
name: "pwdVariable", | ||
message: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why was this added? It should have been fixed in a previously merged PR. Please merge your code with the latest There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. sir my branch is working against develop branch, not |
||
"Please enter the value for PWD (working directory for Docker setup):", | ||
default: ".", | ||
}); | ||
|
||
const config = dotenv.parse(fs.readFileSync(".env")); | ||
|
||
config.MONGO_DB_URL = DB_URL; | ||
config.REDIS_HOST = REDIS_HOST; | ||
config.REDIS_PORT = REDIS_PORT; | ||
config.REDIS_PASSWORD = REDIS_PASSWORD; | ||
config.MINIO_ENDPOINT = MINIO_ENDPOINT; | ||
config.PWD = pwdVariable; | ||
|
||
process.env.MONGO_DB_URL = DB_URL; | ||
process.env.REDIS_HOST = REDIS_HOST; | ||
process.env.REDIS_PORT = REDIS_PORT; | ||
process.env.REDIS_PASSWORD = REDIS_PASSWORD; | ||
process.env.MINIO_ENDPOINT = MINIO_ENDPOINT; | ||
process.env.PWD = pwdVariable; | ||
|
||
updateEnvVariable(config); | ||
console.log(`Your MongoDB URL is:\n${process.env.MONGO_DB_URL}`); | ||
console.log(`Your Redis host is:\n${process.env.REDIS_HOST}`); | ||
console.log(`Your Redis port is:\n${process.env.REDIS_PORT}`); | ||
console.log(`Your MinIO endpoint is:\n${process.env.MINIO_ENDPOINT}`); | ||
console.log(`Your PWD value is:\n${process.env.PWD}`); | ||
} | ||
|
||
if (!isDockerInstallation) { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
.github/workflows/scripts
directory.github/workflows/pull-request.yml
It'll make maintenance easier in future
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
alright will create a new file for the docker script and reference it in this file