{"id":27769267,"url":"https://github.com/sudiptob2/microserve","last_synced_at":"2025-06-30T02:05:46.518Z","repository":{"id":127021574,"uuid":"480882986","full_name":"sudiptob2/microserve","owner":"sudiptob2","description":"Microverservice deployment practice application. Django, Flask, Angular, React, MySQL, Postgress, Rabbit. CI/CD. Deployed on Linode instance Using docker ","archived":false,"fork":false,"pushed_at":"2022-04-27T12:21:59.000Z","size":222,"stargazers_count":7,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-04-29T20:14:21.297Z","etag":null,"topics":["angular","django","docker","flask","mysql","postgressql","rabbit"],"latest_commit_sha":null,"homepage":"https://www.shuta.xyz","language":null,"has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/sudiptob2.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2022-04-12T16:10:46.000Z","updated_at":"2022-08-31T02:04:23.000Z","dependencies_parsed_at":null,"dependency_job_id":"d61e13c6-91ad-4c0f-a5e1-f161b2789b53","html_url":"https://github.com/sudiptob2/microserve","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/sudiptob2/microserve","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sudiptob2%2Fmicroserve","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sudiptob2%2Fmicroserve/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sudiptob2%2Fmicroserve/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sudiptob2%2Fmicroserve/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/sudiptob2","download_url":"https://codeload.github.com/sudiptob2/microserve/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sudiptob2%2Fmicroserve/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":262697255,"owners_count":23349891,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["angular","django","docker","flask","mysql","postgressql","rabbit"],"created_at":"2025-04-29T20:14:16.080Z","updated_at":"2025-06-30T02:05:46.492Z","avatar_url":"https://github.com/sudiptob2.png","language":null,"readme":"# Overview\n\nThis is an experiment/Lab to practice deploying microservice application a local ubuntu VM. The `docker-compose.yml `file aggregates backend images required for the microserve api to work. Backend has two APIs - `microserve-admin` and `microserve-main`\n\nAlso supporting services : `rabbit`, `postgres` and `mysql` are also created with this `docker-compose` in the production server\n\n### Related repositories:\n\n- [microserve-main](https://github.com/sudiptob2/microserve-main)\n- [microserve-main-front](https://github.com/sudiptob2/microserve-main-front)\n- [microserve-admin](https://github.com/sudiptob2/microserve-admin)\n- [microserve-admin-front](https://github.com/sudiptob2/microserve-admin-front)\n\n![Alt text](images/system-architecture.jpg?raw=true \"System Architecture\")\n\n# Setting Up a Ubuntu VM\n\n## Multipass setup\n\nWe will use multipass to create a virtual machine in our host machine. In this case my host machine is **ubuntu-20.0**\n\n- Install multipass\n- Spin up a VM\n\n**commands**\n\n```\nsudo snap install multipass\n\nmultipass launch --name demo-server\n```\n\nThis will create a lightweight VM with Ubuntu OS installed in it.\n\n## NGINX setup\n\nAt this point let's install **NGINX** and **lynx - a command line browser**\n\n```\nmultipass exec demo-server bash\nsudo apt update\nsudo apt install nginx\nsudo apt instll lynx\n```\n\nAfter installation NGINX will be started automatically. Check the status of NGINX using the following command\n\n```\nsudo systemctl status nginx\n```\n\nIf NGINX is not active start the NGINX using the following command.\n\n```\nsudo systemctl start nginx\n```\n\nNow if you visit `lynx http:localhost:80` you will see the default nginx page in this command line browser\n\nIn the host machine terminal use `multipass list` command to list down all multipass instances. Your output will look something like following.\n\n```\nName                    State             IPv4             Image\nprimary                 Suspended         --               Ubuntu 20.04 LTS\ndemo-server             Running           10.79.154.253    Ubuntu 20.04 LTS\n\n```\n\ncopy the IPV4 address of the demo-server and visit the IP address from Chrome browser in your host. You will be able to view the default NGINX page served in the browser.\n\nWe have two front end website as you can see in the system design diagram. Let's create to fake domain aliases in our host machine for them.\n\nI will use _microserve.com_ and _admin.microserve.com_ for main and admin website respectively.\n\n```\nsudo vim /etc/hosts\n\nadd the following lines\n\n...\n10.79.154.253 admin.microserve.com\n10.79.154.253 microserve.com\n...\n\n```\n\nNow if you just type [http://microserve.com](http://microserve.com) it will be redirected to the ip address of the VM and show the default NGINX page at this point.\n\n# Setup Dokcer and docker-compose\n\nAs our backend applications will be running using docker we have to install docker and docker compose. Just follow the official docker instruction to install docker and docker compose in the VM.\n\n- [docker installation](https://docs.docker.com/engine/install/ubuntu/)\n- [must follow post installation guide](https://docs.docker.com/engine/install/linux-postinstall/)\n- [docker-compose installation](https://docs.docker.com/compose/install/)\n\n# Setup GitHub SSH\n\nOur codes are in GitHub. so you have to set up an ssh to pull codes from the GitHub. Otherwise, you can copy codes from host to multipass VM using `multipass transfer` command. We will use both ways in this guide.\n\nHere is a nice blog on how to set up ssh in GitHub. [setup ssh in GitHub](https://www.inmotionhosting.com/support/server/ssh/how-to-add-ssh-keys-to-your-github-account/)\n\nNow pull this repository into your VM.\n\n# Spin up the backend\n\nTo run the backend you have to go to the repository folder. Now create a `.env` file form the `.env.template` file\n\nThen just use following command to run the docker compose.\n\n```\ndocker-compose up -d\n```\n\nsee the status of the containers using following command\n\n```\ndocker ps\n```\n\n# Get the front-end files\n\nWe can pull the front-end code from the github directly into the server. But as I said earlier, we will use `multipass transfer command` to move files from host computer to the server.\n\nPull both front-end repo in your host machine. Now run the following commands to generate production build for the angular and react based frontends.\n\n### Admin frontend(React)\n\nFirst put appropriate env variables in the .env file. Base url in this case will be _admin.microserve.com_\n\n```\ndocker-compose up -d\n```\n\n```\ndocker-compose exec web npm run build\n```\n\nmake zip of the build folder\n\n```\ntar -czvf build-admin.tar.gz build\n```\n\nTransfer files to the multipass server\n\n```\nmultipass transfer  build-admin.tar.gz demo-server:build-admin.tar.gz\n```\n\nNow in the server, unzip the files\n\n```\ntar -xf build-admin.tar.gz\n```\n\nFinally move the files into the `/var/www/admin-front` directory\n\n```\nsudo cp -r build/. /var/www/admin-front/\n```\n\nSimilarly, we have to build and move the build folder to `/var/www/main-front` directory for the angular based main app.\n\n# Setting up nginx configurations\n\nFirst, go to `/etc/nginx/sites-available` directory. Here we will add two configuration file. On for our admin panel website another for main website. First remove the `default` configuration file placed there. Next, create a file `microserve.com` and paste the following configuration there.\n\n```\nserver {\n    listen       80;\n    server_name  microserve.com www.microserve.com;\n\n    location /api/ {\n\t    proxy_set_header HOST $host;\n\t    proxy_set_header X-Forwarded-Proto $scheme;\n    \t    proxy_set_header X-Real-IP $remote_addr;\n    \t    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;\n\t    proxy_pass http://127.0.0.1:8001;\n    }\n\n\n    location / {\n        root   /var/www/main-front;\n        try_files $uri $uri/ /index.html;\n        index  index.html index.htm;\n    }\n\n    error_page   500 502 503 504  /50x.html;\n    location = /50x.html {\n        root   /var/www/error;\n    }\n\n}\n\n\n```\n\ncreate another file `admin.microserve.com` and paste the following configuration there.\n\n```\nserver {\n    listen       80;\n    server_name  admin.microserve.com  www.admin.microserve.com;\n\n    location / {\n        root   /var/www/admin-front;\n        try_files $uri $uri/ /index.html;\n        index  index.html index.htm;\n    }\n\n    location /api/ {\n\t    proxy_set_header HOST $host;\n\t    proxy_set_header X-Forwarded-Proto $scheme;\n    \t    proxy_set_header X-Real-IP $remote_addr;\n    \t    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;\n\t    proxy_pass http://127.0.0.1:8000;\n    }\n\n    error_page   500 502 503 504  /50x.html;\n    location = /50x.html {\n        root   /var/www/error;\n    }\n\n}\n\n```\n\nNow to enable these two configuration file we have to create a `sys link` with the folder `sites-enabled`\n\n```\nsudo ln -s /etc/nginx/sites-available/microserve.com /etc/nginx/sites-enabled/microserve.com\n```\n\n```\nsudo ln -s /etc/nginx/sites-available/admin.microserve.com /etc/nginx/sites-enabled/admin.microserve.com\n```\n\nFinally, we have to reload the NGINX so that the changes can take effect.\n\n```\nnginx -s reload\n```\n\nNow if you visit `microserve.com` and `admin.microserve.com` you will be able to see the desired webpages.\n\nHowever, the websites don't use **https** protocol. Let's install a self-signed **TLS** certificate so that we can use **https**\n\nFollow [this blog](https://www.digitalocean.com/community/tutorials/how-to-create-a-self-signed-ssl-certificate-for-nginx-in-ubuntu-18-04) to install a self-signed certificate.\n\nThe final NGINX config files will look like something as follows.\n\n_microserve.com_\n\n```\nserver {\n\n    listen 443 ssl;\n    listen [::]:443 ssl;\n    include snippets/self-signed.conf;\n    include snippets/ssl-params.conf;\n\n    server_name  microserve.com www.microserve.com;\n\n    location /api/ {\n\t    proxy_set_header HOST $host;\n\t    proxy_set_header X-Forwarded-Proto $scheme;\n    \t    proxy_set_header X-Real-IP $remote_addr;\n    \t    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;\n\n\t    proxy_pass http://127.0.0.1:8001;\n    }\n\n\n    location / {\n        root   /var/www/main-front;\n        try_files $uri $uri/ /index.html;\n        index  index.html index.htm;\n    }\n\n    error_page   500 502 503 504  /50x.html;\n    location = /50x.html {\n        root   /var/www/error;\n    }\n\n}\n\nserver {\n    listen 80;\n    listen [::]:80;\n    server_name  microserve.com www.microserve.com;\n    return 302 https://$server_name$request_uri;\n}\n\n```\n\n_admin.microserve.com_\n\n```\nserver {\n\n    listen 443 ssl;\n    listen [::]:443 ssl;\n    include snippets/self-signed.conf;\n    include snippets/ssl-params.conf;\n\n    server_name  admin.microserve.com  www.admin.microserve.com;\n\n    location / {\n        root   /var/www/admin-front;\n        try_files $uri $uri/ /index.html;\n        index  index.html index.htm;\n    }\n\n    location /api/ {\n\t    proxy_set_header HOST $host;\n\t    proxy_set_header X-Forwarded-Proto $scheme;\n    \t    proxy_set_header X-Real-IP $remote_addr;\n    \t    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;\n\n\t    proxy_pass http://127.0.0.1:8000;\n    }\n\n    error_page   500 502 503 504  /50x.html;\n    location = /50x.html {\n        root   /var/www/error;\n    }\n\n}\n\nserver {\n    listen 80;\n    listen [::]:80;\n    server_name  admin.microserve.com www.admin.microserve.com;\n    return 302 https://$server_name$request_uri;\n}\n\n```\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsudiptob2%2Fmicroserve","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsudiptob2%2Fmicroserve","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsudiptob2%2Fmicroserve/lists"}