Deploy To DockerHub #3
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: Deploy To DockerHub | |
| on: | |
| workflow_call: | |
| workflow_dispatch: | |
| jobs: | |
| dockerhub-deploy: | |
| runs-on: ubuntu-latest | |
| environment: dockerhub | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| - name: Set up Python | |
| uses: actions/setup-python@v5 | |
| with: | |
| python-version: '3.12' | |
| - name: Extract version from pyproject.toml | |
| id: get_version | |
| run: | | |
| VERSION=$(python -c " | |
| try: | |
| import tomllib | |
| with open('pyproject.toml', 'rb') as f: | |
| data = tomllib.load(f) | |
| print(data['project']['version']) | |
| except Exception as e: | |
| print(f'Error reading version: {e}', file=sys.stderr) | |
| exit(1) | |
| ") | |
| echo "version=$VERSION" >> $GITHUB_OUTPUT | |
| - name: Log in to DockerHub | |
| uses: docker/login-action@v3 | |
| with: | |
| username: ${{ secrets.DOCKERHUB_USERNAME }} | |
| password: ${{ secrets.DOCKERHUB_TOKEN }} | |
| - name: Build and push Docker image | |
| uses: docker/build-push-action@v5 | |
| with: | |
| context: . | |
| file: docker/Dockerfile | |
| push: true | |
| tags: | | |
| ${{ secrets.DOCKERHUB_USERNAME }}/photomapai:${{ steps.get_version.outputs.version }} | |
| ${{ secrets.DOCKERHUB_USERNAME }}/photomapai:latest |