-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move to Github Actions build docker crushftp-source (#7)
* Add github actions * Build image * Provide imageTag * quote string * Debug parameter * Debug params, fix missing quote string * Cleanup * supports WhatIf * Build on pull request * Build on pull request
- Loading branch information
Showing
4 changed files
with
126 additions
and
78 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
name: CrushFTP Source | ||
|
||
on: | ||
push: | ||
branches: ["dev-source-*", "source/*", "dev-source/*"] | ||
tags: ["source-*.*.*"] | ||
pull_request: | ||
branches: [main] | ||
|
||
jobs: | ||
build: | ||
strategy: | ||
fail-fast: false | ||
name: crushftp-source | ||
runs-on: ubuntu-latest | ||
env: | ||
CRUSHFTP_VERSION: "10.5.4" | ||
IS_TAG: ${{ startsWith(github.ref, 'refs/tags/') }} | ||
SKIP_DOCKER: false | ||
steps: | ||
- uses: actions/checkout@v3 | ||
|
||
- name: Set up Docker Buildx | ||
if: ${{ success() && env.SKIP_DOCKER != 'true' }} | ||
uses: docker/setup-buildx-action@v2 | ||
|
||
- name: Login to Docker Hub | ||
if: ${{ success() && env.SKIP_DOCKER != 'true' && github.event_name != 'pull_request' }} | ||
uses: docker/login-action@v2 | ||
with: | ||
username: "${{ secrets.DOCKER_HUB_USERNAME }}" | ||
password: "${{ secrets.DOCKER_HUB_ACCESS_TOKEN }}" | ||
|
||
- name: Build and push | ||
if: ${{ success() && env.SKIP_DOCKER != 'true' }} | ||
shell: pwsh | ||
working-directory: ./crushftp-source | ||
run: | | ||
$pattern = '^source-(?<version>\d+\.\d+(\.\d+)?(_.+)?)$' | ||
$crushFtpVersion = '${{ env.CRUSHFTP_VERSION }}' | ||
$imageTag = '${{ github.ref_name }}'.Replace('/','-') | ||
$whatIf = '${{ github.event_name == 'pull_request' }}' -eq $true | ||
if ('${{ env.IS_TAG }}' -eq $true) { | ||
$repos += @('${{ vars.DOCKER_HUB_NETLAH_SOURCE_REPOS }}') | ||
if ('${{ github.ref_name }}' -match $pattern) { | ||
$crushFtpVersion = '${{ github.ref_name }}' -replace $pattern,'${version}' | ||
$imageTag = $crushFtpVersion | ||
} | ||
} | ||
$repos += @('${{ secrets.DOCKER_HUB_SOURCE_REPOS }}') | ||
./docker-build.ps1 -dockerRepository $repos -crushFtpVersion $crushFtpVersion -imageTag $imageTag -WhatIf:$whatIf -Verbose |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
[CmdletBinding()] | ||
param ( | ||
[Parameter(Mandatory = $true)] [string] $imageTag = 'dev', | ||
[Parameter(Mandatory = $false)] [string[]] $dockerRepository, | ||
[Parameter(Mandatory = $false)] [string] $baseImageRepos, | ||
[Parameter(Mandatory = $false)] [string] $sourceMethod, | ||
[Parameter(Mandatory = $false)] [string] $sourceZip, | ||
[Parameter(Mandatory = $false)] [string] $crushFtpVersion, | ||
[Parameter(Mandatory = $false)] [switch] $WhatIf | ||
) | ||
|
||
$dockerImages = @() | ||
foreach ($dockerRepos in $dockerRepository) { | ||
$dockerImages += @("$($dockerRepos):$($imageTag)") | ||
} | ||
|
||
$params = @('build', '.') | ||
|
||
if ($baseImageRepos) { | ||
Write-Verbose "REPO: $baseImageRepos" | ||
$params += @('--build-arg', "REPO=$baseImageRepos") | ||
} | ||
|
||
if ($sourceMethod) { | ||
Write-Verbose "SOURCE_METHOD: $sourceMethod" | ||
$params += @('--build-arg', "SOURCE_METHOD=$sourceMethod") | ||
} | ||
|
||
if ($sourceZip) { | ||
Write-Verbose "SOURCE_ZIP: $sourceZip" | ||
$params += @('--build-arg', "SOURCE_ZIP=$sourceZip") | ||
} | ||
|
||
if ($crushFtpVersion) { | ||
Write-Verbose "CRUSHFTP_VERSION: $crushFtpVersion" | ||
$params += @('--build-arg', "CRUSHFTP_VERSION=$crushFtpVersion") | ||
} | ||
|
||
$params += @('--pull', '--progress=plain') | ||
|
||
Write-Output "Docker images: $dockerImages" | ||
[bool]$isGitHubAction = "$Env:GITHUB_ACTIONS" -eq $true | ||
if (!$isGitHubAction) { | ||
foreach ($dockerImage in $dockerImages) { | ||
$params += @("--cache-from=$($dockerImage)") | ||
} | ||
} | ||
|
||
foreach ($dockerImage in $dockerImages) { | ||
$params += @("--tag=$($dockerImage)") | ||
} | ||
|
||
Write-Verbose "Execute: docker $params" | ||
docker @params | ||
if (!$?) { | ||
$saveLASTEXITCODE = $LASTEXITCODE | ||
Write-Error "docker build failed (exit=$saveLASTEXITCODE)" | ||
exit $saveLASTEXITCODE | ||
} | ||
|
||
if ($WhatIf) { | ||
Write-Host "Skipped pushing docker image" | ||
} | ||
elseif ($dockerImages) { | ||
Write-Host "Pushing docker images" | ||
foreach ($dockerImage in $dockerImages) { | ||
docker push $dockerImage | ||
if (!$?) { | ||
$saveLASTEXITCODE = $LASTEXITCODE | ||
Write-Error "docker push failed (exit=$saveLASTEXITCODE)" | ||
exit $saveLASTEXITCODE | ||
} | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.