Adding a push tags function for docker.
This commit is contained in:
@@ -8,7 +8,7 @@ import (
|
|||||||
var (
|
var (
|
||||||
commands = &cmds.Command{
|
commands = &cmds.Command{
|
||||||
Name: "indra",
|
Name: "indra",
|
||||||
Description: "The indra network daemon.",
|
Description: "Network Freedom.",
|
||||||
Documentation: lorem,
|
Documentation: lorem,
|
||||||
Entrypoint: defaultHandler,
|
Entrypoint: defaultHandler,
|
||||||
Default: cmds.Tags("help"),
|
Default: cmds.Tags("help"),
|
||||||
|
|||||||
@@ -5,10 +5,11 @@ import (
|
|||||||
"github.com/Indra-Labs/indra"
|
"github.com/Indra-Labs/indra"
|
||||||
"github.com/Indra-Labs/indra/pkg/server"
|
"github.com/Indra-Labs/indra/pkg/server"
|
||||||
"github.com/cybriq/proc/pkg/cmds"
|
"github.com/cybriq/proc/pkg/cmds"
|
||||||
|
log2 "github.com/cybriq/proc/pkg/log"
|
||||||
)
|
)
|
||||||
|
|
||||||
var defaultHandler = func(c *cmds.Command, args []string) error {
|
var defaultHandler = func(c *cmds.Command, args []string) error {
|
||||||
fmt.Println("indra.")
|
fmt.Println("indra")
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -19,15 +20,13 @@ var versionHandler = func(c *cmds.Command, args []string) error {
|
|||||||
|
|
||||||
var serveHandler = func(c *cmds.Command, args []string) error {
|
var serveHandler = func(c *cmds.Command, args []string) error {
|
||||||
|
|
||||||
log.I.Ln("-- “Far away in the heavenly abode of the great god indra, there is a wonderful net which has been hung by some cunning artificer in such a manner that it stretches out indefinitely in all directions.”")
|
log.I.Ln("-- ", log2.App, "-" , indra.SemVer, "- Nobody's watching you. Network Freedom. --")
|
||||||
log.I.Ln("-- “In accordance with the extravagant tastes of deities, the artificer has hung a single glittering jewel at the net’s every node, and since the net itself is infinite in dimension, the jewels are infinite in number. There hang the jewels, glittering like stars of the first magnitude, a wonderful sight to behold.”")
|
|
||||||
log.I.Ln("-- “If we now arbitrarily select one of these jewels for inspection and look closely at it, we will discover that in its polished surface there are reflected all the other jewels in the net, infinite in number. Not only that, but each of the jewels reflected in this one jewel is also reflecting all the other jewels, so that the process of reflection is infinite.”")
|
|
||||||
|
|
||||||
log.I.Ln("running serve.")
|
|
||||||
|
|
||||||
var err error
|
var err error
|
||||||
var srv *server.Server
|
var srv *server.Server
|
||||||
|
|
||||||
|
log.I.Ln("running serve.")
|
||||||
|
|
||||||
if srv, err = server.New(server.DefaultServerConfig); check(err) {
|
if srv, err = server.New(server.DefaultServerConfig); check(err) {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@@ -38,6 +37,8 @@ var serveHandler = func(c *cmds.Command, args []string) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
log.I.Ln("-- fin --")
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -16,19 +16,18 @@ func main() {
|
|||||||
|
|
||||||
log2.App = "indra"
|
log2.App = "indra"
|
||||||
|
|
||||||
log.I.Ln("-- indra -", indra.SemVer, "- the indra network tool --")
|
|
||||||
|
|
||||||
var err error
|
var err error
|
||||||
var application *app.App
|
var application *app.App
|
||||||
|
|
||||||
|
// Creates a new application
|
||||||
if application, err = app.New(commands, os.Args); check(err) {
|
if application, err = app.New(commands, os.Args); check(err) {
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Launches a new application
|
||||||
if err = application.Launch(); check(err) {
|
if err = application.Launch(); check(err) {
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
|
|
||||||
log.I.Ln("-- fin --")
|
|
||||||
os.Exit(0)
|
os.Exit(0)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,10 +1,12 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"context"
|
||||||
"github.com/Indra-Labs/indra"
|
"github.com/Indra-Labs/indra"
|
||||||
log2 "github.com/cybriq/proc/pkg/log"
|
log2 "github.com/cybriq/proc/pkg/log"
|
||||||
"github.com/docker/docker/client"
|
"github.com/docker/docker/client"
|
||||||
"os"
|
"os"
|
||||||
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
@@ -38,7 +40,13 @@ func main() {
|
|||||||
|
|
||||||
defer cli.Close()
|
defer cli.Close()
|
||||||
|
|
||||||
build_image(cli)
|
// Set a Timeout for 120 seconds
|
||||||
|
ctx, cancel := context.WithTimeout(context.Background(), time.Second * 120)
|
||||||
|
|
||||||
|
defer cancel()
|
||||||
|
|
||||||
|
//build_image(ctx, cli)
|
||||||
|
push_tags(ctx, cli)
|
||||||
|
|
||||||
/*reader, err := cli.ImagePull(ctx, "docker.io/library/alpine", types.ImagePullOptions{})
|
/*reader, err := cli.ImagePull(ctx, "docker.io/library/alpine", types.ImagePullOptions{})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
@@ -1,23 +1,30 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"bytes"
|
||||||
"context"
|
"context"
|
||||||
|
"encoding/base64"
|
||||||
|
"encoding/json"
|
||||||
"github.com/Indra-Labs/indra"
|
"github.com/Indra-Labs/indra"
|
||||||
"github.com/docker/docker/api/types"
|
"github.com/docker/docker/api/types"
|
||||||
"github.com/docker/docker/api/types/filters"
|
"github.com/docker/docker/api/types/filters"
|
||||||
"github.com/docker/docker/client"
|
"github.com/docker/docker/client"
|
||||||
|
"github.com/docker/cli/cli/config/configfile"
|
||||||
"github.com/docker/docker/pkg/archive"
|
"github.com/docker/docker/pkg/archive"
|
||||||
"github.com/docker/docker/pkg/jsonmessage"
|
"github.com/docker/docker/pkg/jsonmessage"
|
||||||
"github.com/moby/term"
|
"github.com/moby/term"
|
||||||
"io"
|
"io"
|
||||||
|
"io/ioutil"
|
||||||
"os"
|
"os"
|
||||||
"time"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
buildContextFilePath = "/tmp/indra-build.tar"
|
buildContextFilePath = "/tmp/indra-build.tar"
|
||||||
buildOpts = types.ImageBuildOptions{
|
buildOpts = types.ImageBuildOptions{
|
||||||
Tags: []string{"indra-labs/indra:" + indra.SemVer},
|
Tags: []string{
|
||||||
|
"indralabs/indra:" + indra.SemVer,
|
||||||
|
"indralabs/indra:latest",
|
||||||
|
},
|
||||||
Dockerfile: "docker/indra/Dockerfile",
|
Dockerfile: "docker/indra/Dockerfile",
|
||||||
SuppressOutput: false,
|
SuppressOutput: false,
|
||||||
Remove: true,
|
Remove: true,
|
||||||
@@ -26,39 +33,105 @@ var (
|
|||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
func build_image(cli *client.Client) (err error) {
|
func build_image(ctx context.Context, cli *client.Client) (err error) {
|
||||||
|
|
||||||
log.I.Ln("Building", buildOpts.Tags[0], "from", buildOpts.Dockerfile)
|
log.I.Ln("building", buildOpts.Tags[0], "from", buildOpts.Dockerfile)
|
||||||
|
|
||||||
ctx, cancel := context.WithTimeout(context.Background(), time.Second * 120)
|
|
||||||
defer cancel()
|
|
||||||
|
|
||||||
|
// Generate a tar file for docker's build context. It will contain the root of the repository's path.
|
||||||
|
// A tar file is passed in to the docker daemon.
|
||||||
var tar io.ReadCloser
|
var tar io.ReadCloser
|
||||||
|
|
||||||
if tar, err = archive.TarWithOptions(".", &archive.TarOptions{}); check(err) {
|
if tar, err = archive.TarWithOptions(".", &archive.TarOptions{}); check(err) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
defer tar.Close()
|
defer tar.Close()
|
||||||
|
|
||||||
// Here build the actual docker image
|
log.I.Ln("submitting build to docker...")
|
||||||
var response types.ImageBuildResponse
|
|
||||||
|
|
||||||
|
// Submit a build to docker; with the context tar, and default options defined above.
|
||||||
|
var response types.ImageBuildResponse
|
||||||
if response, err = cli.ImageBuild(ctx, tar, buildOpts); check(err) {
|
if response, err = cli.ImageBuild(ctx, tar, buildOpts); check(err) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
defer response.Body.Close()
|
defer response.Body.Close()
|
||||||
|
|
||||||
|
// Generate a terminal for output
|
||||||
termFd, isTerm := term.GetFdInfo(os.Stderr)
|
termFd, isTerm := term.GetFdInfo(os.Stderr)
|
||||||
|
|
||||||
if err = jsonmessage.DisplayJSONMessagesStream(response.Body, os.Stderr, termFd, isTerm, nil); check(err) {
|
if err = jsonmessage.DisplayJSONMessagesStream(response.Body, os.Stderr, termFd, isTerm, nil); check(err) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
log.I.Ln("pruning build container(s)...")
|
||||||
|
|
||||||
|
// Prune the intermediate golang:x.xx builder container
|
||||||
if _, err = cli.ImagesPrune(ctx, filters.NewArgs()); check(err) {
|
if _, err = cli.ImagesPrune(ctx, filters.NewArgs()); check(err) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
log.I.Ln("pruning successful.")
|
||||||
|
log.I.Ln("build successful!")
|
||||||
|
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
var (
|
||||||
|
push_opts = types.ImagePushOptions{}
|
||||||
|
)
|
||||||
|
|
||||||
|
func push_tags(ctx context.Context, cli *client.Client) (err error) {
|
||||||
|
|
||||||
|
log.I.Ln("pushing tagged images to repository...")
|
||||||
|
|
||||||
|
var file []byte
|
||||||
|
if file, err = ioutil.ReadFile(os.Getenv("INDRA_DOCKER_CONFIG")); check(err) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
config := configfile.New("config.json")
|
||||||
|
config.LoadFromReader(bytes.NewReader(file))
|
||||||
|
|
||||||
|
// Generate a terminal for output
|
||||||
|
termFd, isTerm := term.GetFdInfo(os.Stderr)
|
||||||
|
|
||||||
|
var pushResponse io.ReadCloser
|
||||||
|
|
||||||
|
for _, auth := range config.AuthConfigs {
|
||||||
|
|
||||||
|
log.I.Ln("found", auth.ServerAddress)
|
||||||
|
|
||||||
|
authConfigBytes, _ := json.Marshal(auth)
|
||||||
|
authConfigEncoded := base64.URLEncoding.EncodeToString(authConfigBytes)
|
||||||
|
|
||||||
|
push_opts.RegistryAuth = authConfigEncoded
|
||||||
|
|
||||||
|
for _, tag := range buildOpts.Tags {
|
||||||
|
|
||||||
|
log.I.Ln("pushing", tag)
|
||||||
|
|
||||||
|
if pushResponse, err = cli.ImagePush(ctx, tag, push_opts); check(err) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if err = jsonmessage.DisplayJSONMessagesStream(pushResponse, os.Stderr, termFd, isTerm, nil); check(err) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if err = pushResponse.Close(); check(err) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func createNetworkIfNotExists(cli *client.Client) (err error) {
|
||||||
|
|
||||||
|
//ctx, cancel := context.WithTimeout(context.Background(), time.Second * 120)
|
||||||
|
//defer cancel()
|
||||||
|
|
||||||
|
//cli.NetworkCreate(ctx, "indranet")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|||||||
2
go.mod
2
go.mod
@@ -6,6 +6,7 @@ require (
|
|||||||
github.com/cybriq/proc v0.20.9
|
github.com/cybriq/proc v0.20.9
|
||||||
github.com/cybriq/qu v0.1.2
|
github.com/cybriq/qu v0.1.2
|
||||||
github.com/decred/dcrd/dcrec/secp256k1/v4 v4.1.0
|
github.com/decred/dcrd/dcrec/secp256k1/v4 v4.1.0
|
||||||
|
github.com/docker/cli v0.0.0-20191017083524-a8ff7f821017
|
||||||
github.com/docker/docker v20.10.22+incompatible
|
github.com/docker/docker v20.10.22+incompatible
|
||||||
github.com/libp2p/go-libp2p v0.24.1
|
github.com/libp2p/go-libp2p v0.24.1
|
||||||
github.com/libp2p/go-libp2p-kad-dht v0.20.0
|
github.com/libp2p/go-libp2p-kad-dht v0.20.0
|
||||||
@@ -29,6 +30,7 @@ require (
|
|||||||
github.com/davecgh/go-spew v1.1.1 // indirect
|
github.com/davecgh/go-spew v1.1.1 // indirect
|
||||||
github.com/davidlazar/go-crypto v0.0.0-20200604182044-b73af7476f6c // indirect
|
github.com/davidlazar/go-crypto v0.0.0-20200604182044-b73af7476f6c // indirect
|
||||||
github.com/docker/distribution v2.8.1+incompatible // indirect
|
github.com/docker/distribution v2.8.1+incompatible // indirect
|
||||||
|
github.com/docker/docker-credential-helpers v0.6.3 // indirect
|
||||||
github.com/docker/go-connections v0.4.0 // indirect
|
github.com/docker/go-connections v0.4.0 // indirect
|
||||||
github.com/docker/go-units v0.5.0 // indirect
|
github.com/docker/go-units v0.5.0 // indirect
|
||||||
github.com/elastic/gosigar v0.14.2 // indirect
|
github.com/elastic/gosigar v0.14.2 // indirect
|
||||||
|
|||||||
3
go.sum
3
go.sum
@@ -282,6 +282,7 @@ github.com/dgrijalva/jwt-go v0.0.0-20170104182250-a601269ab70c/go.mod h1:E3ru+11
|
|||||||
github.com/dgrijalva/jwt-go v3.2.0+incompatible/go.mod h1:E3ru+11k8xSBh+hMPgOLZmtrrCbhqsmaPHjLKYnJCaQ=
|
github.com/dgrijalva/jwt-go v3.2.0+incompatible/go.mod h1:E3ru+11k8xSBh+hMPgOLZmtrrCbhqsmaPHjLKYnJCaQ=
|
||||||
github.com/dgryski/go-sip13 v0.0.0-20181026042036-e10d5fee7954/go.mod h1:vAd38F8PWV+bWy6jNmig1y/TA+kYO4g3RSRF0IAv0no=
|
github.com/dgryski/go-sip13 v0.0.0-20181026042036-e10d5fee7954/go.mod h1:vAd38F8PWV+bWy6jNmig1y/TA+kYO4g3RSRF0IAv0no=
|
||||||
github.com/dnaeon/go-vcr v1.0.1/go.mod h1:aBB1+wY4s93YsC3HHjMBMrwTj2R9FHDzUr9KyGc8n1E=
|
github.com/dnaeon/go-vcr v1.0.1/go.mod h1:aBB1+wY4s93YsC3HHjMBMrwTj2R9FHDzUr9KyGc8n1E=
|
||||||
|
github.com/docker/cli v0.0.0-20191017083524-a8ff7f821017 h1:2HQmlpI3yI9deH18Q6xiSOIjXD4sLI55Y/gfpa8/558=
|
||||||
github.com/docker/cli v0.0.0-20191017083524-a8ff7f821017/go.mod h1:JLrzqnKDaYBop7H2jaqPtU4hHvMKP+vjCwu2uszcLI8=
|
github.com/docker/cli v0.0.0-20191017083524-a8ff7f821017/go.mod h1:JLrzqnKDaYBop7H2jaqPtU4hHvMKP+vjCwu2uszcLI8=
|
||||||
github.com/docker/distribution v0.0.0-20190905152932-14b96e55d84c/go.mod h1:0+TTO4EOBfRPhZXAeF1Vu+W3hHZ8eLp8PgKVZlcvtFY=
|
github.com/docker/distribution v0.0.0-20190905152932-14b96e55d84c/go.mod h1:0+TTO4EOBfRPhZXAeF1Vu+W3hHZ8eLp8PgKVZlcvtFY=
|
||||||
github.com/docker/distribution v2.7.1-0.20190205005809-0d3efadf0154+incompatible/go.mod h1:J2gT2udsDAN96Uj4KfcMRqY0/ypR+oyYUYmja8H+y+w=
|
github.com/docker/distribution v2.7.1-0.20190205005809-0d3efadf0154+incompatible/go.mod h1:J2gT2udsDAN96Uj4KfcMRqY0/ypR+oyYUYmja8H+y+w=
|
||||||
@@ -291,6 +292,7 @@ github.com/docker/distribution v2.8.1+incompatible/go.mod h1:J2gT2udsDAN96Uj4Kfc
|
|||||||
github.com/docker/docker v1.4.2-0.20190924003213-a8608b5b67c7/go.mod h1:eEKB0N0r5NX/I1kEveEz05bcu8tLC/8azJZsviup8Sk=
|
github.com/docker/docker v1.4.2-0.20190924003213-a8608b5b67c7/go.mod h1:eEKB0N0r5NX/I1kEveEz05bcu8tLC/8azJZsviup8Sk=
|
||||||
github.com/docker/docker v20.10.22+incompatible h1:6jX4yB+NtcbldT90k7vBSaWJDB3i+zkVJT9BEK8kQkk=
|
github.com/docker/docker v20.10.22+incompatible h1:6jX4yB+NtcbldT90k7vBSaWJDB3i+zkVJT9BEK8kQkk=
|
||||||
github.com/docker/docker v20.10.22+incompatible/go.mod h1:eEKB0N0r5NX/I1kEveEz05bcu8tLC/8azJZsviup8Sk=
|
github.com/docker/docker v20.10.22+incompatible/go.mod h1:eEKB0N0r5NX/I1kEveEz05bcu8tLC/8azJZsviup8Sk=
|
||||||
|
github.com/docker/docker-credential-helpers v0.6.3 h1:zI2p9+1NQYdnG6sMU26EX4aVGlqbInSQxQXLvzJ4RPQ=
|
||||||
github.com/docker/docker-credential-helpers v0.6.3/go.mod h1:WRaJzqw3CTB9bk10avuGsjVBZsD05qeibJ1/TYlvc0Y=
|
github.com/docker/docker-credential-helpers v0.6.3/go.mod h1:WRaJzqw3CTB9bk10avuGsjVBZsD05qeibJ1/TYlvc0Y=
|
||||||
github.com/docker/go-connections v0.4.0 h1:El9xVISelRB7BuFusrZozjnkIM5YnzCViNKohAFqRJQ=
|
github.com/docker/go-connections v0.4.0 h1:El9xVISelRB7BuFusrZozjnkIM5YnzCViNKohAFqRJQ=
|
||||||
github.com/docker/go-connections v0.4.0/go.mod h1:Gbd7IOopHjR8Iph03tsViu4nIes5XhDvyHbTtUxmeec=
|
github.com/docker/go-connections v0.4.0/go.mod h1:Gbd7IOopHjR8Iph03tsViu4nIes5XhDvyHbTtUxmeec=
|
||||||
@@ -1505,6 +1507,7 @@ gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C
|
|||||||
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
||||||
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
|
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
|
||||||
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
||||||
|
gotest.tools v2.2.0+incompatible h1:VsBPFP1AI068pPrMxtb/S8Zkgf9xEmTLJjfM+P5UIEo=
|
||||||
gotest.tools v2.2.0+incompatible/go.mod h1:DsYFclhRJ6vuDpmuTbkuFWG+y2sxOXAzmJt81HFBacw=
|
gotest.tools v2.2.0+incompatible/go.mod h1:DsYFclhRJ6vuDpmuTbkuFWG+y2sxOXAzmJt81HFBacw=
|
||||||
gotest.tools/v3 v3.0.2/go.mod h1:3SzNCllyD9/Y+b5r9JIKQ474KzkZyqLqEfYqMsX94Bk=
|
gotest.tools/v3 v3.0.2/go.mod h1:3SzNCllyD9/Y+b5r9JIKQ474KzkZyqLqEfYqMsX94Bk=
|
||||||
gotest.tools/v3 v3.0.3/go.mod h1:Z7Lb0S5l+klDB31fvDQX8ss/FlKDxtlFlw3Oa8Ymbl8=
|
gotest.tools/v3 v3.0.3/go.mod h1:Z7Lb0S5l+klDB31fvDQX8ss/FlKDxtlFlw3Oa8Ymbl8=
|
||||||
|
|||||||
Reference in New Issue
Block a user