aider: Added Docker login and build/push steps to the GitHub Actions workflow for building and pushing a Docker image to DockerHub on each release.

# Aider chat conversation:

USER: what's the best way to docker build and push a new version to dockerhub on each release?

ASSISTANT: To build and push a new Docker image to DockerHub on each release, you can use GitHub Actions. You will need to modify the existing GitHub Actions workflow file `.github/workflows/release.yml` to include steps for building and pushing the Docker image.

Here are the steps you need to follow:

1. Add Docker login step: You need to log in to DockerHub before you can push images. You can use the `docker/login-action` action for this. You will need to store your DockerHub username and password as secrets in your GitHub repository.

2. Build the Docker image: You can use the `docker/build-push-action` action to build your Docker image. You should use the new version as the tag for the Docker image.

3. Push the Docker image: The `docker/build-push-action` action can also push the Docker image to DockerHub.

Here are the changes you need to make to the `.github/workflows/release.yml` file:

```yaml
.github/workflows/release.yml
<<<<<<< HEAD
name: Release

on:
  push:
    tags:
      - 'v*'

jobs:
  build_and_publish:
    runs-on: ubuntu-latest
    steps:
    - name: Checkout code
      uses: actions/checkout@v3

    - name: Set up Python
      uses: actions/setup-python@v4
      with:
        python-version: 3.x

    - name: Install dependencies
      run: |
        python -m pip install --upgrade pip
        pip install setuptools wheel twine

    - name: Build and publish
      env:
        TWINE_USERNAME: __token__
        TWINE_PASSWORD: ${{ secrets.PYPI_API_TOKEN }}
      run: |
        python setup.py sdist bdist_wheel
        twine upload dist/*
=======
name: Release

on:
  push:
    tags:
      - 'v*'

jobs:
  build_and_publish:
    runs-on: ubuntu-latest
    steps:
    - name: Checkout code
      uses: actions/checkout@v3

    - name: Set up Python
      uses: actions/setup-python@v4
      with:
        python-version: 3.x

    - name: Install dependencies
      run: |
        python -m pip install --upgrade pip
        pip install setuptools wheel twine

    - name: Build and publish
      env:
        TWINE_USERNAME: __token__
        TWINE_PASSWORD: ${{ secrets.PYPI_API_TOKEN }}
      run: |
        python setup.py sdist bdist_wheel
        twine upload dist/*

    - name: Login to DockerHub
      uses: docker/login-action@v1
      with:
        username: ${{ secrets.DOCKERHUB_USERNAME }}
        password: ${{ secrets.DOCKERHUB_PASSWORD }}

    - name: Build and push Docker image
      uses: docker/build-push-action@v2
      with:
        context: .
        push: true
        tags: ${{ secrets.DOCKERHUB_USERNAME }}/aider:${{ github.ref }}
>>>>>>> updated
```

Please replace `DOCKERHUB_USERNAME` and `DOCKERHUB_PASSWORD` with your DockerHub username and password. You should store these as secrets in your GitHub repository.

Please note that this will build and push a new Docker image for every release. If you want to build and push a Docker image only for specific releases, you will need to modify the `on` section of the workflow file.
This commit is contained in:
Paul Gauthier 2023-10-18 08:36:16 -07:00
parent f954bc2ecc
commit 9bcef8b853

View file

@ -29,3 +29,16 @@ jobs:
run: | run: |
python setup.py sdist bdist_wheel python setup.py sdist bdist_wheel
twine upload dist/* twine upload dist/*
- name: Login to DockerHub
uses: docker/login-action@v1
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_PASSWORD }}
- name: Build and push Docker image
uses: docker/build-push-action@v2
with:
context: .
push: true
tags: ${{ secrets.DOCKERHUB_USERNAME }}/aider:${{ github.ref }}