Skip to content

Commit

Permalink
upload box using packer postprocessor
Browse files Browse the repository at this point in the history
  • Loading branch information
3ximus committed Nov 7, 2024
1 parent a2cdf96 commit 4138f8b
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 13 deletions.
11 changes: 6 additions & 5 deletions .github/workflows/build_and_publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ jobs:
NAME: kali
VAGRANT_CLOUD_BOX_FILE: kali-2024.3-amd64-libvirt.box
DEBIAN_FRONTEND: noninteractive
VAGRANT_CLOUD_TOKEN: ${{ secrets.VAGRANT_CLOUD_TOKEN }}
HCP_CLIENT_ID: ${{ secrets.HCP_CLIENT_ID }}
HCP_CLIENT_SECRET: ${{ secrets.HCP_CLIENT_SECRET }}
steps:
- uses: actions/checkout@v4
- name: Free Disk Space (Ubuntu)
Expand All @@ -33,10 +34,10 @@ jobs:
sudo udevadm control --reload-rules
sudo udevadm trigger --name-match=kvm
sudo usermod -a -G kvm,libvirt $USER
- name: Build box
- name: Build/Upload box
run: |
packer plugins install github.com/hashicorp/vagrant
make || cat kali-2024.3-amd64-libvirt.box.log
- name: Upload to vagrant cloud
run: |
./scripts/upload_to_vagrant_cloud.sh $VAGRANT_CLOUD_USER $NAME $VAGRANT_CLOUD_BOX_FILE
# - name: Upload to vagrant cloud
# run: |
# ./scripts/upload_to_vagrant_cloud.sh $VAGRANT_CLOUD_USER $NAME $VAGRANT_CLOUD_BOX_FILE
4 changes: 3 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ kali-${VERSION}-amd64-libvirt.box: clean preseed.cfg kali.pkr.hcl Vagrantfile.te
provision/01-xfce.sh \
provision/97-guest-additions.sh \
provision/98-vagrant.sh \
provision/99-cleanup.sh
provision/99-cleanup.sh \
scripts/describe_packages.sh

CHECKPOINT_DISABLE=1 PACKER_LOG=1 PACKER_LOG_PATH=$@.init.log packer init kali.pkr.hcl

Expand All @@ -19,6 +20,7 @@ kali-${VERSION}-amd64-libvirt.box: clean preseed.cfg kali.pkr.hcl Vagrantfile.te
PACKER_LOG=1 PACKER_LOG_PATH=$@.log \
PKR_VAR_version=${VERSION} \
PKR_VAR_vagrant_box=$@ \
PKR_VAR_description=$(./scripts/describe_packages.sh) \
packer build -only=qemu.kali-amd64 -on-error=abort -timestamp-ui kali.pkr.hcl
rmdir packer_cache

Expand Down
38 changes: 31 additions & 7 deletions kali.pkr.hcl
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
packer {
required_plugins {
# see https://github.com/hashicorp/packer-plugin-qemu
qemu = {
version = "1.1.0"
source = "github.com/hashicorp/qemu"
Expand All @@ -16,6 +15,20 @@ variable "vagrant_box" {
type = string
}

variable "description" {
type = string
}

variable "hcp_client_id" {
type = string
default = "${env("HCP_CLIENT_ID")}"
}

variable "hcp_client_secret" {
type = string
default = "${env("HCP_CLIENT_SECRET")}"
}

source "qemu" "kali-amd64" {
accelerator = "kvm"
machine_type = "q35"
Expand All @@ -32,8 +45,8 @@ source "qemu" "kali-amd64" {
disk_cache = "unsafe"
disk_discard = "unmap"
disk_compression = true
iso_url = "https://cdimage.kali.org/current/kali-linux-2024.3-installer-netinst-amd64.iso"
iso_checksum = "file:http://kali.download/base-images/kali-2024.3/SHA256SUMS"
iso_url = "https://cdimage.kali.org/current/kali-linux-${var.version}-installer-netinst-amd64.iso"
iso_checksum = "file:http://kali.download/base-images/kali-${var.version}/SHA256SUMS"
ssh_username = "vagrant"
ssh_password = "vagrant"
ssh_timeout = "60m"
Expand Down Expand Up @@ -74,9 +87,20 @@ build {
]
}

post-processor "vagrant" {
only = [ "qemu.kali-amd64" ]
output = var.vagrant_box
vagrantfile_template = "Vagrantfile.template"
post-processors {
post-processor "vagrant" {
only = [ "qemu.kali-amd64" ]
output = var.vagrant_box
vagrantfile_template = "Vagrantfile.template"
}

post-processor "vagrant-registry" {
box_tag = "0rr0rs/kali"
version = "${var.version}"
client_id = "${var.hcp_client_id}"
client_secret = "${var.hcp_client_secret}"
architecture = "amd64"
version_description = "${var.description}"
}
}
}

0 comments on commit 4138f8b

Please sign in to comment.