From de0f4b0d1167d5b5d63c10bbf137882a9e3eb5f7 Mon Sep 17 00:00:00 2001 From: Zikil Date: Sun, 8 Dec 2024 01:02:05 +0700 Subject: [PATCH] test ci/cd --- .DS_Store | Bin 6148 -> 10244 bytes .gitea/workflows/publish.yml | 33 ++++++++++++ .gitlab-ci.yml | 26 ---------- Dockerfile | 16 +++++- README.md | 94 +---------------------------------- docker-compose.yml | 29 ++++++++++- main.py | 10 ++-- nginx/nginx.conf | 29 +++++++++++ 8 files changed, 109 insertions(+), 128 deletions(-) create mode 100644 .gitea/workflows/publish.yml delete mode 100644 .gitlab-ci.yml create mode 100644 nginx/nginx.conf diff --git a/.DS_Store b/.DS_Store index 9137a828523eb16dec2562cff9692fc6ed8d0d53..aef0571099aeb0b5bcc0e54a79c51d9c8954c038 100644 GIT binary patch literal 10244 zcmeHMTWl0n7(V~Bv@>*|)6z;;3oNY{tOb?=mWz;Wy9l+F*6#KO$TGV#v=e4$mYvxx zTB?nSMnvN6#dwQ}4{8WTi6W7Nn8-yj`k<)6sEPQZ0hPojqYwUP&TQFjyZE3n66Pdx z{`qg`{O8;MpP6%(5CW}fWf>uULI{r+rILuz)%HKlQ`#D^5npXfu&!f`W^oMPz- zJOn%hJOn%hJOn%h{x1mNJDWDXj8U)m5bzN25ST!KJ|FyeQ5tmVIHS&^13PC6fV3FJ zPQ!bN-XQh6H0aWCMp1(em@87|3hovIm^;e-u3gZjpAv$)RK6n0E`%29Z+5D4iF2_*FCNGZ4OEiu$5+;MB zm9&!%(uL2RPGTY+W^BYtx+^{!OX`|s2LfLLS5!Qsq?9k^%lLc4!{$iXmhH6FDyOzm zE@GN`EPF4<`ZRSUDpj?ahAnG`nsOX8MMaZs{hFbeBduoIP%Otc%oM!93sI?NbaYu@ zMWcU3)AF%K|LE$bK%;+UQ($aN;H&GGuI-8L(i4XH7!4mEcJ4!w%wqgRzaQ@ktS%34 zqx6|8SX!AjhC@+97Kg91I0!S##93mbH_|5#M5W3MF1RacYo=lKsVNI-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4)w2~(!U>>M0|%wQD^0^C5_738#yiQkzg^Q(A*9Lm51aWu#u L44dP5<}d>Q#@Z{A diff --git a/.gitea/workflows/publish.yml b/.gitea/workflows/publish.yml new file mode 100644 index 0000000..5439ef4 --- /dev/null +++ b/.gitea/workflows/publish.yml @@ -0,0 +1,33 @@ +name: Deploy FastAPI Application + +on: + push: + branches: [ main ] + +jobs: + deploy: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + + - name: Deploy to server + uses: appleboy/ssh-action@master + with: + host: ${{ secrets.SERVER_HOST }} + username: ${{ secrets.SERVER_USERNAME }} + key: ${{ secrets.SERVER_SSH_KEY }} + script: | + # Переходим в директорию проекта + cd ~/fastapi-app + + # Получаем последние изменения из git + git pull origin main + + # Собираем новый образ + docker-compose build + + # Перезапускаем сервисы + docker-compose up -d + + # Очищаем неиспользуемые образы + docker image prune -f \ No newline at end of file diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml deleted file mode 100644 index e1ab762..0000000 --- a/.gitlab-ci.yml +++ /dev/null @@ -1,26 +0,0 @@ -# You can override the included template(s) by including variable overrides -# SAST customization: https://docs.gitlab.com/ee/user/application_security/sast/#customizing-the-sast-settings -# Secret Detection customization: https://docs.gitlab.com/ee/user/application_security/secret_detection/pipeline/#customization -# Dependency Scanning customization: https://docs.gitlab.com/ee/user/application_security/dependency_scanning/#customizing-the-dependency-scanning-settings -# Container Scanning customization: https://docs.gitlab.com/ee/user/application_security/container_scanning/#customizing-the-container-scanning-settings -# Note that environment variables can be set in several places -# See https://docs.gitlab.com/ee/ci/variables/#cicd-variable-precedence -stages: -- build -- test -- deploy -- review -- dast -- staging -- canary -- production -- incremental rollout 10% -- incremental rollout 25% -- incremental rollout 50% -- incremental rollout 100% -- performance -- cleanup -sast: - stage: test -include: -- template: Auto-DevOps.gitlab-ci.yml diff --git a/Dockerfile b/Dockerfile index 27fd426..570da8d 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,4 @@ -FROM python:3.10 +FROM python:3.10-slim WORKDIR /code @@ -8,4 +8,16 @@ RUN pip install --no-cache-dir --upgrade -r /code/requirements.txt COPY . /code -CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "20000"] \ No newline at end of file +CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "8000"] + + +# FROM python:3.10-slim + +# WORKDIR /app + +# COPY app/requirements.txt . +# RUN pip install --no-cache-dir -r requirements.txt + +# COPY app/ . + +# CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "8000"] \ No newline at end of file diff --git a/README.md b/README.md index be12fc1..388cfcb 100644 --- a/README.md +++ b/README.md @@ -1,93 +1 @@ -# SYBIKO_website - - - -## Getting started - -To make it easy for you to get started with GitLab, here's a list of recommended next steps. - -Already a pro? Just edit this README.md and make it your own. Want to make it easy? [Use the template at the bottom](#editing-this-readme)! - -## Add your files - -- [ ] [Create](https://docs.gitlab.com/ee/user/project/repository/web_editor.html#create-a-file) or [upload](https://docs.gitlab.com/ee/user/project/repository/web_editor.html#upload-a-file) files -- [ ] [Add files using the command line](https://docs.gitlab.com/ee/gitlab-basics/add-file.html#add-a-file-using-the-command-line) or push an existing Git repository with the following command: - -``` -cd existing_repo -git remote add origin https://cv4227119.regru.cloud/root/sybiko_website.git -git branch -M main -git push -uf origin main -``` - -## Integrate with your tools - -- [ ] [Set up project integrations](https://cv4227119.regru.cloud/root/sybiko_website/-/settings/integrations) - -## Collaborate with your team - -- [ ] [Invite team members and collaborators](https://docs.gitlab.com/ee/user/project/members/) -- [ ] [Create a new merge request](https://docs.gitlab.com/ee/user/project/merge_requests/creating_merge_requests.html) -- [ ] [Automatically close issues from merge requests](https://docs.gitlab.com/ee/user/project/issues/managing_issues.html#closing-issues-automatically) -- [ ] [Enable merge request approvals](https://docs.gitlab.com/ee/user/project/merge_requests/approvals/) -- [ ] [Set auto-merge](https://docs.gitlab.com/ee/user/project/merge_requests/merge_when_pipeline_succeeds.html) - -## Test and Deploy - -Use the built-in continuous integration in GitLab. - -- [ ] [Get started with GitLab CI/CD](https://docs.gitlab.com/ee/ci/quick_start/index.html) -- [ ] [Analyze your code for known vulnerabilities with Static Application Security Testing (SAST)](https://docs.gitlab.com/ee/user/application_security/sast/) -- [ ] [Deploy to Kubernetes, Amazon EC2, or Amazon ECS using Auto Deploy](https://docs.gitlab.com/ee/topics/autodevops/requirements.html) -- [ ] [Use pull-based deployments for improved Kubernetes management](https://docs.gitlab.com/ee/user/clusters/agent/) -- [ ] [Set up protected environments](https://docs.gitlab.com/ee/ci/environments/protected_environments.html) - -*** - -# Editing this README - -When you're ready to make this README your own, just edit this file and use the handy template below (or feel free to structure it however you want - this is just a starting point!). Thanks to [makeareadme.com](https://www.makeareadme.com/) for this template. - -## Suggestions for a good README - -Every project is different, so consider which of these sections apply to yours. The sections used in the template are suggestions for most open source projects. Also keep in mind that while a README can be too long and detailed, too long is better than too short. If you think your README is too long, consider utilizing another form of documentation rather than cutting out information. - -## Name -Choose a self-explaining name for your project. - -## Description -Let people know what your project can do specifically. Provide context and add a link to any reference visitors might be unfamiliar with. A list of Features or a Background subsection can also be added here. If there are alternatives to your project, this is a good place to list differentiating factors. - -## Badges -On some READMEs, you may see small images that convey metadata, such as whether or not all the tests are passing for the project. You can use Shields to add some to your README. Many services also have instructions for adding a badge. - -## Visuals -Depending on what you are making, it can be a good idea to include screenshots or even a video (you'll frequently see GIFs rather than actual videos). Tools like ttygif can help, but check out Asciinema for a more sophisticated method. - -## Installation -Within a particular ecosystem, there may be a common way of installing things, such as using Yarn, NuGet, or Homebrew. However, consider the possibility that whoever is reading your README is a novice and would like more guidance. Listing specific steps helps remove ambiguity and gets people to using your project as quickly as possible. If it only runs in a specific context like a particular programming language version or operating system or has dependencies that have to be installed manually, also add a Requirements subsection. - -## Usage -Use examples liberally, and show the expected output if you can. It's helpful to have inline the smallest example of usage that you can demonstrate, while providing links to more sophisticated examples if they are too long to reasonably include in the README. - -## Support -Tell people where they can go to for help. It can be any combination of an issue tracker, a chat room, an email address, etc. - -## Roadmap -If you have ideas for releases in the future, it is a good idea to list them in the README. - -## Contributing -State if you are open to contributions and what your requirements are for accepting them. - -For people who want to make changes to your project, it's helpful to have some documentation on how to get started. Perhaps there is a script that they should run or some environment variables that they need to set. Make these steps explicit. These instructions could also be useful to your future self. - -You can also document commands to lint the code or run tests. These steps help to ensure high code quality and reduce the likelihood that the changes inadvertently break something. Having instructions for running tests is especially helpful if it requires external setup, such as starting a Selenium server for testing in a browser. - -## Authors and acknowledgment -Show your appreciation to those who have contributed to the project. - -## License -For open source projects, say how it is licensed. - -## Project status -If you have run out of energy or time for your project, put a note at the top of the README saying that development has slowed down or stopped completely. Someone may choose to fork your project or volunteer to step in as a maintainer or owner, allowing your project to keep going. You can also make an explicit request for maintainers. +sybiko.ru \ No newline at end of file diff --git a/docker-compose.yml b/docker-compose.yml index 0b05ff2..e2a05ab 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -43,11 +43,36 @@ # version: '3' +version: '3.8' + services: - web: + fastapi: build: . ports: - - "20000:20000" + - "8000:8000" + restart: always + container_name: fastapi-app + networks: + - app-network + + # nginx: + # image: nginx:alpine + # ports: + # - "80:80" + # - "443:443" + # volumes: + # - ./nginx/nginx.conf:/etc/nginx/conf.d/default.conf + # - /etc/letsencrypt:/etc/letsencrypt:ro + # depends_on: + # - fastapi + # networks: + # - app-network + # restart: always + +networks: + app-network: + driver: bridge + # nginx: # image: nginx:alpine diff --git a/main.py b/main.py index 661c160..94e731a 100644 --- a/main.py +++ b/main.py @@ -13,7 +13,7 @@ ID = '340394898' app = FastAPI() # Для совместимости с WSGI -application = WSGIMiddleware(app) +# application = WSGIMiddleware(app) app.mount("/static", StaticFiles(directory="static"), name="static") templates = Jinja2Templates(directory="templates") @@ -30,7 +30,7 @@ async def index(request: Request): async def get_tracklink_presentation(): # Здесь вы можете добавить логику для отслеживания открытий # Например, увеличить счетчик в базе данных - file_path = "static/doc/SYBIKO_TrackLink.pdf" + file_path = "/static/doc/SYBIKO_TrackLink.pdf" headers = { 'Content-Disposition': 'inline; filename="SYBIKO_TrackLink.pdf"' @@ -76,6 +76,6 @@ Email: {form_data.email} print(se) -# Для локальной разработки -if __name__ == "__main__": - uvicorn.run(app, host="0.0.0.0", port=8000) +# # Для локальной разработки +# if __name__ == "__main__": +# uvicorn.run(app, host="0.0.0.0", port=8000) diff --git a/nginx/nginx.conf b/nginx/nginx.conf new file mode 100644 index 0000000..52fd99f --- /dev/null +++ b/nginx/nginx.conf @@ -0,0 +1,29 @@ +server { + listen 80; + server_name sybiko.ru; # Замените на ваш домен + + location / { + return 301 https://$host$request_uri; + } +} + +server { + listen 443 ssl; + server_name sybiko.ru; # Замените на ваш домен + + ssl_certificate /etc/letsencrypt/live/sybiko.ru/fullchain.pem; + ssl_certificate_key /etc/letsencrypt/live/sybiko.ru/privkey.pem; + + ssl_protocols TLSv1.2 TLSv1.3; + ssl_ciphers ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-CHACHA20-POLY1305:DHE-RSA-AES128-GCM-SHA256:DHE-RSA-AES256-GCM-SHA384; + ssl_prefer_server_ciphers off; + + location / { + proxy_pass http://fastapi:8000; + proxy_http_version 1.1; + proxy_set_header Upgrade $http_upgrade; + proxy_set_header Connection 'upgrade'; + proxy_set_header Host $host; + proxy_cache_bypass $http_upgrade; + } +} \ No newline at end of file