docker / build-push-action

GitHub Action to build and push Docker images with Buildx
https://github.com/marketplace/actions/build-and-push-docker-images
Apache License 2.0
4.36k stars 558 forks source link

Is there a way to use env file? #827

Closed alejandroacho closed 1 year ago

alejandroacho commented 1 year ago

Troubleshooting

Hi,

I would like to know if there is a way to use an env file such like this:

    - name: 🏗️ Create ENV file for master
      if: ${{ github.ref == 'refs/heads/dev' }}
      run: echo "${{ secrets.PRODUCTION_ENV_FILE }}" > .env
    - name: 🏗️ Build and push dev
      if: ${{ github.ref == 'refs/heads/dev' }}
      uses: docker/build-push-action@v3
      with:
        context: .
        file: ./Envs/Dev/Dockerfile
        push: true
        tags: |
          ${{ secrets.DOCKERHUB_USERNAME }}/${{ secrets.DOCKERHUB_REPONAME }}:dev-latest
          ${{ secrets.DOCKERHUB_USERNAME }}/${{ secrets.DOCKERHUB_REPONAME }}:${{ github.sha }}
        build-args: cat .env
crazy-max commented 1 year ago

I think you could just do:

    - name: 🏗️ Build and push dev
      if: ${{ github.ref == 'refs/heads/dev' }}
      uses: docker/build-push-action@v3
      with:
        context: .
        file: ./Envs/Dev/Dockerfile
        push: true
        tags: |
          ${{ secrets.DOCKERHUB_USERNAME }}/${{ secrets.DOCKERHUB_REPONAME }}:dev-latest
          ${{ secrets.DOCKERHUB_USERNAME }}/${{ secrets.DOCKERHUB_REPONAME }}:${{ github.sha }}
        build-args: |
          ${{ secrets.PRODUCTION_ENV_FILE }}