Skip to content

Commit

Permalink
implement /out, add log lines
Browse files Browse the repository at this point in the history
  • Loading branch information
vito committed Sep 21, 2018
1 parent 0b55a7c commit cc0d582
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 2 deletions.
6 changes: 6 additions & 0 deletions cmd/in/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ func main() {

dest := os.Args[1]

logrus.Printf("fetching version: %s", req.Version.Version)

versionFile := filepath.Join(dest, "version")
err = ioutil.WriteFile(versionFile, []byte(req.Version.Version+"\n"), os.ModePerm)
if err != nil {
Expand All @@ -58,6 +60,10 @@ func main() {
}

if req.Source.MirrorSelf || req.Params.MirrorSelfViaParams {
logrus.WithFields(logrus.Fields{
"via_params": req.Params.MirrorSelfViaParams,
}).Printf("mirroring self image")

replicateTo(filepath.Join(dest, "rootfs"))

encTo(filepath.Join(dest, "metadata.json"), ImageMetadata{
Expand Down
35 changes: 33 additions & 2 deletions cmd/out/main.go
Original file line number Diff line number Diff line change
@@ -1,17 +1,48 @@
package main

import (
"encoding/json"
"os"

resource "github.com/concourse/mirror-resource"
"github.com/sirupsen/logrus"
)

type OutRequest struct {
Source resource.Source `json:"source"`
Version resource.Version `json:"version"`
Params resource.PutParams `json:"params"`
}

type OutResponse struct {
Version resource.Version `json:"version"`
Metadata []resource.MetadataField `json:"metadata"`
}

func main() {
logrus.SetOutput(os.Stderr)
logrus.SetFormatter(&logrus.TextFormatter{
ForceColors: true,
})

logrus.Error("not implemented")
os.Exit(1)
var req OutRequest
err := json.NewDecoder(os.Stdin).Decode(&req)
if err != nil {
logrus.Errorf("invalid payload: %s", err)
os.Exit(1)
return
}

if len(os.Args) < 2 {
logrus.Errorf("source path not specified")
os.Exit(1)
return
}

logrus.Printf("pushing version: %s", req.Params.Version)

json.NewEncoder(os.Stdout).Encode(OutResponse{
Version: resource.Version{Version: req.Params.Version},
Metadata: []resource.MetadataField{},
})
}
5 changes: 5 additions & 0 deletions types.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,11 @@ type GetParams struct {
MirrorSelfViaParams bool `json:"mirror_self_via_params"`
}

type PutParams struct {
// version to "create"
Version string `json:"version"`
}

type MetadataField struct {
Name string `json:"name"`
Value string `json:"value"`
Expand Down

0 comments on commit cc0d582

Please sign in to comment.