Allow the confoguration of the mongodb host, adds flexibility to the … #84
Workflow file for this run
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# This workflow will build the project with multiple Python versions, lint, run | |
# tests, and build and push Docker images. | |
# For more information see: | |
# https://help.github.com/actions/language-and-framework-guides/using-python-with-github-actions | |
name: Python package | |
on: | |
push: | |
branches: [ dev ] | |
pull_request: | |
branches: [ dev ] | |
jobs: | |
Test: | |
name: Run linting, unit and integration tests | |
runs-on: ubuntu-latest | |
strategy: | |
fail-fast: true | |
matrix: | |
py-version-img: [ | |
["3.8", "3.8-slim-buster"], | |
["3.9", "3.9-slim-buster"], | |
["3.10", "3.10-slim-buster"], | |
] | |
steps: | |
- uses: actions/checkout@v3 | |
- name: Set up Python ${{ matrix.py-version-img[0] }} | |
uses: actions/setup-python@v4 | |
with: | |
python-version: ${{ matrix.py-version-img[0] }} | |
- name: Install requirements | |
run: | | |
pip install -e . | |
pip install -r requirements_dev.txt | |
- name: Lint with flake8 | |
run: flake8 | |
- name: Calculate unit test coverage | |
run: | | |
coverage run --source trs_filer -m pytest -W ignore::DeprecationWarning | |
coverage xml | |
- name: Submit Report to Codecov | |
uses: codecov/codecov-action@v3 | |
with: | |
token: ${{ secrets.CODECOV_TOKEN }} | |
files: ./coverage.xml | |
fail_ci_if_error: true | |
verbose: true | |
- name: Deploy app | |
run: docker-compose up -d --build | |
- name: Wait for app startup | |
run: sleep 20 | |
- name: Run integration tests | |
shell: bash | |
run: pytest tests/integration_tests.py | |
- name: Tear down app | |
run: docker-compose down | |
Publish: | |
name: Build and publish app image | |
runs-on: ubuntu-latest | |
needs: [Test] | |
steps: | |
- name: Checkout Repository | |
uses: actions/checkout@v3 | |
- name: Build & Publish image to DockerHub | |
env: | |
DOCKERHUB_ORG: ${{ secrets.DOCKERHUB_ORG }} | |
DOCKERHUB_LOGIN: ${{ secrets.DOCKERHUB_LOGIN }} | |
DOCKERHUB_TOKEN: ${{ secrets.DOCKERHUB_TOKEN }} | |
REPO_NAME: ${{ github.event.repository.name }} | |
run: | | |
set -x | |
export DEFAULT_BRANCH=${{ github.event.repository.default_branch }} | |
if [[ "${GITHUB_EVENT_NAME}" == "push" ]]; then | |
export BRANCH_NAME=${GITHUB_REF##*/} | |
elif [[ "${GITHUB_EVENT_NAME}" == "pull_request" ]]; then | |
export BRANCH_NAME=${GITHUB_HEAD_REF##*/} | |
else | |
export BRANCH_NAME=INVALID_EVENT_BRANCH_UNKNOWN | |
fi | |
echo "DEFAULT_BRANCH: ${DEFAULT_BRANCH}" | |
echo "BRANCH_NAME: ${BRANCH_NAME}" | |
if [ "$BRANCH_NAME" == "$DEFAULT_BRANCH" ]; then | |
export DOCKER_TAG="$(date '+%Y%m%d')" | |
else | |
export DOCKER_TAG=${BRANCH_NAME//_/-} | |
export DOCKER_TAG=${DOCKER_TAG//\//-} | |
fi | |
echo "TAG: ${DOCKER_TAG}" | |
docker build . \ | |
-t "${DOCKERHUB_ORG}/${REPO_NAME}:latest" \ | |
-t "${DOCKERHUB_ORG}/${REPO_NAME}:${DOCKER_TAG}" | |
echo $DOCKERHUB_TOKEN | \ | |
docker login -u $DOCKERHUB_LOGIN --password-stdin | |
if [ "$BRANCH_NAME" == "$DEFAULT_BRANCH" ]; then | |
docker push "${DOCKERHUB_ORG}/${REPO_NAME}:latest" | |
fi | |
rm ${HOME}/.docker/config.json # delete token |