Skip to content

Commit 93520db

Browse files
committed
chore(gh): using build-args
1 parent ddb9ffd commit 93520db

File tree

1 file changed

+34
-18
lines changed

1 file changed

+34
-18
lines changed

.github/workflows/docker-ci.yml

Lines changed: 34 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,27 @@ jobs:
1010
runs-on: ubuntu-20.04
1111
steps:
1212

13-
-
14-
name: Checkout
13+
- name: Checkout
1514
uses: actions/checkout@v2
1615

17-
-
18-
name: Docker meta
16+
- name: Generate build-args
17+
id: build-args
18+
run: |
19+
# Declate vars for internal use
20+
VERSION=$(git describe --abbrev=0 --tags)
21+
GIT_HEAD_COMMIT=$(git rev-parse --short HEAD)
22+
GIT_TAG_COMMIT=$(git rev-parse --short $VERSION)
23+
GIT_MODIFIED_1=$(git diff $GIT_HEAD_COMMIT $GIT_TAG_COMMIT --quiet && echo "" || echo ".dev")
24+
GIT_MODIFIED_2=$(git diff --quiet && echo "" || echo ".dirty")
25+
# Export to GH_ENV
26+
echo "GIT_LAST_TAG=$VERSION" >> $GITHUB_ENV
27+
echo "GIT_HEAD_COMMIT=$GIT_HEAD_COMMIT" >> $GITHUB_ENV
28+
echo "GIT_TAG_COMMIT=$GIT_TAG_COMMIT" >> $GITHUB_ENV
29+
echo "GIT_MODIFIED=$(echo "$GIT_MODIFIED_1""$GIT_MODIFIED_2")" >> $GITHUB_ENV
30+
echo "GIT_REPO=$(git config --get remote.origin.url)" >> $GITHUB_ENV
31+
echo "BUILD_DATE=$(git log -1 --format="%at" | xargs -I{} date -d @{} +%Y-%m-%dT%H:%M:%S)" >> $GITHUB_ENV
32+
33+
- name: Docker meta
1934
id: meta
2035
uses: docker/metadata-action@v3
2136
with:
@@ -26,48 +41,49 @@ jobs:
2641
flavor: |
2742
latest=false
2843
29-
-
30-
name: Set up QEMU
44+
- name: Set up QEMU
3145
id: qemu
3246
uses: docker/setup-qemu-action@v1
3347
with:
3448
platforms: arm64,arm
3549

36-
-
37-
name: Set up Docker Buildx
50+
- name: Set up Docker Buildx
3851
id: buildx
52+
uses: docker/setup-buildx-action@v1
3953
with:
4054
install: true
41-
uses: docker/setup-buildx-action@v1
4255

43-
-
44-
name: Inspect builder
56+
- name: Inspect builder
4557
run: |
4658
echo "Name: ${{ steps.buildx.outputs.name }}"
4759
echo "Endpoint: ${{ steps.buildx.outputs.endpoint }}"
4860
echo "Status: ${{ steps.buildx.outputs.status }}"
4961
echo "Flags: ${{ steps.buildx.outputs.flags }}"
5062
echo "Platforms: ${{ steps.buildx.outputs.platforms }}"
5163
52-
-
53-
name: Login to quay.io Container Registry
64+
- name: Login to quay.io Container Registry
5465
uses: docker/login-action@v1
5566
with:
5667
registry: quay.io
5768
username: ${{ github.repository_owner }}+github
5869
password: ${{ secrets.BOT_QUAY_IO }}
5970

60-
-
61-
name: Build and push
71+
- name: Build and push
6272
id: build-release
6373
uses: docker/build-push-action@v2
6474
with:
6575
file: Dockerfile
6676
context: .
67-
platforms: linux/amd64,linux/arm64,linux/arm
77+
platforms: linux/amd64
6878
push: true
6979
tags: ${{ steps.meta.outputs.tags }}
80+
build-args: |
81+
GIT_HEAD_COMMIT=${{ env.GIT_HEAD_COMMIT }}
82+
GIT_TAG_COMMIT=${{ env.GIT_TAG_COMMIT }}
83+
GIT_REPO=${{ env.GIT_REPO }}
84+
GIT_LAST_TAG=${{ env.GIT_LAST_TAG }}
85+
GIT_MODIFIED=${{ env.GIT_MODIFIED }}
86+
BUILD_DATE=${{ env.BUILD_DATE }}
7087
71-
-
72-
name: Image digest
88+
- name: Image digest
7389
run: echo ${{ steps.build-release.outputs.digest }}

0 commit comments

Comments
 (0)