forked from mark-kubacki/http.upload
-
Notifications
You must be signed in to change notification settings - Fork 0
/
cloudbuild.yaml
171 lines (153 loc) · 4.99 KB
/
cloudbuild.yaml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
timeout: 300s
options:
env:
- 'GOMODCACHE=/var/lib/go'
- 'GOCACHE=/var/cache/go'
- 'PROJECT_ID=${PROJECT_ID}'
- 'REPO_NAME=${REPO_NAME}'
volumes:
- name: 'GOMODCACHE'
path: '/var/lib/go'
- name: 'GOCACHE'
path: '/var/cache/go'
steps:
- name: 'gcr.io/cloud-builders/docker'
id: 'get golang'
waitFor: ['-']
entrypoint: 'bash'
args:
- -c
- |
set -ex
if ! docker tag golang:cloudbuild_cache localhost/golang:latest; then
docker pull mirror.gcr.io/library/golang:latest
docker tag {mirror.gcr.io/library,localhost}/golang:latest
fi
- name: 'localhost/golang'
id: 'gofmt'
entrypoint: 'bash'
args: ['-c', 'diff <(echo -n) <(gofmt -s -d $(find . -type f -name "*.go" -not -path "./_*"))']
# Usually you'd go about this differently, for instance in hooks:
# gofiles=$(git diff --cached --name-only --diff-filter=ACM "${origin}/master" | grep '\.go$')
# gofmt -l $gofiles
# These two don't use dependencies. If any fails we can skip downloads.
# Indeed, 'golint' has the bad habit of checking anything in vendor/, so it's better to run this now before any deps appear.
- name: 'gcr.io/blitznote/golang/ineffassign'
id: 'ineffassign'
waitFor: ['gofmt']
args: ['.']
- name: 'gcr.io/blitznote/golang/golint'
id: 'lint'
waitFor: ['gofmt']
- name: 'gcr.io/blitznote/cacheutil'
id: 'restore cached var-lib-go'
waitFor: ['gofmt', 'ineffassign', 'lint']
args: ['restore', '/var/lib/go']
- name: 'gcr.io/blitznote/cacheutil'
id: 'restore cached var-cache-go'
waitFor: ['gofmt', 'ineffassign', 'lint']
args: ['restore', '/var/cache/go']
# Now get any remaining dependencies of this plugin.
- &use_go
name: 'localhost/golang'
volumes:
- name: 'tmpfs'
path: '/tmp'
id: 'get dependencies'
entrypoint: 'go'
args: ['mod', 'download']
# Now come steps (in Gitlab this were one stage actually) common to most projects written in Golang.
- <<: *use_go
id: 'vet'
waitFor: ['get dependencies']
env: ['GOPROXY=off']
args: ['vet', './...']
- <<: *use_go
id: 'unittests'
waitFor: ['get dependencies']
env: ['GOPROXY=off']
args: ['test', '-v', './...']
- &build_go
<<: *use_go
waitFor: ['get dependencies', 'vet', 'unittests']
id: 'build linux amd64, Go current'
env: ['GOARCH=amd64', 'GOOS=linux', 'GOPROXY=off']
entrypoint: 'bash'
args:
- -c
- |
pwd;
find -name 'go.mod' -type f;
go env;
go version;
set -euo pipefail;
D="$(mktemp -d)"
<example.go sed \
-e '/build ignore/{N;d}' \
-e 's@"/"@"/web/path"@;s@:9000@:8000@' \
-e '/http.Handle/a\\thttp.Handle(scope+"/", uploadHandler)' \
>$$D/example.go;
cd $$D/;
printf 'module main\nrequire blitznote.com/src/http.upload/v5 v5.0.0\nreplace blitznote.com/src/http.upload/v5 => /workspace\n' >go.mod;
go build \
-ldflags "-s -w -buildid ''" \
-o /workspace/http.upload~$${GOARCH}_$${GOOS} \
example.go;
sed -i \
-e '/uploadHandler\./a\\tuploadHandler.RandomizedSuffixLength = 4' \
example.go;
go build \
-ldflags "-s -w -buildid ''" \
-o /workspace/http.upload.randsuffix4~$${GOARCH}_$${GOOS} \
example.go;
#- <<: *build_go
# id: 'build_windows_amd64'
# env: ['GOARCH=amd64', 'GOOS=windows']
- name: 'gcr.io/blitznote/cacheutil'
id: 'stash cached var-lib-go'
waitFor: ['get dependencies', 'unittests']
args: ['stash', '/var/lib/go']
- name: 'gcr.io/blitznote/cacheutil'
id: 'stash cached var-cache-go'
waitFor: ['build linux amd64, Go current']
args: ['stash', '/var/cache/go']
# Now come integration tests.
- name: 'gcr.io/cloud-builders/curl'
waitFor: ['build linux amd64, Go current']
id: 'integration test, example from doc'
volumes:
- name: 'tmpfs'
path: '/tmp'
entrypoint: 'bash'
args:
- -c
- |
export TMPDIR="$(mktemp -d)"
set -eux;
/workspace/http.upload~amd64_linux & sleep 0.2;
curl -sfS -T /etc/os-release http://localhost:8000/web/path/from-release && test -s $${TMPDIR}/from-release;
curl -sfS -F hostname=@/etc/hostname -F resolv.txt=@/etc/resolv.conf http://localhost:8000/web/path/;
cmp -b /etc/hostname $${TMPDIR}/hostname;
cmp -b /etc/resolv.conf $${TMPDIR}/resolv.conf;
curl -sfS -X MOVE -H "Destination: /web/path/to-release" http://localhost:8000/web/path/from-release && test -s $${TMPDIR}/to-release;
curl -sfS -vX DELETE http://localhost:8000/web/path/to-release;
curl -sfS -T /etc/os-release http://localhost:8000/web/path/subdir/os-release && test -s $${TMPDIR}/subdir/os-release;
kill %1
- name: 'gcr.io/cloud-builders/curl'
waitFor: ['build linux amd64, Go current']
id: 'integration test, image upload'
volumes:
- name: 'tmpfs'
path: '/tmp'
entrypoint: 'bash'
args:
- -c
- |
export TMPDIR="$(mktemp -d)"
set -eux;
/workspace/http.upload.randsuffix4~amd64_linux & sleep 0.2;
truncate --size $[ 1*1024*1024 ] image1.jpg;
curl -sfST image1.jpg http://localhost:8000/web/path/first-image.jpg;
ls -1 $${TMPDIR}/*.jpg;
test -s $${TMPDIR}/first-image_????.jpg;
kill %1