Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Group log lines and make the output less verbose #10

Merged
merged 9 commits into from
Sep 13, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@ RUN apk update \
&& apk -a info curl \
&& apk add curl

# these two are passed as build args and stored as env variables
# these two are passed as build args
ARG BUILD_DATE
ARG GITHUB_SHA

ENV GITHUB_SHA=$GITHUB_SHA

RUN env | sort
90 changes: 39 additions & 51 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,47 +32,42 @@ runs:
shell: bash
env:
GITHUB_TOKEN: ${{ inputs.github_token }}
DOCKER_BUILDKIT: 1
DOCKER_IO_TOKEN: ${{ inputs.docker_io_token }}

run: |
echo "::group::Logging into the GitHub Container registry (ghcr.io) ..."
echo "${GITHUB_TOKEN}" | docker login ghcr.io -u "${{ github.actor }}" --password-stdin
echo "::endgroup::"

- name: Set commit tag and image name
shell: bash
run: |
echo "::group::Set commit tag and image name"
if [ "${{ github.event_name }}" = "release" ]; then
export COMMIT_TAG=${GITHUB_REF:10}
# export COMMIT_TAG=v2.3.0 # debug
echo "COMMIT_TAG=${COMMIT_TAG//v/}" >> $GITHUB_ENV # remove "v" suffix
export COMMIT_TAG=${COMMIT_TAG//v/}
else
echo "COMMIT_TAG=latest" >> $GITHUB_ENV
export COMMIT_TAG=latest
fi

- name: "Build the Docker image"
shell: bash
run: |
# expand commands
set -x

docker -v
echo "Tagging with ${COMMIT_TAG}"
echo "::endgroup::"

export BUILD_DATE=$(date -u +"%Y-%m-%dT%H:%M:%SZ")
export GITHUB_URL=https://github.com/${{ github.repository }}

echo
echo "Building the Docker image: ${{ inputs.repository }}/${{ inputs.image_name }}:${{ env.COMMIT_TAG }} ..."
echo
echo "::group::Building the Docker image: ${{ inputs.repository }}/${{ inputs.image_name }}:${COMMIT_TAG} ..."

# https://docs.docker.com/develop/develop-images/build_enhancements/
# https://docs.docker.com/engine/reference/commandline/build/#specifying-external-cache-sources
DOCKER_BUILDKIT=1 \
docker build . \
docker build . \
--quiet \
--cache-from ${{ inputs.repository }}/${{ inputs.image_name }}:latest \
--build-arg BUILDKIT_INLINE_CACHE=1 \
\
--build-arg BUILD_DATE=${BUILD_DATE} \
--build-arg GITHUB_SHA=${GITHUB_SHA} \
\
--tag ${{ inputs.repository }}/${{ inputs.image_name }}:${{ env.COMMIT_TAG }} \
--tag docker.io/${{ inputs.image_name }}:${{ env.COMMIT_TAG }} \
--tag ${{ inputs.repository }}/${{ inputs.image_name }}:${COMMIT_TAG} \
--tag docker.io/${{ inputs.image_name }}:${COMMIT_TAG} \
\
--label org.label-schema.build-date=${BUILD_DATE} \
--label org.label-schema.vcs-url=${GITHUB_URL} \
Expand All @@ -81,44 +76,37 @@ runs:
--label org.opencontainers.image.created=${BUILD_DATE} \
--label org.opencontainers.image.source=${GITHUB_URL} \
--label org.opencontainers.image.revision=${GITHUB_SHA}

echo
echo "Inspecting the image ..."
echo

echo "::endgroup::"

echo "::group::Inspecting the image ..."
docker images
docker image inspect ${{ inputs.repository }}/${{ inputs.image_name }}:${{ env.COMMIT_TAG }} | jq '.[].Config.Labels'

- name: "Push the Docker image to ghcr.io"
shell: bash
run: |
# expand commands
echo "Labels:"
docker image inspect ${{ inputs.repository }}/${{ inputs.image_name }}:${COMMIT_TAG} | jq '.[].Config.Labels'

echo "Env variables:"
docker image inspect ${{ inputs.repository }}/${{ inputs.image_name }}:${COMMIT_TAG} | jq '.[].Config.Env'

echo "::endgroup::"

echo "::group::Pushing the Docker image to ${{ inputs.repository }} ..."

set -x

echo
echo "Pushing the Docker image to ghcr.io ..."
echo
docker push --quiet ${{ inputs.repository }}/${{ inputs.image_name }}:${COMMIT_TAG}
set +x

docker push ${{ inputs.repository }}/${{ inputs.image_name }}:${{ env.COMMIT_TAG }}
echo "::endgroup::"

- name: "Push the Docker image to docker.io"
shell: bash
env:
DOCKER_TOKEN: ${{ inputs.docker_io_token }}
run: |
if [ -z "${DOCKER_TOKEN}" ]; then
echo
echo "NOT pushing the Docker image to docker.io ... Provide 'docker_io_token' if needed."
echo
if [ -z "${DOCKER_IO_TOKEN}" ]; then
echo "::warning::NOT pushing the Docker image to docker.io ... Provide 'docker_io_token' if needed."
else
# expand commands
set -x
echo "::group::Pushing the Docker image to docker.io ..."
echo "${DOCKER_IO_TOKEN}" | docker login docker.io -u "${{ github.actor }}" --password-stdin

echo
echo "Pushing the Docker image to docker.io ..."
echo

echo "${DOCKER_TOKEN}" | docker login docker.io -u "${{ github.actor }}" --password-stdin
set -x
docker push --quiet docker.io/${{ inputs.image_name }}:${COMMIT_TAG}
set +x

docker push docker.io/${{ inputs.image_name }}:${{ env.COMMIT_TAG }}
echo "::endgroup::"
fi