From 3263d008fe97e847cdfa479f4fce1d5694122eb5 Mon Sep 17 00:00:00 2001 From: Luke Carr Date: Thu, 7 Apr 2022 14:04:03 +0000 Subject: [PATCH] =?UTF-8?q?=F0=9F=91=B7=20Populated=20footer=20build=20inf?= =?UTF-8?q?o=20in=20Docker=20images?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Closes #14 --- .github/workflows/nightly.yml | 8 ++++++++ .github/workflows/release.yml | 8 ++++++++ Dockerfile | 5 ++++- frontend/src/components/Footer.tsx | 8 ++++---- 4 files changed, 24 insertions(+), 5 deletions(-) diff --git a/.github/workflows/nightly.yml b/.github/workflows/nightly.yml index ac8c6a8..efa0cb9 100644 --- a/.github/workflows/nightly.yml +++ b/.github/workflows/nightly.yml @@ -26,9 +26,17 @@ jobs: username: ${{ github.actor }} password: ${{ secrets.GITHUB_TOKEN }} + - name: Generate build date + id: build_date_gen + run: echo ::set-output name=build_date::$(date --iso-8601=minutes) + - name: Build and push image uses: docker/build-push-action@v2 with: context: . push: true + build-args: | + BUILD_DATE:${{ steps.build_date_gen.outputs.build_date }} + BUILD_COMMIT:${{ github.sha }} + BUILD_VERSION:nightly labels: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:nightly diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 261c25d..6619a7f 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -72,10 +72,18 @@ jobs: with: images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} + - name: Generate build date + id: build_date_gen + run: echo ::set-output name=build_date::$(date --iso-8601=minutes) + - name: Build and push image uses: docker/build-push-action@v2 with: context: . push: true + build-args: | + BUILD_DATE:${{ steps.build_date_gen.outputs.build_date }} + BUILD_COMMIT:${{ github.sha }} + BUILD_VERSION:${{ github.ref_name }} tags: ${{ steps.meta.outputs.tags }} labels: ${{ steps.meta.outputs.labels }} diff --git a/Dockerfile b/Dockerfile index 1ce841f..aed11be 100644 --- a/Dockerfile +++ b/Dockerfile @@ -37,7 +37,10 @@ COPY --from=node-builder /build/dist ./frontend/dist/ ENV CGO_ENABLED=0 ENV GOOS=linux ENV GOARCH=amd64 -RUN go build -ldflags='-w -s -extldflags "-static"' -a -o /usr/bin/tiny-todo main.go +ARG BUILD_VERSION +ARG BUILD_COMMIT +ARG BUILD_DATE +RUN go build -ldflags="-w -s -extldflags '-static' -X github.com/lukecarr/tiny-todo/internal/info.Version=${BUILD_VERSION} -X github.com/lukecarr/tiny-todo/internal/info.Commit=${BUILD_COMMIT} -X github.com/lukecarr/tiny-todo/internal/info.Date=${BUILD_DATE}" -a -o /usr/bin/tiny-todo main.go FROM scratch diff --git a/frontend/src/components/Footer.tsx b/frontend/src/components/Footer.tsx index 3a37608..42567a3 100644 --- a/frontend/src/components/Footer.tsx +++ b/frontend/src/components/Footer.tsx @@ -15,12 +15,12 @@ const BuildInfo: FunctionalComponent = () => { return
{data.version &&

- {data.version} + + {data.version} + {data.commit && {' '}({data.commit.slice(0, 7)})} +

}

Built at: {data.date}

- {data.commit &&

- {data.commit.slice(0, 7)} -

}
}