Skip to content

Commit

Permalink
Add debug logs
Browse files Browse the repository at this point in the history
Signed-off-by: Tiago Góes <[email protected]>
  • Loading branch information
tiagodread committed Aug 20, 2024
1 parent 26001ca commit f059da3
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 29 deletions.
52 changes: 28 additions & 24 deletions .github/workflows/build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ on:
branches: [ "main" ]
env:
SHA: ${{ github.sha }}
POSTGRES_USER: ${{ secrets.POSTGRES_USER }}
POSTGRES_PASSWORD: ${{ secrets.POSTGRES_PASSWORD }}
POSTGRES_DB: ${{ secrets.POSTGRES_DB }}
POSTGRES_HOST: ${{ secrets.POSTGRES_HOST }}

jobs:
run-api-tests:
Expand All @@ -13,38 +17,38 @@ jobs:
- uses: actions/checkout@v4

- name: Start containers
uses: hoverkraft-tech/[email protected]
env:
SHA: ${{ env.SHA }}
up-flags: "--force-recreate"
run: |
docker compose build
docker image ls
docker compose up -d --force-recreate
- name: Wait for containers
run: |
docker ps
docker logs database
max_attempts=3
attempt=1
# max_attempts=3
# attempt=1
while [ $attempt -le $max_attempts ]; do
if curl -s http://0.0.0.0:8080/health | grep -q '"status":"OK"'; then
echo "Container is up and healthy!"
break
else
echo "Attempt $attempt/$max_attempts: Waiting for container..."
attempt=$((attempt + 1))
if [ $attempt -le $max_attempts ]; then
sleep 60 # Wait for 60 seconds before the next attempt
fi
fi
done
# while [ $attempt -le $max_attempts ]; do
# if curl -s http://0.0.0.0:8080/health | grep -q '"status":"OK"'; then
# echo "Container is up and healthy!"
# break
# else
# echo "Attempt $attempt/$max_attempts: Waiting for container..."
# attempt=$((attempt + 1))
# if [ $attempt -le $max_attempts ]; then
# sleep 60 # Wait for 60 seconds before the next attempt
# fi
# fi
# done
if [ $attempt -gt $max_attempts ]; then
echo "Container failed to become healthy after $max_attempts attempts."
exit 1
fi
# if [ $attempt -gt $max_attempts ]; then
# echo "Container failed to become healthy after $max_attempts attempts."
# exit 1
# fi
- name: Test
run: go test -v ./...
# - name: Test
# run: go test -v ./...

# build-push-docker-image:
# runs-on: ubuntu-latest
Expand Down
File renamed without changes.
10 changes: 10 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
FROM golang:1.22

ARG POSTGRES_USER
ARG POSTGRES_PASSWORD
ARG POSTGRES_DB
ARG POSTGRES_HOST

ENV POSTGRES_USER=$POSTGRES_USER
ENV POSTGRES_PASSWORD=$POSTGRES_PASSWORD
ENV POSTGRES_DB=$POSTGRES_DB
ENV POSTGRES_HOST=$POSTGRES_HOST

WORKDIR /app

COPY . /app
Expand Down
9 changes: 4 additions & 5 deletions src/db/conn.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,15 @@ import (
"database/sql"
"fmt"
"log"
"os"

_ "github.com/lib/pq"
)

func ConnectDB() (*sql.DB, error) {
POSTGRES_PASSWORD := os.Getenv("POSTGRES_PASSWORD")
POSTGRES_USER := os.Getenv("POSTGRES_USER")
POSTGRES_DB := os.Getenv("POSTGRES_DB")
POSTGRES_HOST := os.Getenv("POSTGRES_HOST")
POSTGRES_PASSWORD := "1234" //os.Getenv("POSTGRES_PASSWORD")
POSTGRES_USER := "postgres" // os.Getenv("POSTGRES_USER")
POSTGRES_DB := "postgres" // os.Getenv("POSTGRES_DB")
POSTGRES_HOST := "db" // os.Getenv("POSTGRES_HOST")

DATABASE_URL := fmt.Sprintf("postgres://%s:%s@%s:5432/%s?sslmode=disable", POSTGRES_USER, POSTGRES_PASSWORD, POSTGRES_HOST, POSTGRES_DB)

Expand Down

0 comments on commit f059da3

Please sign in to comment.