Edit readme.md #17
This file contains hidden or 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
| name: Build and Push Docker Image | |
| on: | |
| push: | |
| branches: | |
| - main | |
| tags: | |
| - 'v*' # reacting to tags like v1.2.3 | |
| env: | |
| APP_NAME: eventhubexplorer # the app name | |
| DOCKER_USER: ${{ secrets.DOCKERHUB_USERNAME }} | |
| DOCKERFILE_PATH: src/WebUI/Dockerfile | |
| DOTNET_VERSION: '9.0.x' | |
| jobs: | |
| build: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout repository | |
| uses: actions/checkout@v4 | |
| - name: Set up .NET | |
| uses: actions/setup-dotnet@v4 | |
| with: | |
| dotnet-version: ${{ env.DOTNET_VERSION }} | |
| - name: Log in to Docker Hub | |
| uses: docker/login-action@v3 | |
| with: | |
| username: ${{ secrets.DOCKERHUB_USERNAME }} | |
| password: ${{ secrets.DOCKERHUB_TOKEN }} | |
| - name: Extract version from tag | |
| id: vars | |
| run: | | |
| if [[ "${GITHUB_REF}" == refs/tags/* ]]; then | |
| VERSION="${GITHUB_REF#refs/tags/v}" | |
| else | |
| VERSION="latest" | |
| fi | |
| echo "version=$VERSION" >> $GITHUB_OUTPUT | |
| - name: Build Docker image | |
| run: | | |
| IMAGE=$DOCKER_USER/$APP_NAME | |
| VERSION=${{ steps.vars.outputs.version }} | |
| echo "Building $IMAGE:$VERSION" from $DOCKERFILE_PATH | |
| docker build -t $IMAGE:$VERSION -f $DOCKERFILE_PATH . | |
| # if this is a tag → push latest version as well | |
| if [ "$VERSION" != "latest" ]; then | |
| docker tag $IMAGE:$VERSION $IMAGE:latest | |
| fi | |
| - name: Push Docker image | |
| run: | | |
| IMAGE=$DOCKER_USER/$APP_NAME | |
| VERSION=${{ steps.vars.outputs.version }} | |
| docker push $IMAGE:$VERSION | |
| if [ "$VERSION" != "latest" ]; then | |
| docker push $IMAGE:latest | |
| fi |