Skip to content

Commit

Permalink
Merge pull request #62 from leojonathanoh/enhancement/add-step-to-com…
Browse files Browse the repository at this point in the history
…posite-variants

Enhancement: Add `step` to composite variants
  • Loading branch information
leojonathanoh authored Nov 2, 2024
2 parents a94b591 + b89e12e commit 32734d2
Show file tree
Hide file tree
Showing 34 changed files with 1,606 additions and 281 deletions.
504 changes: 252 additions & 252 deletions .github/workflows/ci-master-pr.yml

Large diffs are not rendered by default.

28 changes: 14 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,33 +11,33 @@ Dockerized `ansible` with useful tools.
| Tag | Dockerfile Build Context |
|:-------:|:---------:|
| `:10.5.0-alpine-edge`, `:latest` | [View](variants/10.5.0-alpine-edge) |
| `:10.5.0-sops-ssh-alpine-edge` | [View](variants/10.5.0-sops-ssh-alpine-edge) |
| `:10.5.0-sops-ssh-step-alpine-edge` | [View](variants/10.5.0-sops-ssh-step-alpine-edge) |
| `:9.5.1-alpine-3.20` | [View](variants/9.5.1-alpine-3.20) |
| `:9.5.1-sops-ssh-alpine-3.20` | [View](variants/9.5.1-sops-ssh-alpine-3.20) |
| `:9.5.1-sops-ssh-step-alpine-3.20` | [View](variants/9.5.1-sops-ssh-step-alpine-3.20) |
| `:8.6.1-alpine-3.19` | [View](variants/8.6.1-alpine-3.19) |
| `:8.6.1-sops-ssh-alpine-3.19` | [View](variants/8.6.1-sops-ssh-alpine-3.19) |
| `:8.6.1-sops-ssh-step-alpine-3.19` | [View](variants/8.6.1-sops-ssh-step-alpine-3.19) |
| `:7.5.0-alpine-3.18` | [View](variants/7.5.0-alpine-3.18) |
| `:7.5.0-sops-ssh-alpine-3.18` | [View](variants/7.5.0-sops-ssh-alpine-3.18) |
| `:7.5.0-sops-ssh-step-alpine-3.18` | [View](variants/7.5.0-sops-ssh-step-alpine-3.18) |
| `:6.6.0-alpine-3.17` | [View](variants/6.6.0-alpine-3.17) |
| `:6.6.0-sops-ssh-alpine-3.17` | [View](variants/6.6.0-sops-ssh-alpine-3.17) |
| `:6.6.0-sops-ssh-step-alpine-3.17` | [View](variants/6.6.0-sops-ssh-step-alpine-3.17) |
| `:5.8.0-alpine-3.16` | [View](variants/5.8.0-alpine-3.16) |
| `:5.8.0-sops-ssh-alpine-3.16` | [View](variants/5.8.0-sops-ssh-alpine-3.16) |
| `:5.8.0-sops-ssh-step-alpine-3.16` | [View](variants/5.8.0-sops-ssh-step-alpine-3.16) |
| `:4.8.0-alpine-3.15` | [View](variants/4.8.0-alpine-3.15) |
| `:4.8.0-sops-ssh-alpine-3.15` | [View](variants/4.8.0-sops-ssh-alpine-3.15) |
| `:4.8.0-sops-ssh-step-alpine-3.15` | [View](variants/4.8.0-sops-ssh-step-alpine-3.15) |
| `:2.10.7-alpine-3.13` | [View](variants/2.10.7-alpine-3.13) |
| `:2.10.7-sops-ssh-alpine-3.13` | [View](variants/2.10.7-sops-ssh-alpine-3.13) |
| `:2.10.7-sops-ssh-step-alpine-3.13` | [View](variants/2.10.7-sops-ssh-step-alpine-3.13) |
| `:2.9.18-alpine-3.11` | [View](variants/2.9.18-alpine-3.11) |
| `:2.9.18-sops-ssh-alpine-3.11` | [View](variants/2.9.18-sops-ssh-alpine-3.11) |
| `:2.9.18-sops-ssh-step-alpine-3.11` | [View](variants/2.9.18-sops-ssh-step-alpine-3.11) |
| `:2.8.19-alpine-3.10` | [View](variants/2.8.19-alpine-3.10) |
| `:2.8.19-sops-ssh-alpine-3.10` | [View](variants/2.8.19-sops-ssh-alpine-3.10) |
| `:2.8.19-sops-ssh-step-alpine-3.10` | [View](variants/2.8.19-sops-ssh-step-alpine-3.10) |
| `:2.7.17-alpine-3.9` | [View](variants/2.7.17-alpine-3.9) |
| `:2.7.17-sops-ssh-alpine-3.9` | [View](variants/2.7.17-sops-ssh-alpine-3.9) |
| `:2.7.17-sops-ssh-step-alpine-3.9` | [View](variants/2.7.17-sops-ssh-step-alpine-3.9) |
| `:2.6.20-alpine-3.8` | [View](variants/2.6.20-alpine-3.8) |
| `:2.6.20-sops-ssh-alpine-3.8` | [View](variants/2.6.20-sops-ssh-alpine-3.8) |
| `:2.6.20-sops-ssh-step-alpine-3.8` | [View](variants/2.6.20-sops-ssh-step-alpine-3.8) |
| `:2.4.6.0-alpine-3.7` | [View](variants/2.4.6.0-alpine-3.7) |
| `:2.4.6.0-sops-ssh-alpine-3.7` | [View](variants/2.4.6.0-sops-ssh-alpine-3.7) |
| `:2.4.6.0-sops-ssh-step-alpine-3.7` | [View](variants/2.4.6.0-sops-ssh-step-alpine-3.7) |
| `:2.3.0.0-alpine-3.6` | [View](variants/2.3.0.0-alpine-3.6) |
| `:2.3.0.0-sops-ssh-alpine-3.6` | [View](variants/2.3.0.0-sops-ssh-alpine-3.6) |
| `:2.3.0.0-sops-ssh-step-alpine-3.6` | [View](variants/2.3.0.0-sops-ssh-step-alpine-3.6) |

## Development

Expand Down
34 changes: 19 additions & 15 deletions generate/definitions/VARIANTS.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ $local:VARIANTS_MATRIX = @(
distro_version = 'edge'
subvariants = @(
@{ components = @() }
@{ components = @( 'sops', 'ssh' ) }
@{ components = @( 'sops', 'ssh', 'step' ) }
)
}
@{
Expand All @@ -20,7 +20,7 @@ $local:VARIANTS_MATRIX = @(
distro_version = '3.20'
subvariants = @(
@{ components = @() }
@{ components = @( 'sops', 'ssh' ) }
@{ components = @( 'sops', 'ssh', 'step' ) }
)
}
@{
Expand All @@ -30,7 +30,7 @@ $local:VARIANTS_MATRIX = @(
distro_version = '3.19'
subvariants = @(
@{ components = @() }
@{ components = @( 'sops', 'ssh' ) }
@{ components = @( 'sops', 'ssh', 'step' ) }
)
}
@{
Expand All @@ -40,7 +40,7 @@ $local:VARIANTS_MATRIX = @(
distro_version = '3.18'
subvariants = @(
@{ components = @() }
@{ components = @( 'sops', 'ssh' ) }
@{ components = @( 'sops', 'ssh', 'step' ) }
)
}
@{
Expand All @@ -50,7 +50,7 @@ $local:VARIANTS_MATRIX = @(
distro_version = '3.17'
subvariants = @(
@{ components = @() }
@{ components = @( 'sops', 'ssh' ) }
@{ components = @( 'sops', 'ssh', 'step' ) }
)
}
@{
Expand All @@ -60,7 +60,7 @@ $local:VARIANTS_MATRIX = @(
distro_version = '3.16'
subvariants = @(
@{ components = @() }
@{ components = @( 'sops', 'ssh' ) }
@{ components = @( 'sops', 'ssh', 'step' ) }
)
}
@{
Expand All @@ -70,7 +70,7 @@ $local:VARIANTS_MATRIX = @(
distro_version = '3.15'
subvariants = @(
@{ components = @() }
@{ components = @( 'sops', 'ssh' ) }
@{ components = @( 'sops', 'ssh', 'step' ) }
)
}
@{
Expand All @@ -80,7 +80,7 @@ $local:VARIANTS_MATRIX = @(
distro_version = '3.13'
subvariants = @(
@{ components = $null }
@{ components = @( 'sops', 'ssh' ) }
@{ components = @( 'sops', 'ssh', 'step' ) }
)
}
@{
Expand All @@ -90,7 +90,7 @@ $local:VARIANTS_MATRIX = @(
distro_version = '3.11'
subvariants = @(
@{ components = $null }
@{ components = @( 'sops', 'ssh' ) }
@{ components = @( 'sops', 'ssh', 'step' ) }
)
}
@{
Expand All @@ -100,7 +100,7 @@ $local:VARIANTS_MATRIX = @(
distro_version = '3.10'
subvariants = @(
@{ components = $null }
@{ components = @( 'sops', 'ssh' ) }
@{ components = @( 'sops', 'ssh', 'step' ) }
)
}
@{
Expand All @@ -110,7 +110,7 @@ $local:VARIANTS_MATRIX = @(
distro_version = '3.9'
subvariants = @(
@{ components = @() }
@{ components = @( 'sops', 'ssh' ) }
@{ components = @( 'sops', 'ssh', 'step' ) }
)
}
@{
Expand All @@ -120,7 +120,7 @@ $local:VARIANTS_MATRIX = @(
distro_version = '3.8'
subvariants = @(
@{ components = @() }
@{ components = @( 'sops', 'ssh' ) }
@{ components = @( 'sops', 'ssh', 'step' ) }
)
}
@{
Expand All @@ -130,7 +130,7 @@ $local:VARIANTS_MATRIX = @(
distro_version = '3.7'
subvariants = @(
@{ components = @() }
@{ components = @( 'sops', 'ssh' ) }
@{ components = @( 'sops', 'ssh', 'step' ) }
)
}
@{
Expand All @@ -140,7 +140,7 @@ $local:VARIANTS_MATRIX = @(
distro_version = '3.6'
subvariants = @(
@{ components = @() }
@{ components = @( 'sops', 'ssh' ) }
@{ components = @( 'sops', 'ssh', 'step' ) }
)
}
)
Expand All @@ -158,7 +158,11 @@ $VARIANTS = @(
if ($variant['distro'] -eq 'alpine' -and $variant['distro_version'] -in @('3.3', '3.4', '3.5')) {
'linux/amd64'
}else {
'linux/386,linux/amd64,linux/arm/v6,linux/arm/v7,linux/arm64,linux/s390x'
if ($subVariant['components'] -contains 'step') {
'linux/386,linux/amd64,linux/arm/v6,linux/arm/v7,linux/arm64'
}else {
'linux/386,linux/amd64,linux/arm/v6,linux/arm/v7,linux/arm64,linux/s390x'
}
}
}
components = $subVariant['components']
Expand Down
25 changes: 25 additions & 0 deletions generate/functions/Checksums.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Global cache for checksums
function Set-Checksums($k, $url) {
$global:CHECKSUMS = if (Get-Variable -Scope Global -Name CHECKSUMS -ErrorAction SilentlyContinue) { $global:CHECKSUMS } else { @{} }
$global:CHECKSUMS[$k] = if ($global:CHECKSUMS[$k]) { $global:CHECKSUMS[$k] } else {
$r = Invoke-WebRequest $url
$c = if ($r.headers['Content-Type'] -eq 'text/plain') { $r.Content } else { [System.Text.Encoding]::UTF8.GetString($r.Content) }
$c -split "`n"
}
}
function Get-ChecksumsFile ($k, $keyword) {
$file = $global:CHECKSUMS[$k] | ? { $_ -match $keyword } | % { $_ -split "\s" } | Select-Object -Last 1 | % { $_.TrimStart('*') }
if ($file) {
$file
}else {
"No file among $k checksums matching regex: $keyword" | Write-Warning
}
}
function Get-ChecksumsSha ($k, $keyword) {
$sha = $global:CHECKSUMS[$k] | ? { $_ -match $keyword } | % { $_ -split "\s" } | Select-Object -First 1
if ($sha) {
$sha
}else {
"No sha among $k checksums matching regex: $keyword" | Write-Warning
}
}
174 changes: 174 additions & 0 deletions generate/functions/Generate-DownloadBinary.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,174 @@
# Version 0.1.0
function Generate-DownloadBinary ($o) {
Set-StrictMode -Version Latest

$checksumsKey = "$( $o['binary'] )-$( $o['version'] )"
$files = [ordered]@{}
if ($o['checksumsUrl']) {
Set-Checksums $checksumsKey $o['checksumsUrl']
}else {
$release = Invoke-RestMethod "https://api.github.com/repos/$( $o['repository'] )/releases/tags/$( $o['version'] )"
$releaseAssetsFiles = $release.assets | ? { $_.name -match [regex]::Escape($o['binary']) -and $_.name -notmatch '\.sha\d+$' }
foreach ($f in $releaseAssetsFiles ) {
$sha = & {
$shaF = $release.assets | ? { $_.name -eq "$( $f.name ).sha256" -or $_ -eq "$( $f.name ).sha512" }
$r = Invoke-WebRequest $shaF.browser_download_url
$c = if ($r.headers['Content-Type'] -eq 'text/plain') { $r.Content } else { [System.Text.Encoding]::UTF8.GetString($r.Content) }
$c = $c.Trim() -replace '^([a-fA-F0-9]+) .+', '$1' # The checksum is the first column
$c
}
$files[$f.name] = $sha
}
}
$shellVariable = "$( $o['binary'].ToUpper() -replace '[^A-Za-z0-9_]', '_' )_VERSION"
@"
# Install $( $o['binary'] )
RUN set -eux; \
$shellVariable=$( $o['version'] ); \
case "`$( uname -m )" in \
"@

$o['architectures'] = if ($o.Contains('architectures')) { $o['architectures'] } else { 'linux/386,linux/amd64,linux/arm/v6,linux/arm/v7,linux/arm64,linux/ppc64le,linux/riscv64,linux/s390x' }
foreach ($a in ($o['architectures'] -split ',') ) {
$split = $a -split '/'
$os = $split[0] # E.g. 'linux'
$arch = $split[1] # E.g. 'amd64'
$archv = if ($split.Count -gt 2) { $split[2] } else { '' } # E.g. 'v6' or ''
switch ($a) {
"$os/386" {
$hardware = 'x86'
$regex = "$os[-_](i?$arch|x86(_64)?)[-_]?$archv$( [regex]::Escape($o['archiveformat']) )$|(i?$arch|x86(_64)?)[-_]?$archv.*?[-_]$os.*?$( [regex]::Escape($o['archiveformat']) )$"
}
"$os/amd64" {
$hardware = 'x86_64'
$regex = "$os[-_]($arch|x86(_64)?)[-_]?$archv$( [regex]::Escape($o['archiveformat']) )$|($arch|x86(_64)?)[-_]?$archv.*?[-_]$os.*?$( [regex]::Escape($o['archiveformat']) )$"
}
"$os/arm/v6" {
$hardware = 'armhf'
$regex = "$os[-_]($arch|arm)[-_]?($archv)?$( [regex]::Escape($o['archiveformat']) )$|($arch|arm)[-_]?($archv)?.*?[-_]$os.*?$( [regex]::Escape($o['archiveformat']) )$"
}
"$os/arm/v7" {
$hardware = 'armv7l'
$regex = "$os[-_]($arch|arm)[-_]?($archv)?$( [regex]::Escape($o['archiveformat']) )$|($arch|arm)[-_]?($archv)?.*?[-_]$os.*?$( [regex]::Escape($o['archiveformat']) )$"
}
"$os/arm64" {
$hardware = 'aarch64'
$regex = "$os[-_]($arch|aarch64)[-_]?$archv$( [regex]::Escape($o['archiveformat']) )$|($arch|aarch64)[-_]?$archv.*?[-_]$os.*?$( [regex]::Escape($o['archiveformat']) )$"
}
"$os/ppc64le" {
$hardware = 'ppc64le'
$regex = "$os[-_]$arch[-_]?$archv$( [regex]::Escape($o['archiveformat']) )$|$arch[-_]?$archv.*?[-_]$os.*?$( [regex]::Escape($o['archiveformat']) )$"
}
"$os/riscv64" {
$hardware = 'riscv64'
$regex = "$os[-_]$arch[-_]?$archv$( [regex]::Escape($o['archiveformat']) )$|$arch[-_]?$archv.*?[-_]$os.*?$( [regex]::Escape($o['archiveformat']) )$"
}
"$os/s390x" {
$hardware = 's390x'
$regex = "$os[-_]$arch[-_]?$archv$( [regex]::Escape($o['archiveformat']) )$|$arch[-_]?$archv.*?[-_]$os.*?$( [regex]::Escape($o['archiveformat']) )$"
}
default {
throw "Unsupported architecture: $a"
}
}

$file = $sha = $url = ''
if ($o['checksumsUrl']) {
$file = Get-ChecksumsFile $checksumsKey $regex
$sha = Get-ChecksumsSha $checksumsKey $regex
$url = Split-Path $o['checksumsUrl'] -Parent
} else {
$file = $files.Keys | ? { $_ -match $regex } | Select-Object -First 1
if ($file) {
$url = "https://github.com/$( $o['repository'] )/releases/download/$( $o['version'] )"
$sha = $files[$file]
}else {
throw "No file matched regex: $regex"
}
}
if ($file -and $sha) {
@"
'$hardware') \
URL="$url/$file"; \
SHA256=$sha; \
;; \
"@
}
}

@"
*) \
echo "Architecture not supported"; \
exit 1; \
;; \
esac; \
"@

@"
FILE=$( $o['binary'] )$( $o['archiveformat'] ); \
wget -q "`$URL" -O "`$FILE"; \
echo "`$SHA256 `$FILE" | sha256sum -c -; \
"@

if ($o['archiveformat'] -match '\.tar\.gz|\.tgz') {
if ($o['archivefiles'].Count -gt 0) {
@"
tar -xvf "`$FILE" --no-same-owner --no-same-permissions -- $( $o['archivefiles'] -join ' ' ); \
rm -f "`$FILE"; \
"@
}else {
@"
tar -xvf "`$FILE" --no-same-owner --no-same-permissions; \
rm -f "`$FILE"; \
"@
}
}elseif ($o['archiveformat'] -match '\.bz2') {
@"
bzip2 -d "`$FILE"; \
"@
}elseif ($o['archiveformat'] -match '\.gz') {
@"
gzip -d "`$FILE"; \
"@
}elseif ($o['archiveformat'] -match '\.zip') {
@"
unzip "`$FILE" $( $o['binary'] ); \
"@
}

$destination = if ($o.Contains('destination')) { $o['destination'] } else { "/usr/local/bin/$( $o['binary'] )" }
$destinationDir = Split-Path $destination -Parent
@"
mkdir -pv $destinationDir; \
BIN=`$( find . -type f -name "$( $o['binary'] )" | head -n1 ); \
mv -v "`$BIN" $destination; \
chmod +x $destination; \
$( $o['testCommand'] ); \
"@

if ($o.Contains('archivefiles')) {
if ($license = $o['archivefiles'] | ? { $_ -match 'LICENSE' }) {
@"
mkdir -p /licenses; \
mv -v $license /licenses/$license; \
"@
}
}

@"
:
"@
}
Loading

0 comments on commit 32734d2

Please sign in to comment.