diff --git a/.github/labels.yml b/.github/labels.yml deleted file mode 100644 index 2322961b..00000000 --- a/.github/labels.yml +++ /dev/null @@ -1,105 +0,0 @@ -## more info https://github.com/crazy-max/ghaction-github-labeler -- # maintenance - name: "type: :wrench: maintenance" - color: "" - description: "" -- # bug - name: "type: :bug: bug" - color: "FBCA04" - description: "" -- # documentation - name: "type: :memo: documentation" - color: "FBCA04" - description: "" -- # duplicate - name: "status: :busts_in_silhouette: duplicate" - color: "cccccc" - description: "" -- # enhancement - name: "type: :sparkles: enhancement" - color: "FBCA04" - description: "" -- # feature request - name: "type: :bulb: feature request" - color: "FBCA04" - description: "" -- # need feedback - name: "status: :mega: need feedback" - color: "cccccc" - description: "" -- # future maybe - name: ":rocket: future maybe" - color: "fef2c0" - description: "" -- # good first issue - name: ":hatching_chick: good first issue" - color: "7057ff" - description: "" -- # help wanted - name: "status: :pray: help wanted" - color: "cccccc" - description: "" -- # invalid - name: "status: :no_entry_sign: invalid" - color: "cccccc" - description: "" -- # investigate - name: "type: :mag: investigate" - color: "FBCA04" - description: "" -- # needs more info - name: "status: :thinking: needs more info" - color: "cccccc" - description: "" -- # question - name: "type: :question: question" - color: "FBCA04" - description: "" -- # won't do/fix - name: "status: :coffin: won't do/fix" - color: "cccccc" - description: "" -- # security - name: "type: :lock: security" - description: "" - color: "B60205" -- # on hold - name: "status: :zzz: on hold" - description: "" - color: "cccccc" -- # discussion - name: "type: :speech_balloon: discussion" - description: "" - color: "FBCA04" -- # blocked - name: "status: :scream_cat: blocked" - description: "" - color: "cccccc" -- # confirmed - name: "status: :writing_hand: confirmed" - description: "" - color: "93D8B2" -- # refactor - name: "type: :neckbeard: refactor" - description: "" - color: "FBCA04" -- # build - name: "type: :hammer: build" - description: "" - color: "FBCA04" -- # ci - name: "type: :ship: ci" - description: "" - color: "FBCA04" -- # test - name: "type: :traffic_light: test" - description: "" - color: "FBCA04" -- # chore - name: "type: :construction: chore" - description: "" - color: "FBCA04" -- # perf - name: "type: :speedboat: perf" - description: "" - color: "FBCA04" diff --git a/.github/workflows/label-importer.yaml b/.github/workflows/label-importer.yaml deleted file mode 100644 index 6df282f4..00000000 --- a/.github/workflows/label-importer.yaml +++ /dev/null @@ -1,22 +0,0 @@ -name: Github Label Importer - -on: - workflow_dispatch: - -jobs: - labeler: - runs-on: ubuntu-latest - steps: - - name: Checkout - uses: actions/checkout@v4 - - - name: Run Labeler - uses: crazy-max/ghaction-github-labeler@v5 - with: - github-token: ${{ secrets.GITHUB_TOKEN }} - yaml-file: .github/labels.yml - skip-delete: false - dry-run: false - exclude: | - help* - *issue diff --git a/.github/workflows/on-push-main-branch.yaml b/.github/workflows/on-push-main-branch.yaml index 64ec8986..e05d0fe4 100644 --- a/.github/workflows/on-push-main-branch.yaml +++ b/.github/workflows/on-push-main-branch.yaml @@ -20,6 +20,7 @@ jobs: needs: tests name: "Generate changelog" uses: ./.github/workflows/generate-changelog.yaml + docs: needs: generate-changelog name: "Build and publish docs" diff --git a/.github/workflows/publish-image.yaml b/.github/workflows/publish-image.yaml index fa5389c5..06c16497 100644 --- a/.github/workflows/publish-image.yaml +++ b/.github/workflows/publish-image.yaml @@ -14,7 +14,6 @@ on: env: IMAGE_REGISTRY: ghcr.io - REGISTRY_USER: $GITHUB_ACTOR API_IMAGE: ghcr.io/equinor/template-fastapi-react/api NGINX_IMAGE: ghcr.io/equinor/template-fastapi-react/nginx @@ -26,8 +25,12 @@ jobs: with: fetch-depth: 2 - - name: "Login to image registry" - run: echo ${{ secrets.GITHUB_TOKEN }} | docker login $IMAGE_REGISTRY -u $GITHUB_ACTOR --password-stdin + - name: "Login to GitHub Container Registry" + uses: docker/login-action@v3 + with: + registry: ${{ env.IMAGE_REGISTRY }} + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} - name: "Build web" run: | @@ -60,8 +63,12 @@ jobs: with: fetch-depth: 2 - - name: "Login to image registry" - run: echo ${{ secrets.GITHUB_TOKEN }} | docker login $IMAGE_REGISTRY -u $GITHUB_ACTOR --password-stdin + - name: "Login to GitHub Container Registry" + uses: docker/login-action@v3 + with: + registry: ${{ env.IMAGE_REGISTRY }} + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} - name: "Build API" run: | diff --git a/.github/workflows/tests.yaml b/.github/workflows/tests.yaml index 3abb3c1d..e6b8aed9 100644 --- a/.github/workflows/tests.yaml +++ b/.github/workflows/tests.yaml @@ -10,72 +10,94 @@ on: required: false env: - IMAGE_REGISTRY: ghcr.io - REGISTRY_USER: $GITHUB_ACTOR - API_IMAGE: ghcr.io/equinor/template-fastapi-react/api - WEB_IMAGE: ghcr.io/equinor/template-fastapi-react/web + REGISTRY: ghcr.io + API_IMAGE_NAME: api jobs: api-unit-tests: runs-on: ubuntu-latest + defaults: + run: + working-directory: ./api steps: - - uses: actions/checkout@v4 + - name: "Setup: checkout repository" + uses: actions/checkout@v4 - - name: Login to image registry - run: echo ${{ secrets.GITHUB_TOKEN }} | docker login $IMAGE_REGISTRY -u $GITHUB_ACTOR --password-stdin + - name: "Setup: install poetry" + run: pipx install poetry - - name: Build API image - run: | - docker pull $API_IMAGE - docker build --target development --tag api-development ./api # TODO: --cache-from $API_IMAGE + - name: "Setup: add python" + uses: actions/setup-python@v5 + with: + python-version: "3.12" + cache: "poetry" - - name: Pytest Unit tests - run: docker compose -f docker-compose.yml -f docker-compose.ci.yml run --rm api pytest --unit + - name: "Run: pytest unit tests" + run: poetry run pytest --unit api-integration-tests: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v4 + - name: "Setup: checkout repository" + uses: actions/checkout@v4 + + - name: "Setup: Set image name" + run: echo "API_IMAGE=${{ env.REGISTRY }}/${{ github.repository }}/${{ env.API_IMAGE_NAME }}" >> "$GITHUB_ENV" - - name: Login to image registry - run: echo ${{ secrets.GITHUB_TOKEN }} | docker login $IMAGE_REGISTRY -u $GITHUB_ACTOR --password-stdin + - name: "Setup: Login to GitHub Container Registry" + uses: docker/login-action@v3 + with: + registry: ${{ env.REGISTRY }} + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + + # - name: "Setup: Docker Buildx" + # uses: docker/setup-buildx-action@v3 + + - name: "Setup: Build API image" + uses: docker/build-push-action@v6 + with: + context: ./api + target: development + load: true + tags: ${{ env.API_IMAGE }}:dev + cache-from: type=registry,ref=${{ env.API_IMAGE }}:dev + # cache-to: type=registry,ref=${{ env.API_IMAGE }}:dev,mode=max - - name: Build API image - run: | - docker pull $API_IMAGE - docker build --target development --tag api-development ./api # TODO: --cache-from $API_IMAGE + - name: "Run: Integration tests (pytest)" + run: docker compose -f docker-compose.yml -f docker-compose.ci.yml run --rm api python -m pytest --integration - - name: BDD Integration tests + - name: "Run: Integration tests (behave)" if: ${{ false }} # disable for now run: docker compose -f docker-compose.yml -f docker-compose.ci.yml run api behave - - name: Pytest Integration tests - run: docker compose -f docker-compose.yml -f docker-compose.ci.yml run --rm api pytest --integration - web-tests: runs-on: ubuntu-latest + if: ${{ false }} # disable for now as they do not currently work steps: - - uses: actions/checkout@v4 - - - name: Login to image registry - run: echo ${{ secrets.GITHUB_TOKEN }} | docker login $IMAGE_REGISTRY -u $GITHUB_ACTOR --password-stdin + - name: "Setup: checkout repository" + uses: actions/checkout@v4 - - name: Build Web Image - run: | - docker pull $WEB_IMAGE - docker build --cache-from $WEB_IMAGE --target development --tag web-dev ./web + - name: "Setup: Build web image" + uses: docker/build-push-action@v6 + with: + context: ./web + target: development + load: true + tags: web:dev - - name: Run Web tests - if: ${{ false }} # disable for now as they do not currently work + - name: "Run: Web tests" run: docker compose -f docker-compose.yml -f docker-compose.ci.yml run --rm web yarn test docs-tests: name: test-docs runs-on: ubuntu-latest - + defaults: + run: + working-directory: ./documentation steps: # If you know your docs does not rely on anything outside of the documentation folder, the commented out code below can be used to only test the docs build if the documentation folder changes. - - name: Checkout GitHub Action + - name: "Setup: checkout repository" uses: actions/checkout@v4 # with: # fetch-depth: 0 @@ -85,17 +107,21 @@ jobs: # shell: bash # run: echo "changes=$(git diff --name-only $(git merge-base HEAD origin/main) HEAD | grep documentation/ | wc -l)" >> $GITHUB_OUTPUT - - name: Setup node + - name: "Setup: node" + if: ${{ false }} # if: steps.docs-changes.outputs.changes > 0 + id: setup-node uses: actions/setup-node@v4 with: node-version: 20 cache: yarn cache-dependency-path: documentation/yarn.lock - - name: Install dependencies and build website - # if: steps.docs-changes.outputs.changes > 0 - run: | - cd documentation - yarn install --frozen-lockfile - yarn build + - name: "Setup: Install dependencies" + id: install-deps + if: steps.setup-node.outcome == 'success' + run: yarn install --frozen-lockfile + + - name: "Run: Build docs" + if: steps.install-deps.outcome == 'success' + run: yarn build diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 4f5d37e7..daab6115 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -68,16 +68,3 @@ repos: name: "Lint : biome (ts/js)" additional_dependencies: ["@biomejs/biome@1.9.4"] args: ["--config-path", "web"] - - - repo: https://github.com/codespell-project/codespell - rev: v2.4.1 - hooks: - - id: codespell - name: "Lint : spelling" - description: Checks for common misspellings in text files. - entry: codespell --toml=api/pyproject.toml - exclude: documentation/docs/changelog/changelog.md - language: python - types: [text] - additional_dependencies: - - tomli diff --git a/api/Dockerfile b/api/Dockerfile index f85e5196..5c6da76b 100644 --- a/api/Dockerfile +++ b/api/Dockerfile @@ -1,4 +1,4 @@ -FROM --platform=linux/amd64 python:3.13-slim AS base +FROM python:3.13-slim AS base WORKDIR /code CMD ["/code/src/init.sh", "api"] EXPOSE 5000 @@ -7,8 +7,8 @@ ENV PYTHONUNBUFFERED=1 ENV PYTHONPATH=/code RUN pip install --upgrade pip && \ - pip install poetry && \ - poetry config virtualenvs.create false + pip install poetry && \ + poetry config virtualenvs.create false COPY pyproject.toml pyproject.toml COPY poetry.lock poetry.lock diff --git a/api/pyproject.toml b/api/pyproject.toml index bd1b59de..e74dfc4f 100644 --- a/api/pyproject.toml +++ b/api/pyproject.toml @@ -28,44 +28,20 @@ mongomock = "^4.1.2" mypy = "^1.14.1" types-cachetools = "^5.5.0.20240820" -[tool.interrogate] -ignore-init-method = true -ignore-init-module = true -ignore-magic = false -ignore-semiprivate = false -ignore-private = false -ignore-property-decorators = false -ignore-module = false -ignore-nested-functions = false -ignore-nested-classes = true -ignore-setters = false -fail-under = 0 -exclude = ["setup.py", "docs", "build"] -ignore-regex = ["^get$", "^mock_.*", ".*BaseClass.*"] -# possible values: 0 (minimal output), 1 (-v), 2 (-vv) -verbose = 0 -quiet = false -whitelist-regex = [] -color = true -omit-covered-files = false - [build-system] requires = ["poetry-core>=1.0.0"] build-backend = "poetry.core.masonry.api" [tool.mypy] - plugins = ["pydantic.mypy"] -# strict = true +strict = true exclude = ["/tests/"] ignore_missing_imports = true namespace_packages = true explicit_package_bases = true allow_subclassing_any = true - [tool.ruff] - src = ["src"] target-version = "py312" line-length = 119 diff --git a/docker-compose.ci.yml b/docker-compose.ci.yml index 8364f2fb..ad0918c5 100644 --- a/docker-compose.ci.yml +++ b/docker-compose.ci.yml @@ -1,6 +1,6 @@ services: api: - image: development + image: ghcr.io/equinor/template-fastapi-react/api:dev build: target: development environment: @@ -12,11 +12,14 @@ services: MONGODB_PORT: 27017 SECRET_KEY: sg9aeUM5i1JO4gNN8fQadokJa3_gXQMLBjSGGYcfscs= AUTH_ENABLED: "False" - depends_on: - - db links: - db + nginx: + image: web:dev + build: + target: development + db: environment: MONGO_INITDB_ROOT_USERNAME: root diff --git a/docker-compose.override.yml b/docker-compose.override.yml index 2f0d6dd0..3465cb33 100644 --- a/docker-compose.override.yml +++ b/docker-compose.override.yml @@ -1,9 +1,9 @@ services: - api: + image: template-api-dev build: target: development - image: template-api-dev + platform: linux/amd64 volumes: - ./api/src/:/code/src env_file: diff --git a/docker-compose.yml b/docker-compose.yml index 35cd195f..932642da 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -12,7 +12,9 @@ services: api: image: ghcr.io/equinor/template-fastapi-react/api - build: ./api + build: + target: prod + context: ./api restart: unless-stopped depends_on: - db