Compare commits
10 Commits
1f06ba238f
...
master
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
53a3a86403 | ||
|
|
ba48937b12 | ||
|
|
6603cc9518 | ||
|
|
13433cd7eb | ||
|
|
9c075ea2f3 | ||
|
|
ff22a6dda6 | ||
|
|
ed10ea5bab | ||
|
|
1d64683963 | ||
|
|
a7330ce9e7 | ||
|
|
d39b4bd362 |
@@ -28,7 +28,10 @@ To get started with **skz-opack**, follow these steps:
|
||||
- [libvirt](https://libvirt.org/)
|
||||
- [Vagrant](https://developer.hashicorp.com/vagrant/downloads)
|
||||
- [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.
|
||||
|
||||
@@ -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_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_VAGRANT_NETWORK`: Define additional custom Vagrant networks
|
||||
|
||||
## Examples
|
||||
|
||||
|
||||
@@ -37,7 +37,7 @@ endef
|
||||
|
||||
define OPACK_INSTALL_CLOUD_CONTENT =
|
||||
Choose your keyboard layout = fr
|
||||
System hostname = $(OPACK_SYS_HOSTNAME)-$(OPACK_TARGET)
|
||||
System hostname = $(OPACK_SYS_HOSTNAME)
|
||||
Which network interface = vio0
|
||||
IPv4 address for vio0 = dhcp
|
||||
IPv6 address for vio0 = none
|
||||
@@ -93,8 +93,8 @@ define OPACK_TERRAFORM_CONTENT =
|
||||
|
||||
variable "credentials" { default = "../$(OPACK_GCE_JSON_KEY)" }
|
||||
variable "project" { default = "$(OPACK_GCE_PROJECT)" }
|
||||
variable "region" { default = "europe-west4" }
|
||||
variable "zone" { default = "europe-west4-b" }
|
||||
variable "region" { default = "$(OPACK_GCE_REGION)" }
|
||||
variable "zone" { default = "$(OPACK_GCE_ZONE)" }
|
||||
|
||||
provider "google" {
|
||||
region = "$${var.region}"
|
||||
|
||||
@@ -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};
|
||||
endef
|
||||
|
||||
ifdef OPACK_DEBUG
|
||||
$(info $(OPACK_BANNER))
|
||||
endif
|
||||
|
||||
include $(OPACK_DIR)/options.mk
|
||||
include $(OPACK_DIR)/defines.mk
|
||||
@@ -111,7 +113,7 @@ $(OPACK_VAGRANT_FILE):
|
||||
|
||||
opack: $(OPACK_META_FILE) $(OPACK_VAGRANT_FILE)
|
||||
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
|
||||
vagrant up
|
||||
endif
|
||||
@@ -128,12 +130,12 @@ opack-cloud: | $(OPACK_TERRAFORM_DIR)/terraform.tfstate
|
||||
|
||||
opack-clean:
|
||||
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
|
||||
-vagrant destroy -f
|
||||
-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_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
|
||||
|
||||
opack-cleancache:
|
||||
|
||||
@@ -4,6 +4,9 @@ OPACK_SYS_HOSTNAME?= opack
|
||||
# Set the username for the virtual machine to 'opack' if not specified
|
||||
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
|
||||
OPACK_SYS_PASSWORD?= opack
|
||||
|
||||
@@ -106,6 +109,10 @@ OPACK_AUTODISKLABEL_FILE?=$(OPACK_DIR)autodisklabel
|
||||
# Define the 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
|
||||
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?=$(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
|
||||
OPACK_GCE_MACHINE?=e2-micro
|
||||
|
||||
@@ -135,9 +148,9 @@ OPACK_TERRAFORM_DIR?=opack_deploy_$(OPACK_SHORT_REV)
|
||||
# Terraform module dir
|
||||
OPACK_TERRAFORM_MODULE_DIR?=$(OPACK_TERRAFORM_DIR)/opack-module
|
||||
|
||||
ifdef OPACK_DEBUG
|
||||
ifndef OPACK_DEBUG
|
||||
$(info ░ BOX $(OPACK_BOX_FILE))
|
||||
$(info ▒ HOSTNAME $(OPACK_SYS_HOSTNAME)-$(OPACK_TARGET))
|
||||
$(info ▒ HOSTNAME $(OPACK_SYS_HOSTNAME))
|
||||
$(info ░ USER $(OPACK_SYS_USER))
|
||||
$(info ▒ PASSWORD $(OPACK_SYS_PASSWORD))
|
||||
$(info ░ DISK-SIZE $(OPACK_SYS_DISK_SIZE)m)
|
||||
|
||||
@@ -52,7 +52,7 @@ define OPACK_PACKER_CLOUD_CONTENT =
|
||||
},
|
||||
{
|
||||
"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": [ [
|
||||
|
||||
@@ -48,7 +48,7 @@ define OPACK_PACKER_CONTENT =
|
||||
},
|
||||
{
|
||||
"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": [ [
|
||||
|
||||
@@ -7,14 +7,16 @@ Vagrant.configure("2") do |config|
|
||||
config.vm.define "$(OPACK_TARGET)"
|
||||
config.vm.box = "$(OPACK_BOX_TAG)"
|
||||
config.ssh.shell = "ksh -l"
|
||||
config.ssh.username = "$(OPACK_SYS_USER)"
|
||||
config.ssh.username = "$(OPACK_SSH_USER)"
|
||||
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.provision "shell", path: "$(OPACK_RUNTIME_PROVISION_FILE)"
|
||||
$(OPACK_VAGRANT_NETWORK)
|
||||
config.vm.provider "libvirt" do |l|
|
||||
l.cpus = $(OPACK_SYS_CPU)
|
||||
l.memory = $(OPACK_SYS_MEMORY)
|
||||
l.qemu_use_session = false
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
Reference in New Issue
Block a user