User Tools

Site Tools


devops:vagrant

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
devops:vagrant [2022/01/19 17:39] skipidardevops:vagrant [2024/06/22 16:41] (current) – [Error: Authentication failure. Retrying...] skipidar
Line 2: Line 2:
 By Hashicorp. By Hashicorp.
  
-== WOrkflow ==+== Workflow ==
  
 {{http://czerasz.com/assets/1441437275524/img/posts/vagrant-workflows-phases.png}} {{http://czerasz.com/assets/1441437275524/img/posts/vagrant-workflows-phases.png}}
Line 280: Line 280:
  
 which redirects, via the ssh-tunnel to remote server i-012412412ASF2: which redirects, via the ssh-tunnel to remote server i-012412412ASF2:
-**localhost:4440**+**i-012412412ASF2:4440**
  
  
Line 287: Line 287:
 see https://docs.aws.amazon.com/systems-manager/latest/userguide/session-manager-getting-started-enable-ssh-connections.html see https://docs.aws.amazon.com/systems-manager/latest/userguide/session-manager-getting-started-enable-ssh-connections.html
  
-Opens tunnel from + 
 + 
 +===== Setting up Rsync folder-synch on Windows ===== 
 + 
 +=== Why === 
 +When **developing code** in an **IDE on Windows-Host** \\ 
 +I would like to have the possibility  
 +of running code in the Guest-VM. In an environment as close to the deployment as possible: \\ 
 +e.g. on Kubernetes, integrated with other containers. 
 + 
 +**File-system watcher:** 
 + 
 +Requirement: 
 + 
 +On the Guest - the changes of "file-system" of code-project must be recognized\\ 
 +and the code-project rebuilt. \\ 
 + 
 +Also changes in the **IDE on Windows-Host** \\  
 +must trigger changes on the file-system in "Guest-VM". \\ 
 + 
 +Problem: 
 + 
 +When sharing code-project via **Oracle-Virtualbox shared-folders** \\ 
 +and files where changed on **IDE on Windows-Host** \\ 
 +unfortunately, **NO changes where triggered** on **Guest** file-system-watcher. 
 + 
 +When sharing a code-project via **Rsync**  - the requirement was fulfilled. 
 + 
 + 
 +=== How === 
 +An example of setting up the environment 
 + 
 +  *   On Guest. Install Cygwin, to get Rsync on Windows 
 +  *   On Guest. Add the "code-project-folder" to the same folder, where "Vagrantfile" is located 
 +  *   Configure Vagrantfile to sync "code-project-folder" 
 +  *   On Guest. Run automatic sync command in one cmd-shell 
 +  *   Ssh into Vagrant. Run continuos build in one shell 
 +  *   Configure the Spring Boot application to hot-deploy changes 
 +  *   Ssh into Vagrant. Run application like Spring Boot application 
 + 
 + 
 +== On Guest. Install Cygwin, to get Rsync on Windows == 
 + 
 +<code> 
 +winget install -e --id Cygwin.Cygwin 
 +</code> 
 + 
 + 
 +==On Guest. Add the "code-project-folder" to the same folder, where "Vagrantfile" is located== 
 + 
 +<code> 
 +cd "VagrantProjectFolder" 
 +mkdir "spring-boot-code-project-folder" 
 +</code> 
 + 
 + 
 +==Configure Vagrantfile to sync "code-project-folder"== 
 +Sync folder `spring-boot-code-project-folder`. 
 +Based on `checksum`, not timestamp. 
 + 
 +Vagrantfile 
 +<sxh ruby> 
 +... 
 + config.vm.synced_folder "./spring-boot-code-project-folder", "//mnt/spring-boot-code-project-folder/",  
 + type: "rsync",  
 + rsync__auto: true, 
 + rsync__args: ["--verbose", "--ignore-times", "--checksum", "--rsync-path='rsync'", "--archive", "--delete", "-z"], 
 + id: "spring" 
 + 
 +.. 
 +</sxh> 
 + 
 + 
 +==On Guest. Run automatic sync command in one cmd-shell== 
 + 
 +Open a new [[https://apps.microsoft.com/store/detail/windows-terminal/9N0DX20HK701?hl=de-ch&gl=ch| Windows-Terminal ]] Tab and run the continuous sync in there: 
 +<sxh shell> 
 +vagrant rsync-auto 
 +</sxh> 
 + 
 +{{https://s3.eu-central-1.amazonaws.com/alf-digital-wiki-pics/sharex/kSQKOKRZ1C.png}} 
 + 
 + 
 +==Ssh into Vagrant. Run continuos build in one shell== 
 + 
 +See https://docs.gradle.org/current/userguide/command_line_interface.html#sec:continuous_build 
 + 
 +Skip the tests.\\ 
 +Dont use the daemon. 
 + 
 +<sxh shell> 
 +vagrant ssh 
 +cd "/mnt/spring-boot-code-project-folder" 
 +./gradlew build -xtest --no-daemon --continuous 
 +</sxh> 
 + 
 + 
 +== Configure the Spring Boot application to hot-deploy changes == 
 + 
 +The Spring boot applications needs to be advised, \\ 
 +to take up any rebuilt app and hot-deploy it. 
 + 
 +Add dependency to "devtools"
 + 
 +build.gradle 
 +<sxh> 
 +dependencies { 
 + 
 + // makes Spring boot hot swap rebuilt jar to tomcat 
 + developmentOnly 'org.springframework.boot:spring-boot-devtools' 
 +
 +</sxh> 
 + 
 + 
 +==Ssh into Vagrant. Run application like Spring Boot application== 
 + 
 + 
 +<sxh shell> 
 +vagrant ssh 
 +cd "/mnt/spring-boot-code-project-folder" 
 +./gradlew bootRun --args='--server.port=8888' 
 +</sxh> 
 + 
 +{{https://s3.eu-central-1.amazonaws.com/alf-digital-wiki-pics/sharex/YuluwvPA2V.png}} 
 + 
 + 
 +===== Error: Authentication failure. Retrying... ===== 
 + 
 +Thats also the reason for disk /mnt/d not being mounted correctly 
 + 
 +<sxh shell> 
 + 
 + # give the home permissions back to vagrant  
 + # without that -  /home/vagrant is owned by root.  
 + # and also /home/vagrant/.ssh/authorized_keys 
 + # so that no ssh connection works and  
 + # vagrant ssh - failes with "Error: Authentication failure. Retrying..." 
 + sudo chown -R vagrant:vagrant "/home/vagrant" 
 +</sxh> 
devops/vagrant.1642613954.txt.gz · Last modified: by skipidar