To synchronize dependencies run:
go mod tidyYou can run it by writing:
go run .When running you can find it on: http://localhost:5001
To use an empty database you need to simply delete the database folder in the tmp folder. This can be done like:
rm /tmp/minitwit.dbThe repository contains a small database file contained with some messages and users. To make the application use this database you need to copy the minitwit.db from the root folder to the "/tmp" folder on your machine.
cp minitwit.db /tmp/Load the variables from the .env file into the shell environment:
set -a && source .env && set +aThen run:
make runlocalswarmThis command is idempotent. The result should be a swarm of the application that uses a postgresql database. If you want to spin up the monitoring stack you can run:
make deploymonitoringTo remove the solution and/or monitoring do:
make cleanYou can also do the steps manually if you desire:
Docker swarm does not support building the images using "build" in the compose file. Therefore the local images must be built before deploying the stack:
# API
docker build -t minitwit-api:dev -f Dockerfile.api .
# Web
docker build -t minitwit-web:dev -f Dockerfile.web .
# both
make buildlocaldocker swarm initdocker network create --driver overlay minitwit-networkLoad the variables from the .env file into the shell environment:
set -a && source .env && set +a# API And Web services
docker stack deploy -c docker-compose.develop.yml minitwit
# Monitoring services
docker stack deploy -c docker-compose.monitoring.yml monitoringdocker service ls## For API
docker service logs minitwit_api
## For Web
docker service logs minitwit_webdocker stack rm minitwit
docker stack rm monitoringThe docker commands have been inserted into a Makefile. To build and run the application with docker:
make runlocalStop minitwit (using docker):
docker compose downpython3 minitwit_simulator.py http://localhost:5001/apiThe API is part of the application. It is accessible on the same host but with the route /api. See api.go
This requires two console windows.
1) Run minitwit
cd /minitwit-devops
run go .
2) Run the minitwit_sim_api_test.py inside the test folder.
cd /minitwit-devops/test
pytest minitwit_sim_api_test.pyCreate a Personal Access Token (Write scope) in:
DigitalOcean → API → Tokens/Keys → Generate New Token
Copy the token (looks like dop_v1_...).
Temporary (current terminal only):
export DIGITAL_OCEAN_TOKEN="dop_v1_..."Persistent (add to ~/.zshrc or ~/.bashrc):
echo 'export DIGITAL_OCEAN_TOKEN="dop_v1_..."' >> ~/.bashrc
source ~/.bashrcIf you don’t set it, your Vagrantfile uses ~/.ssh/do_vagrant.
You must have these files on your host:
~/.ssh/do_vagrant (private key)
~/.ssh/do_vagrant.pub (public key)
Create them (recommended):
ssh-keygen -t ed25519 -f ~/.ssh/do_vagrant -C "do-vagrant"export DIGITAL_OCEAN_SSH_KEY_PATH="~/.ssh/some/path"This is the name of the SSH key object inside DigitalOcean. Default is do-vagrant.
export DIGITAL_OCEAN_SSH_KEY_NAME="do-vagrant-myname"echo $DIGITAL_OCEAN_TOKEN
echo $DIGITAL_OCEAN_SSH_KEY_PATH
echo $DIGITAL_OCEAN_SSH_KEY_NAMEvagrant up --provider=digital_ocean