Skip to content

Commit 275ef40

Browse files
author
Matthew Fisher
committed
feat(pkg): add pkg time
This package is used to control how we utilize the time package across the Deis Platform, including application logs, component logs, API datetime structures, etc.
1 parent 13cabc0 commit 275ef40

9 files changed

Lines changed: 73 additions & 84 deletions

File tree

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ deisctl/makeself/
4141
docs/_build/
4242
docs/docs.zip
4343
logspout/build/
44+
logspout/image/logspout
4445
logspout/Godeps/
4546
publisher/Godeps/
4647
router/Godeps/

builder/Dockerfile

Lines changed: 0 additions & 19 deletions
This file was deleted.

builder/Makefile

Lines changed: 7 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -4,31 +4,19 @@ COMPONENT = builder
44
IMAGE = $(IMAGE_PREFIX)$(COMPONENT):$(BUILD_TAG)
55
DEV_IMAGE = $(DEV_REGISTRY)/$(IMAGE)
66
BUILD_IMAGE := $(COMPONENT)-build
7+
BINARIES := extract-domain extract-types extract-version generate-buildhook get-app-config get-app-values publish-release-controller yaml2json-procfile
78
BINARY_DEST_DIR := image/bin
89

910
build: check-docker
10-
cp -pR ../Godeps .
11-
docker build -t $(BUILD_IMAGE) .
12-
docker cp `docker create $(BUILD_IMAGE)`:/go/bin/extract-domain $(BINARY_DEST_DIR)/
13-
docker cp `docker create $(BUILD_IMAGE)`:/go/bin/extract-types $(BINARY_DEST_DIR)/
14-
docker cp `docker create $(BUILD_IMAGE)`:/go/bin/extract-version $(BINARY_DEST_DIR)/
15-
docker cp `docker create $(BUILD_IMAGE)`:/go/bin/generate-buildhook $(BINARY_DEST_DIR)/
16-
docker cp `docker create $(BUILD_IMAGE)`:/go/bin/get-app-config $(BINARY_DEST_DIR)/
17-
docker cp `docker create $(BUILD_IMAGE)`:/go/bin/get-app-values $(BINARY_DEST_DIR)/
18-
docker cp `docker create $(BUILD_IMAGE)`:/go/bin/publish-release-controller $(BINARY_DEST_DIR)/
19-
docker cp `docker create $(BUILD_IMAGE)`:/go/bin/yaml2json-procfile $(BINARY_DEST_DIR)/
11+
for i in $(BINARIES); do \
12+
GOOS=linux GOARCH=amd64 CGO_ENABLED=0 godep go build -a -v -ldflags '-s' -o $(BINARY_DEST_DIR)/$$i bin/$$i.go ; \
13+
done
2014
docker build -t $(IMAGE) image
2115

2216
clean: check-docker check-registry
23-
rm -rf Godeps
24-
rm -f $(BINARY_DEST_DIR)/extract-domain
25-
rm -f $(BINARY_DEST_DIR)/extract-types
26-
rm -f $(BINARY_DEST_DIR)/extract-version
27-
rm -f $(BINARY_DEST_DIR)/generate-buildhook
28-
rm -f $(BINARY_DEST_DIR)/get-app-config
29-
rm -f $(BINARY_DEST_DIR)/get-app-values
30-
rm -f $(BINARY_DEST_DIR)/publish-release-controller
31-
rm -f $(BINARY_DEST_DIR)/yaml2json-procfile
17+
for i in $(BINARIES); do \
18+
rm -rf $(BINARY_DEST_DIR)/$$i ; \
19+
done
3220
docker rmi $(IMAGE)
3321

3422
full-clean: check-docker check-registry clean

builder/types.go

Lines changed: 3 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,7 @@
11
package builder
22

33
import (
4-
"time"
5-
)
6-
7-
const (
8-
DEIS_DATETIME string = "2006-01-02T15:04:05MST"
4+
"github.com/deis/deis/pkg/time"
95
)
106

117
// ProcessType represents the key/value mappings of a process type to a process inside
@@ -45,38 +41,6 @@ type Config struct {
4541
CPU map[string]int `json:"cpu"`
4642
Tags map[string]string `json:"tags"`
4743
UUID string `json:"uuid"`
48-
Created DeisTime `json:"created"`
49-
Updated DeisTime `json:"updated"`
50-
}
51-
52-
// DeisTime represents the standard datetime format used across the platform.
53-
type DeisTime struct {
54-
time.Time
55-
}
56-
57-
func (t *DeisTime) format() string {
58-
return t.Time.Format(DEIS_DATETIME)
59-
}
60-
61-
// MarshalJSON implements the json.Marshaler interface.
62-
// The time is a quoted string in Deis' datetime format.
63-
func (t *DeisTime) MarshalJSON() ([]byte, error) {
64-
return []byte(t.Time.Format(`"` + DEIS_DATETIME + `"`)), nil
65-
}
66-
67-
// UnmarshalText implements the encoding.TextUnmarshaler interface.
68-
// The time is expected to be in Deis' datetime format.
69-
func (t *DeisTime) UnmarshalText(data []byte) (err error) {
70-
tt, err := time.Parse(DEIS_DATETIME, string(data))
71-
*t = DeisTime{tt}
72-
return
73-
}
74-
75-
// UnmarshalJSON implements the json.Unmarshaler interface.
76-
// The time is expected to be a quoted string in Deis' datetime format.
77-
func (t *DeisTime) UnmarshalJSON(data []byte) (err error) {
78-
// Fractional seconds are handled implicitly by Parse.
79-
tt, err := time.Parse(`"`+DEIS_DATETIME+`"`, string(data))
80-
*t = DeisTime{tt}
81-
return
44+
Created time.Time `json:"created"`
45+
Updated time.Time `json:"updated"`
8246
}

builder/utils_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
"strings"
88
"testing"
99
"time"
10+
dtime "github.com/deis/deis/pkg/time"
1011
)
1112

1213
type ClosingBuffer struct {
@@ -167,7 +168,7 @@ func TestParseControllerConfigGood(t *testing.T) {
167168
}
168169

169170
func TestTimeSerialize(t *testing.T) {
170-
time, err := json.Marshal(&DeisTime{time.Now().UTC()})
171+
time, err := json.Marshal(&dtime.Time{time.Now().UTC()})
171172

172173
if err != nil {
173174
t.Errorf("expected to be able to serialize time as json, got '%v'", err)

docs/contributing/hacking.rst

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,25 @@ Prerequisites
1919
You can develop on any supported platform including your laptop, cloud providers or
2020
on bare metal. We strongly recommend a minimum 3-node cluster.
2121

22+
Deis is written in both python and Go, so you will need to install both Python 2.7 and
23+
the latest version of Go.
24+
25+
If your local workstation does not support the linux/amd64 target environment, you will
26+
have to install Go from source with cross-compile support for that environment. This is
27+
because some of the components are built on your local machine and then injected into a
28+
docker container. To do that, run
29+
30+
.. code-block:: console
31+
32+
$ sudo su
33+
$ curl -sSL https://golang.org/dl/go1.4.src.tar.gz | tar -v -C /usr/local -xz
34+
$ cd /usr/local/go/src
35+
$ # compile Go for our default platform first, then add cross-compile support
36+
$ ./make.bash --no-clean
37+
$ GOOS=linux GOARCH=amd64 ./make.bash --no-clean
38+
39+
After that, you should be able to compile Deis' components as normal.
40+
2241
The development workflow requires a Docker Registry that is accessible to you
2342
(the developer) and to all of the hosts in your cluster.
2443

logspout/Makefile

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,11 @@ RELEASE_IMAGE := $(DOCKER_IMAGE):$(BUILD_TAG)
77
DEV_DOCKER_IMAGE := $(DEV_REGISTRY)/$(RELEASE_IMAGE)
88

99
build: check-docker
10-
cp -pR ../Godeps .
11-
docker build -t $(BUILD_IMAGE) .
12-
docker cp `docker run -d $(BUILD_IMAGE)`:/go/bin/logspout image/
10+
GOOS=linux GOARCH=amd64 CGO_ENABLED=0 godep go build -a -v -ldflags '-s' -o image/logspout
1311
docker build -t $(RELEASE_IMAGE) image
14-
rm -rf image/logspout
1512

1613
clean: check-docker check-registry
17-
rm -rf Godeps
14+
rm -rf image/logspout
1815
docker rmi $(RELEASE_IMAGE) $(BUILD_IMAGE)
1916

2017
full-clean: check-docker check-registry

logspout/logspout.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import (
1111
"strconv"
1212
"strings"
1313
"time"
14+
dtime "github.com/deis/deis/pkg/time"
1415

1516
"code.google.com/p/go.net/websocket"
1617
"github.com/coreos/go-etcd/etcd"
@@ -72,7 +73,7 @@ func syslogStreamer(target Target, types []string, logstream chan *Log) {
7273
// HACK: Go's syslog package hardcodes the log format, so let's send our own message
7374
_, err = fmt.Fprintf(conn,
7475
"%s %s[%s]: %s",
75-
time.Now().Format("2006-01-02T15:04:05MST"),
76+
time.Now().Format(dtime.DEIS_DATETIME_FORMAT),
7677
tag,
7778
pid,
7879
logline.Data)

pkg/time/time.go

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
package time
2+
3+
import "time"
4+
5+
const DEIS_DATETIME_FORMAT string = "2006-01-02T15:04:05MST"
6+
7+
// Time represents the standard datetime format used across the Deis Platform.
8+
type Time struct {
9+
time.Time
10+
}
11+
12+
func (t *Time) format() string {
13+
return t.Time.Format(DEIS_DATETIME_FORMAT)
14+
}
15+
16+
// MarshalJSON implements the json.Marshaler interface.
17+
// The time is a quoted string in Deis' datetime format.
18+
func (t *Time) MarshalJSON() ([]byte, error) {
19+
return []byte(t.Time.Format(`"` + DEIS_DATETIME_FORMAT + `"`)), nil
20+
}
21+
22+
// UnmarshalText implements the encoding.TextUnmarshaler interface.
23+
// The time is expected to be in Deis' datetime format.
24+
func (t *Time) UnmarshalText(data []byte) (err error) {
25+
tt, err := time.Parse(DEIS_DATETIME_FORMAT, string(data))
26+
*t = Time{tt}
27+
return
28+
}
29+
30+
// UnmarshalJSON implements the json.Unmarshaler interface.
31+
// The time is expected to be a quoted string in Deis' datetime format.
32+
func (t *Time) UnmarshalJSON(data []byte) (err error) {
33+
// Fractional seconds are handled implicitly by Parse.
34+
tt, err := time.Parse(`"`+DEIS_DATETIME_FORMAT+`"`, string(data))
35+
*t = Time{tt}
36+
return
37+
}

0 commit comments

Comments
 (0)