diff --git a/.github/actions/docker/Dockerfile b/.github/actions/docker/Dockerfile new file mode 100644 index 000000000..a709d0db8 --- /dev/null +++ b/.github/actions/docker/Dockerfile @@ -0,0 +1,19 @@ +FROM docker:stable + +LABEL "name"="Docker tag and push action" +LABEL "maintainer"="Stefan Prodan " +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"] diff --git a/.github/actions/docker/entrypoint.sh b/.github/actions/docker/entrypoint.sh new file mode 100755 index 000000000..8d23842a1 --- /dev/null +++ b/.github/actions/docker/entrypoint.sh @@ -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}" diff --git a/.github/main.workflow b/.github/main.workflow index 2e0957817..e20523b7b 100644 --- a/.github/main.workflow +++ b/.github/main.workflow @@ -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"] }