Skip to content

Commit

Permalink
Implement Docker Image CI (#1)
Browse files Browse the repository at this point in the history
* Add Github Actions Workflow docker-image

* Fix env

* Fix checkout

* Fix invalid imageTag

* Fix default version 6.0.8 instead of 6.8.0

* Add Labels
  • Loading branch information
thohng authored Sep 21, 2022
1 parent 179ad88 commit 165ae73
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 1 deletion.
56 changes: 56 additions & 0 deletions .github/workflows/docker-image.yml
Original file line number Diff line number Diff line change
@@ -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
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 3 additions & 1 deletion docker-build.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 165ae73

Please sign in to comment.