diff --git a/.gitea/workflows/build.yaml b/.gitea/workflows/build.yaml new file mode 100644 index 0000000..e343ff7 --- /dev/null +++ b/.gitea/workflows/build.yaml @@ -0,0 +1,107 @@ +name: Build & Publish Backend +on: + push: + paths: + - "api/**" + - "frontend/**" + - "telegram_bot/**" +jobs: + build: + runs-on: ubuntu-latest + steps: + - name: Check out the repo + uses: actions/checkout@v3 + + - name: Check changed directories + uses: https://github.com/dorny/paths-filter@v2 + id: changes + with: + filters: | + api: + - 'api/**' + frontend: + - 'frontend/**' + telegram_bot: + - 'telegram_bot/**' + + # Frontend + - name: "[Frontend] Docker meta" + if: steps.changes.outputs.frontend == 'true' + id: frontend-meta + uses: https://github.com/docker/metadata-action@v4 + with: + images: git.flokaiser.com/dhbw/aktienbot-frontend + tags: | + type=sha,enable=true,priority=100,prefix={{branch}}-,suffix=,format=short + type=raw,value=latest,enable={{is_default_branch}} + + # API + - name: "[API] Docker meta" + if: steps.changes.outputs.api == 'true' + id: api-meta + uses: https://github.com/docker/metadata-action@v4 + with: + images: git.flokaiser.com/dhbw/aktienbot-api + tags: | + type=sha,enable=true,priority=100,prefix={{branch}}-,suffix=,format=short + type=raw,value=latest,enable={{is_default_branch}} + + # Bot + - name: "[Bot] Docker meta" + if: steps.changes.outputs.telegram_bot == 'true' + id: bot-meta + uses: https://github.com/docker/metadata-action@v4 + with: + images: git.flokaiser.com/dhbw/aktienbot-bot + tags: | + type=sha,enable=true,priority=100,prefix={{branch}}-,suffix=,format=short + type=raw,value=latest,enable={{is_default_branch}} + + - name: Get get-docker.sh + run: curl -fsSL https://get.docker.com -o get-docker.sh + + - name: Install docker + run: sh get-docker.sh + + - name: Login to Registry + uses: docker/login-action@v2 + with: + registry: git.flokaiser.com + username: ${{ secrets.REGISTRY_USERNAME }} + password: ${{ secrets.REGISTRY_TOKEN }} + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v2 + + # Frontend + - name: "[Frontend] Build and push" + if: steps.changes.outputs.frontend == 'true' + uses: docker/build-push-action@v4 + with: + file: Dockerfile + context: "{{defaultContext}}:frontend" + platforms: linux/amd64 + push: true + tags: ${{ steps.frontend-meta.outputs.tags }} + + # API + - name: "[API] Build and push" + if: steps.changes.outputs.api == 'true' + uses: docker/build-push-action@v4 + with: + file: Dockerfile + context: "{{defaultContext}}:api" + platforms: linux/amd64 + push: true + tags: ${{ steps.api-meta.outputs.tags }} + + # Bot + - name: "[Bot] Build and push" + if: steps.changes.outputs.bot == 'true' + uses: docker/build-push-action@v4 + with: + file: Dockerfile + context: "{{defaultContext}}:telegram_bot" + platforms: linux/amd64 + push: true + tags: ${{ steps.bot-meta.outputs.tags }} \ No newline at end of file diff --git a/.woodpecker.yml b/.woodpecker.yml deleted file mode 100644 index 201f398..0000000 --- a/.woodpecker.yml +++ /dev/null @@ -1,87 +0,0 @@ -pipeline: - generate_docker_tag: - image: golang - commands: - - echo -n "${CI_COMMIT_BRANCH//\//-}-${CI_COMMIT_SHA:0:8}, latest" > .tags - when: - path: [ "frontend/**", "telegram_bot/**", "api/**" ] - event: push - - - # -------------------------------------- API -------------------------------------- - build_api: - image: woodpeckerci/plugin-docker-buildx - settings: - repo: - from_secret: repo_api - username: - from_secret: username - password: - from_secret: password - registry: - from_secret: registry - dockerfile: api/Dockerfile - platforms: linux/amd64 - when: - path: "api/**" - event: push - - - # -------------------------------------- Bot -------------------------------------- - build_bot: - image: woodpeckerci/plugin-docker-buildx - settings: - repo: - from_secret: repo_bot - username: - from_secret: username - password: - from_secret: password - registry: - from_secret: registry - dockerfile: telegram_bot/Dockerfile - platforms: linux/amd64 - when: - path: "telegram_bot/**" - event: push - - - # -------------------------------------- Frontend -------------------------------------- - build_frontend: - image: woodpeckerci/plugin-docker-buildx - settings: - repo: - from_secret: repo_frontend - username: - from_secret: username - password: - from_secret: password - registry: - from_secret: registry - dockerfile: frontend/Dockerfile - platforms: linux/amd64 - when: - path: "frontend/**" - event: push - - - # -------------------------------------- Deploy -------------------------------------- - deploy: - image: appleboy/drone-ssh - network_mode: host - settings: - host: - from_secret: ssh_host - username: - from_secret: ssh_user - password: - from_secret: ssh_password - script: - - cd ~/docker-compose-files/telegram_aktien_bot - - docker-compose pull - - docker-compose --env-file ~/docker-compose-env/telegram_aktien_bot.env up -d - when: - path: [ "frontend/**", "telegram_bot/**", "api/**" ] - event: push - -branches: main diff --git a/README.md b/README.md index 66d415e..dca3269 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,3 @@ -[![Build Status](https://gitea.woodpecker.flokaiser.com/api/badges/DHBW/TelegramAktienBot/status.svg)](https://gitea.woodpecker.flokaiser.com/DHBW/TelegramAktienBot) # TelegramAktienBot WebEngineering2 Projekt: Aktien und News Bot für Telegram diff --git a/api/Dockerfile b/api/Dockerfile index b778de2..bb30a85 100644 --- a/api/Dockerfile +++ b/api/Dockerfile @@ -7,12 +7,12 @@ WORKDIR /srv/flask_app RUN apt update && apt install -y python3 python3-pip curl nginx && rm -rf /var/lib/apt/lists/* # Install the dependencies -COPY api/requirements.txt /srv/flask_app/ +COPY requirements.txt /srv/flask_app/ RUN pip install -r requirements.txt --src /usr/local/src --no-warn-script-location # Copy the source code to the working directory -COPY api /srv/flask_app -COPY api/deploy/nginx.conf /etc/nginx +COPY . /srv/flask_app +COPY ./deploy/nginx.conf /etc/nginx # Change file permissions RUN chmod +x ./deploy/start.sh diff --git a/api/README.md b/api/README.md index 035e097..c92a81a 100644 --- a/api/README.md +++ b/api/README.md @@ -49,7 +49,7 @@ docker run -d \ --env "MYSQL_PORT=" \ --env "MYSQL_DATABASE=" \ --restart unless-stopped \ - registry.flokaiser.com/aktienbot/api:latest + git.flokaiser.com/dhbw/aktienbot-api:latest ``` or load environment variables from file by using `--env-file ` \ No newline at end of file diff --git a/api/requirements.txt b/api/requirements.txt index 74c67a0..2392c52 100644 --- a/api/requirements.txt +++ b/api/requirements.txt @@ -1,18 +1,17 @@ -Flask~=2.1.2 -python-dotenv==0.21.0 +Flask==2.2.3 +python-dotenv==1.0.0 uwsgi==2.0.21 -Flask_SQLAlchemy==3.0.2 -python-dotenv==0.21.0 +Flask_SQLAlchemy==3.0.3 pymysql==1.0.2 pyjwt==2.6.0 -apiflask==1.0.0 +apiflask==1.3.1 flask-cors==3.0.10 bcrypt==4.0.1 -pytest~=7.2.0 -pytest-cov -marshmallow~=3.19.0 -faker~=15.3.4 -requests~=2.28.1 -investpy~=1.0.8 -pandas~=1.5.0 -currencyconverter~=0.17.1 \ No newline at end of file +pytest==7.2.2 +pytest-cov==4.0. +marshmallow==3.19.0 +faker==18.3.1 +requests==2.28.1 +investpy==1.0.8 +pandas==1.5.3 +currencyconverter==0.17.6 \ No newline at end of file diff --git a/frontend/Dockerfile b/frontend/Dockerfile index 10d959c..ccf7ab9 100644 --- a/frontend/Dockerfile +++ b/frontend/Dockerfile @@ -1,10 +1,10 @@ -FROM node:latest as build +FROM node:18 as build # Change to the project directory WORKDIR /usr/local/app # Copy the project files to the container -COPY frontend/ /usr/local/app/ +COPY . /usr/local/app/ # Install dependencies RUN npm install @@ -16,8 +16,8 @@ FROM nginx:latest COPY --from=build /usr/local/app/dist/aktienbot /usr/share/nginx/html # Copy configuration files -COPY frontend/deploy/nginx.conf /etc/nginx -COPY frontend/deploy deploy/ +COPY ./deploy/nginx.conf /etc/nginx +COPY ./deploy deploy/ # Change file permissions RUN chmod +x ./deploy/healthcheck.sh diff --git a/frontend/package.json b/frontend/package.json index c6730c9..2b63f22 100644 --- a/frontend/package.json +++ b/frontend/package.json @@ -4,50 +4,50 @@ "scripts": { "ng": "ng", "start": "ng serve", - "build": "ng build --configuration production --build-optimizer", - "watch": "ng build --configuration development --watch", + "build": "ng build --prod --build-optimizer", + "watch": "ng build --watch --configuration development", "test": "ng test", "lint": "ng lint", "compodoc": "npx compodoc -p tsconfig.doc.json" }, "private": true, "dependencies": { - "@angular/animations": "~15.0.0", - "@angular/cdk": "^15.0.0", - "@angular/common": "~15.0.0", - "@angular/compiler": "~15.0.0", - "@angular/core": "~15.0.0", - "@angular/forms": "~15.0.0", - "@angular/material": "^15.0.0", - "@angular/platform-browser": "~15.0.0", - "@angular/platform-browser-dynamic": "~15.0.0", - "@angular/router": "~15.0.0", - "bootstrap": "^5.1.3", - "ngx-cron-editor": "^0.7.3", - "rxjs": "~7.6.0", - "tslib": "^2.4.0", - "zone.js": "~0.12.0" + "@angular/animations": "~13.2.0", + "@angular/cdk": "~13.2.6", + "@angular/common": "~13.2.0", + "@angular/compiler": "~13.2.0", + "@angular/core": "~13.2.0", + "@angular/forms": "~13.2.0", + "@angular/material": "13.2.6", + "@angular/platform-browser": "~13.2.0", + "@angular/platform-browser-dynamic": "~13.2.0", + "@angular/router": "~13.2.0", + "bootstrap": "5.1.3", + "ngx-cron-editor": "0.7.3", + "rxjs": "~7.5.0", + "tslib": "2.4.0", + "zone.js": "~0.11.4" }, "devDependencies": { - "@angular-devkit/build-angular": "~15.0.0", - "@angular-eslint/builder": "15.1.0", - "@angular-eslint/eslint-plugin": "15.1.0", - "@angular-eslint/eslint-plugin-template": "15.1.0", - "@angular-eslint/schematics": "15.1.0", - "@angular-eslint/template-parser": "15.1.0", - "@angular/cli": "~15.0.0", - "@angular/compiler-cli": "~15.0.0", - "@types/jasmine": "~4.3.0", - "@types/node": "^18.0.0", - "@typescript-eslint/eslint-plugin": "5.46.1", - "@typescript-eslint/parser": "5.46.1", + "@angular-devkit/build-angular": "~13.3.5", + "@angular-eslint/builder": "13.2.1", + "@angular-eslint/eslint-plugin": "13.2.1", + "@angular-eslint/eslint-plugin-template": "13.2.1", + "@angular-eslint/schematics": "13.2.1", + "@angular-eslint/template-parser": "13.2.1", + "@angular/cli": "~13.3.5", + "@angular/compiler-cli": "~13.2.0", + "@types/jasmine": "~4.0.3", + "@types/node": "^12.11.1", + "@typescript-eslint/eslint-plugin": "5.23.0", + "@typescript-eslint/parser": "5.22.0", "eslint": "^8.15.0", - "jasmine-core": "~4.5.0", - "karma": "~6.4.0", + "jasmine-core": "~4.1.0", + "karma": "~6.3.19", "karma-chrome-launcher": "~3.1.0", "karma-coverage": "~2.2.0", - "karma-jasmine": "~5.1.0", - "karma-jasmine-html-reporter": "~2.0.0", - "typescript": "~4.9.0" + "karma-jasmine": "~5.0.0", + "karma-jasmine-html-reporter": "~1.7.0", + "typescript": "~4.5.2" } } diff --git a/telegram_bot/Dockerfile b/telegram_bot/Dockerfile index 3a780ec..ab856dc 100644 --- a/telegram_bot/Dockerfile +++ b/telegram_bot/Dockerfile @@ -3,12 +3,16 @@ FROM python:3.11-slim # Change the working directory to the root of the project WORKDIR /srv/flask_app +# Create venv +RUN python -m venv myvenv +ENV PATH="myvenv/bin:$PATH" + # Install the dependencies -COPY telegram_bot/requirements.txt /srv/flask_app/ +COPY requirements.txt /srv/flask_app/ RUN pip install -r requirements.txt --src /usr/local/src --no-warn-script-location # Copy the source code to the working directory -COPY telegram_bot /srv/flask_app +COPY . /srv/flask_app # Change file permissions RUN chmod +x ./deploy/start.sh diff --git a/telegram_bot/README.md b/telegram_bot/README.md index 855fb63..9024860 100644 --- a/telegram_bot/README.md +++ b/telegram_bot/README.md @@ -32,7 +32,7 @@ docker run -d \ --env "BOT_API_KEY=" \ --env "NEWS_API_KEY=" \ --restart unless-stopped \ - registry.flokaiser.com/aktienbot/bot:latest + git.flokaiser.com/dhbw/aktienbot-bot:latest ``` or load environment variables from file by using `--env-file `