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 8515e38 commit f27460e
Show file tree
Hide file tree
Showing 2 changed files with 86 additions and 2 deletions.
79 changes: 79 additions & 0 deletions Run-Docker.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
param (
[string]$DockerFileName = "Dockerfile",
[string]$DockerImageName = "example",
[string]$DockerContainerName = "ubuntu",
[string]$WorkingDirectory = (Get-Location).Path,
[string]$DebugMode = "false"
)

# Function to check if the Dockerfile exists
function Check-DockerFileExists {
$filePath = Join-Path -Path $WorkingDirectory -ChildPath $DockerFileName
if (-not (Test-Path -Path $filePath)) {
Write-Error "Error: Dockerfile not found at $filePath. Exiting."
exit 1
}
else {
Write-Host "Success: Dockerfile found at: $filePath" -ForegroundColor Green
}
}

# Function to check if Docker is installed
function Check-DockerExists {
try {
$dockerPath = Get-Command docker -ErrorAction Stop
Write-Host "Success: Docker found at: $($dockerPath.Source)" -ForegroundColor Green
}
catch {
Write-Error "Error: Docker is not installed or not in PATH. Exiting."
exit 1
}
}

# Function to build a Docker image
function Build-DockerImage {
try {
Write-Host "Info: Building Docker image $DockerImageName from $DockerFileName" -ForegroundColor Green
docker build -t $DockerImageName -f $DockerFileName | Out-Host
if ($LASTEXITCODE -eq 0) {
return $true
}
else {
Write-Error "Error: Docker build failed with exit code $LASTEXITCODE"
return $false
}
}
catch {
Write-Error "Error: Docker build encountered an exception"
return $false
}
}

# Convert string parameters to boolean
$DebugMode = $DebugMode -eq "true"

# Enable debug mode if DebugMode is set to $true
if ($DebugMode) {
$DebugPreference = "Continue"
}

# Diagnostic output
Write-Debug "DockerFileName: $DockerFileName"
Write-Debug "DockerImageName: $DockerImageName"
Write-Debug "DockerContainerName: $DockerContainerName"
Write-Debug "DebugMode: $DebugMode"

# Checking prerequisites
Check-DockerExists
Check-DockerFileExists

# Execution flow
$buildSuccess = Build-DockerImage | Out-Host

if ($buildSuccess -eq $true) {
Write-Host "Docker build complete." -ForegroundColor Green
}
else {
Write-Host "Docker build failed." -ForegroundColor Green
exit 1
}
9 changes: 7 additions & 2 deletions containers/ubuntu/packer.pkr.hcl
Original file line number Diff line number Diff line change
Expand Up @@ -214,16 +214,21 @@ build {
}

provisioner "shell" {
environment_vars = ["DEBIAN_FRONTEND=noninteractive", "PATH=${local.path_var}", "USER=${var.normal_user}"]
environment_vars = ["DEBIAN_FRONTEND=noninteractive", "PATH=${local.path_var}", "USER=${var.normal_user}", "PYENV_ROOT=/home/${var.normal_user}/.pyenv"]
execute_command = "sudo -Hu ${var.normal_user} sh -c '{{ .Vars }} {{ .Path }}'"
inline = [
"eval \"$(pyenv init --path)\"",
"pyenvLatestStable=$(pyenv install --list | grep -v - | grep -E \"^ [0-9]\" | grep -vE 'dev|alpha|beta|rc' | tail -1)",
"pyenv install $pyenvLatestStable",
"pyenv global $pyenvLatestStable",
"pip install --upgrade pip"
"pip install --user pipenv virtualenv terraform-compliance checkov pywinrm",
"pip install --user azure-cli"
]
}

provisioner "shell" {
environment_vars = ["DEBIAN_FRONTEND=noninteractive", "PATH=${local.path_var}", "USER=${var.normal_user}"]
environment_vars = ["DEBIAN_FRONTEND=noninteractive", "PATH=${local.path_var}", "USER=${var.normal_user}", "PYENV_ROOT=/home/${var.normal_user}/.pyenv"]
execute_command = "sudo -Hu ${var.normal_user} sh -c '{{ .Vars }} {{ .Path }}'"
inline = [
"echo -en '\\n' | /bin/bash -c \"$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)\"",
Expand Down

0 comments on commit f27460e

Please sign in to comment.