Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
151 changes: 151 additions & 0 deletions .github/workflows/basic-build-test-ci.yml
Original file line number Diff line number Diff line change
@@ -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 }}
43 changes: 43 additions & 0 deletions .github/workflows/unit-test-ci.yml
Original file line number Diff line number Diff line change
@@ -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"
2 changes: 1 addition & 1 deletion app/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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/
Expand Down
11 changes: 11 additions & 0 deletions docker-description.md
Original file line number Diff line number Diff line change
@@ -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.