SgMakarov
    • Create new note
    • Create a note from template
      • Sharing URL Link copied
      • /edit
      • View mode
        • Edit mode
        • View mode
        • Book mode
        • Slide mode
        Edit mode View mode Book mode Slide mode
      • Customize slides
      • Note Permission
      • Read
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Write
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Engagement control Commenting, Suggest edit, Emoji Reply
    • Invite by email
      Invitee

      This note has no invitees

    • Publish Note

      Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

      Your note will be visible on your profile and discoverable by anyone.
      Your note is now live.
      This note is visible on your profile and discoverable online.
      Everyone on the web can find and read all notes of this public team.
      See published notes
      Unpublish note
      Please check the box to agree to the Community Guidelines.
      View profile
    • Commenting
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
      • Everyone
    • Suggest edit
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
    • Emoji Reply
    • Enable
    • Versions and GitHub Sync
    • Note settings
    • Note Insights New
    • Engagement control
    • Make a copy
    • Transfer ownership
    • Delete this note
    • Save as template
    • Insert from template
    • Import from
      • Dropbox
      • Google Drive
      • Gist
      • Clipboard
    • Export to
      • Dropbox
      • Google Drive
      • Gist
    • Download
      • Markdown
      • HTML
      • Raw HTML
Menu Note settings Note Insights Versions and GitHub Sync Sharing URL Create Help
Create Create new note Create a note from template
Menu
Options
Engagement control Make a copy Transfer ownership Delete this note
Import from
Dropbox Google Drive Gist Clipboard
Export to
Dropbox Google Drive Gist
Download
Markdown HTML Raw HTML
Back
Sharing URL Link copied
/edit
View mode
  • Edit mode
  • View mode
  • Book mode
  • Slide mode
Edit mode View mode Book mode Slide mode
Customize slides
Note Permission
Read
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Write
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Engagement control Commenting, Suggest edit, Emoji Reply
  • Invite by email
    Invitee

    This note has no invitees

  • Publish Note

    Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

    Your note will be visible on your profile and discoverable by anyone.
    Your note is now live.
    This note is visible on your profile and discoverable online.
    Everyone on the web can find and read all notes of this public team.
    See published notes
    Unpublish note
    Please check the box to agree to the Community Guidelines.
    View profile
    Engagement control
    Commenting
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    • Everyone
    Suggest edit
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    Emoji Reply
    Enable
    Import from Dropbox Google Drive Gist Clipboard
       Owned this note    Owned this note      
    Published Linked with GitHub
    • Any changes
      Be notified of any changes
    • Mention me
      Be notified of mention me
    • Unsubscribe
    # CREDENTIALS Team: * Daniil Manakovskiy (d.manakovskiy@innopolis.university) * Sergey Makarov (s.makarov@innopolis.university) * Maks Kureikin (m.kureykin@innopolis.university) [TOC] ## Apllication description The application used is a bit modified Innopolis University's sport course service (https://sport.innopolis.university). Original source code: https://github.com/WinnerOK/SWP_sport_back Modified source code: https://github.com/SgMakarov/SWP_sport_back ## Machines Zerotier network: `af415e486fac1c46` ### InnoVM (for CI) ip (innopolis net): `10.90.138.210` ip (zerotier): `192.168.196.167` login: `root` password: `R00tR00t` ### InnoVM (web1) ip (innopolis net): `10.90.138.215` ip (zerotier): `192.168.196.14` login: `root` password: `R00tR00t` ### InnoVM (web2) ip (innopolis net): `10.90.138.216` ip (zerotier): `192.168.196.25` login: `root` password: `R00tR00t` ### InnoVM (db) ip (innopolis net) `10.90.138.217` ip (zerotier): `192.168.196.120` login: `root` password: `R00tR00t` ### InnoVM (backup) ip (innopolis net) `10.90.138.219` ip (zerotier): `192.168.196.232` login: `root` password: `RootRott123_` ### AWS (load balancer) ip (public): `3.131.64.143` ip (zerotier): `192.168.196.10` login: ubuntu ## Services ### CI * ssh: ubuntu@ci.snafinal.sgmakarov.ru * jenkins: `ciadmin`:`jfkdls;a` * gh token: `d9683b5ae03224b868ce1f1b4f6d752c8a317d21` ### DB user: `pguser` password: `qwertypassword` database: `sport_database` ### Sport username: `root` password: `qwertyytrewq` ## To backup ### from CI: * `/var/lib/jenkins` ### from web[1-2] * `/var/app/` ### from load balancer * `/etc/haproxy` ### from DB * `/var/db` ## /etc/hosts/ 192.168.196.167 ci_server 192.168.196.14 web_server1 192.168.196.25 web_server2 192.168.196.120 db_server 192.168.196.10 balancer_server 192.168.196.232 backup_server # CONFIGS ## Load balancer ![](https://i.imgur.com/p4THF2o.png) ![](https://i.imgur.com/CK1CpRV.png) ![](https://i.imgur.com/Qr1f2Fa.png) ## Bacula ![](https://i.imgur.com/Lmun8BV.png) ![](https://i.imgur.com/gj1OVq9.jpg) ![](https://i.imgur.com/YYsZYsM.jpg) ![](https://i.imgur.com/GXIxIAv.png) Here are represented only full level backups available for manual start up: ![](https://i.imgur.com/Z2nWziF.jpg) ![](https://i.imgur.com/dAECpiM.jpg) ![](https://i.imgur.com/ibNLwcq.jpg) ## Jenkins We have installed the following plugins and their dependencies: * all default plugins * Blue Ocean * Ansible plugin * Docker plugin * Git plugin Jenkinsfile: ```jenkinsfile pipeline { agent any stages { stage('Test') { post { cleanup { echo 'Cleanup...' sh 'docker-compose down -v --rmi all && rm docker-compose.yml' } } steps { echo 'Testing..' sh ''' ln -s docker-compose-test.yml docker-compose.yml echo "Building test images..." docker-compose build --no-cache docker-compose up -d echo "Waiting for database to go up..." docker-compose exec -T adminpanel bash -c "while !</dev/tcp/db/5432; do sleep 1; done;" echo "Making migrations..." docker-compose exec -T adminpanel python manage.py makemigrations docker-compose exec -T adminpanel python manage.py migrate echo "Running tests..." docker-compose exec -T adminpanel pytest echo "done" ''' } } stage('Build') { environment { PYTHON_VERSION = credentials('python-version') } steps { echo 'Building..' script { dockerInstanceDjango = docker.build("winnerokay/sna-app", '-t latest --build-arg PYTHON_VERSION=$PYTHON_VERSION ./adminpage') dockerInstanceNginx = docker.build("winnerokay/sna-app-nginx", '-t latest ./nginx') } } } stage('Migrate') { environment { ENV_FILE = credentials('production-envfile') } steps { echo 'Making migrations to the db...' sh ' docker run --env-file $ENV_FILE -e POSTGRES_SERVER=$(getent hosts db_server | awk \'{ print $1 }\') winnerokay/sna-app:latest bash -c "python manage.py makemigrations && python manage.py migrate"' } } stage('Push to registry') { environment { registryCredentialSet = 'dockerhub' } steps { echo 'Publishing....' script { docker.withRegistry('', registryCredentialSet){ dockerInstanceDjango.push("${env.GIT_COMMIT}") dockerInstanceDjango.push("latest") dockerInstanceNginx.push("${env.GIT_COMMIT}") dockerInstanceNginx.push("latest") } } } } stage('Deploy') { environment { ansibleInventoryFile = credentials('ansible-inventory-web') productionEnvfile = credentials('production-envfile') } steps { echo 'Deploying...' ansiblePlaybook( playbook: "deploy_web.yml", inventory: "$ansibleInventoryFile", extras: '-e envfilePath=$productionEnvfile' ) } } } } ``` ## Ansible ### Inventory ```ini [snafinal_web] # web 1 10.90.138.215 # web 2 10.90.138.216 [snafinal_db] 10.90.138.217 [snafinal_ci] 10.90.138.210 [snafinal_backup] 10.90.138.219 [snafinal_loadbalancer] [snafinal_loadbalancer:vars] ansible_user=ubuntu [snafinal:children] snafinal_web snafinal_db snafinal_loadbalancer snafinal_ci snafinal_backup [snafinal:vars] ansible_user=ansible ansible_password=qwertyytrewq ``` ### Add all hosts to `/etc/hosts` ```yaml - name: add addresses hosts: snafinal become: true tasks: - name: Ensure CI server present lineinfile: path: /etc/hosts regexp: 'ci_server' line: 192.168.196.167 ci_server - name: Ensure web1 server present lineinfile: path: /etc/hosts regexp: 'web_server1' line: 192.168.196.14 web_server1 - name: Ensure web2 server present lineinfile: path: /etc/hosts regexp: 'web_server2' line: 192.168.196.25 web_server2 - name: Ensure db server present lineinfile: path: /etc/hosts regexp: 'db_server' line: 192.168.196.120 db_server - name: Ensure balancer server present lineinfile: path: /etc/hosts regexp: 'balancer_server' line: 192.168.196.10 balancer_server - name: Ensure backup server present lineinfile: path: /etc/hosts regexp: 'backup_server' line: 192.168.196.232 backup_server ``` ### Setup bacula client ```yaml - name: setup bacula hosts: snafinal_web:snafinal_db:snafinal_ci:snafinal_loadbalancer become: true tasks: - name: Update apt repos apt: update_cache: yes - name: Install bacula client apt: state: present name: - bacula-client ``` ### Install docker ```yaml --- - name: docker_setup hosts: snafinal_web become: true tasks: - name: download docker get_url: url: https://get.docker.com dest: /tmp/get_docker.sh mode: '0770' - name: install docker shell: /tmp/get_docker.sh - name: download docker-compose get_url: url: "https://github.com/docker/compose/releases/download/1.27.4/docker-compose-Linux-x86_64" dest: /usr/local/bin/docker-compose mode: '0770' ``` ### Add to zerotier network ```yaml --- - name: setup_zerotier hosts: snafinal tasks: - name: Download zerotier get_url: url: https://install.zerotier.com dest: /tmp/get_zerotier.sh mode: '0770' - name: Install zerotier become: true shell: /tmp/get_zerotier.sh - name: Join network become: true shell: zerotier-cli join af415e486fac1c46 - name: Print zerotier IDs become: true command: zerotier-cli info register: info - debug: msg="{{info.stdout}}" ``` ### Start database ```yaml - name: start postgres hosts: snafinal_db tasks: - name: Make db_data folder become: true file: path: /var/db/data state: directory - name: Run database container become: true shell: docker run -d -p 5432:5432 --name db -v /var/db/data:/var/lib/postgresql/data -e POSTGRES_USER=pguser -e POSTGRES_PASSWORD=qwertypassword -e POSTGRES_DB=sport_database --restart unless-stopped postgres:11-alpine ``` ### Deploy web ```yaml - name: deploy web app hosts: snafinal_web become: true vars: envfilePath: .env tasks: - name: Get running containers shell: docker ps -aq register: running_containers - name: Stop all docker containers shell: docker stop $(docker ps -aq) when: running_containers.stdout | length > 0 - name: Delete all stopped docker containers shell: docker rm $(docker ps -aq) when: running_containers.stdout | length > 0 - name: Remove unused/dangling image shell: docker image prune -af - name: Get db_server ip shell: "getent hosts db_server | awk '{ print $1 }'" register: db_server_ip - name: Copy production compose copy: src: ./docker-compose-sna-prod.yml dest: /root/docker-compose.yml - name: Copy production env copy: src: "{{ envfilePath }}" dest: /root/.env - name: Run docker-compose shell: docker-compose -f /root/docker-compose.yml up -d environment: POSTGRES_SERVER: "{{ db_server_ip.stdout }}" - name: Collect statics shell: docker-compose -f /root/docker-compose.yml exec -T adminpanel bash -c './manage.py collectstatic --noinput' - name: Restart nginx shell: docker-compose -f /root/docker-compose.yml restart nginx ```

    Import from clipboard

    Paste your markdown or webpage here...

    Advanced permission required

    Your current role can only read. Ask the system administrator to acquire write and comment permission.

    This team is disabled

    Sorry, this team is disabled. You can't edit this note.

    This note is locked

    Sorry, only owner can edit this note.

    Reach the limit

    Sorry, you've reached the max length this note can be.
    Please reduce the content or divide it to more notes, thank you!

    Import from Gist

    Import from Snippet

    or

    Export to Snippet

    Are you sure?

    Do you really want to delete this note?
    All users will lose their connection.

    Create a note from template

    Create a note from template

    Oops...
    This template has been removed or transferred.
    Upgrade
    All
    • All
    • Team
    No template.

    Create a template

    Upgrade

    Delete template

    Do you really want to delete this template?
    Turn this template into a regular note and keep its content, versions, and comments.

    This page need refresh

    You have an incompatible client version.
    Refresh to update.
    New version available!
    See releases notes here
    Refresh to enjoy new features.
    Your user state has changed.
    Refresh to load new user state.

    Sign in

    Forgot password

    or

    By clicking below, you agree to our terms of service.

    Sign in via Facebook Sign in via Twitter Sign in via GitHub Sign in via Dropbox Sign in with Wallet
    Wallet ( )
    Connect another wallet

    New to HackMD? Sign up

    Help

    • English
    • 中文
    • Français
    • Deutsch
    • 日本語
    • Español
    • Català
    • Ελληνικά
    • Português
    • italiano
    • Türkçe
    • Русский
    • Nederlands
    • hrvatski jezik
    • język polski
    • Українська
    • हिन्दी
    • svenska
    • Esperanto
    • dansk

    Documents

    Help & Tutorial

    How to use Book mode

    Slide Example

    API Docs

    Edit in VSCode

    Install browser extension

    Contacts

    Feedback

    Discord

    Send us email

    Resources

    Releases

    Pricing

    Blog

    Policy

    Terms

    Privacy

    Cheatsheet

    Syntax Example Reference
    # Header Header 基本排版
    - Unordered List
    • Unordered List
    1. Ordered List
    1. Ordered List
    - [ ] Todo List
    • Todo List
    > Blockquote
    Blockquote
    **Bold font** Bold font
    *Italics font* Italics font
    ~~Strikethrough~~ Strikethrough
    19^th^ 19th
    H~2~O H2O
    ++Inserted text++ Inserted text
    ==Marked text== Marked text
    [link text](https:// "title") Link
    ![image alt](https:// "title") Image
    `Code` Code 在筆記中貼入程式碼
    ```javascript
    var i = 0;
    ```
    var i = 0;
    :smile: :smile: Emoji list
    {%youtube youtube_id %} Externals
    $L^aT_eX$ LaTeX
    :::info
    This is a alert area.
    :::

    This is a alert area.

    Versions and GitHub Sync
    Get Full History Access

    • Edit version name
    • Delete

    revision author avatar     named on  

    More Less

    Note content is identical to the latest version.
    Compare
      Choose a version
      No search result
      Version not found
    Sign in to link this note to GitHub
    Learn more
    This note is not linked with GitHub
     

    Feedback

    Submission failed, please try again

    Thanks for your support.

    On a scale of 0-10, how likely is it that you would recommend HackMD to your friends, family or business associates?

    Please give us some advice and help us improve HackMD.

     

    Thanks for your feedback

    Remove version name

    Do you want to remove this version name and description?

    Transfer ownership

    Transfer to
      Warning: is a public team. If you transfer note to this team, everyone on the web can find and read this note.

        Link with GitHub

        Please authorize HackMD on GitHub
        • Please sign in to GitHub and install the HackMD app on your GitHub repo.
        • HackMD links with GitHub through a GitHub App. You can choose which repo to install our App.
        Learn more  Sign in to GitHub

        Push the note to GitHub Push to GitHub Pull a file from GitHub

          Authorize again
         

        Choose which file to push to

        Select repo
        Refresh Authorize more repos
        Select branch
        Select file
        Select branch
        Choose version(s) to push
        • Save a new version and push
        • Choose from existing versions
        Include title and tags
        Available push count

        Pull from GitHub

         
        File from GitHub
        File from HackMD

        GitHub Link Settings

        File linked

        Linked by
        File path
        Last synced branch
        Available push count

        Danger Zone

        Unlink
        You will no longer receive notification when GitHub file changes after unlink.

        Syncing

        Push failed

        Push successfully