Skip to content

Commit d460532

Browse files
committed
feat: read built timestamp from git
1 parent 097ebfa commit d460532

3 files changed

Lines changed: 29 additions & 16 deletions

File tree

Dockerfile

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@
66
FROM docker.io/library/bash:5.2.37@sha256:01a15c6f48f6a3c08431cd77e11567823530b18159889dca3b7309b707beef91
77
SHELL ["/usr/local/bin/bash", "-u", "-e", "-o", "pipefail", "-c"]
88

9+
# workaround until we have a env `CI_COMMIT_TIMESTAMP`
10+
# see https://github.com/woodpecker-ci/woodpecker/issues/5245
11+
RUN apk add git~=2 --no-cache
12+
913
RUN ARCH=$(uname -m) && \
1014
[[ $ARCH == x86_64 ]] && export SUFFIX=amd64; \
1115
[[ $ARCH == aarch64 ]] && export SUFFIX=arm64; \

README.md

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -72,21 +72,21 @@ docker run --rm --user=$(id -u) --volume=$HOME:$HOME:ro --workdir=$PWD --env=PLU
7272

7373
## Settings
7474

75-
| Settings Name | Environment | Default | Description |
76-
| ------------------- | ------------------------ | ---------------- | ----------------------------------------------------------------------------------------------- |
77-
| `addr` | PLUGIN_ADDR | `$BUILDKIT_HOST` | Buildkit host to use. |
78-
| `frontend` | PLUGIN_FRONTEND | `dockerfile.v0` | Only dockerfile frontend supported right now |
79-
| `context` | PLUGIN_CONTEXT | `$PWD` | Context directory to use for build |
80-
| `dockerfile` | PLUGIN_DOCKERFILE | `Dockerfile` | Dockerfile to use. |
81-
| `target` | PLUGIN_TARGET | `none` | Dockerfile target |
82-
| `build-args` | PLUGIN_BUILD_ARGS | `none` | Build args to pass to build |
83-
| `platform` | PLUGIN_PLATFORM | `none` | Target platform for container image. |
84-
| `source-epoch-date` | PLUGIN_SOURCE_DATE_EPOCH | `0` | Timestamp to use for reproduceable builds. |
85-
| `name` | PLUGIN_NAME | `none` | Images names where to push the image. |
86-
| `annotation` | PLUGIN_ANNOTATION | `none` | Annotations (also known as labels) to add to image |
87-
| `push` | PLUGIN_PUSH | `true` | Push images if output names are set. |
88-
| `auth` | PLUGIN_AUTH | `none` | Auth for private registries |
89-
| `env-file` | PLUGIN_ENV_FILE | `none` | Source environment values from given file |
75+
| Settings Name | Environment | Default | Description |
76+
| ------------------- | ------------------------ | --------------------------- | -------------------------------------------------- |
77+
| `addr` | PLUGIN_ADDR | `$BUILDKIT_HOST` | Buildkit host to use. |
78+
| `frontend` | PLUGIN_FRONTEND | `dockerfile.v0` | Only dockerfile frontend supported right now |
79+
| `context` | PLUGIN_CONTEXT | `$PWD` | Context directory to use for build |
80+
| `dockerfile` | PLUGIN_DOCKERFILE | `Dockerfile` | Dockerfile to use. |
81+
| `target` | PLUGIN_TARGET | `none` | Dockerfile target |
82+
| `build-args` | PLUGIN_BUILD_ARGS | `none` | Build args to pass to build |
83+
| `platform` | PLUGIN_PLATFORM | `none` | Target platform for container image. |
84+
| `source-epoch-date` | PLUGIN_SOURCE_DATE_EPOCH | `git log -1 --format="%at"` | Timestamp to use for reproduceable builds. |
85+
| `name` | PLUGIN_NAME | `none` | Images names where to push the image. |
86+
| `annotation` | PLUGIN_ANNOTATION | `none` | Annotations (also known as labels) to add to image |
87+
| `push` | PLUGIN_PUSH | `true` | Push images if output names are set. |
88+
| `auth` | PLUGIN_AUTH | `none` | Auth for private registries |
89+
| `env-file` | PLUGIN_ENV_FILE | `none` | Source environment values from given file |
9090

9191
## Alternatives
9292

entrypoint.sh

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,15 @@
11
#!/usr/bin/env bash
22
set -eu;
33

4+
##
5+
## workaround until we have a env `CI_COMMIT_TIMESTAMP`
6+
## see https://github.com/woodpecker-ci/woodpecker/issues/5245
7+
##
8+
9+
if [[ -z "${CI_COMMIT_TIMESTAMP:-}" ]]; then
10+
CI_COMMIT_TIMESTAMP=$(git log -1 --format="%at")
11+
fi
12+
413
##
514
## check input
615
##
@@ -27,7 +36,7 @@ if [[ "$BUILDCTL_FRONTEND" != "dockerfile.v0" ]]; then
2736
exit 1
2837
fi
2938

30-
SOURCE_DATE_EPOCH=${PLUGIN_SOURCE_DATE_EPOCH:-0}
39+
SOURCE_DATE_EPOCH=${PLUGIN_SOURCE_DATE_EPOCH:-${CI_COMMIT_TIMESTAMP:-0}}
3140

3241
if [[ -n "${PLUGIN_AUTH:-}" ]]; then
3342
echo "$PLUGIN_AUTH" | jq -r 'to_entries|map({(.key):{"auth":(.value.username+":"+.value.password)|@base64}})|add|{"auths":.}' > "$HOME/.docker/config.json"

0 commit comments

Comments
 (0)