Skip to content

Commit

Permalink
Merge pull request #1 from pl-strflt/fix-workdir
Browse files Browse the repository at this point in the history
refactor: Updated Docker Container Action action.yml file to include…
  • Loading branch information
galargh authored Mar 5, 2023
2 parents 45616ac + 296a345 commit 48611e5
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 14 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,14 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## Unreleased

## [1.1.1] - 2023-03-05
### Added
- Added `ref` input to accept the GitHub repository ref
- Added `image` input to specify the docker image name (defaults to repository)

### Changed
- `tag` is no longer required, defaults to `ref` which is now the required input

## [1.1.0] - 2023-03-05
### Changed
- Updated the output of the action to include all the outputs of the docker run step in JSON format, using the `toJSON` function. Removed the previous output file.
Expand Down
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 48611e5

Please sign in to comment.