Skip to content

itu-devops-groupn/itu-minitwit

Repository files navigation

Setting up Docker Swarm test environment

To set up Docker Swarm using Ansible, follow these steps:

  1. Ensure Ansible is installed (example for Mac):

    brew install ansible
  2. Create a PAT token in your Digital Ocean project (OBS! not used on prod yet, create your own project to test).

  3. Export necessary environment variables:

    export TEST_DIGITAL_OCEAN_TOKEN="your_digital_ocean_token"
    export FINGER_PRINT="your_ssh_key_fingerprint"
  4. Run Ansible playbook to create/update droplets:

    ansible-playbook -i ansible/inventory.ini ansible/create_droplets.yml
  5. Whitelist the IPs in our Digital Ocean production DB cluster. And manually deploy via the manager.

    ssh root@<created_manager_IP> "cd /remote_files && bash deploy.sh"
  6. Cleanup:

    ansible-playbook -i ansible/inventory.ini ansible/create_droplets.yml --tags teardown

Autorelease and semantic versioning (how-to)

A workflow is run on every merge where changes are made to the src-folder on main. The workflow will take the latest release version tag and increment the patch number by default. This means, that if you merge 10 commits to main, only 1 version increment will happen.

It is also possible to update the minor- and major-version by either writing #minor or #major in the commit message. This will then increment the major (and reset patch and minor) if that is asked for, or increment minor (and reset patch).

Note: A release will also be made and set to latest.
The release will have the autogenerated changelog for releases and the tag defined above will be used.

How to run in docker

Prerequisites

Docker

To do this, you need a connection string file with the filename connstring.txt in your /tmp folder. Get the file from one of your colleagues. Example if it is in your downloads folder:

cp ~/Downloads/connstring.txt /tmp/connstring.txt

Digital Ocean

You need to make sure your current IP address is an allowed host in the Digital Ocean database. You can do this by going to the Digital Ocean console and adding your IP address to the allowed hosts.

Running the application locally

To run the program, follow these steps:

  1. Build Docker Images:

    docker-compose build
  2. Start Containers:

    docker-compose up

Setup test suite (not updated to psql)

  1. Create empty test db

    touch /tmp/test-minitwit.db &&
    sqlite3 /tmp/test-minitwit.db < schema.sql
  2. Start your application in docker

  3. Make sure you have downloaded 'minitwit_simulator.py' and 'minitwit_scenario.csv'. Run following commands from repo root directory (itu-minitwit):

    curl -L -o test/minitwit_simulator.py https://raw.githubusercontent.com/itu-devops/lecture_notes/master/sessions/session_03/API_Spec/minitwit_simulator.py
    curl -L -o test/minitwit_scenario.csv https://raw.githubusercontent.com/itu-devops/lecture_notes/master/sessions/session_03/API_Spec/minitwit_scenario.csv
  4. Test

    python3 test/minitwit_simulator.py "http://localhost:5050"

    Only errors are displayed in the output

  5. Verify that /tmp/test-minitwit.db is now filled up with data