From eada314471c5adc6bef5dd0bb590b988e9458587 Mon Sep 17 00:00:00 2001 From: Craig Thacker Date: Mon, 11 Dec 2023 20:13:22 +0000 Subject: [PATCH] Update module --- Run-Packer.ps1 | 24 +++++++++++--- containers/ubuntu/packer.pkr.hcl | 55 +++++++++++++++++++++++++++----- 2 files changed, 66 insertions(+), 13 deletions(-) diff --git a/Run-Packer.ps1 b/Run-Packer.ps1 index 612918c..e2e6aab 100644 --- a/Run-Packer.ps1 +++ b/Run-Packer.ps1 @@ -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) { @@ -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 } diff --git a/containers/ubuntu/packer.pkr.hcl b/containers/ubuntu/packer.pkr.hcl index 781de1d..80a0208 100644 --- a/containers/ubuntu/packer.pkr.hcl +++ b/containers/ubuntu/packer.pkr.hcl @@ -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 @@ -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 @@ -85,6 +115,8 @@ 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") ] } @@ -92,12 +124,19 @@ 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" {