Skip to content

Commit 48611e5

Browse files
authored
Merge pull request #1 from pl-strflt/fix-workdir
refactor: Updated Docker Container Action action.yml file to include…
2 parents 45616ac + 296a345 commit 48611e5

File tree

2 files changed

+35
-14
lines changed

2 files changed

+35
-14
lines changed

CHANGELOG.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,14 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
66

77
## Unreleased
88

9+
## [1.1.1] - 2023-03-05
10+
### Added
11+
- Added `ref` input to accept the GitHub repository ref
12+
- Added `image` input to specify the docker image name (defaults to repository)
13+
14+
### Changed
15+
- `tag` is no longer required, defaults to `ref` which is now the required input
16+
917
## [1.1.0] - 2023-03-05
1018
### Changed
1119
- 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.

action.yml

Lines changed: 27 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,17 @@ name: 'Docker Container Action'
22
description: 'A reimplementation of docker container action'
33
inputs:
44
repository:
5-
description: 'The docker image repository'
5+
description: 'The GitHub repository name'
66
required: true
7-
tag:
8-
description: 'The docker image tag'
7+
ref:
8+
description: 'The GitHub repository ref'
99
required: true
10+
image:
11+
description: 'The docker image name (defaults to repository)'
12+
required: false
13+
tag:
14+
description: 'The docker image tag (defaults to ref)'
15+
required: false
1016
dockerfile:
1117
description: 'The dockerfile path'
1218
required: false
@@ -38,30 +44,37 @@ runs:
3844
steps:
3945
- id: pull
4046
env:
41-
INPUT_REPOSITORY: ${{ inputs.repository }}
42-
INPUT_TAG: ${{ inputs.tag }}
43-
INPUT_DOCKER_REGISTRY_URL: ${{ inputs.docker-registry-url }}
44-
run: echo "exit=$(docker pull ${INPUT_DOCKER_REGISTRY_URL#http*://}/$INPUT_REPOSITORY:$INPUT_TAG; echo $?)" >> $GITHUB_OUTPUT
47+
IMAGE: ${{ inputs.image || inputs.repository }}
48+
TAG: ${{ inputs.tag || inputs.ref }}
49+
DOCKER_REGISTRY_URL: ${{ inputs.docker-registry-url }}
50+
run: echo "exit=$(docker pull ${DOCKER_REGISTRY_URL#http*://}/$IMAGE:$TAG; echo $?)" >> $GITHUB_OUTPUT
4551
shell: bash
4652
- if: steps.pull.outputs.exit == 1
4753
env:
48-
INPUT_REPOSITORY: ${{ inputs.repository }}
49-
INPUT_TAG: ${{ inputs.tag }}
50-
INPUT_DOCKERFILE: ${{ inputs.dockerfile }}
51-
INPUT_GITHUB_SERVER_URL: ${{ inputs.github-server-url }}
52-
INPUT_DOCKER_REGISTRY_URL: ${{ inputs.docker-registry-url }}
53-
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
54+
REPOSITORY: ${{ inputs.repository }}
55+
REF: ${{ inputs.ref }}
56+
IMAGE: ${{ inputs.image || inputs.repository }}
57+
TAG: ${{ inputs.tag || inputs.ref }}
58+
DOCKERFILE: ${{ inputs.dockerfile }}
59+
GITHUB_SERVER_URL: ${{ inputs.github-server-url }}
60+
DOCKER_REGISTRY_URL: ${{ inputs.docker-registry-url }}
61+
run: docker build -t ${DOCKER_REGISTRY_URL#http*://}/$IMAGE:$TAG -f $DOCKERFILE $GITHUB_SERVER_URL/$REPOSITORY.git#$REF
5462
shell: bash
5563
- id: run
5664
env:
65+
DOCKER_REGISTRY_URL: ${{ inputs.docker-registry-url }}
66+
IMAGE: ${{ inputs.image || inputs.repository }}
67+
TAG: ${{ inputs.tag || inputs.ref }}
5768
INPUT_REPOSITORY: ${{ inputs.repository }}
69+
INPUT_REF: ${{ inputs.ref }}
70+
INPUT_IMAGE: ${{ inputs.image }}
5871
INPUT_TAG: ${{ inputs.tag }}
5972
INPUT_DOCKERFILE: ${{ inputs.dockerfile }}
6073
INPUT_OPTS: ${{ inputs.opts }}
6174
INPUT_ARGS: ${{ inputs.args }}
6275
INPUT_WORKING_DIRECTORY: ${{ inputs.working-directory }}
6376
INPUT_GITHUB_SERVER_URL: ${{ inputs.github-server-url }}
6477
INPUT_DOCKER_REGISTRY_URL: ${{ inputs.docker-registry-url }}
65-
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 }}
78+
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 }}
6679
working-directory: ${{ inputs.working-directory }}
6780
shell: bash

0 commit comments

Comments
 (0)