From de27a85eb999f8daab422223b37acef1cc827fca Mon Sep 17 00:00:00 2001 From: Liam Stanley Date: Sat, 12 Feb 2022 22:40:34 -0500 Subject: [PATCH 1/4] add support for 'initial_version' field Signed-off-by: Liam Stanley --- README.md | 32 ++++++++++++++++++++++++++++++++ check_command.go | 3 +++ models/models.go | 11 ++++++----- 3 files changed, 41 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index cdab019..53bb0a7 100644 --- a/README.md +++ b/README.md @@ -65,6 +65,38 @@ level of precision is better left to other tools. These can be combined to emit a new version on an interval during a particular time period. +* `initial_version`: *Optional.* When using `start` and `stop` as a trigger for + a job, you will be unable to run the job manually until it goes into the + configured time range for the first time (manual runs will work once the `time` + resource has produced it's first version). + + To get around this issue, there are two approaches. + * Use `initial_version: true`, which will produce a new version that is + set to the current time, if `check` runs and there isn't already a version + specified. This has a downside that if used with `trigger: true`, it will + kick off the correlating job when the pipeline is first created, even + outside of the specified window. + * Once you push a pipeline that utilizes `start` and `stop`, run the + following fly command to run the resource check from a previous point + in time (see [this issue](https://github.com/concourse/time-resource/issues/24#issuecomment-689422764) + for 6.x.x+ or [this issue](https://github.com/concourse/time-resource/issues/11#issuecomment-562385742) + for older Concourse versions). + + ``` + fly -t \ + check-resource + --from "time:2000-01-01T00:00:00Z" # the important part + ``` + + This has the benefit that it shouldn't trigger that initial job run, but + will still allow you to manually run the job if needed. + + e.g. + + ``` + initial_version: true + ``` + ## Behavior ### `check`: Produce timestamps satisfying the interval. diff --git a/check_command.go b/check_command.go index afdee69..0e0d34f 100644 --- a/check_command.go +++ b/check_command.go @@ -37,6 +37,9 @@ func (*CheckCommand) Run(request models.CheckRequest) ([]models.Version, error) if !previousTime.IsZero() { versions = append(versions, models.Version{Time: previousTime}) + } else if request.Source.InitialVersion { + versions = append(versions, models.Version{Time: currentTime}) + return versions, nil } if tl.Check(currentTime) { diff --git a/models/models.go b/models/models.go index 6a97694..ab85658 100644 --- a/models/models.go +++ b/models/models.go @@ -39,11 +39,12 @@ type CheckRequest struct { type CheckResponse []Version type Source struct { - Interval *Interval `json:"interval"` - Start *TimeOfDay `json:"start"` - Stop *TimeOfDay `json:"stop"` - Days []Weekday `json:"days"` - Location *Location `json:"location"` + InitialVersion bool `json:"initial_version"` + Interval *Interval `json:"interval"` + Start *TimeOfDay `json:"start"` + Stop *TimeOfDay `json:"stop"` + Days []Weekday `json:"days"` + Location *Location `json:"location"` } func (source Source) Validate() error { From 409240ee67808d65c07ff4676409574e39283d6f Mon Sep 17 00:00:00 2001 From: Liam Stanley Date: Sat, 12 Feb 2022 22:41:31 -0500 Subject: [PATCH 2/4] add default base_image arg for ubuntu, to match alpine Dockerfile Signed-off-by: Liam Stanley --- dockerfiles/ubuntu/Dockerfile | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/dockerfiles/ubuntu/Dockerfile b/dockerfiles/ubuntu/Dockerfile index 427e281..1592083 100644 --- a/dockerfiles/ubuntu/Dockerfile +++ b/dockerfiles/ubuntu/Dockerfile @@ -1,4 +1,4 @@ -ARG base_image +ARG base_image=ubuntu:latest ARG builder_image=concourse/golang-builder FROM ${builder_image} AS builder @@ -12,19 +12,19 @@ RUN go build -o /assets/out github.com/concourse/time-resource/out RUN go build -o /assets/in github.com/concourse/time-resource/in RUN go build -o /assets/check github.com/concourse/time-resource/check RUN set -e; for pkg in $(go list ./...); do \ - go test -o "/tests/$(basename $pkg).test" -c $pkg; \ + go test -o "/tests/$(basename $pkg).test" -c $pkg; \ done FROM ${base_image} AS resource RUN apt update && apt upgrade -y -o Dpkg::Options::="--force-confdef" RUN apt update && apt install -y --no-install-recommends tzdata \ - && rm -rf /var/lib/apt/lists/* + && rm -rf /var/lib/apt/lists/* COPY --from=builder /assets /opt/resource FROM resource AS tests COPY --from=builder /tests /tests RUN set -e; for test in /tests/*.test; do \ - $test; \ + $test; \ done FROM resource From 10158617c158cf6681937a63caaf9a36a10144bd Mon Sep 17 00:00:00 2001 From: Liam Stanley Date: Sat, 12 Feb 2022 22:42:45 -0500 Subject: [PATCH 3/4] fix indentation Signed-off-by: Liam Stanley --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 53bb0a7..f2414eb 100644 --- a/README.md +++ b/README.md @@ -62,8 +62,8 @@ level of precision is better left to other tools. days: [Monday, Wednesday] ``` -These can be combined to emit a new version on an interval during a particular -time period. + These can be combined to emit a new version on an interval during a particular + time period. * `initial_version`: *Optional.* When using `start` and `stop` as a trigger for a job, you will be unable to run the job manually until it goes into the From d3cecb58c5b533fbfd0085e9c358f71cd9ce03c6 Mon Sep 17 00:00:00 2001 From: Liam Stanley Date: Sat, 12 Feb 2022 22:57:39 -0500 Subject: [PATCH 4/4] initial_version: make some of the docs a bit clearer Signed-off-by: Liam Stanley --- README.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index f2414eb..96ce479 100644 --- a/README.md +++ b/README.md @@ -70,13 +70,13 @@ level of precision is better left to other tools. configured time range for the first time (manual runs will work once the `time` resource has produced it's first version). - To get around this issue, there are two approaches. + To get around this issue, there are two approaches: * Use `initial_version: true`, which will produce a new version that is set to the current time, if `check` runs and there isn't already a version - specified. This has a downside that if used with `trigger: true`, it will + specified. **NOTE: This has a downside that if used with `trigger: true`, it will kick off the correlating job when the pipeline is first created, even - outside of the specified window. - * Once you push a pipeline that utilizes `start` and `stop`, run the + outside of the specified window**. + * Alternatively, once you push a pipeline that utilizes `start` and `stop`, run the following fly command to run the resource check from a previous point in time (see [this issue](https://github.com/concourse/time-resource/issues/24#issuecomment-689422764) for 6.x.x+ or [this issue](https://github.com/concourse/time-resource/issues/11#issuecomment-562385742)