Skip to content

Commit

Permalink
Move to Github Actions build docker crushftp-source (#7)
Browse files Browse the repository at this point in the history
* 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
thohng authored Nov 15, 2023
1 parent 6be0ace commit fa161c8
Show file tree
Hide file tree
Showing 4 changed files with 126 additions and 78 deletions.
51 changes: 51 additions & 0 deletions .github/workflows/source.yml
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
2 changes: 1 addition & 1 deletion crushftp-source/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ This intermediate docker image contains crushftp.zip for next docker build image
## Docker Specifications

- Base: Alpine 3.13 Linux
- CrushFTP 10 (v10.1.0_62)
- CrushFTP 10 (v10.5.4)
- Repository: [hub.docker.com/r/netlah/crushftp](hub.docker.com/r/netlah/crushftp)
- Docker: [hub.docker.com/r/netlah/crushftp-source](hub.docker.com/r/netlah/crushftp-source)

Expand Down
74 changes: 74 additions & 0 deletions crushftp-source/docker-build.ps1
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
}
}
}
77 changes: 0 additions & 77 deletions crushftp-source/hooks/build

This file was deleted.

0 comments on commit fa161c8

Please sign in to comment.