Skip to content

Commit

Permalink
feat: script to start all service, database migration and starting up…
Browse files Browse the repository at this point in the history
… the backend server all together.

- update docs accordingly
  • Loading branch information
Shaktizala committed Jan 31, 2024
1 parent 3e43356 commit 55039ca
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 0 deletions.
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,14 @@ Ory Kratos doesn't provide UI, You have to specify the endpoints for different U
3. Build image using ```docker build -t golang-api .```
4. Run ```docker run golang-api``` to run the container.

**Another Way:**
- For starting All services including kratos, runinng databse migrations and starting up golang server all together, run the script `local.sh` inside `/pkg/kratos`.
```bash
cd pkg/kratos
./local.sh
```
**Note:** Use this for local development environment.

### **Migrations**
- **CREATE :** To create migrations i have discribed details in [Kick Start Commands](#kick-start-commands) section.
- **RUN :** To run migration there is two command `make migration-up` && `make migration-down`.
Expand Down
1 change: 1 addition & 0 deletions docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ version: "3.8"
services:
postgresdb:
image: postgres:15.2-alpine
container_name: golang-api-postgresdb
environment:
POSTGRES_USER: golang-api
POSTGRES_PASSWORD: golang-api
Expand Down
30 changes: 30 additions & 0 deletions pkg/kratos/local.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#!/bin/sh

# starting up all services including kratos
docker-compose --profile kratos up -d

# function to check if the docker container is running
container_is_running() {
docker inspect -f '{{.State.Running}}' "$1" 2>/dev/null
}

# function to wait for a docker container to start
wait_for_container() {
container_name=$1
while ! container_is_running $container_name; do
sleep 1
done
# extra delay to wait, otherwise gettinng error while connecting to database while migrating
sleep 2
echo "===== Container $container_name is running"
}

wait_for_container "golang-api-postgresdb"

echo "===== Running the migrations..."
# running the migrations
make -C ../../. migrate-up

echo "===== Starting golang api server..."
# starting the golang backend server
make -C ../../. start-api

0 comments on commit 55039ca

Please sign in to comment.