Skip to content

Commit

Permalink
Add test and build jobs
Browse files Browse the repository at this point in the history
  • Loading branch information
thomashbrnrd committed Oct 9, 2023
1 parent 4e000cf commit 23a9e3a
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 12 deletions.
33 changes: 33 additions & 0 deletions .github/workflows/pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,39 @@ jobs:
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: docker/setup-qemu-action@v3
- uses: docker/setup-buildx-action@v3
- uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Build and push
uses: docker/build-push-action@v5
with:
context: ./backend
push: true
tags: ghcr.io/datalab-mi/basegun/basegun-backend:${{ github.head_ref }}
target: dev

test:
needs: build
runs-on: ubuntu-latest
container:
image: ghcr.io/datalab-mi/basegun/basegun-backend:${{ github.head_ref }}
env:
WORKSPACE: dev
AWS_REGION: gra
AWS_DEFAULT_REGION: gra
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
steps:
- run: cd /app && python -m unittest

build-and-test:
uses: ./.github/workflows/test-on-kube.yml
needs: tag-pr
Expand Down
6 changes: 1 addition & 5 deletions .github/workflows/test-on-kube.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ jobs:
- name: Build and install basegun with helm, and test if deployment is successful
id: tests
run: |
TAG=$(make get-current-tag) BUILD_TARGET=test docker-compose -f docker-compose-prod.yml build
TAG=$(make get-current-tag) BUILD_TARGET=prod docker-compose -f docker-compose-prod.yml build
kind load docker-image \
basegun-backend:$(make get-current-tag) \
basegun-frontend:$(make get-current-tag) \
Expand All @@ -70,10 +70,6 @@ jobs:
kubectl logs deploy/basegun-backend --all-containers --ignore-errors
kubectl logs deploy/basegun-frontend --all-containers --ignore-errors
- name: Test unitests on backend
run : |
kubectl exec deploy/basegun-backend -c basegun-backend -- python -m unittest discover -v
- name: Setup nodejs (for cypress)
uses: actions/setup-node@v3
with:
Expand Down
7 changes: 1 addition & 6 deletions backend/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,9 @@ RUN mkdir -p src/weights \
&& mv model.pth src/weights/model.pth \
&& echo '{"app": "'${VERSION}'", "model": "'${MODEL}'"}' > versions.json

# launch website
FROM base as dev
CMD ["uvicorn", "src.main:app", "--reload", "--host", "0.0.0.0", "--port", "5000"]

FROM base as test
RUN pip install requests && rm -r /root/.cache
COPY tests/ tests/
CMD ["uvicorn", "src.main:app", "--host", "0.0.0.0", "--port", "5000"]
CMD ["uvicorn", "src.main:app", "--reload", "--host", "0.0.0.0", "--port", "5000"]

FROM base as prod
RUN pip install --extra-index-url https://download.pytorch.org/whl/cpu \
Expand Down
2 changes: 1 addition & 1 deletion backend/tests/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ def test_home(self):
def test_version(self):
"""Checks that the route /version sends a version"""
response = client.get("/version")
self.assertNotEqual(response.text, "-1")
self.assertNotEqual(response.status_code, 200)
self.assertEqual(len(response.text.split('.')), 2) # checks version has format X.Y

def check_log_base(self, log):
Expand Down

0 comments on commit 23a9e3a

Please sign in to comment.