Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 34 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,40 @@ 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
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. **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**.
* 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)
for older Concourse versions).

```
fly -t <your target> \
check-resource <your 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

Expand Down
3 changes: 3 additions & 0 deletions check_command.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
8 changes: 4 additions & 4 deletions dockerfiles/ubuntu/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
ARG base_image
ARG base_image=ubuntu:latest
ARG builder_image=concourse/golang-builder

FROM ${builder_image} AS builder
Expand All @@ -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
11 changes: 6 additions & 5 deletions models/models.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down