Skip to content

Commit

Permalink
Update module
Browse files Browse the repository at this point in the history
  • Loading branch information
craigthackerx committed Dec 11, 2023
1 parent 3061392 commit eada314
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 13 deletions.
24 changes: 19 additions & 5 deletions Run-Packer.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,19 @@ Check-PackerFileExists
function Run-PackerInit {
if ($RunPackerInit -eq $true) {
try {
if ($isWindows) {
Write-Host "Info: Running Packer init in $WorkingDirectory" -ForegroundColor Green
packer init -upgrade $PackerFileName | Out-Host
if ($LASTEXITCODE -eq 0) {
return $true
}
else {
Write-Error "Error: Packer init failed with exit code $LASTEXITCODE"
return $false
}
}
else
{
Write-Host "Info: Running Packer init in $WorkingDirectory" -ForegroundColor Green
packer init -force $PackerFileName | Out-Host
if ($LASTEXITCODE -eq 0) {
Expand All @@ -140,12 +153,13 @@ function Run-PackerInit {
return $false
}
}
catch {
Write-Error "Error: Packer init encountered an exception"
return $false
}
}
return $false
catch {
Write-Error "Error: Packer init encountered an exception"
return $false
}
}
return $false
}


Expand Down
55 changes: 47 additions & 8 deletions containers/ubuntu/packer.pkr.hcl
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,6 @@ packer {
}
}

variable "DEBIAN_FRONTEND" {
description = "Debian frontend setting"
type = string
default = "noninteractive"
}

variable "container_name" {
description = "The name of the container name"
type = string
Expand Down Expand Up @@ -77,6 +71,42 @@ variable "tags" {
default = ["latest"]
}

locals {
path_var = "/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/opt:/opt/bin:/home/linuxbrew/.linuxbrew/bin:/home/linuxbrew/.local/bin:/home/${var.normal_user}/.local:/home/${var.normal_user}/.tfenv:/home/${var.normal_user}/.tfenv/bin:/home/${var.normal_user}/.pkenv:/home/${var.normal_user}/.pkenv/bin:/home/${var.normal_user}/.pyenv:/home/${var.normal_user}/.pyenv/bin:/home/${var.normal_user}/.pyenv/shims:/home/${var.normal_user}/.local/bin"
apt_packages = [
"apt-transport-https",
"bash",
"libbz2-dev",
"ca-certificates",
"curl",
"gcc",
"gnupg",
"gnupg2",
"git",
"jq",
"libffi-dev",
"libicu-dev",
"make",
"software-properties-common",
"libsqlite3-dev",
"libssl-dev",
"unzip",
"wget",
"zip",
"zlib1g-dev",
"build-essential",
"sudo",
"libreadline-dev",
"llvm",
"libncurses5-dev",
"xz-utils",
"tk-dev",
"libxml2-dev",
"libxmlsec1-dev",
"liblzma-dev"
]
}

source "docker" "ubuntu" {
image = "ubuntu:latest"
commit = true
Expand All @@ -85,19 +115,28 @@ source "docker" "ubuntu" {
format("LABEL org.opencontainers.image.title=%s", var.container_name),
format("LABEL org.opencontainers.image.source=%s/%s/%s", var.registry, var.org, var.project),
format("LABEL org.opencontainers.image.title=%s", var.container_name),
format("ENV PATH=%s", local.path_var),
format("ENV DEBIAN_FRONTEND=%s", "noninteractive")
]
}

build {
sources = ["source.docker.ubuntu"]

provisioner "shell" {
environment_vars = ["DEBIAN_FRONTEND=noninteractive"]
execute_command = "sh -c '{{ .Vars }} {{ .Path }}'"
inline = [
"rm -rf /bin/sh && ln -sf /bin/bash /bin/sh",
"useradd -ms /bin/bash ${var.normal_user}",
"mkdir -p /home/linuxbrew",
"chown -R ${var.normal_user}:${var.normal_user} /home/linuxbrew",
"apt-get update",
"apt-get install -y software-properties-common",
"apt-get dist-upgrade -y",
"apt-get install -y ${join(" ", local.apt_packages)}",
"echo 'PATH=${local.path_var}' > /etc/environment"
]
}
}

post-processors {
post-processor "docker-tag" {
Expand Down

0 comments on commit eada314

Please sign in to comment.