Compare commits
2 Commits
Author | SHA1 | Date | |
---|---|---|---|
0283ddf0d5 | |||
aee0deba4a |
12
.ledo.yml
12
.ledo.yml
@ -8,15 +8,3 @@ docker:
|
|||||||
modes:
|
modes:
|
||||||
dev: docker/docker-compose.yml docker/docker-compose.dev.yml
|
dev: docker/docker-compose.yml docker/docker-compose.dev.yml
|
||||||
launch: docker/docker-compose.yml
|
launch: docker/docker-compose.yml
|
||||||
providers:
|
|
||||||
# you can mix and match many files
|
|
||||||
dotenv:
|
|
||||||
env_sync:
|
|
||||||
path: .env-dist
|
|
||||||
vault:
|
|
||||||
env_sync:
|
|
||||||
path: environment/data/billing/web/env
|
|
||||||
env:
|
|
||||||
SMTP_PASS:
|
|
||||||
path: environment/data/billing/global
|
|
||||||
field: SMTP
|
|
1
Dockerfile
Normal file
1
Dockerfile
Normal file
@ -0,0 +1 @@
|
|||||||
|
FROM alpine
|
@ -1,9 +1,8 @@
|
|||||||
package cmd
|
package cmd
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"ledo/app/cmd/docker"
|
|
||||||
|
|
||||||
"github.com/urfave/cli/v2"
|
"github.com/urfave/cli/v2"
|
||||||
|
"ledo/app/cmd/docker"
|
||||||
)
|
)
|
||||||
|
|
||||||
var CmdDocker = cli.Command{
|
var CmdDocker = cli.Command{
|
||||||
@ -12,10 +11,8 @@ var CmdDocker = cli.Command{
|
|||||||
Category: catHelpers,
|
Category: catHelpers,
|
||||||
Usage: "docker helper",
|
Usage: "docker helper",
|
||||||
Description: `Manage docker-compose in project`,
|
Description: `Manage docker-compose in project`,
|
||||||
Action: runDockerDefault,
|
|
||||||
Subcommands: []*cli.Command{
|
Subcommands: []*cli.Command{
|
||||||
&docker.CmdDockerPs,
|
&docker.CmdDockerPs,
|
||||||
&docker.CmdDockerFqn,
|
|
||||||
&docker.CmdDockerUp,
|
&docker.CmdDockerUp,
|
||||||
&docker.CmdComposeBuild,
|
&docker.CmdComposeBuild,
|
||||||
&docker.CmdComposeDebug,
|
&docker.CmdComposeDebug,
|
||||||
@ -31,7 +28,3 @@ var CmdDocker = cli.Command{
|
|||||||
&docker.CmdDockerLogin,
|
&docker.CmdDockerLogin,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
func runDockerDefault(ctx *cli.Context) error {
|
|
||||||
return docker.RunComposePs(ctx)
|
|
||||||
}
|
|
||||||
|
23
app/cmd/image.go
Normal file
23
app/cmd/image.go
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
package cmd
|
||||||
|
|
||||||
|
import (
|
||||||
|
"ledo/app/cmd/image"
|
||||||
|
|
||||||
|
"github.com/urfave/cli/v2"
|
||||||
|
)
|
||||||
|
|
||||||
|
var CmdImage = cli.Command{
|
||||||
|
Name: "image",
|
||||||
|
Aliases: []string{"i"},
|
||||||
|
Category: catHelpers,
|
||||||
|
Usage: "docker container helper",
|
||||||
|
Description: `docker container helper`,
|
||||||
|
Subcommands: []*cli.Command{
|
||||||
|
&image.CmdDockerFqn,
|
||||||
|
&image.CmdDockerPush,
|
||||||
|
&image.CmdDockerRetag,
|
||||||
|
&image.CmdDockerBuild,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
|
45
app/cmd/image/build.go
Normal file
45
app/cmd/image/build.go
Normal file
@ -0,0 +1,45 @@
|
|||||||
|
package image
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/urfave/cli/v2"
|
||||||
|
"ledo/app/modules/context"
|
||||||
|
"ledo/app/modules/docker"
|
||||||
|
)
|
||||||
|
|
||||||
|
var CmdDockerBuild = cli.Command{
|
||||||
|
Name: "build",
|
||||||
|
Aliases: []string{"b"},
|
||||||
|
Usage: "build docker image",
|
||||||
|
Description: `Build docker image`,
|
||||||
|
ArgsUsage: "version",
|
||||||
|
Action: RunDockerBuild,
|
||||||
|
Flags: []cli.Flag{
|
||||||
|
&cli.StringFlag{
|
||||||
|
Name: "stage",
|
||||||
|
Aliases: []string{"s"},
|
||||||
|
Value: "",
|
||||||
|
Usage: "select stage to build (multi-stage dockerfile)",
|
||||||
|
Required: false,
|
||||||
|
},
|
||||||
|
&cli.StringFlag{
|
||||||
|
Name: "dockerfile",
|
||||||
|
Aliases: []string{"f"},
|
||||||
|
Value: "./Dockerfile",
|
||||||
|
Usage: "select dockerfile",
|
||||||
|
Required: false,
|
||||||
|
},
|
||||||
|
&cli.StringFlag{
|
||||||
|
Name: "opts",
|
||||||
|
Aliases: []string{"o"},
|
||||||
|
Value: "--compress",
|
||||||
|
Usage: "Additional build options",
|
||||||
|
Required: false,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
func RunDockerBuild(cmd *cli.Context) error {
|
||||||
|
ctx := context.InitCommand(cmd)
|
||||||
|
docker.ExecDockerBuild(ctx, cmd.Args(), *cmd)
|
||||||
|
return nil
|
||||||
|
}
|
@ -1,9 +1,9 @@
|
|||||||
package docker
|
package image
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/urfave/cli/v2"
|
"github.com/urfave/cli/v2"
|
||||||
"ledo/app/modules/compose"
|
"ledo/app/modules/docker"
|
||||||
"ledo/app/modules/context"
|
"ledo/app/modules/context"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -17,6 +17,6 @@ var CmdDockerFqn = cli.Command{
|
|||||||
|
|
||||||
func RunDockerFqn(cmd *cli.Context) error {
|
func RunDockerFqn(cmd *cli.Context) error {
|
||||||
ctx := context.InitCommand(cmd)
|
ctx := context.InitCommand(cmd)
|
||||||
fmt.Printf("%v", compose.ShowDockerImageFQN(ctx))
|
fmt.Printf("%v", docker.ShowDockerImageFQN(ctx))
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
22
app/cmd/image/push.go
Normal file
22
app/cmd/image/push.go
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
package image
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/urfave/cli/v2"
|
||||||
|
"ledo/app/modules/context"
|
||||||
|
"ledo/app/modules/docker"
|
||||||
|
)
|
||||||
|
|
||||||
|
var CmdDockerPush = cli.Command{
|
||||||
|
Name: "push",
|
||||||
|
Aliases: []string{"p"},
|
||||||
|
Usage: "push docker to registry",
|
||||||
|
Description: `Push docker image to docker registry`,
|
||||||
|
ArgsUsage: "version",
|
||||||
|
Action: RunDockerPush,
|
||||||
|
}
|
||||||
|
|
||||||
|
func RunDockerPush(cmd *cli.Context) error {
|
||||||
|
ctx := context.InitCommand(cmd)
|
||||||
|
docker.ExecDockerPush(ctx, cmd.Args())
|
||||||
|
return nil
|
||||||
|
}
|
22
app/cmd/image/retag.go
Normal file
22
app/cmd/image/retag.go
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
package image
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/urfave/cli/v2"
|
||||||
|
"ledo/app/modules/context"
|
||||||
|
"ledo/app/modules/docker"
|
||||||
|
)
|
||||||
|
|
||||||
|
var CmdDockerRetag = cli.Command{
|
||||||
|
Name: "retag",
|
||||||
|
Aliases: []string{"r"},
|
||||||
|
Usage: "retag docker image",
|
||||||
|
Description: `Change docker image tag`,
|
||||||
|
ArgsUsage: "fromTag toTag",
|
||||||
|
Action: RunDockerRetag,
|
||||||
|
}
|
||||||
|
|
||||||
|
func RunDockerRetag(cmd *cli.Context) error {
|
||||||
|
ctx := context.InitCommand(cmd)
|
||||||
|
docker.ExecDockerRetag(ctx, cmd.Args())
|
||||||
|
return nil
|
||||||
|
}
|
@ -15,7 +15,6 @@ import (
|
|||||||
|
|
||||||
var CmdInit = cli.Command{
|
var CmdInit = cli.Command{
|
||||||
Name: "init",
|
Name: "init",
|
||||||
Aliases: []string{"i"},
|
|
||||||
Category: catSetup,
|
Category: catSetup,
|
||||||
Usage: "Init ledo in project",
|
Usage: "Init ledo in project",
|
||||||
Description: `Initialize LeadDocker in current project`,
|
Description: `Initialize LeadDocker in current project`,
|
||||||
|
@ -3,7 +3,6 @@ package compose
|
|||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
|
||||||
"github.com/Masterminds/semver"
|
"github.com/Masterminds/semver"
|
||||||
"github.com/urfave/cli/v2"
|
"github.com/urfave/cli/v2"
|
||||||
"gopkg.in/yaml.v3"
|
"gopkg.in/yaml.v3"
|
||||||
@ -15,7 +14,7 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
const DockerComposeVersion = ">= 1.28.6"
|
const DockerComposeVersion = ">= 1.28.0"
|
||||||
|
|
||||||
func CheckDockerComposeVersion() {
|
func CheckDockerComposeVersion() {
|
||||||
// cmd := exec.Command("docker-compose", "--version")
|
// cmd := exec.Command("docker-compose", "--version")
|
||||||
@ -36,7 +35,7 @@ func CheckDockerComposeVersion() {
|
|||||||
composeSemVer, _ := semver.NewVersion(composeVersion)
|
composeSemVer, _ := semver.NewVersion(composeVersion)
|
||||||
|
|
||||||
if !verConstraint.Check(composeSemVer) {
|
if !verConstraint.Check(composeSemVer) {
|
||||||
log.Fatal("Wrong docker-compose version, please update to 1.28.6 or higher.")
|
log.Fatal("Wrong docker-compose version, please update to "+DockerComposeVersion+" or higher.")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -78,11 +77,6 @@ func MergeComposerFiles(filenames ...string) (string, error) {
|
|||||||
return string(bs), nil
|
return string(bs), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func ShowDockerImageFQN(ctx *context.LedoContext) string {
|
|
||||||
fqn := fmt.Sprintf("%s/%s/%s/master", ctx.Config.Docker.Registry, ctx.Config.Docker.Namespace, ctx.Config.Docker.Name)
|
|
||||||
return strings.ToLower(fqn)
|
|
||||||
}
|
|
||||||
|
|
||||||
func ExecComposerUp(ctx *context.LedoContext) {
|
func ExecComposerUp(ctx *context.LedoContext) {
|
||||||
args := ctx.ComposeArgs
|
args := ctx.ComposeArgs
|
||||||
args = append(args, "up", "-d")
|
args = append(args, "up", "-d")
|
||||||
|
@ -86,6 +86,6 @@ func (lx *LedoContext) ExecCmdSilent(cmd string, cmdArgs []string) error {
|
|||||||
command := exec.Command(cmd, cmdArgs...)
|
command := exec.Command(cmd, cmdArgs...)
|
||||||
command.Stdin = os.Stdin
|
command.Stdin = os.Stdin
|
||||||
command.Stdout = os.Stdout
|
command.Stdout = os.Stdout
|
||||||
command.Stderr = os.Stderr
|
command.Stderr = nil
|
||||||
return command.Run()
|
return command.Run()
|
||||||
}
|
}
|
||||||
|
95
app/modules/docker/docker.go
Normal file
95
app/modules/docker/docker.go
Normal file
@ -0,0 +1,95 @@
|
|||||||
|
package docker
|
||||||
|
|
||||||
|
import (
|
||||||
|
b64 "encoding/base64"
|
||||||
|
"fmt"
|
||||||
|
"github.com/urfave/cli/v2"
|
||||||
|
"ledo/app/modules/aws_ledo"
|
||||||
|
"ledo/app/modules/context"
|
||||||
|
"net/url"
|
||||||
|
"os"
|
||||||
|
"strings"
|
||||||
|
)
|
||||||
|
|
||||||
|
func trimLeftChars(s string, n int) string {
|
||||||
|
m := 0
|
||||||
|
for i := range s {
|
||||||
|
if m >= n {
|
||||||
|
return s[i:]
|
||||||
|
}
|
||||||
|
m++
|
||||||
|
}
|
||||||
|
return s[:0]
|
||||||
|
}
|
||||||
|
|
||||||
|
func DockerEcrLogin(ctx *context.LedoContext) error {
|
||||||
|
ecr, err := aws_ledo.EcrLogin()
|
||||||
|
if err != nil {
|
||||||
|
fmt.Println("Ecr login error: %s", err)
|
||||||
|
os.Exit(1)
|
||||||
|
}
|
||||||
|
password := *ecr.AuthorizationData[0].AuthorizationToken
|
||||||
|
ecrUrl := *ecr.AuthorizationData[0].ProxyEndpoint
|
||||||
|
sDec, _ := b64.StdEncoding.DecodeString(password)
|
||||||
|
registryAddr, err := url.Parse(ecrUrl)
|
||||||
|
if err != nil {
|
||||||
|
fmt.Printf("Ecr endpoint addr parse error: %s", err)
|
||||||
|
os.Exit(1)
|
||||||
|
}
|
||||||
|
ctx.ExecCmdSilent("docker", []string{"login", "-u", "AWS", "-p", string(trimLeftChars(string(sDec), 4)), registryAddr.Host})
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func ShowDockerImageFQN(ctx *context.LedoContext) string {
|
||||||
|
fqn := fmt.Sprintf("%s/%s/%s", ctx.Config.Docker.Registry, ctx.Config.Docker.Namespace, ctx.Config.Docker.Name)
|
||||||
|
return strings.ToLower(fqn)
|
||||||
|
}
|
||||||
|
|
||||||
|
func ExecDockerPush(ctx *context.LedoContext, command cli.Args) {
|
||||||
|
var version string
|
||||||
|
var args []string
|
||||||
|
if command.First() == "" {
|
||||||
|
version = "latest"
|
||||||
|
} else {
|
||||||
|
version = command.First()
|
||||||
|
}
|
||||||
|
image := ShowDockerImageFQN(ctx)
|
||||||
|
args = append(args, "push")
|
||||||
|
args = append(args, "-f", image + ":" + version)
|
||||||
|
ctx.ExecCmd("docker", args[0:])
|
||||||
|
}
|
||||||
|
|
||||||
|
func ExecDockerRetag(ctx *context.LedoContext, command cli.Args) {
|
||||||
|
var args []string
|
||||||
|
|
||||||
|
from := command.Get(0)
|
||||||
|
to := command.Get(1)
|
||||||
|
image := ShowDockerImageFQN(ctx)
|
||||||
|
args = append(args, "tag")
|
||||||
|
args = append(args, image + ":" + from)
|
||||||
|
args = append(args, image + ":" + to)
|
||||||
|
ctx.ExecCmd("docker", args[0:])
|
||||||
|
}
|
||||||
|
|
||||||
|
func ExecDockerBuild(ctx *context.LedoContext, command cli.Args, cmdCtx cli.Context) {
|
||||||
|
var version string
|
||||||
|
var args []string
|
||||||
|
if command.First() == "" {
|
||||||
|
version = "latest"
|
||||||
|
} else {
|
||||||
|
version = command.First()
|
||||||
|
}
|
||||||
|
|
||||||
|
opts := strings.Split(strings.Trim(cmdCtx.String("opts"), " "), " ")
|
||||||
|
image := ShowDockerImageFQN(ctx)
|
||||||
|
args = append(args, "build")
|
||||||
|
args = append(args, "-t", image+":"+version)
|
||||||
|
args = append(args, "-f", cmdCtx.String("dockerfile"))
|
||||||
|
args = append(args, opts...)
|
||||||
|
if cmdCtx.String("stage") != "" {
|
||||||
|
args = append(args, "--target", cmdCtx.String("stage"))
|
||||||
|
}
|
||||||
|
args = append(args, ".")
|
||||||
|
ctx.ExecCmd("docker", args[0:])
|
||||||
|
}
|
@ -1,40 +0,0 @@
|
|||||||
package docker
|
|
||||||
|
|
||||||
import (
|
|
||||||
b64 "encoding/base64"
|
|
||||||
"fmt"
|
|
||||||
"ledo/app/modules/aws_ledo"
|
|
||||||
"ledo/app/modules/context"
|
|
||||||
"net/url"
|
|
||||||
"os"
|
|
||||||
)
|
|
||||||
|
|
||||||
func trimLeftChars(s string, n int) string {
|
|
||||||
m := 0
|
|
||||||
for i := range s {
|
|
||||||
if m >= n {
|
|
||||||
return s[i:]
|
|
||||||
}
|
|
||||||
m++
|
|
||||||
}
|
|
||||||
return s[:0]
|
|
||||||
}
|
|
||||||
|
|
||||||
func DockerEcrLogin(ctx *context.LedoContext) error {
|
|
||||||
ecr, err := aws_ledo.EcrLogin()
|
|
||||||
if err != nil {
|
|
||||||
fmt.Println("Ecr login error: %s", err)
|
|
||||||
os.Exit(1)
|
|
||||||
}
|
|
||||||
password := *ecr.AuthorizationData[0].AuthorizationToken
|
|
||||||
ecrUrl := *ecr.AuthorizationData[0].ProxyEndpoint
|
|
||||||
sDec, _ := b64.StdEncoding.DecodeString(password)
|
|
||||||
registryAddr, err := url.Parse(ecrUrl)
|
|
||||||
if err != nil {
|
|
||||||
fmt.Printf("Ecr endpoint addr parse error: %s", err)
|
|
||||||
os.Exit(1)
|
|
||||||
}
|
|
||||||
ctx.ExecCmdSilent("docker", []string{"login", "-u", "AWS", "-p", string(trimLeftChars(string(sDec), 4)), registryAddr.Host})
|
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
|
Loading…
Reference in New Issue
Block a user