mirror of
https://github.com/elgohr/Publish-Docker-Github-Action.git
synced 2026-03-12 18:07:12 -04:00
Add buildoptions
This commit is contained in:
16
README.md
16
README.md
@@ -123,6 +123,22 @@ All `buildargs` will be masked, so that they don't appear in the logs.
|
||||
buildargs: MY_FIRST,MY_SECOND
|
||||
```
|
||||
|
||||
### buildoptions
|
||||
Use `buildoptions` when you want to configure [options](https://docs.docker.com/engine/reference/commandline/build/#options) for building.
|
||||
|
||||
```yaml
|
||||
- name: Publish to Registry
|
||||
uses: elgohr/Publish-Docker-Github-Action@master
|
||||
env:
|
||||
MY_FIRST: variableContent
|
||||
MY_SECOND: variableContent
|
||||
with:
|
||||
name: myDocker/repository
|
||||
username: ${{ secrets.DOCKER_USERNAME }}
|
||||
password: ${{ secrets.DOCKER_PASSWORD }}
|
||||
buildoptions: "--compress --force-rm"
|
||||
```
|
||||
|
||||
### cache
|
||||
Use `cache` when you have big images, that you would only like to build partially (changed layers).
|
||||
> CAUTION: Docker builds will cache non-repoducable commands, such as installing packages. If you use this option, your packages will never update. To avoid this, run this action on a schedule with caching **disabled** to rebuild the cache periodically.
|
||||
|
||||
@@ -100,13 +100,13 @@ function changeWorkingDirectory() {
|
||||
}
|
||||
|
||||
function useCustomDockerfile() {
|
||||
BUILDPARAMS="$BUILDPARAMS -f ${INPUT_DOCKERFILE}"
|
||||
BUILDPARAMS="${BUILDPARAMS} -f ${INPUT_DOCKERFILE}"
|
||||
}
|
||||
|
||||
function addBuildArgs() {
|
||||
for arg in $(echo "${INPUT_BUILDARGS}" | tr ',' '\n'); do
|
||||
BUILDPARAMS="$BUILDPARAMS --build-arg ${arg}"
|
||||
echo "::add-mask::${arg}"
|
||||
for ARG in $(echo "${INPUT_BUILDARGS}" | tr ',' '\n'); do
|
||||
BUILDPARAMS="${BUILDPARAMS} --build-arg ${ARG}"
|
||||
echo "::add-mask::${ARG}"
|
||||
done
|
||||
}
|
||||
|
||||
@@ -129,14 +129,14 @@ function pushWithSnapshot() {
|
||||
local SHORT_SHA=$(echo "${GITHUB_SHA}" | cut -c1-6)
|
||||
local SNAPSHOT_TAG="${TIMESTAMP}${SHORT_SHA}"
|
||||
local SHA_DOCKER_NAME="${INPUT_NAME}:${SNAPSHOT_TAG}"
|
||||
docker build $BUILDPARAMS -t ${DOCKERNAME} -t ${SHA_DOCKER_NAME} ${CONTEXT}
|
||||
docker build ${INPUT_BUILDOPTIONS} ${BUILDPARAMS} -t ${DOCKERNAME} -t ${SHA_DOCKER_NAME} ${CONTEXT}
|
||||
docker push ${DOCKERNAME}
|
||||
docker push ${SHA_DOCKER_NAME}
|
||||
echo ::set-output name=snapshot-tag::"${SNAPSHOT_TAG}"
|
||||
}
|
||||
|
||||
function pushWithoutSnapshot() {
|
||||
docker build $BUILDPARAMS -t ${DOCKERNAME} ${CONTEXT}
|
||||
docker build ${INPUT_BUILDOPTIONS} ${BUILDPARAMS} -t ${DOCKERNAME} ${CONTEXT}
|
||||
docker push ${DOCKERNAME}
|
||||
}
|
||||
|
||||
|
||||
24
test.bats
24
test.bats
@@ -417,6 +417,30 @@ teardown() {
|
||||
/usr/local/bin/docker inspect --format={{index .RepoDigests 0}} my/repository:latest"
|
||||
}
|
||||
|
||||
@test "it uses buildoptions for building, if configured" {
|
||||
export INPUT_BUILDOPTIONS='--compress --force-rm'
|
||||
|
||||
run /entrypoint.sh
|
||||
|
||||
expectMockCalled "/usr/local/bin/docker build --compress --force-rm -t my/repository:latest ."
|
||||
}
|
||||
|
||||
@test "it uses buildoptions for building with snapshot, if configured" {
|
||||
export INPUT_BUILDOPTIONS='--compress --force-rm'
|
||||
export INPUT_SNAPSHOT='true'
|
||||
|
||||
export GITHUB_SHA='12169ed809255604e557a82617264e9c373faca7'
|
||||
|
||||
declare -A -p MOCK_RETURNS=(
|
||||
['/usr/local/bin/docker']=""
|
||||
['/usr/bin/date']="197001010101"
|
||||
) > mockReturns
|
||||
|
||||
run /entrypoint.sh
|
||||
|
||||
expectMockCalled "/usr/local/bin/docker build --compress --force-rm -t my/repository:latest -t my/repository:19700101010112169e ."
|
||||
}
|
||||
|
||||
function expectStdOutContains() {
|
||||
local expected=$(echo "${1}" | tr -d '\n')
|
||||
local got=$(echo "${output}" | tr -d '\n')
|
||||
|
||||
Reference in New Issue
Block a user