ready env container #33
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 Docker Container | |
| on: | |
| push: | |
| branches: [main] | |
| tags: ['*'] | |
| env: | |
| REGISTRY: ghcr.io | |
| # Hardcoded name change | |
| IMAGE_NAME: ${{ github.repository_owner }}/say_hello | |
| jobs: | |
| build-docker: | |
| runs-on: ubuntu-latest | |
| permissions: | |
| contents: read | |
| packages: write | |
| steps: | |
| - name: Checkout repository | |
| uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: 0 | |
| - name: Extract SCM versions | |
| id: scm | |
| run: | | |
| # The raw version hatch gives us (e.g., 0.1.dev51+gf41b6) | |
| RAW_VERSION=$(pipx run hatch version) | |
| # 1. Version for Python/Hatch (Keep the +) | |
| echo "py_version=$RAW_VERSION" >> $GITHUB_OUTPUT | |
| # 2. Version for Docker Tags (Replace + with -) | |
| CLEAN_VERSION=$(echo $RAW_VERSION | tr '+' '-') | |
| echo "tag_version=$CLEAN_VERSION" >> $GITHUB_OUTPUT | |
| - name: Extract metadata | |
| id: meta | |
| uses: docker/metadata-action@v5 | |
| with: | |
| images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} | |
| tags: | | |
| type=raw,value=latest,enable={{is_default_branch}} | |
| type=sha,format=short | |
| # Use the SANITIZED version for the registry tag | |
| type=raw,value=${{ steps.scm.outputs.tag_version }} | |
| - name: Log in to GHCR | |
| uses: docker/login-action@v3 | |
| with: | |
| registry: ${{ env.REGISTRY }} | |
| username: ${{ github.actor }} | |
| password: ${{ secrets.GITHUB_TOKEN }} | |
| - name: Build and push | |
| uses: docker/build-push-action@v5 | |
| with: | |
| context: . | |
| file: containers/say_hello.Dockerfile | |
| push: true | |
| tags: ${{ steps.meta.outputs.tags }} | |
| build-args: | | |
| # Use the RAW version for the internal Python build | |
| VERSION=${{ steps.scm.outputs.py_version }} |