mirror of
https://github.com/elgohr/Publish-Docker-Github-Action.git
synced 2026-03-12 18:07:12 -04:00
Add snapshot image push
This commit is contained in:
1
.dockerignore
Normal file
1
.dockerignore
Normal file
@@ -0,0 +1 @@
|
|||||||
|
.git
|
||||||
@@ -18,7 +18,7 @@ FROM runtime as test
|
|||||||
ADD test.sh /test.sh
|
ADD test.sh /test.sh
|
||||||
ADD mock.sh /fake_bin/docker
|
ADD mock.sh /fake_bin/docker
|
||||||
# Use mock instead of real docker
|
# Use mock instead of real docker
|
||||||
ENV PATH="/bin:/fake_bin"
|
ENV PATH="usr/bin:/bin:/fake_bin"
|
||||||
RUN /test.sh
|
RUN /test.sh
|
||||||
|
|
||||||
FROM runtime
|
FROM runtime
|
||||||
|
|||||||
11
README.md
11
README.md
@@ -25,6 +25,17 @@ jobs:
|
|||||||
run: docker logout
|
run: docker logout
|
||||||
```
|
```
|
||||||
|
|
||||||
|
#### Optional Arguments
|
||||||
|
|
||||||
|
Push an additional image, which is tagged with the git sha.
|
||||||
|
When you would like to think about versioning images, this might be useful.
|
||||||
|
```yaml
|
||||||
|
with:
|
||||||
|
args: myDocker/repository
|
||||||
|
snapshot: true
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
### Old workflow
|
### Old workflow
|
||||||
```hcl
|
```hcl
|
||||||
workflow "Publish Docker" {
|
workflow "Publish Docker" {
|
||||||
|
|||||||
@@ -3,7 +3,7 @@
|
|||||||
DOCKER_REPOSITORY=$*
|
DOCKER_REPOSITORY=$*
|
||||||
BRANCH=$(echo ${GITHUB_REF} | sed -e "s/refs\/heads\///g")
|
BRANCH=$(echo ${GITHUB_REF} | sed -e "s/refs\/heads\///g")
|
||||||
|
|
||||||
if [ "${BRANCH}" = "master" ]; then
|
if [ "${BRANCH}" == "master" ]; then
|
||||||
BRANCH="latest"
|
BRANCH="latest"
|
||||||
fi;
|
fi;
|
||||||
|
|
||||||
@@ -14,5 +14,13 @@ fi;
|
|||||||
|
|
||||||
DOCKERNAME="${DOCKER_REPOSITORY}:${BRANCH}"
|
DOCKERNAME="${DOCKER_REPOSITORY}:${BRANCH}"
|
||||||
|
|
||||||
docker build -t ${DOCKERNAME} .
|
if [ "${INPUT_snapshot}" == "true" ]; then
|
||||||
docker push ${DOCKERNAME}
|
SHA=$(env | grep ^github\\.sha= | cut -d= -f2-) # Thank you Github for using dots in variables
|
||||||
|
SHA_DOCKER_NAME="${DOCKER_REPOSITORY}:${SHA}"
|
||||||
|
docker build -t ${DOCKERNAME} -t ${SHA_DOCKER_NAME} .
|
||||||
|
docker push ${DOCKERNAME}
|
||||||
|
docker push ${SHA_DOCKER_NAME}
|
||||||
|
else
|
||||||
|
docker build -t ${DOCKERNAME} .
|
||||||
|
docker push ${DOCKERNAME}
|
||||||
|
fi
|
||||||
|
|||||||
27
test.sh
27
test.sh
@@ -2,8 +2,8 @@
|
|||||||
|
|
||||||
function itPushesMasterBranchToLatest() {
|
function itPushesMasterBranchToLatest() {
|
||||||
export GITHUB_REF='refs/heads/master'
|
export GITHUB_REF='refs/heads/master'
|
||||||
result=$(exec /entrypoint.sh 'my/repository')
|
local result=$(exec /entrypoint.sh 'my/repository')
|
||||||
expected="Called mock with: build -t my/repository:latest .
|
local expected="Called mock with: build -t my/repository:latest .
|
||||||
Called mock with: push my/repository:latest"
|
Called mock with: push my/repository:latest"
|
||||||
if [ "$result" != "$expected" ]; then
|
if [ "$result" != "$expected" ]; then
|
||||||
echo "Expected: $expected
|
echo "Expected: $expected
|
||||||
@@ -14,8 +14,8 @@ Called mock with: push my/repository:latest"
|
|||||||
|
|
||||||
function itPushesBranchAsNameOfTheBranch() {
|
function itPushesBranchAsNameOfTheBranch() {
|
||||||
export GITHUB_REF='refs/heads/myBranch'
|
export GITHUB_REF='refs/heads/myBranch'
|
||||||
result=$(exec /entrypoint.sh 'my/repository')
|
local result=$(exec /entrypoint.sh 'my/repository')
|
||||||
expected="Called mock with: build -t my/repository:myBranch .
|
local expected="Called mock with: build -t my/repository:myBranch .
|
||||||
Called mock with: push my/repository:myBranch"
|
Called mock with: push my/repository:myBranch"
|
||||||
if [ "$result" != "$expected" ]; then
|
if [ "$result" != "$expected" ]; then
|
||||||
echo "Expected: $expected
|
echo "Expected: $expected
|
||||||
@@ -26,8 +26,8 @@ Called mock with: push my/repository:myBranch"
|
|||||||
|
|
||||||
function itPushesReleasesToLatest() {
|
function itPushesReleasesToLatest() {
|
||||||
export GITHUB_REF='refs/tags/myRelease'
|
export GITHUB_REF='refs/tags/myRelease'
|
||||||
result=$(exec /entrypoint.sh 'my/repository')
|
local result=$(exec /entrypoint.sh 'my/repository')
|
||||||
expected="Called mock with: build -t my/repository:latest .
|
local expected="Called mock with: build -t my/repository:latest .
|
||||||
Called mock with: push my/repository:latest"
|
Called mock with: push my/repository:latest"
|
||||||
if [ "$result" != "$expected" ]; then
|
if [ "$result" != "$expected" ]; then
|
||||||
echo "Expected: $expected
|
echo "Expected: $expected
|
||||||
@@ -36,6 +36,21 @@ Called mock with: push my/repository:latest"
|
|||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function itPushesBranchByShaInAddition() {
|
||||||
|
export GITHUB_REF='refs/tags/myRelease'
|
||||||
|
export INPUT_snapshot='true'
|
||||||
|
local result=$(exec env 'github.sha'=COMMIT_SHA /entrypoint.sh 'my/repository')
|
||||||
|
local expected="Called mock with: build -t my/repository:latest -t my/repository:COMMIT_SHA .
|
||||||
|
Called mock with: push my/repository:latest
|
||||||
|
Called mock with: push my/repository:COMMIT_SHA"
|
||||||
|
if [ "$result" != "$expected" ]; then
|
||||||
|
echo "Expected: $expected
|
||||||
|
Got: $result"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
itPushesMasterBranchToLatest
|
itPushesMasterBranchToLatest
|
||||||
itPushesBranchAsNameOfTheBranch
|
itPushesBranchAsNameOfTheBranch
|
||||||
itPushesReleasesToLatest
|
itPushesReleasesToLatest
|
||||||
|
itPushesBranchByShaInAddition
|
||||||
|
|||||||
Reference in New Issue
Block a user