From dcaca63b1318b9080a611bc9bd5f4c4d664ce456 Mon Sep 17 00:00:00 2001 From: hyung-hwan Date: Sun, 29 Aug 2021 04:19:19 +0000 Subject: [PATCH] added some vagrant files for experiment --- vagrant/Jenkinsfile | 43 +++++++++++++++++++++ vagrant/Makefile | 35 +++++++++++++++++ vagrant/Vagrantfile | 75 +++++++++++++++++++++++++++++++++++++ vagrant/ansible-initial.yml | 12 ++++++ vagrant/readme.txt | 38 +++++++++++++++++++ 5 files changed, 203 insertions(+) create mode 100644 vagrant/Jenkinsfile create mode 100644 vagrant/Makefile create mode 100644 vagrant/Vagrantfile create mode 100644 vagrant/ansible-initial.yml create mode 100644 vagrant/readme.txt diff --git a/vagrant/Jenkinsfile b/vagrant/Jenkinsfile new file mode 100644 index 0000000..599d024 --- /dev/null +++ b/vagrant/Jenkinsfile @@ -0,0 +1,43 @@ +pipeline { + agent any + + ##environment { + ## CC = 'gcc' + ## BUILD_TYPE = 'xxxx' + ##} + + stages { + + stage('Build') { + steps { + echo "Building a virtual machine - ${env.BUILD_ID} on ${env.JENKINS_URL}" + sh "make init && make up" + } + } + + + stage('Test') { + steps { + echo "Testing the virtual machine built" + ## TODO run the internal test script to check the internal aspect of the machine + ## TODO run the external test scripts to test the machine over the network + } + } + + + stage('Deploy') { + when { + expression { + currentBuild.result == null || currentBuild.result == 'SUCCESS' + } + } + steps { + echo "Publishing the virtual machine built" + ## TODO clean up before packaging + sh "make package" + ## TODO copy the final artifacts to an artifact repository + ##sh "make clean" + } + } + } +} diff --git a/vagrant/Makefile b/vagrant/Makefile new file mode 100644 index 0000000..444f11d --- /dev/null +++ b/vagrant/Makefile @@ -0,0 +1,35 @@ +# vagrant init without the box name used the default box 'base' +# in the produced Vagrantfile. +# +# + +##PROVIDER ?= libvirt +PROVIDER ?= virtualbox + +all: + @echo choose one of the targets: + @echo " init up provision halt destory clean" + +init: + #vagrant init antlabs/sg5-centos8-base + vagrant init generic/rocky8 + ##vagrant init + +up: + ##vagrant up + vagrant up --provider=$(PROVIDER) + +provision: up + vagrant provision + +package: + vagrant package --vagrantfile Vagrantfile + +halt: + vagrant halt + +destroy: halt + vagrant destroy -f + +clean: destroy + rm -rf .vagrant package.box diff --git a/vagrant/Vagrantfile b/vagrant/Vagrantfile new file mode 100644 index 0000000..beb6999 --- /dev/null +++ b/vagrant/Vagrantfile @@ -0,0 +1,75 @@ +# -*- 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 = "generic/rocky8" + + # 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" + + # 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 "ansible" do | ansible | + ansible.verbose = "v" + ansible.playbook = "ansible-initial.yml" + end +end diff --git a/vagrant/ansible-initial.yml b/vagrant/ansible-initial.yml new file mode 100644 index 0000000..8a7485f --- /dev/null +++ b/vagrant/ansible-initial.yml @@ -0,0 +1,12 @@ +- hosts: all + become: true + become_method: sudo + tasks: + - name: intall gcc + yum: + name: gcc + state: present + - name: intall valgrind + yum: + name: valgrind + state: present diff --git a/vagrant/readme.txt b/vagrant/readme.txt new file mode 100644 index 0000000..e98345d --- /dev/null +++ b/vagrant/readme.txt @@ -0,0 +1,38 @@ + +$ vagrant plugin list +$ dnf install vagrant vagrant-libvirt +$ vagrant plugin list +$ (NOT GOOD) vagrant plugin install vagrant-libvirt + +# -------------------------------------------------------------------------------- + +$ vagrant box add generic/rocky8 --provider=libvirt + +# -------------------------------------------------------------------------------- + +$ vagrant box add generic/rocky8 +==> box: Loading metadata for box 'generic/rocky8' + box: URL: https://vagrantcloud.com/generic/rocky8 +This box can work with multiple providers! The providers that it +can work with are listed below. Please review the list and choose +the provider you will be working with. + +1) hyperv +2) libvirt +3) parallels +4) virtualbox +5) vmware_desktop + +Enter your choice: 2 +==> box: Adding box 'generic/rocky8' (v3.4.0) for provider: libvirt + box: Downloading: https://vagrantcloud.com/generic/boxes/rocky8/versions/3.4.0/providers/libvirt.box + box: Calculating and comparing box checksum... +==> box: Successfully added box 'generic/rocky8' (v3.4.0) for 'libvirt'! + +# +$ ls -l ~/.vagrant.d/boxes/generic-VAGRANTSLASH-rocky8/3.4.0/libvirt/ +total 1029128 +-rw-rw-r-- 1 hyung-hwan hyung-hwan 1053807104 Aug 29 09:41 box.img +-rw-rw-r-- 1 hyung-hwan hyung-hwan 301 Aug 29 09:41 info.json +-rw-rw-r-- 1 hyung-hwan hyung-hwan 59 Aug 29 09:41 metadata.json +-rw-rw-r-- 1 hyung-hwan hyung-hwan 1987 Aug 29 09:41 Vagrantfile