Skip to content

Commit

Permalink
Change files structure
Browse files Browse the repository at this point in the history
  • Loading branch information
exdial committed Sep 3, 2023
1 parent e45870c commit b4c424a
Show file tree
Hide file tree
Showing 8 changed files with 43 additions and 27 deletions.
25 changes: 14 additions & 11 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,16 +1,19 @@
# Created by https://gitignore.io/api/packer,vagrant

### Packer ###
# Cache objects
packer_cache/

# Crash log
crash.log

# https://www.packer.io/guides/hcl/variables
# Exclude all .pkrvars.hcl files, which are likely to contain sensitive data,
# such as password, private keys, and other secrets. These should not be part of
# version control as they are data points which are potentially sensitive and
# subject to change depending on the environment.
#
*.pkrvars.hcl
.packer.d/

# For built boxes
*.box

### Packer Patch ###
# ignore temporary output files
output/

### Vagrant ###
# General
.vagrant/

# End of https://gitignore.io/api/packer,vagrant
7 changes: 5 additions & 2 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,11 @@ repos:
- id: end-of-file-fixer
- id: check-yaml
- id: check-shebang-scripts-are-executable
- repo: git@github.com:exdial/pre-commit-hooks.git
rev: e3433e140adaa767ddf14f1abfa9066a7ec6fae7
- repo: https://github.com/exdial/pre-commit-hooks
rev: v0.0.5
hooks:
- id: packer-validate
- id: packer-fmt
- id: terraform-validate
- id: terraform-fmt
- id: terragrunt-hclfmt
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,4 @@ It supports a large variety of cloud infrastructures.

## Building

`packer -var-file=(ci|prod).pkrvars.hcl 20-04-focal.pkr.hcl`
`packer build -var-file=vars/(focal|jammy).pkvars.hcl ubuntu.pkr.hcl`
12 changes: 10 additions & 2 deletions http/provision.sh
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
#!/usr/bin/env bash
set -exu

export DEBIAN_FRONTEND=noninteractive

USERNAME="vagrant"
MOUNT_DIR="/tmp/isomount"
HOME_DIR="/home/vagrant"
HOME_DIR="/home/${USERNAME}"
ISO_FILE="/tmp/VBoxGuestAdditions.iso"

errdebug() {
Expand All @@ -20,6 +23,7 @@ get_vagrant_key() {
if get_vagrant_key; then
chmod 0700 "$HOME_DIR"/.ssh
chmod 0600 "$HOME_DIR"/.ssh/authorized_keys
chown -R $USERNAME:$USERNAME "$HOME_DIR"/.ssh
else
echo "Download failed!"
errdebug
Expand All @@ -33,7 +37,7 @@ mount_guest_additions() {
if mount_guest_additions; then
apt-get update
apt-get install -y --no-install-recommends --fix-missing \
ca-certificates gcc make
ca-certificates gcc make bzip2 tar
# Hack: VBoxLinuxAdditions.run every time exited with non-zero code,
# so we will change the exit code to zero with the "true" command
"$MOUNT_DIR"/VBoxLinuxAdditions.run --nox11 && true
Expand All @@ -56,6 +60,10 @@ if check_vbox_version && check_module_loaded; then
rm -f "$ISO_FILE"

# Cleanup
snap remove --purge lxd
snap remove --purge core20
snap remove --purge snapd
apt --purge autoremove -y snapd
truncate -s 0 /etc/resolv.conf
rm -rf /tmp/*
rm -f /var/log/wtmp /var/log/btmp .bash_history
Expand Down
2 changes: 1 addition & 1 deletion http/user-data.pkrtpl.hcl
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ autoinstall:
version: 2
ethernets:
enp0s3:
dhcp4: yes
dhcp4: true
identity:
hostname: ${var.vm_name}
username: ${var.ssh_username}
Expand Down
10 changes: 6 additions & 4 deletions ubuntu/vagrant.pkr.hcl → ubuntu.pkr.hcl
Original file line number Diff line number Diff line change
Expand Up @@ -13,22 +13,24 @@ packer {
}
}

# The default value is requred by `packer validate` command
variable "iso_url" {
type = string
description = "The URL of the OS image file."
default = ""
default = "null"
}

# The default value here is md5 from "null".
variable "iso_checksum" {
type = string
description = "The checksum value of `iso_url`."
default = ""
default = "674441960ca1ba2de08ad4e50c9fde98"
}

variable "vm_name" {
type = string
description = "The name of the host."
default = ""
default = "null"
}

variable "boot_command" {
Expand Down Expand Up @@ -98,7 +100,7 @@ source "virtualbox-iso" "ubuntu" {
# Instead of keeping an empty meta-data file in the repository,
# serve the empty location "/meta-data" by HTTP.
http_content = {
"/user-data" = templatefile("../http/user-data.pkrtpl.hcl", { var = var }),
"/user-data" = templatefile("http/user-data.pkrtpl.hcl", { var = var }),
"/meta-data" = ""
}

Expand Down
6 changes: 3 additions & 3 deletions vars/focal.pkvars.hcl
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
iso_url = "https://releases.ubuntu.com/20.04.6/ubuntu-20.04.6-live-server-amd64.iso"
iso_url = "https://releases.ubuntu.com/20.04.6/ubuntu-20.04.6-live-server-amd64.iso"
iso_checksum = "file:http://releases.ubuntu.com/20.04/SHA256SUMS"
vm_name = "focal"
headless = true
vm_name = "focal"
headless = true
boot_command = [
"<tab><tab><tab><tab><tab><wait>",
"<esc><wait><f6><wait><esc><wait>",
Expand Down
6 changes: 3 additions & 3 deletions vars/jammy.pkvars.hcl
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
iso_url = "https://releases.ubuntu.com/22.04.3/ubuntu-22.04.3-live-server-amd64.iso"
iso_url = "https://releases.ubuntu.com/22.04.3/ubuntu-22.04.3-live-server-amd64.iso"
iso_checksum = "file:http://releases.ubuntu.com/22.04/SHA256SUMS"
vm_name = "jammy"
headless = true
vm_name = "jammy"
headless = true
boot_command = [
"<tab><tab><tab><tab><tab><wait>",
"c<wait2>",
Expand Down

0 comments on commit b4c424a

Please sign in to comment.