Compare commits

..

8 Commits

Author SHA1 Message Date
hasslesstech d60b5a0f0f fix workflows for multiple branches
test-backend / test-x86_64 (push) Successful in 23s
2025-05-25 22:48:03 +03:00
hasslesstech fd3fa4b531 fix backend testing script
test-backend / test-x86_64 (push) Successful in 23s
2025-05-25 21:59:37 +03:00
hasslesstech 8454474820 increase testing consistency
test-backend / test-x86_64 (push) Failing after 24s
2025-05-25 21:57:15 +03:00
hasslesstech 13b6bf3fde make cleanup happen even if workflow fails
test-backend / test-x86_64 (push) Failing after 29s
2025-05-25 21:56:04 +03:00
hasslesstech 79ef0a093c improve testing workflow
test-backend / test-x86_64 (push) Failing after 13s
2025-05-25 21:21:16 +03:00
hasslesstech c75f55c050 improve testing performance
test-backend / test-x86_64 (push) Successful in 7s
2025-05-25 21:06:27 +03:00
hasslesstech 642c1fa944 add postgresql container to run tests in
test-backend / test-x86_64 (push) Successful in 22s
2025-05-25 19:51:17 +03:00
hasslesstech 393b426e85 add workflow for building containers 2025-05-25 18:06:25 +03:00
9 changed files with 189 additions and 17 deletions
@@ -0,0 +1,57 @@
name: build-container-backend
on:
workflow_dispatch:
jobs:
build-x86_64:
runs-on: hardware-x86_64
steps:
- name: Pull repository
run: |
git init
git remote add gitea http://10.1.1.1:3000/hasslesstech/sdlc-project
git fetch gitea
git checkout ${{ gitea.ref_name }}
- name: Build docker image
run: docker build backend/ -f backend/Dockerfile-x86_64 -t 10.5.1.5:5000/sdlc/x86_64
- name: Push docker image to registry
run: docker push 10.5.1.5:5000/sdlc/x86_64
build-x86_64-testing:
runs-on: hardware-x86_64
steps:
#- name: Install docker
# shell: sh
# run: apk --update add docker
#- name: Install git
# shell: sh
# run: apk add git
- 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: Build docker image
shell: sh
run: DOCKER_BUILDKIT=1 docker build backend/ -f tests/backend-testing-env -t 10.5.1.5:5000/sdlc/x86_64-testing
- name: Push docker image to registry
shell: sh
run: docker push 10.5.1.5:5000/sdlc/x86_64-testing
# build-armv7:
# runs-on: hardware-armv7
# steps:
# - name: Pull repository
# run: |
# git init
# git remote add gitea http://10.1.1.1:3000/hasslesstech/sdlc-project
# git fetch gitea
# git checkout gitea/master
# - name: Build docker image
# run: docker build backend/ -f backend/Dockerfile-armv7 -t 10.5.1.5:5000/sdlc/armv7
# - name: Push docker image to registry
# run: docker push 10.5.1.5:5000/sdlc/armv7
+34
View File
@@ -0,0 +1,34 @@
name: test-backend
on:
push:
jobs:
test-x86_64:
runs-on: hardware-x86_64
steps:
- 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.ref_name }}
- name: Deploy testing environment
shell: sh
run: docker-compose -f backend/docker-compose-x86_64.yaml up -d --force-recreate
- name: Add tables to DB
shell: sh
run: docker-compose -f backend/docker-compose-x86_64.yaml exec -T postgres psql -U postgres < backend/db/create.sql
- name: Populate DB
shell: sh
run: docker-compose -f backend/docker-compose-x86_64.yaml exec -T postgres psql -U postgres < backend/db/populate.sql
- name: Run test requests
shell: sh
run: |
chmod +x tests/backend.sh
tests/backend.sh
- name: Clean up testing environment
if: always()
shell: sh
run: docker-compose -f backend/docker-compose-x86_64.yaml down
@@ -1,6 +1,6 @@
FROM alpine:latest AS build FROM alpine:latest AS build
RUN apk add python3 RUN apk --update add python3
RUN mkdir /venv /app RUN mkdir /venv /app
RUN python3 -m venv /venv RUN python3 -m venv /venv
ENV PATH="/venv/bin:$PATH" ENV PATH="/venv/bin:$PATH"
@@ -8,13 +8,6 @@ ENV PATH="/venv/bin:$PATH"
RUN apk add build-base linux-headers musl-dev python3-dev libpq-dev RUN apk add build-base linux-headers musl-dev python3-dev libpq-dev
RUN pip3 install flask uwsgi psycopg2 RUN pip3 install flask uwsgi psycopg2
#FROM alpine:latest AS prod
#RUN apk add python3
#ENV PATH="/venv/bin:$PATH"
#COPY --from=build /venv /venv
EXPOSE 9090/tcp EXPOSE 9090/tcp
ENTRYPOINT ["uwsgi", "--http", ":9090", "--callable", "app", "--wsgi-file", "/app/main.py"] ENTRYPOINT ["uwsgi", "--http", ":9090", "--callable", "app", "--wsgi-file", "/app/main.py"]
+7
View File
@@ -0,0 +1,7 @@
INSERT INTO public.movie (uuid, name, scheduled_datetime, movie_details, image_url, max_passes)
VALUES ('742a2542-2b50-11f0-ae4c-f7bedd5fcc88',
'Movie 1',
'1997-12-15 21:30:00',
'This movie dives deep into many topics...',
'https://cdn.cinema.com/img/movie1.webp',
150);
+37
View File
@@ -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:
-8
View File
@@ -1,8 +0,0 @@
services:
backend:
build: .
ports:
- "80:9090"
volumes:
- "./src/:/app:ro"
env_file: backend.env
+7
View File
@@ -16,7 +16,14 @@ db_params = {
'port': int(env.get('DB_PORT')) 'port': int(env.get('DB_PORT'))
} }
db = None
for _ in range(5):
try:
db = psql.connect(**db_params) db = psql.connect(**db_params)
except Exception as e:
print(f"Failed to connect ({e}), retrying...")
time.sleep(5)
class PassQueue: class PassQueue:
def __init__(self): def __init__(self):
+4
View File
@@ -0,0 +1,4 @@
FROM alpine:latest
RUN --mount=type=bind,source=/var/run/docker.sock,target=/var/run/docker.sock apk --update add git docker docker-compose postgresql
RUN --mount=type=bind,source=/var/run/docker.sock,target=/var/run/docker.sock docker pull postgres
+41
View File
@@ -0,0 +1,41 @@
#!/bin/sh
assert_good_status () {
if [ $? -ne 0 ]; then
exit 1
fi
}
assert_bad_status () {
if [ $? -eq 0 ]; then
exit 1
fi
}
HOST=127.0.0.1
ARGS="--fail-with-body"
curl $ARGS http://$HOST/movies
assert_good_status
curl $ARGS http://$HOST/passes
assert_good_status
curl -X POST $ARGS http://$HOST/apply_for_pass
assert_bad_status
curl -X POST $ARGS http://$HOST/apply_for_pass \
-H "Content-Type: application/json" \
--data '{"first": "Hannah",
"last": "Dirt",
"email": "hannah.dirt@mail.com",
"type": 1,
"price": 50,
"movie_uuid": "742a2542-2b50-11f0-ae4c-f7bedd5fcc88"}'
assert_good_status
sleep 5
curl $ARGS -s http://$HOST/passes
test "$(curl $ARGS -s http://$HOST/passes | jq '.result.[0]')" != "null"
assert_good_status