Build & Push Docker image #12
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 & Push Docker image | |
| on: | |
| push: | |
| tags: | |
| - 'v*.*.*' | |
| workflow_dispatch: | |
| inputs: | |
| version: | |
| description: 'Docker tag version' | |
| required: true | |
| permissions: | |
| contents: read | |
| jobs: | |
| docker: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Determine version | |
| id: ver | |
| run: | | |
| set -euo pipefail | |
| if [ "${{ github.event_name }}" = "push" ]; then | |
| echo "version=${{ github.ref_name }}" >> $GITHUB_OUTPUT | |
| else | |
| echo "version=${{ github.event.inputs.version }}" >> $GITHUB_OUTPUT | |
| fi | |
| - name: Validate version format | |
| run: | | |
| set -euo pipefail | |
| VERSION="${{ steps.ver.outputs.version }}" | |
| if [[ ! "$VERSION" =~ ^v[0-9]+\.[0-9]+\.[0-9]+$ ]]; then | |
| echo "Invalid version: $VERSION (expected vMAJOR.MINOR.PATCH, e.g. v1.1.0)" | |
| exit 1 | |
| fi | |
| - name: Debug refs | |
| run: | | |
| echo "event: ${{ github.event_name }}" | |
| echo "ref: ${{ github.ref }}" | |
| echo "ref_name: ${{ github.ref_name }}" | |
| echo "version: ${{ steps.ver.outputs.version }}" | |
| - name: Checkout | |
| uses: actions/checkout@v4 | |
| - name: Set up Docker Buildx | |
| uses: docker/setup-buildx-action@v3 | |
| - name: Log in to Docker Hub | |
| uses: docker/login-action@v3 | |
| with: | |
| username: ${{ secrets.DOCKERHUB_USERNAME }} | |
| password: ${{ secrets.DOCKERHUB_TOKEN }} | |
| - name: Build and push (version + latest) | |
| uses: docker/build-push-action@v6 | |
| with: | |
| context: . | |
| file: ./Dockerfile | |
| push: true | |
| tags: | | |
| oceanenterprise/market:${{ steps.ver.outputs.version }} | |
| oceanenterprise/market:latest | |
| cache-from: type=gha | |
| cache-to: type=gha,mode=max |