Skip to content

Commit c91145b

Browse files
authored
Merge pull request #10 from macbre/group-logs-less-verbose
Group log lines and make the output less verbose
2 parents bc28083 + c49557b commit c91145b

File tree

2 files changed

+42
-52
lines changed

2 files changed

+42
-52
lines changed

Dockerfile

+3-1
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,10 @@ RUN apk update \
55
&& apk -a info curl \
66
&& apk add curl
77

8-
# these two are passed as build args and stored as env variables
8+
# these two are passed as build args
99
ARG BUILD_DATE
1010
ARG GITHUB_SHA
1111

12+
ENV GITHUB_SHA=$GITHUB_SHA
13+
1214
RUN env | sort

action.yml

+39-51
Original file line numberDiff line numberDiff line change
@@ -32,47 +32,42 @@ runs:
3232
shell: bash
3333
env:
3434
GITHUB_TOKEN: ${{ inputs.github_token }}
35+
DOCKER_BUILDKIT: 1
36+
DOCKER_IO_TOKEN: ${{ inputs.docker_io_token }}
37+
3538
run: |
39+
echo "::group::Logging into the GitHub Container registry (ghcr.io) ..."
3640
echo "${GITHUB_TOKEN}" | docker login ghcr.io -u "${{ github.actor }}" --password-stdin
41+
echo "::endgroup::"
3742
38-
- name: Set commit tag and image name
39-
shell: bash
40-
run: |
43+
echo "::group::Set commit tag and image name"
4144
if [ "${{ github.event_name }}" = "release" ]; then
4245
export COMMIT_TAG=${GITHUB_REF:10}
43-
# export COMMIT_TAG=v2.3.0 # debug
44-
echo "COMMIT_TAG=${COMMIT_TAG//v/}" >> $GITHUB_ENV # remove "v" suffix
46+
export COMMIT_TAG=${COMMIT_TAG//v/}
4547
else
46-
echo "COMMIT_TAG=latest" >> $GITHUB_ENV
48+
export COMMIT_TAG=latest
4749
fi
4850
49-
- name: "Build the Docker image"
50-
shell: bash
51-
run: |
52-
# expand commands
53-
set -x
54-
55-
docker -v
51+
echo "Tagging with ${COMMIT_TAG}"
52+
echo "::endgroup::"
5653
5754
export BUILD_DATE=$(date -u +"%Y-%m-%dT%H:%M:%SZ")
5855
export GITHUB_URL=https://github.com/${{ github.repository }}
5956
60-
echo
61-
echo "Building the Docker image: ${{ inputs.repository }}/${{ inputs.image_name }}:${{ env.COMMIT_TAG }} ..."
62-
echo
57+
echo "::group::Building the Docker image: ${{ inputs.repository }}/${{ inputs.image_name }}:${COMMIT_TAG} ..."
6358
6459
# https://docs.docker.com/develop/develop-images/build_enhancements/
6560
# https://docs.docker.com/engine/reference/commandline/build/#specifying-external-cache-sources
66-
DOCKER_BUILDKIT=1 \
67-
docker build . \
61+
docker build . \
62+
--quiet \
6863
--cache-from ${{ inputs.repository }}/${{ inputs.image_name }}:latest \
6964
--build-arg BUILDKIT_INLINE_CACHE=1 \
7065
\
7166
--build-arg BUILD_DATE=${BUILD_DATE} \
7267
--build-arg GITHUB_SHA=${GITHUB_SHA} \
7368
\
74-
--tag ${{ inputs.repository }}/${{ inputs.image_name }}:${{ env.COMMIT_TAG }} \
75-
--tag docker.io/${{ inputs.image_name }}:${{ env.COMMIT_TAG }} \
69+
--tag ${{ inputs.repository }}/${{ inputs.image_name }}:${COMMIT_TAG} \
70+
--tag docker.io/${{ inputs.image_name }}:${COMMIT_TAG} \
7671
\
7772
--label org.label-schema.build-date=${BUILD_DATE} \
7873
--label org.label-schema.vcs-url=${GITHUB_URL} \
@@ -81,44 +76,37 @@ runs:
8176
--label org.opencontainers.image.created=${BUILD_DATE} \
8277
--label org.opencontainers.image.source=${GITHUB_URL} \
8378
--label org.opencontainers.image.revision=${GITHUB_SHA}
84-
85-
echo
86-
echo "Inspecting the image ..."
87-
echo
8879
80+
echo "::endgroup::"
81+
82+
echo "::group::Inspecting the image ..."
8983
docker images
90-
docker image inspect ${{ inputs.repository }}/${{ inputs.image_name }}:${{ env.COMMIT_TAG }} | jq '.[].Config.Labels'
9184
92-
- name: "Push the Docker image to ghcr.io"
93-
shell: bash
94-
run: |
95-
# expand commands
85+
echo "Labels:"
86+
docker image inspect ${{ inputs.repository }}/${{ inputs.image_name }}:${COMMIT_TAG} | jq '.[].Config.Labels'
87+
88+
echo "Env variables:"
89+
docker image inspect ${{ inputs.repository }}/${{ inputs.image_name }}:${COMMIT_TAG} | jq '.[].Config.Env'
90+
91+
echo "::endgroup::"
92+
93+
echo "::group::Pushing the Docker image to ${{ inputs.repository }} ..."
94+
9695
set -x
97-
98-
echo
99-
echo "Pushing the Docker image to ghcr.io ..."
100-
echo
96+
docker push --quiet ${{ inputs.repository }}/${{ inputs.image_name }}:${COMMIT_TAG}
97+
set +x
10198
102-
docker push ${{ inputs.repository }}/${{ inputs.image_name }}:${{ env.COMMIT_TAG }}
99+
echo "::endgroup::"
103100
104-
- name: "Push the Docker image to docker.io"
105-
shell: bash
106-
env:
107-
DOCKER_TOKEN: ${{ inputs.docker_io_token }}
108-
run: |
109-
if [ -z "${DOCKER_TOKEN}" ]; then
110-
echo
111-
echo "NOT pushing the Docker image to docker.io ... Provide 'docker_io_token' if needed."
112-
echo
101+
if [ -z "${DOCKER_IO_TOKEN}" ]; then
102+
echo "::warning::NOT pushing the Docker image to docker.io ... Provide 'docker_io_token' if needed."
113103
else
114-
# expand commands
115-
set -x
104+
echo "::group::Pushing the Docker image to docker.io ..."
105+
echo "${DOCKER_IO_TOKEN}" | docker login docker.io -u "${{ github.actor }}" --password-stdin
116106
117-
echo
118-
echo "Pushing the Docker image to docker.io ..."
119-
echo
120-
121-
echo "${DOCKER_TOKEN}" | docker login docker.io -u "${{ github.actor }}" --password-stdin
107+
set -x
108+
docker push --quiet docker.io/${{ inputs.image_name }}:${COMMIT_TAG}
109+
set +x
122110
123-
docker push docker.io/${{ inputs.image_name }}:${{ env.COMMIT_TAG }}
111+
echo "::endgroup::"
124112
fi

0 commit comments

Comments
 (0)