Compare commits
8 Commits
99152733ce
...
master
| Author | SHA1 | Date | |
|---|---|---|---|
| d60b5a0f0f | |||
| fd3fa4b531 | |||
| 8454474820 | |||
| 13b6bf3fde | |||
| 79ef0a093c | |||
| c75f55c050 | |||
| 642c1fa944 | |||
| 393b426e85 |
@@ -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
|
||||
@@ -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
|
||||
|
||||
RUN apk add python3
|
||||
RUN apk --update add python3
|
||||
RUN mkdir /venv /app
|
||||
RUN python3 -m venv /venv
|
||||
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 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
|
||||
|
||||
ENTRYPOINT ["uwsgi", "--http", ":9090", "--callable", "app", "--wsgi-file", "/app/main.py"]
|
||||
@@ -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);
|
||||
@@ -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:
|
||||
@@ -1,8 +0,0 @@
|
||||
services:
|
||||
backend:
|
||||
build: .
|
||||
ports:
|
||||
- "80:9090"
|
||||
volumes:
|
||||
- "./src/:/app:ro"
|
||||
env_file: backend.env
|
||||
+8
-1
@@ -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):
|
||||
|
||||
@@ -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
|
||||
@@ -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
|
||||
Reference in New Issue
Block a user