diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..997ca2f --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +.vagrant \ No newline at end of file diff --git a/README.md b/README.md index cba250d..8d6bb04 100644 --- a/README.md +++ b/README.md @@ -23,6 +23,48 @@ Forum API Microservices ![Software Architecture](docs/imgs/arch.jpeg) +## Vagrant Sample + +### Provider - Virtual Box + +```mermaid +architecture-beta + group vm(server)[Virtual Machine] + + group docker(cloud)[Docker] in vm + + service sv1(server)[Service 1] in docker + service sv2(server)[Service 2] in docker + service db1(database)[Database 1] in docker + service db2(database)[Database 2] in docker + service redis(database)[Cache] in docker + + sv1:B -- T:db1 + sv2:B -- T:db2 + sv1:R -- L:redis + sv2:L -- R:redis +``` + +### Docker without Vagrant + +```mermaid +architecture-beta + + group docker(cloud)[Docker] + + service sv1(server)[Service 1] in docker + service sv2(server)[Service 2] in docker + service db1(database)[Database 1] in docker + service db2(database)[Database 2] in docker + service redis(database)[Cache] in docker + + sv1:B -- T:db1 + sv2:B -- T:db2 + sv1:R -- L:redis + sv2:L -- R:redis +``` + + ## License MIT diff --git a/Vagrantfile b/Vagrantfile new file mode 100644 index 0000000..78603fd --- /dev/null +++ b/Vagrantfile @@ -0,0 +1,91 @@ +# -*- mode: ruby -*- +# vi: set ft=ruby : + +# All Vagrant configuration is done below. The "2" in Vagrant.configure +# configures the configuration version (we support older styles for +# backwards compatibility). Please don't change it unless you know what +# you're doing. +Vagrant.configure("2") do |config| + # The most common configuration options are documented and commented below. + # For a complete reference, please see the online documentation at + # https://docs.vagrantup.com. + + # Every Vagrant development environment requires a box. You can search for + # boxes at https://vagrantcloud.com/search. + config.vm.box = "hashicorp-education/ubuntu-24-04" + config.vm.box_version = "0.1.0" + + + # Disable automatic box update checking. If you disable this, then + # boxes will only be checked for updates when the user runs + # `vagrant box outdated`. This is not recommended. + # config.vm.box_check_update = false + + # Create a forwarded port mapping which allows access to a specific port + # within the machine from a port on the host machine. In the example below, + # accessing "localhost:8080" will access port 80 on the guest machine. + # NOTE: This will enable public access to the opened port + # config.vm.network "forwarded_port", guest: 80, host: 8080 + + # Create a forwarded port mapping which allows access to a specific port + # within the machine from a port on the host machine and only allow access + # via 127.0.0.1 to disable public access + # config.vm.network "forwarded_port", guest: 80, host: 8080, host_ip: "127.0.0.1" + + # Create a private network, which allows host-only access to the machine + # using a specific IP. + # config.vm.network "private_network", ip: "192.168.33.10" + + # Create a public network, which generally matched to bridged network. + # Bridged networks make the machine appear as another physical device on + # your network. + # config.vm.network "public_network" + + # Share an additional folder to the guest VM. The first argument is + # the path on the host to the actual folder. The second argument is + # the path on the guest to mount the folder. And the optional third + # argument is a set of non-required options. + # config.vm.synced_folder "../data", "/vagrant_data" + + # Disable the default share of the current code directory. Doing this + # provides improved isolation between the vagrant box and your host + # by making sure your Vagrantfile isn't accessible to the vagrant box. + # If you use this you may want to enable additional shared subfolders as + # shown above. + # config.vm.synced_folder ".", "/vagrant", disabled: true + + # Provider-specific configuration so you can fine-tune various + # backing providers for Vagrant. These expose provider-specific options. + # Example for VirtualBox: + # + # config.vm.provider "virtualbox" do |vb| + # # Display the VirtualBox GUI when booting the machine + # vb.gui = true + # + # # Customize the amount of memory on the VM: + # vb.memory = "1024" + # end + # + # View the documentation for the provider you are using for more + # information on available options. + + # Enable provisioning with a shell script. Additional provisioners such as + # Ansible, Chef, Docker, Puppet and Salt are also available. Please see the + # documentation for more information about their specific syntax and use. + # config.vm.provision "shell", inline: <<-SHELL + # apt-get update + # apt-get install -y apache2 + # SHELL + config.vm.provision "docker" do |d| + d.run "redis", image: "redis:8", args: "-p 6379:6379" + d.run "mongo", image: "mongo:8", args: "-p 27017:27017" + d.run "jaeger", image: "jaegertracing/all-in-one:1.73.0", args: "-p 16686:16686 -p 14268:14268 -p 14250:14250 -p 9411:9411" + d.run "mongo-express", image: "mongo-express:latest", args: "-p 8081:8081 --link mongo -e ME_CONFIG_MONGODB_SERVER=mongo" + d.build_image "/vagrant/app/auth-service", args: "-t 'auth-service:latest'" + d.build_image "/vagrant/app/user-service", args: "-t 'user-service:latest'" + d.build_image "/vagrant/app/thread-service", args: "-t 'thread-service:latest'" + d.run "auth-service", image: "auth-service:latest", args: "-p 9000:80 --link redis --link mongo --link jaeger" + d.run "user-service", image: "user-service:latest", args: "-p 9001:5000 --link mongo --link jaeger --link redis" + d.run "thread-service", image: "thread-service:latest", args: "-p 9002:80 --link mongo --link jaeger --link redis" + end +end diff --git a/app/auth-service/Dockerfile b/app/auth-service/Dockerfile index bf25620..f999847 100644 --- a/app/auth-service/Dockerfile +++ b/app/auth-service/Dockerfile @@ -1,4 +1,4 @@ -FROM node:lts-alpine as build +FROM node:lts-alpine AS build WORKDIR /app COPY package.json yarn.lock ./ RUN yarn --frozen-lockfile @@ -6,7 +6,7 @@ COPY src/ . COPY tsconfig.json . RUN yarn compile -FROM node:lts-alpine as runtime +FROM node:lts-alpine AS runtime WORKDIR /app COPY --from=build /app/node_modules/ /app/node_modules COPY --from=build /app/lib /app/lib diff --git a/app/thread-service/Dockerfile b/app/thread-service/Dockerfile index 7923b9f..8770396 100644 --- a/app/thread-service/Dockerfile +++ b/app/thread-service/Dockerfile @@ -1,9 +1,9 @@ -FROM mcr.microsoft.com/dotnet/sdk:8.0 as build +FROM mcr.microsoft.com/dotnet/sdk:8.0 AS build WORKDIR /app COPY . . RUN dotnet publish -c Release -o published -FROM mcr.microsoft.com/dotnet/aspnet:8.0 as runtime +FROM mcr.microsoft.com/dotnet/aspnet:8.0 AS runtime WORKDIR /app COPY --from=build /app/published . ENTRYPOINT [ "dotnet", "ThreadService.dll" ] diff --git a/app/user-service/Dockerfile b/app/user-service/Dockerfile index eaef354..b08de05 100644 --- a/app/user-service/Dockerfile +++ b/app/user-service/Dockerfile @@ -1,9 +1,9 @@ -FROM mcr.microsoft.com/dotnet/sdk:8.0 as build +FROM mcr.microsoft.com/dotnet/sdk:8.0 AS build WORKDIR /app COPY . . RUN dotnet publish -c Release -o published -FROM mcr.microsoft.com/dotnet/aspnet:8.0 as runtime +FROM mcr.microsoft.com/dotnet/aspnet:8.0 AS runtime WORKDIR /app COPY --from=build /app/published . ENTRYPOINT [ "dotnet", "UserService.dll" ]