Skip to content

Commit bb053a7

Browse files
committed
refactor: extract commands from Makefile to bash scripts
1 parent 88e329d commit bb053a7

File tree

7 files changed

+25
-9
lines changed

7 files changed

+25
-9
lines changed

.dockerignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
.git
2-
__pycache__
2+
__pycache__
3+
./scripts

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,5 +159,6 @@ cython_debug/
159159
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
160160
#.idea/
161161

162+
Instructions.md
162163

163-
Instructions.md
164+
.idea

Makefile

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,10 @@ help: ##@target Show target help options.
2424
@perl -e '$(HELP_FUN)' $(MAKEFILE_LIST)
2525

2626
start-app-db: FORCE ##@target Starts the app and db with sample data dump
27-
docker compose up -d ;\
28-
docker compose exec db /bin/bash ./opt/upload.sh
27+
./scripts/start.sh
28+
29+
stop-app-db: FORCE ##@target stops the app and db with sample data dump
30+
docker compose down && docker container prune -f && docker rmi abhisheksr01/python-postgres-azure:0.0.1 -f && docker ps -a
2931

3032
clear: FORCE ##@target Clears the "__pycache__" & ".pytest_cache". Will be required to run twice.
3133
@find . -name "__pycache__" -exec rm -rf {} \;

db/upload.sh

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +0,0 @@
1-
#!/usr/bin/env bash
2-
psql -h localhost -U postgres < ./opt/rates.sql
3-
psql -h localhost -U postgres -c "SELECT 'alive'"
4-
psql -h localhost -U postgres -c "SELECT current_database();"

docker-compose.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ version: '3'
33
services:
44
app:
55
image: 'abhisheksr01/python-postgres-azure:0.0.1'
6+
restart: on-failure
67
build:
78
context: .
89
container_name: app
@@ -24,4 +25,5 @@ services:
2425
- POSTGRES_USER=postgres
2526
- POSTGRES_PASSWORD=secret
2627
volumes:
27-
- ./db/:/opt/
28+
- ./db/:/opt/
29+
- ./scripts/upload.sh:/opt/upload.sh

scripts/start.sh

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#!/usr/bin/env bash
2+
echo "** Starting the app and db"
3+
docker compose up -d
4+
echo "** Sleeping for 10 sec to ensure db services are running before uploading dump data"
5+
sleep 10
6+
echo "** Uploading dump data & then sleeping for 5 sec **"
7+
docker compose exec db /bin/bash ./opt/upload.sh
8+
sleep 5
9+
echo "Performing Health Check on the App"
10+
curl "http://127.0.0.1:3000/"

scripts/upload.sh

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#!/usr/bin/env bash
2+
psql -h localhost -U postgres < ./opt/rates.sql
3+
psql -h localhost -U postgres -c "SELECT 'alive'"
4+
psql -h localhost -U postgres -c "SELECT current_database();"

0 commit comments

Comments
 (0)