action.yml (1495B)
1 name: 'Run in Docker with environment' 2 description: 'Run a command in a Docker container, while passing explicitly set environment variables into the container.' 3 inputs: 4 dockerfile: 5 description: 'A Dockerfile that defines an image' 6 required: true 7 tag: 8 description: 'A tag of an image' 9 required: true 10 command: 11 description: 'A command to run in a container' 12 required: false 13 default: ./ci/ci.sh 14 runs: 15 using: "composite" 16 steps: 17 - uses: docker/setup-buildx-action@v3 18 19 - uses: docker/build-push-action@v5 20 id: main_builder 21 continue-on-error: true 22 with: 23 context: . 24 file: ${{ inputs.dockerfile }} 25 tags: ${{ inputs.tag }} 26 load: true 27 cache-from: type=gha 28 29 - uses: docker/build-push-action@v5 30 id: retry_builder 31 if: steps.main_builder.outcome == 'failure' 32 with: 33 context: . 34 file: ${{ inputs.dockerfile }} 35 tags: ${{ inputs.tag }} 36 load: true 37 cache-from: type=gha 38 39 - # Tell Docker to pass environment variables in `env` into the container. 40 run: > 41 docker run \ 42 $(echo '${{ toJSON(env) }}' | jq -r 'keys[] | "--env \(.) "') \ 43 --volume ${{ github.workspace }}:${{ github.workspace }} \ 44 --workdir ${{ github.workspace }} \ 45 ${{ inputs.tag }} bash -c " 46 git config --global --add safe.directory ${{ github.workspace }} 47 ${{ inputs.command }} 48 " 49 shell: bash