Skip to content

Commit

Permalink
fix empty context bug
Browse files Browse the repository at this point in the history
  • Loading branch information
damoon committed May 25, 2021
1 parent bd9ca85 commit 9b9a86e
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 7 deletions.
3 changes: 3 additions & 0 deletions .tiltignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.git
tilt_modules
vendor
2 changes: 1 addition & 1 deletion cmd/d8s/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -333,7 +333,6 @@ func localServer(localAddr string) (int, error) {

func uploadContextHandlerFunc(proxy *httputil.ReverseProxy, localAddr string) http.HandlerFunc {
re := regexp.MustCompile(`^/[^/]+/build$`)
chunksList := bytes.Buffer{}

return func(w http.ResponseWriter, r *http.Request) {
if !re.MatchString(r.URL.Path) {
Expand All @@ -342,6 +341,7 @@ func uploadContextHandlerFunc(proxy *httputil.ReverseProxy, localAddr string) ht
}

chnker := chunker.New(r.Body, staticPol)
chunksList := bytes.Buffer{}

for {
c, err := chnker.Next(nil)
Expand Down
23 changes: 19 additions & 4 deletions pkg/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,16 @@ func (s Service) build(w http.ResponseWriter, r *http.Request) {
}
defer os.Remove(tempfile.Name())

err = s.restoreContext(ctx, r.Body, tempfile)
buf := new(bytes.Buffer)
_, err = buf.ReadFrom(r.Body)
if err != nil {
w.WriteHeader(http.StatusInternalServerError)
w.Write([]byte(fmt.Sprintf("read chunk list: %v", err)))
log.Printf("read chunk list: %v", err)
return
}

err = s.restoreContext(ctx, buf, tempfile)
if err != nil {
w.WriteHeader(http.StatusInternalServerError)
w.Write([]byte(fmt.Sprintf("restore context: %v", err)))
Expand All @@ -93,7 +102,7 @@ func (s Service) build(w http.ResponseWriter, r *http.Request) {
if err != nil {
w.WriteHeader(http.StatusInternalServerError)
w.Write([]byte(fmt.Sprintf("store context: %v", err)))
log.Printf("execute build: %v", err)
log.Printf("store context: %v", err)
return
}
defer func() {
Expand Down Expand Up @@ -367,7 +376,7 @@ unset x
echo download build context
cd ~ && mkdir context && cd context
wget -O - "%s" | tar -xf -
wget -O - "${CONTEXT_URL}" | tar -xf -
set -x
buildctl-daemonless.sh \
Expand All @@ -382,7 +391,7 @@ buildctl-daemonless.sh \
%s \
--export-cache=type=registry,ref=wedding-registry:5000/cache-repo,mode=max \
--import-cache=type=registry,ref=wedding-registry:5000/cache-repo
`, presignedContextURL, dockerfileDir, dockerfileName, buildargs, labels, target, destination)
`, dockerfileDir, dockerfileName, buildargs, labels, target, destination)

buildkitdMemory := 100 * 1024 * 1024

Expand All @@ -407,6 +416,12 @@ buildctl-daemonless.sh \
Name: "buildkitd-config",
},
},
Env: []corev1.EnvVar{
{
Name: "CONTEXT_URL",
Value: presignedContextURL,
},
},
Resources: corev1.ResourceRequirements{
Limits: corev1.ResourceList{
corev1.ResourceCPU: resource.MustParse(fmt.Sprintf("%dm", cfg.cpuMilliseconds)),
Expand Down
2 changes: 0 additions & 2 deletions pkg/chunks.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,6 @@ func (s Service) addChunk(w http.ResponseWriter, r *http.Request) {
hashHex := make([]byte, hex.EncodedLen(len(hash)))
hex.Encode(hashHex, hash)

log.Printf("calculated hash: %v", string(hashHex))

path := filepath.Join("chunks", string(hashHex))

_, err = s.objectStore.Uploader.UploadWithContext(r.Context(), &s3manager.UploadInput{
Expand Down

0 comments on commit 9b9a86e

Please sign in to comment.