Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add custom GitHub action for docker tag and push
- if the push refers a branch the docker tag will be branch-sha - if the push refers a git tag the docker tag will be th git tag
- Loading branch information
1 parent
7d4c89d
commit d3208cd
Showing
3 changed files
with
46 additions
and
59 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
FROM docker:stable | ||
|
||
LABEL "name"="Docker tag and push action" | ||
LABEL "maintainer"="Stefan Prodan <support@gweave.works>" | ||
LABEL "version"="1.0.0" | ||
|
||
LABEL "com.github.actions.icon"="terminal" | ||
LABEL "com.github.actions.color"="gray-dark" | ||
LABEL "com.github.actions.name"="Docker Publish" | ||
LABEL "com.github.actions.description"="This is an Action to run docker tag and push commands." | ||
|
||
RUN apk update \ | ||
&& apk add --no-cache ca-certificates bash git curl \ | ||
&& (apk info | xargs -n1 -I{} apk --quiet add {}-doc); true \ | ||
&& rm -rf /var/cache/apk/* | ||
|
||
COPY entrypoint.sh /entrypoint.sh | ||
|
||
ENTRYPOINT ["/entrypoint.sh"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
#!/usr/bin/env bash | ||
|
||
set -o errexit | ||
set -o nounset | ||
set -o pipefail | ||
|
||
echo "Starting tag and push for image ${DOCKER_IMAGE} release ${GITHUB_REF}" | ||
|
||
DOCKER_TAG="latest" | ||
if [[ "${GITHUB_REF}" == "refs/tags"* ]]; then | ||
DOCKER_TAG=$(echo ${GITHUB_REF} | rev | cut -d/ -f1 | rev) | ||
else | ||
DOCKER_TAG=$(echo ${GITHUB_REF} | rev | cut -d/ -f1 | rev)-$(echo ${GITHUB_SHA} | head -c7) | ||
fi | ||
|
||
docker tag app ${DOCKER_IMAGE}:${DOCKER_TAG} | ||
docker push ${DOCKER_IMAGE}:${DOCKER_TAG} | ||
|
||
echo "Docker image pushed to ${DOCKER_IMAGE}:${DOCKER_TAG}" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,72 +1,21 @@ | ||
workflow "Publish branch" { | ||
workflow "Publish container" { | ||
on = "push" | ||
resolves = ["Is branch", "Push branch"] | ||
resolves = ["Docker tag and push"] | ||
} | ||
|
||
action "Is branch" { | ||
uses = "actions/bin/filter@master" | ||
args = "ref refs/heads/*" | ||
} | ||
|
||
action "Test and build branch" { | ||
needs = ["Is branch"] | ||
uses = "actions/docker/cli@master" | ||
args = "build -t app -f Dockerfile.ci ." | ||
} | ||
|
||
action "Tag branch" { | ||
needs = ["Test and build branch"] | ||
uses = "actions/docker/cli@master" | ||
args = "tag app ${DOCKER_IMAGE}:$(echo ${GITHUB_REF} | rev | cut -d/ -f1 | rev)-$(echo ${GITHUB_SHA} | head -c7)" | ||
secrets = ["DOCKER_IMAGE"] | ||
} | ||
|
||
action "Login branch" { | ||
needs = ["Tag branch"] | ||
uses = "actions/docker/login@master" | ||
secrets = ["DOCKER_USERNAME", "DOCKER_PASSWORD"] | ||
} | ||
|
||
action "Push branch" { | ||
needs = ["Login branch"] | ||
uses = "actions/docker/cli@master" | ||
args = "push ${DOCKER_IMAGE}:$(echo ${GITHUB_REF} | rev | cut -d/ -f1 | rev)-$(echo ${GITHUB_SHA} | head -c7)" | ||
secrets = ["DOCKER_IMAGE"] | ||
} | ||
|
||
|
||
workflow "Publish release" { | ||
on = "release" | ||
resolves = ["Push release"] | ||
} | ||
|
||
action "Is release" { | ||
uses = "actions/bin/filter@master" | ||
args = "ref refs/tags/v*" | ||
} | ||
|
||
action "Test and build release" { | ||
needs = ["Is release"] | ||
action "Test and build" { | ||
uses = "actions/docker/cli@master" | ||
args = "build -t app -f Dockerfile.ci ." | ||
} | ||
|
||
action "Login release" { | ||
needs = ["Test and build release"] | ||
action "Docker login" { | ||
needs = ["Test and build"] | ||
uses = "actions/docker/login@master" | ||
secrets = ["DOCKER_USERNAME", "DOCKER_PASSWORD"] | ||
} | ||
|
||
action "Tag release" { | ||
needs = ["Login release"] | ||
uses = "actions/docker/cli@master" | ||
args = "tag app ${DOCKER_IMAGE}:$(echo ${GITHUB_REF} | rev | cut -d/ -f1 | rev)" | ||
secrets = ["DOCKER_IMAGE"] | ||
} | ||
|
||
action "Push release" { | ||
needs = ["Tag release"] | ||
uses = "actions/docker/cli@master" | ||
args = "push ${DOCKER_IMAGE}:$(echo ${GITHUB_REF} | rev | cut -d/ -f1 | rev)" | ||
action "Docker tag and push" { | ||
needs = ["Docker login"] | ||
uses = "./.github/actions/docker" | ||
secrets = ["DOCKER_IMAGE"] | ||
} |