diff --git a/.gitea/workflows/test-backend.yaml b/.gitea/workflows/test-backend.yaml new file mode 100644 index 0000000..7304aed --- /dev/null +++ b/.gitea/workflows/test-backend.yaml @@ -0,0 +1,29 @@ +name: test-backend + +on: + push: + +jobs: + test-x86_64: + runs-on: alpine + steps: + - name: Install tools for testing + shell: sh + run: | + apk --update add git docker docker-compose postgresql + - name: Pull postgres docker image + shell: sh + run: docker pull postgres + - name: Pull custom docker image + shell: sh + run: docker pull 10.5.1.5:5000/sdlc/x86_64 + - name: Pull repository + shell: sh + run: | + git init + git remote add gitea http://10.1.1.1:3000/hasslesstech/sdlc-project + git fetch gitea + git checkout gitea/master + - name: Deploy testing environment + shell: sh + run: docker-compose up -d -f backend/docker-compose-x86_64.yaml diff --git a/backend/Dockerfile-armv7 b/backend/Dockerfile-armv7 deleted file mode 100644 index 94475c4..0000000 --- a/backend/Dockerfile-armv7 +++ /dev/null @@ -1,13 +0,0 @@ -FROM cmosh/alpine-arm AS build - -RUN apk --update add python3 -RUN mkdir /venv /app -RUN python3 -m venv /venv -ENV PATH="/venv/bin:$PATH" - -RUN apk add build-base linux-headers musl-dev python3-dev libpq-dev -RUN pip3 install flask uwsgi psycopg2 - -EXPOSE 9090/tcp - -ENTRYPOINT ["uwsgi", "--http", ":9090", "--callable", "app", "--wsgi-file", "/app/main.py"] diff --git a/backend/docker-compose-x86_64.yaml b/backend/docker-compose-x86_64.yaml new file mode 100644 index 0000000..b263598 --- /dev/null +++ b/backend/docker-compose-x86_64.yaml @@ -0,0 +1,37 @@ +services: + postgres: + image: postgres + environment: + - POSTGRES_USER=postgres + - POSTGRES_PASSWORD=postgres + - POSTGRES_DB=postgres + networks: + - testing + healthcheck: + test: ["CMD-SHELL", "pg_isready -U ${POSTGRES_USER} -d ${POSTGRES_DB}"] + interval: 10s + retries: 5 + start_period: 30s + timeout: 3s + + backend: + image: 10.5.1.5:5000/sdlc/x86_64 + ports: + - "80:9090" + volumes: + - "./src/:/app:ro" + environment: + - DB_NAME=postgres + - DB_USER=postgres + - DB_PASS=postgres + - DB_HOST=postgres + - DB_PORT=5432 + networks: + - testing + depends_on: + postgres: + condition: service_healthy + # restart: true + +networks: + testing: diff --git a/backend/docker-compose.yaml b/backend/docker-compose.yaml deleted file mode 100644 index 33060e4..0000000 --- a/backend/docker-compose.yaml +++ /dev/null @@ -1,8 +0,0 @@ -services: - backend: - build: . - ports: - - "80:9090" - volumes: - - "./src/:/app:ro" - env_file: backend.env diff --git a/backend/src/main.py b/backend/src/main.py index 952b3e6..5249185 100644 --- a/backend/src/main.py +++ b/backend/src/main.py @@ -16,7 +16,14 @@ db_params = { 'port': int(env.get('DB_PORT')) } -db = psql.connect(**db_params) +db = None + +for _ in range(5): + try: + db = psql.connect(**db_params) + except Exception as e: + print(f"Failed to connect ({e}), retrying...") + time.sleep(5) class PassQueue: def __init__(self):