Compare commits

...

10 Commits

Author SHA1 Message Date
Samuel Aubertin
53a3a86403 Display hostname and not hostname+target 2025-04-27 16:45:36 +02:00
Samuel Aubertin
ba48937b12 Variabilize GCE region and zone, only use hostname for cloud, not hostname+target 2025-04-27 16:43:03 +02:00
Samuel Aubertin
6603cc9518 Fixes in README 2025-04-27 16:08:59 +02:00
Samuel Aubertin
13433cd7eb Do not show banner everytime 2024-02-28 15:19:38 +01:00
Samuel Aubertin
9c075ea2f3 dont use libvirt session 2024-02-28 14:25:33 +01:00
Samuel Aubertin
ff22a6dda6 escape %c in Vagrantfile 2024-02-15 18:23:25 +01:00
Samuel Aubertin
ed10ea5bab OPACK_VAGRANT_NETWORK doc 2024-02-14 10:20:00 +01:00
Samuel Aubertin
1d64683963 Define custom networks with OPACK_VAGRANT_NETWORK override 2024-02-14 10:18:52 +01:00
Samuel Aubertin
a7330ce9e7 Add OPACK_SSH_USER for weird cases like when OPACK_SYS_USER is already used by the base system 2023-10-17 09:22:00 +02:00
Samuel Aubertin
d39b4bd362 remove the box json on clean 2023-10-17 09:21:20 +02:00
7 changed files with 39 additions and 18 deletions

View File

@@ -28,7 +28,10 @@ To get started with **skz-opack**, follow these steps:
- [libvirt](https://libvirt.org/) - [libvirt](https://libvirt.org/)
- [Vagrant](https://developer.hashicorp.com/vagrant/downloads) - [Vagrant](https://developer.hashicorp.com/vagrant/downloads)
- [Vagrant-Libvirt module](https://github.com/vagrant-libvirt/vagrant-libvirt) - [Vagrant-Libvirt module](https://github.com/vagrant-libvirt/vagrant-libvirt)
- [Terraform](https://developer.hashicorp.com/terraform/downloads) (for `opack-cloud`)
Additionally, for `opack-cloud`:
- [Packer googlecompute module](https://developer.hashicorp.com/packer/integrations/hashicorp/googlecompute)
- [Terraform](https://developer.hashicorp.com/terraform/downloads)
3. Use the project by including `path/to/skz-opack/src/opack.mk` and invoking the `opack` target in your Makefile to create a local OpenBSD virtual machine with Packer and Vagrant. Use the 'opack-cloud' target to run the same virtual machine in GCP with Terraform. 3. Use the project by including `path/to/skz-opack/src/opack.mk` and invoking the `opack` target in your Makefile to create a local OpenBSD virtual machine with Packer and Vagrant. Use the 'opack-cloud' target to run the same virtual machine in GCP with Terraform.
@@ -68,6 +71,7 @@ Every default option ending with an `?` in "src/options.mk" can be overrided in
- `OPACK_GCE_PROJECT`: The Google Cloud project name where the VM will be created - `OPACK_GCE_PROJECT`: The Google Cloud project name where the VM will be created
- `OPACK_GCE_JSON_KEY`: The filename of the Google Cloud service account JSON key - `OPACK_GCE_JSON_KEY`: The filename of the Google Cloud service account JSON key
- `OPACK_GCE_BUCKET`: The Google Cloud Storage bucket name to use for the image import - `OPACK_GCE_BUCKET`: The Google Cloud Storage bucket name to use for the image import
- `OPACK_VAGRANT_NETWORK`: Define additional custom Vagrant networks
## Examples ## Examples

View File

@@ -37,7 +37,7 @@ endef
define OPACK_INSTALL_CLOUD_CONTENT = define OPACK_INSTALL_CLOUD_CONTENT =
Choose your keyboard layout = fr Choose your keyboard layout = fr
System hostname = $(OPACK_SYS_HOSTNAME)-$(OPACK_TARGET) System hostname = $(OPACK_SYS_HOSTNAME)
Which network interface = vio0 Which network interface = vio0
IPv4 address for vio0 = dhcp IPv4 address for vio0 = dhcp
IPv6 address for vio0 = none IPv6 address for vio0 = none
@@ -93,8 +93,8 @@ define OPACK_TERRAFORM_CONTENT =
variable "credentials" { default = "../$(OPACK_GCE_JSON_KEY)" } variable "credentials" { default = "../$(OPACK_GCE_JSON_KEY)" }
variable "project" { default = "$(OPACK_GCE_PROJECT)" } variable "project" { default = "$(OPACK_GCE_PROJECT)" }
variable "region" { default = "europe-west4" } variable "region" { default = "$(OPACK_GCE_REGION)" }
variable "zone" { default = "europe-west4-b" } variable "zone" { default = "$(OPACK_GCE_ZONE)" }
provider "google" { provider "google" {
region = "$${var.region}" region = "$${var.region}"

View File

@@ -27,7 +27,9 @@ echo -n "$(2) "
($(1)) & pid=$$!; i=0; while ps -a | awk '{print $$1}' | grep -q "$${pid}"; do c=`expr $${i} % 4`; case $${c} in 0) echo -e "◐\c" ;; 1) echo -e "◓\c" ;; 2) echo -e "◑\c" ;; 3) echo -e "◒\c" ;; esac; i=`expr $${i} + 1`; sleep 0.2; echo -e "\b\c"; done; echo; wait $${pid}; ret=$$?; exit $${ret}; ($(1)) & pid=$$!; i=0; while ps -a | awk '{print $$1}' | grep -q "$${pid}"; do c=`expr $${i} % 4`; case $${c} in 0) echo -e "◐\c" ;; 1) echo -e "◓\c" ;; 2) echo -e "◑\c" ;; 3) echo -e "◒\c" ;; esac; i=`expr $${i} + 1`; sleep 0.2; echo -e "\b\c"; done; echo; wait $${pid}; ret=$$?; exit $${ret};
endef endef
ifdef OPACK_DEBUG
$(info $(OPACK_BANNER)) $(info $(OPACK_BANNER))
endif
include $(OPACK_DIR)/options.mk include $(OPACK_DIR)/options.mk
include $(OPACK_DIR)/defines.mk include $(OPACK_DIR)/defines.mk
@@ -111,7 +113,7 @@ $(OPACK_VAGRANT_FILE):
opack: $(OPACK_META_FILE) $(OPACK_VAGRANT_FILE) opack: $(OPACK_META_FILE) $(OPACK_VAGRANT_FILE)
ifndef OPACK_DEBUG ifndef OPACK_DEBUG
$(call spinner,vagrant up > /dev/null,█ $(shell date +'%H:%M:%S') Starting $(OPACK_HOSTNAME)-$(OPACK_TARGET) with Vagrant) $(call spinner,vagrant up > /dev/null,█ $(shell date +'%H:%M:%S') Starting $(OPACK_BOX_TAG) with Vagrant)
else else
vagrant up vagrant up
endif endif
@@ -128,12 +130,12 @@ opack-cloud: | $(OPACK_TERRAFORM_DIR)/terraform.tfstate
opack-clean: opack-clean:
ifndef OPACK_DEBUG ifndef OPACK_DEBUG
-$(call spinner,vagrant destroy -f >/dev/null; cd opack_deploy_$(OPACK_SHORT_REV) 2>/dev/null && terraform destroy -auto-approve >> opack.log && cd .. && rm -rf opack_deploy_$(OPACK_SHORT_REV); rm -rf $(OPACK_VAGRANT_FILE) opack_installer_$(OPACK_SHORT_REV) *.log ssh-config .vagrant opack-cloud,█ $(shell date +'%H:%M:%S') Cleaning up) -$(call spinner,vagrant destroy -f >/dev/null; cd opack_deploy_$(OPACK_SHORT_REV) 2>/dev/null && terraform destroy -auto-approve >> opack.log && cd .. && rm -rf opack_deploy_$(OPACK_SHORT_REV); rm -rf $(OPACK_VAGRANT_FILE) opack_installer_$(OPACK_SHORT_REV) *.log ssh-config .vagrant opack-cloud $(OPACK_TARGET).json,█ $(shell date +'%H:%M:%S') Cleaning up)
else else
-vagrant destroy -f -vagrant destroy -f
-cd opack_deploy_$(OPACK_SHORT_REV) 2>/dev/null && terraform destroy -auto-approve >> opack.log -cd opack_deploy_$(OPACK_SHORT_REV) 2>/dev/null && terraform destroy -auto-approve >> opack.log
-rm -rf opack_deploy_$(OPACK_SHORT_REV) -rm -rf opack_deploy_$(OPACK_SHORT_REV)
-rm -rf $(OPACK_VAGRANT_FILE) opack_installer_$(OPACK_SHORT_REV) *.log ssh-config .vagrant opack-cloud -rm -rf $(OPACK_VAGRANT_FILE) opack_installer_$(OPACK_SHORT_REV) *.log ssh-config .vagrant opack-cloud $(OPACK_TARGET).json
endif endif
opack-cleancache: opack-cleancache:

View File

@@ -4,6 +4,9 @@ OPACK_SYS_HOSTNAME?= opack
# Set the username for the virtual machine to 'opack' if not specified # Set the username for the virtual machine to 'opack' if not specified
OPACK_SYS_USER?= opack OPACK_SYS_USER?= opack
# Set the username for the virtual machine to 'opack' if not specified
OPACK_SSH_USER?= $(OPACK_SYS_USER)
# Set the password for the virtual machine to 'opack' if not specified # Set the password for the virtual machine to 'opack' if not specified
OPACK_SYS_PASSWORD?= opack OPACK_SYS_PASSWORD?= opack
@@ -106,6 +109,10 @@ OPACK_AUTODISKLABEL_FILE?=$(OPACK_DIR)autodisklabel
# Define the Vagrantfile # Define the Vagrantfile
OPACK_VAGRANT_FILE=Vagrantfile OPACK_VAGRANT_FILE=Vagrantfile
# Define custom networks for Vagrant
OPACK_VAGRANT_NETWORK?=
#OPACK_VAGRANT_NETWORK=config.vm.network "private_network", auto_config: false
# Define the runtime provisioning script for Vagrant # Define the runtime provisioning script for Vagrant
OPACK_RUNTIME_PROVISION_FILE?=$(OPACK_DIR)vagrant-provision.sh OPACK_RUNTIME_PROVISION_FILE?=$(OPACK_DIR)vagrant-provision.sh
@@ -122,6 +129,12 @@ OPACK_GCE_JSON_KEY?=
# OPACK_GCE_BUCKET: The Google Cloud Storage bucket name, typically associated with the project, for the image import. # OPACK_GCE_BUCKET: The Google Cloud Storage bucket name, typically associated with the project, for the image import.
OPACK_GCE_BUCKET?=$(OPACK_GCE_PROJECT) OPACK_GCE_BUCKET?=$(OPACK_GCE_PROJECT)
# OPACK_GCE_REGION: The Google Cloud Compute Engine region.
OPACK_GCE_REGION?=europe-west4
# OPACK_GCE_REGION: The Google Cloud Compute Engine zone.
OPACK_GCE_REGION?=europe-west4-b
# Define the machine type for the VM # Define the machine type for the VM
OPACK_GCE_MACHINE?=e2-micro OPACK_GCE_MACHINE?=e2-micro
@@ -135,9 +148,9 @@ OPACK_TERRAFORM_DIR?=opack_deploy_$(OPACK_SHORT_REV)
# Terraform module dir # Terraform module dir
OPACK_TERRAFORM_MODULE_DIR?=$(OPACK_TERRAFORM_DIR)/opack-module OPACK_TERRAFORM_MODULE_DIR?=$(OPACK_TERRAFORM_DIR)/opack-module
ifdef OPACK_DEBUG ifndef OPACK_DEBUG
$(infoBOX $(OPACK_BOX_FILE)) $(infoBOX $(OPACK_BOX_FILE))
$(infoHOSTNAME $(OPACK_SYS_HOSTNAME)-$(OPACK_TARGET)) $(infoHOSTNAME $(OPACK_SYS_HOSTNAME))
$(infoUSER $(OPACK_SYS_USER)) $(infoUSER $(OPACK_SYS_USER))
$(infoPASSWORD $(OPACK_SYS_PASSWORD)) $(infoPASSWORD $(OPACK_SYS_PASSWORD))
$(infoDISK-SIZE $(OPACK_SYS_DISK_SIZE)m) $(infoDISK-SIZE $(OPACK_SYS_DISK_SIZE)m)

View File

@@ -52,7 +52,7 @@ define OPACK_PACKER_CLOUD_CONTENT =
}, },
{ {
"type": "shell", "type": "shell",
"inline": ["cp /root/.ssh/authorized_keys /home/$(OPACK_SYS_USER)/.ssh/authorized_keys; chown $(OPACK_SYS_USER) /home/$(OPACK_SYS_USER)/.ssh/authorized_keys"] "inline": ["mkdir -p /home/$(OPACK_SYS_USER)/.ssh; cp /root/.ssh/authorized_keys /home/$(OPACK_SYS_USER)/.ssh/authorized_keys; chown $(OPACK_SYS_USER) /home/$(OPACK_SYS_USER)/.ssh/authorized_keys"]
} }
], ],
"post-processors": [ [ "post-processors": [ [

View File

@@ -48,7 +48,7 @@ define OPACK_PACKER_CONTENT =
}, },
{ {
"type": "shell", "type": "shell",
"inline": ["cp /root/.ssh/authorized_keys /home/$(OPACK_SYS_USER)/.ssh/authorized_keys; chown $(OPACK_SYS_USER) /home/$(OPACK_SYS_USER)/.ssh/authorized_keys"] "inline": ["mkdir -p /home/$(OPACK_SYS_USER)/.ssh; cp /root/.ssh/authorized_keys /home/$(OPACK_SYS_USER)/.ssh/authorized_keys; chown $(OPACK_SYS_USER) /home/$(OPACK_SYS_USER)/.ssh/authorized_keys"]
} }
], ],
"post-processors": [ [ "post-processors": [ [

View File

@@ -7,14 +7,16 @@ Vagrant.configure("2") do |config|
config.vm.define "$(OPACK_TARGET)" config.vm.define "$(OPACK_TARGET)"
config.vm.box = "$(OPACK_BOX_TAG)" config.vm.box = "$(OPACK_BOX_TAG)"
config.ssh.shell = "ksh -l" config.ssh.shell = "ksh -l"
config.ssh.username = "$(OPACK_SYS_USER)" config.ssh.username = "$(OPACK_SSH_USER)"
config.ssh.extra_args = "-tt" config.ssh.extra_args = "-tt"
config.ssh.sudo_command = "doas env %c" config.ssh.sudo_command = "doas env %%c"
config.vm.synced_folder ".", "/vagrant", disabled: true config.vm.synced_folder ".", "/vagrant", disabled: true
config.vm.provision "shell", path: "$(OPACK_RUNTIME_PROVISION_FILE)" config.vm.provision "shell", path: "$(OPACK_RUNTIME_PROVISION_FILE)"
$(OPACK_VAGRANT_NETWORK)
config.vm.provider "libvirt" do |l| config.vm.provider "libvirt" do |l|
l.cpus = $(OPACK_SYS_CPU) l.cpus = $(OPACK_SYS_CPU)
l.memory = $(OPACK_SYS_MEMORY) l.memory = $(OPACK_SYS_MEMORY)
l.qemu_use_session = false
end end
end end