Skip to content

Commit

Permalink
Merge branch 'master' of github.com:wmgeolab/scope
Browse files Browse the repository at this point in the history
  • Loading branch information
jamesnelmore committed Nov 2, 2024
2 parents 8ecb8b3 + d21f699 commit 7314afe
Show file tree
Hide file tree
Showing 4 changed files with 163 additions and 7 deletions.
46 changes: 46 additions & 0 deletions .github/workflows/build-backend-image.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
name: Build Backend Docker Image

on:
push:
branches:
- master
- "backend/"
- "backend/scopeBackend"
pull_request:
branches:
- master
- "backend/"
- "backend/scopeBackend"
# these path settings ensure this workflow only executes on a push
# to this YML itself, or any file in the backend or scopeBackend folders

jobs:
build:
runs-on: ubuntu-latest
permissions:
contents: read
packages: write

steps:
- name: Check out the repository
uses: actions/checkout@v4

- name: Log in to GitHub Container Registry
uses: docker/login-action@v2
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
# GitHub sets up this token for you

- name: Create db_config.cnf
run: echo "${{ secrets.DB_CONFIG }}" > ./backend/db_config.cnf

- name: Build and push the Docker image
run: docker build -t ghcr.io/${{ github.repository_owner }}/backend:latest ./backend

- name: Push the Docker image
run: docker push ghcr.io/${{ github.repository_owner }}/backend:latest

- name: Delete db_config.cnf
run: rm ./backend/db_config.cnf
10 changes: 5 additions & 5 deletions backend/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,25 +1,25 @@

FROM docker.io/library/python:3.11-slim

EXPOSE 8000

WORKDIR /app
COPY . /app

# FIRST: Copy the db_config.cnf from the scope/ folder into the scope/backend/ folder.
COPY ./db_config.cnf /
WORKDIR /app

ENV PYTHONUNBUFFERED=1

RUN groupadd app -g 1000 \
&& useradd -m -u 1000 -g app app \
&& apt-get update \
&& apt-get install -y default-libmysqlclient-dev build-essential \
&& apt-get install -y --no-install-recommends default-libmysqlclient-dev build-essential \
&& pip install --no-cache-dir -r requirements.txt \
&& apt-get purge -y --auto-remove build-essential \
&& rm -Rf /var/lib/apt/lists/* \
&& rm -rf /var/lib/apt/lists/* \
&& chown -R app:app /app

USER app

EXPOSE 8000

CMD ["python3", "manage.py", "runserver", "0.0.0.0:8000"]
110 changes: 110 additions & 0 deletions backend/scopeBackend/Hurl Endpoint Tests.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
#Create a workspace
POST http://127.0.0.1:8000/api/workspaces/
Authorization: Token fadc41688e2228acb6c2cd435362f4eda6f4130d
Content-Type: application/json

{
"name": "test222",
"password": "test222"
}
HTTP 201

DELETE http://127.0.0.1:8000/api/workspaces/
Authorization: Token fadc41688e2228acb6c2cd435362f4eda6f4130d
Content-Type: application/json

{
"name": "test222",
"password": "test222"
}
HTTP 200

#Get all workspaces that a user is in
GET http://127.0.0.1:8000/api/workspaces/
Authorization: Token fadc41688e2228acb6c2cd435362f4eda6f4130d
Content-Type: application/json
HTTP 201

#Delete a workspace
POST http://127.0.0.1:8000/api/workspaces/
Authorization: Token fadc41688e2228acb6c2cd435362f4eda6f4130d
Content-Type: application/json

{
"name": "test222",
"password": "test222"
}
HTTP 201

DELETE http://127.0.0.1:8000/api/workspaces/
Authorization: Token fadc41688e2228acb6c2cd435362f4eda6f4130d
Content-Type: application/json

{
"name": "test222",
"password": "test222"
}
HTTP 200

#Add a tag to a workspace
POST http://127.0.0.1:8000/api/workspaces/
Authorization: Token fadc41688e2228acb6c2cd435362f4eda6f4130d
Content-Type: application/json

{
"name": "test222",
"password": "test222"
}
HTTP 201
[Captures]
workspace: jsonpath "$.workspace"

POST http://127.0.0.1:8000/api/tags/
Authorization: Token fadc41688e2228acb6c2cd435362f4eda6f4130d
Content-Type: application/json

{
"workspace": {{workspace}},
"tag": "tag"
}
HTTP 201

DELETE http://127.0.0.1:8000/api/workspaces/
Authorization: Token fadc41688e2228acb6c2cd435362f4eda6f4130d
Content-Type: application/json

{
"name": "test222",
"password": "test222"
}
HTTP 200

#Joining a workspace
POST http://127.0.0.1:8000/api/workspaces/
Authorization: Token fadc41688e2228acb6c2cd435362f4eda6f4130d
Content-Type: application/json

{
"name": "test222",
"password": "test222"
}
HTTP 201

GET http://127.0.0.1:8000/api/workspaces/join/
Authorization: Token fadc41688e2228acb6c2cd435362f4eda6f4130d
Content-Type: application/json
{
"name": "test222",
"password": "test222"
}
HTTP 201

DELETE http://127.0.0.1:8000/api/workspaces/
Authorization: Token fadc41688e2228acb6c2cd435362f4eda6f4130d
Content-Type: application/json

{
"name": "test222",
"password": "test222"
}
HTTP 200
4 changes: 2 additions & 2 deletions backend/scopeBackend/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@ def delete(self, request):
if workspace.creatorId != self.request.user:
return Response({'error':'Only the workspace creator can delete'}, status=status.HTTP_403_FORBIDDEN)
# workspace.delete()
workspace.hidden = True
#workspace.hidden = True
return Response('Workspace has been deleted', status=status.HTTP_200_OK)

# accessible at /api/workspaces/ [POST]
Expand Down Expand Up @@ -447,7 +447,7 @@ class TestView(viewsets.ModelViewSet):

def get_queryset(self):
return Response({"success":"Test view reached!"}, status=status.HTTP_200_OK)

class AiResponseView(viewsets.ModelViewSet):
permission_classes = [IsAuthenticated]
serializer_class = AiResponseSerializer
Expand Down

0 comments on commit 7314afe

Please sign in to comment.