dockerhub

Use environment variables with sensible information in Docker Hub autobuild


Docker Hub has a section in the "Build configurations" section to specify build environment variables:

enter image description here

The problem is that the value of the variable appears in clear text, which makes this mechanism unsuitable for variables holding sensitive information (e.g. passwords).

I was thinking in something similar to the secrets mechanism in GitHub which allow to define variables which value is seen only one time (in the moment of creating them) but can be latter used in GitHub Actions as many times as you want.

Is there a way to define build variables in Docker Hub without showing the value in the interface? Or any other suitable workaround?


Solution

  • Given that it seems there is no solution to this in the dockerhub space, I have opted for the workaround of solving it with a GitAction. Something like this:

    name: Publish Docker image (master)
    
    on:
      push:
        branches:
          - master      
    
    jobs:
      build-and-push:
        runs-on: ubuntu-latest
    
        steps:
        - name: Checkout code
          uses: actions/checkout@v3
    
        - name: Set up Docker Buildx
          uses: docker/setup-buildx-action@v2
    
        - name: Log in to Docker Hub
          uses: docker/login-action@v2
          with:
            username: ${{ secrets.DOCKERHUB_TEF_USERNAME }}
            password: ${{ secrets.DOCKERHUB_TEF_TOKEN }}
    
        - name: Build Docker image
          run: docker build -t telefonicaiot/fiware-orion:latest --build-arg GIT_REV_ORION=master --build-arg REPO_ACCESS_TOKEN=${{ secrets.REPO_ACCESS_TOKEN }} --no-cache -f docker/Dockerfile .
    
        - name: Push Docker image
          run: docker push telefonicaiot/fiware-orion:latest
    

    Where secrets.REPO_ACCESS_TOKEN holds the secret that I cannot use at dockerhub.