name: "Update Image and Push to Github Packages and Docker Hub when Dockerfile is changed" # Run this workflow every time a new commit pushed to your repository on: push: jobs: rebuild-container: name: "Rebuild Container with the latest base image" runs-on: ubuntu-latest steps: - name: Set up Docker Buildx uses: docker/setup-buildx-action@v2 - name: Login to GitHub Container Registry uses: docker/login-action@v2 with: registry: ghcr.io username: ${{ github.repository_owner }} password: ${{ secrets.GITHUB_TOKEN }} - name: Login to DockerHub uses: docker/login-action@v2 with: username: ${{ secrets.DOCKER_USERNAME }} password: ${{ secrets.DOCKER_PASSWORD }} - name: "Checkout repository" uses: "actions/checkout@v3" - name: Build and push to Docker Hub and Github Packages Docker Registry id: docker_build uses: docker/build-push-action@v3 with: push: true tags: | ghcr.io/${{ github.repository_owner }}/teddit:latest ${{ secrets.DOCKER_USERNAME }}/teddit:latest labels: | org.opencontainers.image.source=${{ github.event.repository.html_url }} org.opencontainers.image.created=${{ steps.prep.outputs.created }} org.opencontainers.image.revision=${{ github.sha }} cache-from: type=registry,ref=${{ secrets.DOCKER_USERNAME }}/teddit:latest cache-to: type=inline - name: Image digest run: echo ${{ steps.docker_build.outputs.digest }}