Skip to content

Commit

Permalink
DEV: piecemeal commands
Browse files Browse the repository at this point in the history
run build only
  • Loading branch information
featheredtoast committed May 24, 2024
1 parent b8a7795 commit 807cf04
Show file tree
Hide file tree
Showing 24 changed files with 7 additions and 1,973 deletions.
104 changes: 0 additions & 104 deletions .github/workflows/launcher_go.yml

This file was deleted.

2 changes: 0 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,3 @@ image/discourse_dev/postgres.template.yml
image/discourse_dev/redis.template.yml
.gc-state/*
.vagrant/
/launcher2
tmp/*
52 changes: 0 additions & 52 deletions launcher2.sh

This file was deleted.

73 changes: 0 additions & 73 deletions launcher_go/v2/cli_build.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ import (
"errors"
"github.com/discourse/discourse_docker/launcher_go/v2/config"
"github.com/discourse/discourse_docker/launcher_go/v2/docker"
"github.com/discourse/discourse_docker/launcher_go/v2/utils"
"github.com/google/uuid"
"os"
"strings"
)
Expand Down Expand Up @@ -61,84 +59,13 @@ func (r *DockerBuildCmd) Run(cli *Cli, ctx *context.Context) error {
return nil
}

type DockerConfigureCmd struct {
Tag string `default:"latest" help:"Resulting image tag."`
Config string `arg:"" name:"config" help:"config" predictor:"config"`
}

func (r *DockerConfigureCmd) Run(cli *Cli, ctx *context.Context) error {
config, err := config.LoadConfig(cli.ConfDir, r.Config, true, cli.TemplatesDir)
if err != nil {
return errors.New("YAML syntax error. Please check your containers/*.yml config files.")
}

containerId := "discourse-build-" + uuid.NewString()
pups := docker.DockerPupsRunner{
Config: config,
PupsArgs: "--tags=db,precompile",
SavedImageName: utils.BaseImageName + r.Config + ":" + r.Tag,
ExtraEnv: []string{"SKIP_EMBER_CLI_COMPILE=1"},
Ctx: ctx,
ContainerId: containerId,
}
return pups.Run()
}

type DockerMigrateCmd struct {
Config string `arg:"" name:"config" help:"config" predictor:"config"`
SkipPostDeploymentMigrations bool `env:"SKIP_POST_DEPLOYMENT_MIGRATIONS" help:"Skip post-deployment migrations. Runs safe migrations only. Defers breaking-change migrations. Make sure you run post-deployment migrations after a full deploy is complete if you use this option."`
}

func (r *DockerMigrateCmd) Run(cli *Cli, ctx *context.Context) error {
config, err := config.LoadConfig(cli.ConfDir, r.Config, true, cli.TemplatesDir)
if err != nil {
return errors.New("YAML syntax error. Please check your containers/*.yml config files.")
}
containerId := "discourse-build-" + uuid.NewString()
env := []string{"SKIP_EMBER_CLI_COMPILE=1"}
if r.SkipPostDeploymentMigrations {
env = append(env, "SKIP_POST_DEPLOYMENT_MIGRATIONS=1")
}
pups := docker.DockerPupsRunner{
Config: config,
PupsArgs: "--tags=db,migrate",
ExtraEnv: env,
Ctx: ctx,
ContainerId: containerId,
}
return pups.Run()
}

type DockerBootstrapCmd struct {
Config string `arg:"" name:"config" help:"config" predictor:"config"`
}

func (r *DockerBootstrapCmd) Run(cli *Cli, ctx *context.Context) error {
buildStep := DockerBuildCmd{Config: r.Config, BakeEnv: false}
migrateStep := DockerMigrateCmd{Config: r.Config}
configureStep := DockerConfigureCmd{Config: r.Config}
if err := buildStep.Run(cli, ctx); err != nil {
return err
}
if err := migrateStep.Run(cli, ctx); err != nil {
return err
}
if err := configureStep.Run(cli, ctx); err != nil {
return err
}
return nil
}

type CleanCmd struct {
Config string `arg:"" name:"config" help:"config to clean" predictor:"config"`
}

func (r *CleanCmd) Run(cli *Cli) error {
dir := cli.BuildDir + "/" + r.Config
os.Remove(dir + "/docker-compose.yaml")
os.Remove(dir + "/config.yaml")
os.Remove(dir + "/.envrc")
os.Remove(dir + "/" + "Dockerfile")
if err := os.Remove(dir); err != nil {
return err
}
Expand Down
88 changes: 0 additions & 88 deletions launcher_go/v2/cli_build_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,99 +57,11 @@ var _ = Describe("Build", func() {
Expect(buf.String()).ToNot(ContainSubstring("SKIP_EMBER_CLI_COMPILE=1"))
}

var checkMigrateCmd = func(cmd exec.Cmd) {
Expect(cmd.String()).To(ContainSubstring("docker run"))
Expect(cmd.String()).To(ContainSubstring("--env DISCOURSE_DEVELOPER_EMAILS"))
Expect(cmd.String()).To(ContainSubstring("--env SKIP_EMBER_CLI_COMPILE=1"))
// no commit after, we expect an --rm as the container isn't needed after it is stopped
Expect(cmd.String()).To(ContainSubstring("--rm"))
Expect(cmd.Env).To(ContainElement("DISCOURSE_DB_PASSWORD=SOME_SECRET"))
buf := new(strings.Builder)
io.Copy(buf, cmd.Stdin)
// docker run's stdin is a pups config
Expect(buf.String()).To(ContainSubstring("path: /etc/service/nginx/run"))
}

var checkConfigureCmd = func(cmd exec.Cmd) {
Expect(cmd.String()).To(ContainSubstring("docker run"))
Expect(cmd.String()).To(ContainSubstring("--env DISCOURSE_DEVELOPER_EMAILS"))
Expect(cmd.String()).To(ContainSubstring("--env SKIP_EMBER_CLI_COMPILE=1"))
// we commit, we need the container to stick around after it is stopped.
Expect(cmd.String()).ToNot(ContainSubstring("--rm"))

// we don't expose ports on configure command
Expect(cmd.String()).ToNot(ContainSubstring("-p 80"))
Expect(cmd.Env).To(ContainElement("DISCOURSE_DB_PASSWORD=SOME_SECRET"))
buf := new(strings.Builder)
io.Copy(buf, cmd.Stdin)
// docker run's stdin is a pups config
Expect(buf.String()).To(ContainSubstring("path: /etc/service/nginx/run"))
}

// commit on configure
var checkConfigureCommit = func(cmd exec.Cmd) {
Expect(cmd.String()).To(ContainSubstring("docker commit"))
Expect(cmd.String()).To(ContainSubstring("--change CMD [\"/sbin/boot\"]"))
Expect(cmd.String()).To(ContainSubstring("discourse-build"))
Expect(cmd.String()).To(ContainSubstring("local_discourse/test"))
Expect(cmd.Env).ToNot(ContainElement("DISCOURSE_DB_PASSWORD=SOME_SECRET"))
}

// configure also cleans up
var checkConfigureClean = func(cmd exec.Cmd) {
Expect(cmd.String()).To(ContainSubstring("docker rm -f discourse-build-"))
}

It("Should run docker build with correct arguments", func() {
runner := ddocker.DockerBuildCmd{Config: "test"}
runner.Run(cli, &ctx)
Expect(len(RanCmds)).To(Equal(1))
checkBuildCmd(RanCmds[0])
})

It("Should run docker migrate with correct arguments", func() {
runner := ddocker.DockerMigrateCmd{Config: "test"}
runner.Run(cli, &ctx)
Expect(len(RanCmds)).To(Equal(1))
checkMigrateCmd(RanCmds[0])
})

It("Should allow skip post deployment migrations", func() {
runner := ddocker.DockerMigrateCmd{Config: "test", SkipPostDeploymentMigrations: true}
runner.Run(cli, &ctx)
Expect(len(RanCmds)).To(Equal(1))
cmd := RanCmds[0]
Expect(cmd.String()).To(ContainSubstring("docker run"))
Expect(cmd.String()).To(ContainSubstring("--env DISCOURSE_DEVELOPER_EMAILS"))
Expect(cmd.String()).To(ContainSubstring("--env SKIP_POST_DEPLOYMENT_MIGRATIONS=1"))
Expect(cmd.String()).To(ContainSubstring("--env SKIP_EMBER_CLI_COMPILE=1"))
// no commit after, we expect an --rm as the container isn't needed after it is stopped
Expect(cmd.String()).To(ContainSubstring("--rm"))
Expect(cmd.Env).To(ContainElement("DISCOURSE_DB_PASSWORD=SOME_SECRET"))
buf := new(strings.Builder)
io.Copy(buf, cmd.Stdin)
// docker run's stdin is a pups config
Expect(buf.String()).To(ContainSubstring("path: /etc/service/nginx/run"))
})

It("Should run docker run followed by docker commit and rm container when configuring", func() {
runner := ddocker.DockerConfigureCmd{Config: "test"}
runner.Run(cli, &ctx)
Expect(len(RanCmds)).To(Equal(3))
checkConfigureCmd(RanCmds[0])
checkConfigureCommit(RanCmds[1])
checkConfigureClean(RanCmds[2])
})

It("Should run all docker commands for full bootstrap", func() {
runner := ddocker.DockerBootstrapCmd{Config: "test"}
runner.Run(cli, &ctx)
Expect(len(RanCmds)).To(Equal(5))
checkBuildCmd(RanCmds[0])
checkMigrateCmd(RanCmds[1])
checkConfigureCmd(RanCmds[2])
checkConfigureCommit(RanCmds[3])
checkConfigureClean(RanCmds[4])
})
})
})
Loading

0 comments on commit 807cf04

Please sign in to comment.