diff --git a/.github/workflows/docker-image.yml b/.github/workflows/docker-image.yml new file mode 100644 index 0000000..4bda080 --- /dev/null +++ b/.github/workflows/docker-image.yml @@ -0,0 +1,56 @@ +name: Docker Image CI + +on: + push: + branches: ["main", "dev*"] + tags: ["*.*.*"] + +jobs: + build: + strategy: + fail-fast: false + matrix: + image-tag: [alpine3.16, bullseye-slim, focal, jammy] + name: ${{ matrix.image-tag }} + runs-on: ubuntu-latest + env: + ASPNET_VERSION: "6.0.8" + SKIP_DOCKER: "false" + steps: + - name: Set version from TAG + if: ${{ startsWith(github.ref, 'refs/tags/') }} + run: | + echo "ASPNET_VERSION=${GITHUB_REF#refs/*/}" >> $GITHUB_ENV + echo "Update ASPNET_VERSION to ${GITHUB_REF#refs/*/}" + - name: Skip docker build + if: ${{ matrix.image-tag == 'focal' && startsWith(env.ASPNET_VERSION, '7.0') }} + run: echo "SKIP_DOCKER=true" >> $GITHUB_ENV + - uses: actions/checkout@v2 + if: ${{ env.SKIP_DOCKER != 'true' }} + - name: Docker meta + id: meta + if: ${{ env.SKIP_DOCKER != 'true' }} + uses: docker/metadata-action@v3 + with: + images: netlah/aspnet-webssh + tags: | + type=ref,event=branch,priority=600,prefix=,suffix= + type=sha,enable=true,priority=500,prefix=sha-,suffix=,format=short + - name: Login to Docker Hub + if: ${{ success() && env.SKIP_DOCKER != 'true' && github.event_name != 'pull_request' }} + uses: docker/login-action@v1 + with: + username: ${{ secrets.DOCKER_HUB_USERNAME }} + password: ${{ secrets.DOCKER_HUB_ACCESS_TOKEN }} + - name: Build and push on tag + if: ${{ success() && env.SKIP_DOCKER != 'true' && github.event_name != 'pull_request' && startsWith(github.ref, 'refs/tags/') }} + env: + IMAGE_TAG: ${{ env.ASPNET_VERSION }}-${{ matrix.image-tag }} + shell: pwsh + run: ./docker-build.ps1 -imageTag ${{ env.IMAGE_TAG }} -dockerRepository netlah/aspnet-webssh,${{ secrets.DOCKER_HUB_REPOS }} -Labels "${{ steps.meta.outputs.labels }}" -Verbose + - name: Build and push on branch + if: ${{ success() && env.SKIP_DOCKER != 'true' && github.event_name != 'pull_request' && !startsWith(github.ref, 'refs/tags/') }} + env: + IMAGE_TAG: ${{ env.ASPNET_VERSION }}-${{ matrix.image-tag }} + shell: pwsh + run: ./docker-build.ps1 -imageTag ${{ env.IMAGE_TAG }} -dockerRepository ${{ secrets.DOCKER_HUB_REPOS }} -Labels "${{ steps.meta.outputs.labels }}" -Verbose diff --git a/README.md b/README.md index 3324525..43b5f3d 100644 --- a/README.md +++ b/README.md @@ -11,6 +11,10 @@ A customized ASP.NET Core container supports Azure AppService Web SSH. Docker im https://github.com/NetLah/aspnet-webssh +## Build Status + +[![Docker Image CI](https://github.com/NetLah/aspnet-webssh/actions/workflows/docker-image.yml/badge.svg)](https://github.com/NetLah/aspnet-webssh/actions/workflows/docker-image.yml) + ## Reference - https://learn.microsoft.com/en-us/azure/app-service/configure-custom-container?pivots=container-linux#enable-ssh diff --git a/docker-build.ps1 b/docker-build.ps1 index 779b3e2..7149b83 100644 --- a/docker-build.ps1 +++ b/docker-build.ps1 @@ -39,7 +39,9 @@ function getMajorSdk($imageTag) { } $imageTagMajor = getMajorSdk $imageTag -$imageArch = $mappingArch[$imageTagMajor] +if ($imageTagMajor) { + $imageArch = $mappingArch[$imageTagMajor] +} if (!$imageTag -or !$imageTagMajor -or !$imageArch) { Write-Error "SDK Image Tag '$imageTag' is not supported" -ErrorAction Stop