mirror of
https://github.com/elgohr/Publish-Docker-Github-Action.git
synced 2026-03-12 18:07:12 -04:00
Change snapshot tag to contain the date
This commit is contained in:
@@ -16,9 +16,10 @@ ENTRYPOINT ["/entrypoint.sh"]
|
||||
|
||||
FROM runtime as test
|
||||
ADD test.sh /test.sh
|
||||
ADD mock.sh /fake_bin/docker
|
||||
ADD stub.sh /fake_bin/docker
|
||||
ADD mock.sh /fake_bin/date
|
||||
# Use mock instead of real docker
|
||||
ENV PATH="usr/bin:/bin:/fake_bin"
|
||||
ENV PATH="/fake_bin:usr/bin:/bin"
|
||||
RUN /test.sh
|
||||
|
||||
FROM runtime
|
||||
|
||||
@@ -41,7 +41,8 @@ with:
|
||||
registry: "docker.pkg.github.com"
|
||||
```
|
||||
|
||||
Use `snapshot` to push an additional image, which is tagged with the git sha.
|
||||
Use `snapshot` to push an additional image, which is tagged with {YEAR}{MONTH}{DAY}{HOUR}{MINUTE}{SECOND}{first 6 digits of the git sha}.
|
||||
The date was inserted to prevent new builds with external dependencies override older builds with the same sha.
|
||||
When you would like to think about versioning images, this might be useful.
|
||||
|
||||
```yaml
|
||||
|
||||
@@ -36,7 +36,9 @@ fi
|
||||
echo ${INPUT_PASSWORD} | docker login -u ${INPUT_USERNAME} --password-stdin ${INPUT_REGISTRY}
|
||||
|
||||
if [ "${INPUT_SNAPSHOT}" == "true" ]; then
|
||||
SHA_DOCKER_NAME="${INPUT_NAME}:${GITHUB_SHA}"
|
||||
timestamp=`date +%Y%m%d%H%M%S`
|
||||
shortSha=$(echo "${GITHUB_SHA}" | cut -c1-6)
|
||||
SHA_DOCKER_NAME="${INPUT_NAME}:${timestamp}${shortSha}"
|
||||
docker build $CUSTOMDOCKERFILE -t ${DOCKERNAME} -t ${SHA_DOCKER_NAME} .
|
||||
docker push ${DOCKERNAME}
|
||||
docker push ${SHA_DOCKER_NAME}
|
||||
|
||||
4
mock.sh
4
mock.sh
@@ -1,3 +1,5 @@
|
||||
#!/bin/sh
|
||||
echo "Called mock with: $@"
|
||||
if [ ! -z "${MOCK_DATE}" ]; then
|
||||
echo "${MOCK_DATE}"
|
||||
fi
|
||||
exit 0
|
||||
|
||||
22
test.sh
22
test.sh
@@ -76,18 +76,19 @@ Called mock with: logout"
|
||||
cleanEnvironment
|
||||
}
|
||||
|
||||
function itPushesBranchByShaInAddition() {
|
||||
function itPushesBranchByShaAndDateInAddition() {
|
||||
export GITHUB_REF='refs/tags/myRelease'
|
||||
export INPUT_SNAPSHOT='true'
|
||||
export GITHUB_SHA='COMMIT_SHA'
|
||||
export GITHUB_SHA='12169ed809255604e557a82617264e9c373faca7'
|
||||
export MOCK_DATE='197001010101'
|
||||
export INPUT_USERNAME='USERNAME'
|
||||
export INPUT_PASSWORD='PASSWORD'
|
||||
export INPUT_NAME='my/repository'
|
||||
local result=$(exec /entrypoint.sh)
|
||||
local expected="Called mock with: login -u USERNAME --password-stdin
|
||||
Called mock with: build -t my/repository:latest -t my/repository:COMMIT_SHA .
|
||||
Called mock with: build -t my/repository:latest -t my/repository:19700101010112169e .
|
||||
Called mock with: push my/repository:latest
|
||||
Called mock with: push my/repository:COMMIT_SHA
|
||||
Called mock with: push my/repository:19700101010112169e
|
||||
Called mock with: logout"
|
||||
if [ "$result" != "$expected" ]; then
|
||||
echo "Expected: $expected
|
||||
@@ -97,19 +98,20 @@ Called mock with: logout"
|
||||
cleanEnvironment
|
||||
}
|
||||
|
||||
function itPushesBranchByShaInAdditionWithSpecificDockerfile() {
|
||||
function itPushesBranchByShaAndDateInAdditionWithSpecificDockerfile() {
|
||||
export GITHUB_REF='refs/tags/myRelease'
|
||||
export INPUT_SNAPSHOT='true'
|
||||
export INPUT_DOCKERFILE='MyDockerFileName'
|
||||
export GITHUB_SHA='COMMIT_SHA'
|
||||
export GITHUB_SHA='12169ed809255604e557a82617264e9c373faca7'
|
||||
export MOCK_DATE='197001010101'
|
||||
export INPUT_USERNAME='USERNAME'
|
||||
export INPUT_PASSWORD='PASSWORD'
|
||||
export INPUT_NAME='my/repository'
|
||||
local result=$(exec /entrypoint.sh)
|
||||
local expected="Called mock with: login -u USERNAME --password-stdin
|
||||
Called mock with: build -f MyDockerFileName -t my/repository:latest -t my/repository:COMMIT_SHA .
|
||||
Called mock with: build -f MyDockerFileName -t my/repository:latest -t my/repository:19700101010112169e .
|
||||
Called mock with: push my/repository:latest
|
||||
Called mock with: push my/repository:COMMIT_SHA
|
||||
Called mock with: push my/repository:19700101010112169e
|
||||
Called mock with: logout"
|
||||
if [ "$result" != "$expected" ]; then
|
||||
echo "Expected: $expected
|
||||
@@ -178,8 +180,8 @@ itPushesMasterBranchToLatest
|
||||
itPushesBranchAsNameOfTheBranch
|
||||
itPushesReleasesToLatest
|
||||
itPushesSpecificDockerfileReleasesToLatest
|
||||
itPushesBranchByShaInAddition
|
||||
itPushesBranchByShaInAdditionWithSpecificDockerfile
|
||||
itPushesBranchByShaAndDateInAddition
|
||||
itPushesBranchByShaAndDateInAdditionWithSpecificDockerfile
|
||||
itLogsIntoAnotherRegistryIfConfigured
|
||||
itErrorsWhenNameWasNotSet
|
||||
itErrorsWhenUsernameWasNotSet
|
||||
|
||||
Reference in New Issue
Block a user