Skip to content

Commit

Permalink
Merge pull request #82 from Bot-detector/develop
Browse files Browse the repository at this point in the history
Release
  • Loading branch information
extreme4all authored Jan 24, 2024
2 parents 4abb1bb + 2cf27ed commit cc3e9ac
Show file tree
Hide file tree
Showing 36 changed files with 1,617 additions and 1,517 deletions.
2 changes: 0 additions & 2 deletions .env-example

This file was deleted.

51 changes: 34 additions & 17 deletions .github/workflows/hetzner-dvp-workflow.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,15 @@ permissions: write-all
env:
VALUE_FILE: bd-web-dvp/deployment.yaml
REGISTRY: quay.io/bot_detector/bd-web

ENVIRONMENT: dvp

# A workflow run is made up of one or more jobs that can run sequentially or in parallel
jobs:
# This workflow contains a single job called "build"
# This workflow contains two jobs: build_image and update_image_version
build_image:
# The type of runner that the job will run on
runs-on: [self-hosted,hetzner]

runs-on: [self-hosted, "hetzner"]
if: github.repository_owner == 'Bot-detector'
# Steps represent a sequence of tasks that will be executed as part of the job
steps:
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
Expand All @@ -35,35 +35,52 @@ jobs:
id: vars
run: |
echo "GIT_HASH=$(git rev-parse --short "$GITHUB_SHA")" >> $GITHUB_OUTPUT
echo "REGISTRY=$REGISTRY" >> $GITHUB_OUTPUT
echo "VALUE_FILE=$VALUE_FILE" >> $GITHUB_OUTPUT
# Runs a command using the runners shell
- name: docker build
run: docker build . --file Dockerfile --network=host -t "$REGISTRY:${{ steps.vars.outputs.GIT_HASH }}"
- name: login to registry
run: echo "${{ secrets.QUAY_REGISTERY_PASSWORD }}" | docker login -u="bot_detector+quay_robot" quay.io --password-stdin
- name: Docker Build
run: |
docker build . --file Dockerfile --network=host -t "${REGISTRY}:${{ steps.vars.outputs.GIT_HASH }}" --target production --build-arg api_port=8000 --build-arg root_path=""
- name: Login to Quay registry
run: echo "${{ secrets.QUAY_REGISTERY_PASSWORD }}" | docker login -u "bot_detector+quay_robot" quay.io --password-stdin

- name: Tag image
run: |
docker tag "${REGISTRY}:${{ steps.vars.outputs.GIT_HASH }}" "${REGISTRY}:${ENVIRONMENT}"
- name: Docker Push image to Quay registry
run: |
docker push "${REGISTRY}:${{ steps.vars.outputs.GIT_HASH }}"
docker push "${REGISTRY}:${ENVIRONMENT}"
- name: docker push image to registry
run: docker push "$REGISTRY:${{ steps.vars.outputs.GIT_HASH }}"
update_image_version:
runs-on: [self-hosted, "hetzner"]
if: github.repository_owner == 'Bot-detector'
needs: build_image # This ensures that the build_image job is completed before running this job

steps:
- name: Checkout Target Repository
uses: actions/checkout@v3
with:
repository: Bot-detector/bot-detector-k8s

- name: Set vars
id: vars
run: |
echo "GIT_HASH=$(git rev-parse --short "$GITHUB_SHA")" >> $GITHUB_OUTPUT
- name: Update Image Version
uses: fjogeleit/yaml-update-action@main
with:
repository: Bot-detector/bot-detector-k8s
valueFile: "${{ steps.vars.outputs.VALUE_FILE }}"
token: ${{ secrets.HETZNER_ACTIONS_RUNNER_TOKEN }}
valueFile: ${{ env.VALUE_FILE }}
token: "${{ secrets.HETZNER_ACTIONS_RUNNER_TOKEN }}"
commitChange: true
branch: "${{ steps.vars.outputs.GIT_HASH }}"
title: "${{ steps.vars.outputs.GIT_HASH }}_${{ env.VALUE_FILE }}"
branch: "${{ steps.vars.outputs.GIT_HASH }}_${{ env.VALUE_FILE }}"
targetBranch: develop
masterBranchName: develop
createPR: true
changes: |
{
"spec.template.spec.containers[0].image":"${{ steps.vars.outputs.REGISTRY }}:${{ steps.vars.outputs.GIT_HASH }}"
"spec.template.spec.containers[0].image": "${{ env.REGISTRY }}:${{ steps.vars.outputs.GIT_HASH }}"
}
51 changes: 34 additions & 17 deletions .github/workflows/hetzner-prd-workflow.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,15 @@ permissions: write-all
env:
VALUE_FILE: bd-web-prd/deployment.yaml
REGISTRY: quay.io/bot_detector/bd-web

ENVIRONMENT: prd

# A workflow run is made up of one or more jobs that can run sequentially or in parallel
jobs:
# This workflow contains a single job called "build"
# This workflow contains two jobs: build_image and update_image_version
build_image:
# The type of runner that the job will run on
runs-on: [self-hosted,hetzner]

runs-on: [self-hosted, "hetzner"]
if: github.repository_owner == 'Bot-detector'
# Steps represent a sequence of tasks that will be executed as part of the job
steps:
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
Expand All @@ -35,35 +35,52 @@ jobs:
id: vars
run: |
echo "GIT_HASH=$(git rev-parse --short "$GITHUB_SHA")" >> $GITHUB_OUTPUT
echo "REGISTRY=$REGISTRY" >> $GITHUB_OUTPUT
echo "VALUE_FILE=$VALUE_FILE" >> $GITHUB_OUTPUT
# Runs a command using the runners shell
- name: docker build
run: docker build . --file Dockerfile --network=host --target production -t "$REGISTRY:${{ steps.vars.outputs.GIT_HASH }}"
- name: login to registry
run: echo "${{ secrets.QUAY_REGISTERY_PASSWORD }}" | docker login -u="bot_detector+quay_robot" quay.io --password-stdin
- name: Docker Build
run: |
docker build . --file Dockerfile --network=host -t "${REGISTRY}:${{ steps.vars.outputs.GIT_HASH }}" --target production --build-arg api_port=8000 --build-arg root_path=""
- name: Login to Quay registry
run: echo "${{ secrets.QUAY_REGISTERY_PASSWORD }}" | docker login -u "bot_detector+quay_robot" quay.io --password-stdin

- name: Tag image
run: |
docker tag "${REGISTRY}:${{ steps.vars.outputs.GIT_HASH }}" "${REGISTRY}:${ENVIRONMENT}"
- name: Docker Push image to Quay registry
run: |
docker push "${REGISTRY}:${{ steps.vars.outputs.GIT_HASH }}"
docker push "${REGISTRY}:${ENVIRONMENT}"
- name: docker push image to registry
run: docker push "$REGISTRY:${{ steps.vars.outputs.GIT_HASH }}"
update_image_version:
runs-on: [self-hosted, "hetzner"]
if: github.repository_owner == 'Bot-detector'
needs: build_image # This ensures that the build_image job is completed before running this job

steps:
- name: Checkout Target Repository
uses: actions/checkout@v3
with:
repository: Bot-detector/bot-detector-k8s

- name: Set vars
id: vars
run: |
echo "GIT_HASH=$(git rev-parse --short "$GITHUB_SHA")" >> $GITHUB_OUTPUT
- name: Update Image Version
uses: fjogeleit/yaml-update-action@main
with:
repository: Bot-detector/bot-detector-k8s
valueFile: "${{ steps.vars.outputs.VALUE_FILE }}"
token: ${{ secrets.HETZNER_ACTIONS_RUNNER_TOKEN }}
valueFile: ${{ env.VALUE_FILE }}
token: "${{ secrets.HETZNER_ACTIONS_RUNNER_TOKEN }}"
commitChange: true
branch: "${{ steps.vars.outputs.GIT_HASH }}"
title: "${{ steps.vars.outputs.GIT_HASH }}_${{ env.VALUE_FILE }}"
branch: "${{ steps.vars.outputs.GIT_HASH }}_${{ env.VALUE_FILE }}"
targetBranch: develop
masterBranchName: develop
createPR: true
changes: |
{
"spec.template.spec.containers[0].image":"${{ steps.vars.outputs.REGISTRY }}:${{ steps.vars.outputs.GIT_HASH }}"
"spec.template.spec.containers[0].image": "${{ env.REGISTRY }}:${{ steps.vars.outputs.GIT_HASH }}"
}
20 changes: 10 additions & 10 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
repos:
- repo: https://github.com/psf/black
rev: 23.10.1
hooks:
- id: black
- repo: https://github.com/pycqa/isort
rev: 5.12.0
hooks:
- id: isort
args: ["--profile", "black"]
repos:
- repo: https://github.com/psf/black
rev: 23.10.1
hooks:
- id: black
- repo: https://github.com/pycqa/isort
rev: 5.12.0
hooks:
- id: isort
args: ["--profile", "black"]
142 changes: 71 additions & 71 deletions notes.md
Original file line number Diff line number Diff line change
@@ -1,72 +1,72 @@
# api documentation
```sh
http://127.0.0.1:5000/docs
http://127.0.0.1:5000/redoc
```
# extra info
```sh
POST: to create data.
GET: to read data.
PUT: to update data.
DELETE: to delete data.
```
# keeping fork up to date
```sh
git checkout develop
git pull --rebase upstream develop
git push
```
# setup
## linux
```sh
python3 -m venv .venv
source .venv/bin/activate
python3 -m pip install --upgrade pip
pip install -r requirements.txt
```
## windows
creating a python venv to work in and install the project requirements
```sh
python -m venv .venv
.venv\Scripts\activate
python -m pip install --upgrade pip
pip install -r requirements.txt
```
# for admin purposes saving & upgrading
## linux
```sh
#!/bin/bash

# Replace '==' with '>=' in requirements.txt
sed -i 's/==/>=/g' requirements.txt

# Install or upgrade packages
pip install -r requirements.txt --upgrade

# Save the installed package versions to requirements.txt
pip freeze > requirements.txt

# Replace '>=' with '==' in requirements.txt
sed -i 's/>=/==/g' requirements.txt
```
## windows
when you added some dependancies update the requirements
```sh
venv\Scripts\activate
call pip freeze > requirements.txt
```
when you want to upgrade the dependancies
```sh
venv\Scripts\activate
powershell "(Get-Content requirements.txt) | ForEach-Object { $_ -replace '==', '>=' } | Set-Content requirements.txt"
call pip install -r requirements.txt --upgrade
call pip freeze > requirements.txt
powershell "(Get-Content requirements.txt) | ForEach-Object { $_ -replace '>=', '==' } | Set-Content requirements.txt"
```
# branch cleanup
if your branch gets out of sync and for some reason you have many pushes and pulls, to become insync without pushing some random changes do this
```sh
git fetch origin
git reset --hard origin/{branchname}
git clean -f -d
# api documentation
```sh
http://127.0.0.1:5000/docs
http://127.0.0.1:5000/redoc
```
# extra info
```sh
POST: to create data.
GET: to read data.
PUT: to update data.
DELETE: to delete data.
```
# keeping fork up to date
```sh
git checkout develop
git pull --rebase upstream develop
git push
```
# setup
## linux
```sh
python3 -m venv .venv
source .venv/bin/activate
python3 -m pip install --upgrade pip
pip install -r requirements.txt
```
## windows
creating a python venv to work in and install the project requirements
```sh
python -m venv .venv
.venv\Scripts\activate
python -m pip install --upgrade pip
pip install -r requirements.txt
```
# for admin purposes saving & upgrading
## linux
```sh
#!/bin/bash

# Replace '==' with '>=' in requirements.txt
sed -i 's/==/>=/g' requirements.txt

# Install or upgrade packages
pip install -r requirements.txt --upgrade

# Save the installed package versions to requirements.txt
pip freeze > requirements.txt

# Replace '>=' with '==' in requirements.txt
sed -i 's/>=/==/g' requirements.txt
```
## windows
when you added some dependancies update the requirements
```sh
venv\Scripts\activate
call pip freeze > requirements.txt
```
when you want to upgrade the dependancies
```sh
venv\Scripts\activate
powershell "(Get-Content requirements.txt) | ForEach-Object { $_ -replace '==', '>=' } | Set-Content requirements.txt"
call pip install -r requirements.txt --upgrade
call pip freeze > requirements.txt
powershell "(Get-Content requirements.txt) | ForEach-Object { $_ -replace '>=', '==' } | Set-Content requirements.txt"
```
# branch cleanup
if your branch gets out of sync and for some reason you have many pushes and pulls, to become insync without pushing some random changes do this
```sh
git fetch origin
git reset --hard origin/{branchname}
git clean -f -d
```
Loading

0 comments on commit cc3e9ac

Please sign in to comment.