diff --git a/.github/workflows/basic-build-test-ci.yml b/.github/workflows/basic-build-test-ci.yml new file mode 100644 index 0000000..7b9a4db --- /dev/null +++ b/.github/workflows/basic-build-test-ci.yml @@ -0,0 +1,151 @@ +name: CI/CD MyLibrary Backend build and test + +# This workflow will build docker image and run tests inside the container. +# only executed if there are changes on: workflows folder, requirement.txt, DockerFile, docker-compose files and .env file + +on: + pull_request: + branches: + - main # executed on every pull request to main + + paths: + - '.github/workflows/**' + - ' app/requirements.txt' + - ' app/DockerFile + - ' docker-compose-dev-yml ' + - ' docker-compose.yml' + - '.env' + + + push: + branches: + - main + + release: + types: [published] + + # allows to manually start a workflow run from the GitHub UI or using the GitHub API. + workflow_dispatch: + inputs: + push-image: + description: "Push image to docker hub" + required: false + type: boolean + default: false + push-description: + description: "Update docker hub description" + required: false + type: boolean + default: false + tag: + description: "Tag for the docker image" + required: false + default: "workflow-dispatch" + + +jobs: + + build-and-test: + runs-on: ubuntu-latest + + steps: + - name: Checkout Code + uses: actions/checkout@v4 + + + - name: Setup Python + uses: actions/setup-python@v5 + with: + python-version: '3.10' + + - name: install deps + run: | + python -m pip install --upgrade pip + pip install -r ./app/requirements.txt + + - name: run Tests + run: echo " TODO implement test on pytest" + + + docker-img: + needs: build-and-test + runs-on: ubuntu-latest + + steps: + - name: Checkout Code + uses: actions/checkout@v4 + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + + - name: Log in to DockerHub + uses: docker/login-action@v3 + with: + username: ${{ secrets.DOCKERHUB_USERNAME }} + password: ${{ secrets.DOCKERHUB_TOKEN }} + + - name: Build and push Docker image (Dev) + uses: docker/build-push-action@v5 + with: + context: . + file: ./app/Dockerfile + tags: aiod/mylibrary-backend-api:develop + outputs: type=docker,dest=/tmp/aiod_my_library_backend_dev.tar + cache-from: type=gha + cache-to: type=gha,mode=min + + + - name: Store Image dev + uses: actions/upload-artifact@v4 + with: + name: aiod_my_library_backend_dev + path: /tmp/aiod_my_library_backend_dev.tar + + + publish: + needs: [docker-img] + runs-on: ubuntu-latest + if: github.event_name != 'pull_request' + steps: + - name: Set Develop Tag + if: github.ref == 'refs/heads/develop' + run: echo "IMAGE_TAGS=aiod/mylibrary-backend-api:develop" >> "$GITHUB_ENV" + + - name: Set Release Tag + if: github.event_name == 'release' + run: echo "IMAGE_TAGS=aiod/mylibrary-backend:latest,aiod/mylibrary-backend:${{ github.event.release.tag_name }}" >> "$GITHUB_ENV" + + - name: Set Dispatch Tag + if: github.event_name == 'workflow_dispatch' + run: echo "IMAGE_TAGS=aiod/mylibrary-backend:${{ inputs.tag }}" >> "$GITHUB_ENV" + - uses: actions/checkout@v4 + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + - uses: docker/login-action@v3 + with: + username: ${{ secrets.DOCKERHUB_USERNAME }} + password: ${{ secrets.AIOD_DOCKER_PAT }} + - name: Echo tags + run: echo $IMAGE_TAGS + - name: Build + if: (github.event_name != 'workflow_dispatch') || inputs.push-image + uses: docker/build-push-action@v5 + with: + push: true + context: . + file: ./Dockerfile + tags: ${{ env.IMAGE_TAGS }} + cache-from: type=gha + cache-to: type=gha,mode=min + - name: Update repository description + if: (github.event_name == 'release') || inputs.push-description + uses: peter-evans/dockerhub-description@v4 + with: + username: ${{ secrets.DOCKERHUB_USERNAME }} + password: ${{ secrets.AIOD_DOCKER_PAT }} + repository: aiod/mylibrary-backend + readme-filepath: ./docker-description.md + short-description: "My library Backend API for AI on Demand." + + - name: Verify pushed image (optional) + run: docker pull ${{ env.IMAGE_TAGS }} diff --git a/.github/workflows/unit-test-ci.yml b/.github/workflows/unit-test-ci.yml new file mode 100644 index 0000000..4a72d95 --- /dev/null +++ b/.github/workflows/unit-test-ci.yml @@ -0,0 +1,43 @@ +name: CI/CD MyLibrary Backend build and test + +# This workflow will run unit tests with Pytest TODO: IMPLEMENT TEST ON PYTEST +# This workflow is only executed if there is pull request with change in app folder, + + +on: + pull_request: + branches: + - main # executed on every pull request to main + + paths: + - 'app/**' + + + push: + branches: + - main + + release: + types: [published] + +jobs: + + build-and-test: + runs-on: ubuntu-latest + + steps: + - name: Checkout Code + uses: actions/checkout@v4 + + - name: Setup Python + uses: actions/setup-python@v5 + with: + python-version: '3.10' + + - name: install deps + run: | + python -m pip install --upgrade pip + pip install -r ./app/requirements.txt + + - name: run Tests + run: echo " TODO implement test on pytest" diff --git a/app/Dockerfile b/app/Dockerfile index 09ee37a..e900c60 100644 --- a/app/Dockerfile +++ b/app/Dockerfile @@ -6,7 +6,7 @@ ENV PYTHONDONTWRITEBYTECODE 1 ENV PYTHONUNBUFFERED 1 RUN pip install --upgrade pip -COPY requirements.txt /code/ +COPY ./app/requirements.txt /code/ RUN pip install -r requirements.txt COPY . ./code/ diff --git a/docker-description.md b/docker-description.md new file mode 100644 index 0000000..1432452 --- /dev/null +++ b/docker-description.md @@ -0,0 +1,11 @@ +# AIOD MyLibrary FrontEnd + +Image for AI on Demand's (AIOD) MyLibrary Backend, developed on [Github](https://github.com/aiondemand/AIOD-mylibrary-backend/). +This image requires a properly configured authentication (via Keycloak). Please refer to the documentation available in the "README"⁠ of the repository. ["AIOD-myLibrary-api"](https://github.com/aiondemand/AIOD-mylibrary-backend/) repository. + +The following tags are available: + + - `latest`: the latest official release + - `develop`: the head of the development branch + - `v*`, e.g. `v1.3.20240308`: that specific release + - a number of custom tags may be introduced for testing, but these are not intended for general use. \ No newline at end of file