Skip to content

Commit

Permalink
add: vm initialization script
Browse files Browse the repository at this point in the history
  • Loading branch information
Silvija Tovernic committed Sep 19, 2024
1 parent ee615f3 commit 1c32b8f
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 34 deletions.
42 changes: 8 additions & 34 deletions images/packer/image-factory-vm/build.pkr.hcl
Original file line number Diff line number Diff line change
Expand Up @@ -3,43 +3,17 @@ build {
"source.azure-arm.vm"
]

provisioner "file" {
source = "images/packer/image-factory-vm/scripts/setup-vm.sh"
destination = "/tmp/setup.sh"
}

provisioner "shell" {
execute_command = "chmod +x {{ .Path }}; {{ .Vars }} sudo -E sh '{{ .Path }}'"

inline = [
"apt-get update",
"apt-get upgrade -y",
"/usr/sbin/waagent -force -deprovision+user && export HISTSIZE=0 && sync",

# Install required packages
"apt-get install --no-install-recommends -y \\",
"apt-transport-https \\",
"buildah \\",
"ca-certificates \\",
"curl \\",
"git \\",
"gnupg \\",
"jq \\",
"libcap2-bin \\",
"lsb-release \\",
"podman \\",
"slirp4netns \\",
"software-properties-common \\",
"unzip \\",
"vim \\",
"wget",

# Clean up
"rm -rf /var/lib/apt/lists/*",

# Install Azure CLI
"curl -sL https://aka.ms/InstallAzureCLIDeb | bash",

# Set up Trivy repository and install Trivy
"wget -qO - https://aquasecurity.github.io/trivy-repo/deb/public.key | apt-key add -",
"echo deb https://aquasecurity.github.io/trivy-repo/deb $(lsb_release -sc) main | tee -a /etc/apt/sources.list.d/trivy.list",
"apt-get update",
"apt-get install -y trivy"
"chmod +x /tmp/setup.sh",
"/tmp/setup.sh"
]
}
}
40 changes: 40 additions & 0 deletions images/packer/image-factory-vm/scripts/setup-vm.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#!/bin/bash

set -e

# Update and upgrade the system
apt-get update
apt-get upgrade -y

# Deprovision user
/usr/sbin/waagent -force -deprovision+user && export HISTSIZE=0 && sync

# Install required packages
apt-get install --no-install-recommends -y \
apt-transport-https \
buildah \
ca-certificates \
curl \
git \
gnupg \
jq \
libcap2-bin \
lsb-release \
podman \
slirp4netns \
software-properties-common \
unzip \
vim \
wget

# Clean up
rm -rf /var/lib/apt/lists/*

# Install Azure CLI
curl -sL https://aka.ms/InstallAzureCLIDeb | bash

# Set up Trivy repository and install Trivy
wget -qO - https://aquasecurity.github.io/trivy-repo/deb/public.key | apt-key add -
echo "deb https://aquasecurity.github.io/trivy-repo/deb \$(lsb_release -sc) main" | tee -a /etc/apt/sources.list.d/trivy.list
apt-get update
apt-get install -y trivy

0 comments on commit 1c32b8f

Please sign in to comment.