Skip to content

Commit

Permalink
refactor: Updated Docker Container Action action.yml file to include …
Browse files Browse the repository at this point in the history
…additional inputs and environment variables
  • Loading branch information
galargh committed Mar 5, 2023
1 parent 45616ac commit 0065109
Showing 1 changed file with 27 additions and 14 deletions.
41 changes: 27 additions & 14 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,17 @@ name: 'Docker Container Action'
description: 'A reimplementation of docker container action'
inputs:
repository:
description: 'The docker image repository'
description: 'The GitHub repository name'
required: true
tag:
description: 'The docker image tag'
ref:
description: 'The GitHub repository ref'
required: true
image:
description: 'The docker image name (defaults to repository)'
required: false
tag:
description: 'The docker image tag (defaults to ref)'
required: false
dockerfile:
description: 'The dockerfile path'
required: false
Expand Down Expand Up @@ -38,30 +44,37 @@ runs:
steps:
- id: pull
env:
INPUT_REPOSITORY: ${{ inputs.repository }}
INPUT_TAG: ${{ inputs.tag }}
INPUT_DOCKER_REGISTRY_URL: ${{ inputs.docker-registry-url }}
run: echo "exit=$(docker pull ${INPUT_DOCKER_REGISTRY_URL#http*://}/$INPUT_REPOSITORY:$INPUT_TAG; echo $?)" >> $GITHUB_OUTPUT
IMAGE: ${{ inputs.image || inputs.repository }}
TAG: ${{ inputs.tag || inputs.ref }}
DOCKER_REGISTRY_URL: ${{ inputs.docker-registry-url }}
run: echo "exit=$(docker pull ${DOCKER_REGISTRY_URL#http*://}/$IMAGE:$TAG; echo $?)" >> $GITHUB_OUTPUT
shell: bash
- if: steps.pull.outputs.exit == 1
env:
INPUT_REPOSITORY: ${{ inputs.repository }}
INPUT_TAG: ${{ inputs.tag }}
INPUT_DOCKERFILE: ${{ inputs.dockerfile }}
INPUT_GITHUB_SERVER_URL: ${{ inputs.github-server-url }}
INPUT_DOCKER_REGISTRY_URL: ${{ inputs.docker-registry-url }}
run: docker build -t ${INPUT_DOCKER_REGISTRY_URL#http*://}/$INPUT_REPOSITORY:$INPUT_TAG -f $INPUT_DOCKERFILE $INPUT_GITHUB_SERVER_URL/$INPUT_REPOSITORY.git#$INPUT_TAG
REPOSITORY: ${{ inputs.repository }}
REF: ${{ inputs.ref }}
IMAGE: ${{ inputs.image || inputs.repository }}
TAG: ${{ inputs.tag || inputs.ref }}
DOCKERFILE: ${{ inputs.dockerfile }}
GITHUB_SERVER_URL: ${{ inputs.github-server-url }}
DOCKER_REGISTRY_URL: ${{ inputs.docker-registry-url }}
run: docker build -t ${DOCKER_REGISTRY_URL#http*://}/$IMAGE:$TAG -f $DOCKERFILE $GITHUB_SERVER_URL/$REPOSITORY.git#$REF
shell: bash
- id: run
env:
DOCKER_REGISTRY_URL: ${{ inputs.docker-registry-url }}
IMAGE: ${{ inputs.image || inputs.repository }}
TAG: ${{ inputs.tag || inputs.ref }}
INPUT_REPOSITORY: ${{ inputs.repository }}
INPUT_REF: ${{ inputs.ref }}
INPUT_IMAGE: ${{ inputs.image }}
INPUT_TAG: ${{ inputs.tag }}
INPUT_DOCKERFILE: ${{ inputs.dockerfile }}
INPUT_OPTS: ${{ inputs.opts }}
INPUT_ARGS: ${{ inputs.args }}
INPUT_WORKING_DIRECTORY: ${{ inputs.working-directory }}
INPUT_GITHUB_SERVER_URL: ${{ inputs.github-server-url }}
INPUT_DOCKER_REGISTRY_URL: ${{ inputs.docker-registry-url }}
run: docker run --workdir "/github/workspace" --rm --env-file <(env | grep -E '^(ACTIONS|GITHUB|INPUT|RUNNER)_') -e HOME -e CI -v "/var/run/docker.sock":"/var/run/docker.sock" -v "/home/runner/work/_temp/_github_home":"/github/home" -v "/home/runner/work/_temp/_github_workflow":"/github/workflow" -v "/home/runner/work/_temp/_runner_file_commands":"/github/file_commands" -v "$GITHUB_WORKSPACE":"/github/workspace" ${{ inputs.opts }} "${INPUT_DOCKER_REGISTRY_URL#http*://}/$INPUT_REPOSITORY:$INPUT_TAG" ${{ inputs.args }}
run: docker run --workdir "${PWD/"$GITHUB_WORKSPACE"/"/github/workspace"}" --rm --env-file <(env | grep -E '^(ACTIONS|GITHUB|INPUT|RUNNER)_') -e HOME -e CI -v "/var/run/docker.sock":"/var/run/docker.sock" -v "/home/runner/work/_temp/_github_home":"/github/home" -v "/home/runner/work/_temp/_github_workflow":"/github/workflow" -v "/home/runner/work/_temp/_runner_file_commands":"/github/file_commands" -v "$GITHUB_WORKSPACE":"/github/workspace" ${{ inputs.opts }} "${DOCKER_REGISTRY_URL#http*://}/$IMAGE:$TAG" ${{ inputs.args }}
working-directory: ${{ inputs.working-directory }}
shell: bash

0 comments on commit 0065109

Please sign in to comment.